Question
How to run a Bluetooth LE application on the STM32WB without an LSE crystal
Summary
This article summarizes a method to remove the external 32.768 LSE crystal and replace its functionality with a clock reference sourcing from the 32MHz HSE. It also describes the necessary configuration modifications to implement a Bluetooth LE firmware project to run without the external LSE crystal and run from the HSE clock. Overview
The Bluetooth Low Energy specification requires that a low frequency crystal, not exceed a frequency deviation of 500 ppm. On the STM32WB, this low frequency functionality is provided by the external LSE crystal (typically). The LSE serves as the clock reference for the RF wake up subsystem of the BLE radio. When the main system clocks are shutoff during low power mode, it will remain running during this event if low power modes, such as STOP/STOP2, have been enabled. This is unlike the operation of the rest of the system clocks generated by the 32MHz system clock. As the radio is required to wake up precisely on time to service the connection intervals, thus it always requires an active clock source. This functionality is typically provided by the LSE clock. Furthermore, the LSE is also used to clock the RTC for application timing, as it is an accurate and stable clock source compared to the internal LSI oscillators.It is possible to remove the external LSE crystal and use the 32MHz HSE in its place, which is already used as the main system clock source. The tradeoff with this configuration is that of no longer being able to go into low power modes lower than SLEEP mode. For example, STOP/STOP2/STANDBY modes would no longer be available to the user, since the HSE is inevitably shutoff when the system enters these deeper low power modes. In a system implementation where there is no low power requirement, such as devices that are mains powered (not battery powered), this may be a viable alternative. If your application is ok with not supporting low power modes lower than SLEEP mode, then the following steps can be followed to configure the STM32WB program to run only from the HSE only and not use the LSE.Note that all examples in the STM32CubeWB firmware package are preconfigured to use the LSE for the RF wake up and RTC, so any can be used to demonstrate the changes that need to be made for this. In this case, the “BLE_p2pServer” example, found under “STM32Cube_FW_WB_V1.12.0\Projects\P-NUCLEO-WB55.Nucleo\Applications\BLE\BLE_p2pServer”, will be used to demonstrate how to do this. The changes will be applied from its respective CubeMX project.
-
Open its BLE_p2pServer.ioc with CubeMX v6.3.0+.
-
From the “RCC” configuration window, change the LSE mode to “Disable”
-
From the “STM32_WPAN” middleware configuration window, go to the “Configuration” tab
-
Change the CFG_LPM_SUPPORTED parameter to “Disable”. This disables the low power manager support to keep the system always in Run mode.
-
-
Change the CFG_BLE_LSE_SOURCE parameter to “Enable” to select the extern HSE as the source of the RF wake-up.
-
-
Change the CFG_RTC_ASYNCH_PRESCALER parameter to 127 and CFG_RTC_SYNCH_PRESCALER to 7812 to obtain an internal clock frequency of 1 Hz (ck_spre). This will also keep the same real time base for the Virtual Timer utility (from hw_timerserver.c).
-
Change the clock tree configuration
-
Select “HSE_RTC” for the RTC Source Mux
-
Select “HSE” for the RF system wakeup
-
Regenerate the code project for your favorite IDE.
-
Once code project is opened in the IDE, find app_conf.h to make the following manual edit to the #define CFG_TS_TICK_VAL. Note that this parameter is not available within CubeMX as it is considered part of the example’s application user code.
-
Find stm32wbxx_hal_msp.c and add the following lines of code inside HAL_RTC_MspInit().
-
Build project and run on target (NUCLEO-WB55RG). At this point, the STM32WB is no longer utilizing the LSE.
Last update:
2021-11-01
12:05 PM