In this use case, the RTC is set up in count mode.
The quick start configures the RTC in 32-bit mode and . The rest of the configuration is according to the default. A callback is implemented for when the RTC capture tamper stamp.
Setup
Prerequisites
The Generic Clock Generator for the RTC should be configured and enabled; if you are using the System Clock driver, this may be done via conf_clocks.h
.
Code
Add to the main application source file, outside of any functions:
DmacDescriptor example_descriptor SECTION_DMAC_DESCRIPTOR;
The following must be added to the user application: Function for setting up the module:
void configure_rtc(void)
{
config_rtc_tamper.dma_tamper_enable = true;
}
Callback function:
void rtc_tamper_callback(void)
{
LED_On(LED_0_PIN);
}
Function for setting up the callback functionality of the driver:
Add to user application initialization (typically the start of main()
):
configure_rtc();
while (true) {
}
Workflow
- Initialize system.
- Configure and enable module.
- Create a RTC configuration structure to hold the desired RTC driver settings and fill it with the configuration values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Initialize the RTC module.
- Create a RTC tamper configuration structure and fill it with the configuration values.
config_rtc_tamper.dma_tamper_enable = true;
- Enable the RTC module, so that it may begin counting.
- Configure callback functionality.
- Register overflow callback.
- Enable overflow callback.
- Configure the DMA.
- Create a DMA resource configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
- Initialize the DMA resource configuration struct with the module's. default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Set extra configurations for the DMA resource. ADC_DMAC_ID_RESRDY trigger causes a beat transfer in this example.
config.peripheral_trigger = RTC_DMAC_ID_TIMESTAMP;
- Allocate a DMA resource with the configurations.
- Create a DMA transfer descriptor configuration structure, which can be filled out to adjust the configuration of a single DMA transfer.
- Initialize the DMA transfer descriptor configuration struct with the module's default values.
- Note
- This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
- Set the specific parameters for a DMA transfer with transfer size, source address, and destination address.
descriptor_config.dst_increment_enable = false;
descriptor_config.src_increment_enable = false;
descriptor_config.block_transfer_count = 1;
descriptor_config.source_address = (uint32_t)(&
rtc_instance.hw->MODE0.TIMESTAMP.reg);
descriptor_config.destination_address = (uint32_t)(buffer_rtc_tamper);
descriptor_config.next_descriptor_address = (uint32_t)descriptor;
- Create the DMA transfer descriptor.
- Add DMA descriptor to DMA resource.
Implementation
Code
Add to user application main:
- Infinite while loop while waiting for callbacks.
Callback
When the RTC tamper captured, the callback function will be called.
- LED0 on for RTC tamper capture: