AN4759

STM32L4 API and smooth digital calibration application example

4STM32L4 API and smooth digital calibration application example

4.1STM32CubeL4 firmware libraries for smooth calibration

The timer peripheral comes with:

a firmware driver API abstracting the timer features for the end-user

Refer to stm32l4xx_hal_tim.c and stm32l4xx_hal_tim_ex.c files in \STM32Cube_FW_L4_Vx.y.z\Drivers\STM32L4xx_HAL_Driver\

a set of example projects in \STM32Cube_FW_L4_Vx.y.z\Projects\STM32L476RG-Nucleo\Examples\TIM

The RTC comes with:

a firmware driver API abstracting the RTC features for the end-user Refer to stm32l4xx_hal_rtc.c and stm32l4xx_hal_rtc_ex.c files in \STM32Cube_FW_L4_Vx.y.z\Drivers\STM32L4xx_HAL_Driver\

a set of example projects in \STM32Cube_FW_L4_Vx.y.z\Projects\STM32L476RG-Nucleo\Examples\RTC

4.2X-CUBE-RTC for smooth calibration

X-CUBE-RTC shows an implementation of the smooth digital calibration feature of the RTC (using also the GPTIMER HAL API).

In this example, the RTC_CLK is smoothly calibrated based on an external 1 Hz reference (STM32CubeExpansion_AN4759_RTC_STM32L_Vx.y.z\Projects\STM32L476RG_Nucleo\RTC_SmoothCalib).

The firmware implements:

a GPTIMER (general-purpose timer) in Master mode using channel 1 in output compare mode (and using an external trigger clock)

a GPTIMER in Master mode using channel 1 in input capture mode and channel 2 in output compare mode This timer is also configured to use the LSE clock thanks to the TIM option register.

the RTC with the CALR register programming

GPIOs to connect the input 1 Hz reference clock and the “corrected” RTC_OUT_CALIB clock

AN4759 - Rev 8

page 39/60