cancel
Showing results for 
Search instead for 
Did you mean: 

Configuring STM32WB for Bluetooth LE without an LSE crystal

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.
 
  1. Open its BLE_p2pServer.ioc with CubeMX v6.3.0+.

  2. From the “RCC” configuration window, change the LSE mode to “Disable”

654.png
 

 

  1. From the “STM32_WPAN” middleware configuration window, go to the “Configuration” tab

    1. Change the CFG_LPM_SUPPORTED parameter to “Disable”. This disables the low power manager support to keep the system always in Run mode. 

656.png
 
    1. Change the CFG_BLE_LSE_SOURCE parameter to “Enable” to select the extern HSE as the source of the RF wake-up.

659.png
 
    1. 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).

661.png
 
  1. Change the clock tree configuration

    1. Select “HSE_RTC” for the RTC Source Mux

    2. Select “HSE” for the RF system wakeup

662.png
 
663.png               664.png
 
  1. Regenerate the code project for your favorite IDE.

 
  1. 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.


665.png
 
  1. Find stm32wbxx_hal_msp.c and add the following lines of code inside HAL_RTC_MspInit().

666.png
 
  1. Build project and run on target (NUCLEO-WB55RG).  At this point, the STM32WB is no longer utilizing the LSE. 

Comments
gongw
Associate II

Hi JT,

For CubeMX6.4.0 and CubeWBv1.13.1, there are few differences:

step 6:

/** tick timer values */

//#define CFG_TS_TICK_VAL      DIVR( (CFG_RTCCLK_DIV * 1000000), LSE_VALUE )

//#define CFG_TS_TICK_VAL_PS    DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)LSE_VALUE )

#define CFG_TS_TICK_VAL      DIVR( (CFG_RTCCLK_DIV * 1000000), HSE_VALUE/32 )

#define CFG_TS_TICK_VAL_PS    DIVR( ((uint64_t)CFG_RTCCLK_DIV * 1e12), (uint64_t)(HSE_VALUE/32) )

step 7: CubeWBv1.13.1 has already configure the RTCClockSelection as RCC_RTCCLKSOURCE_LSE

the regenerated coded by CubeMXv6.4.0 has already configure the RTCClockSelection as RCC_RTCCLKSOURCE_HSE_DIV32

 /** Initializes the peripherals clock

 */

  PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_RTC;

  PeriphClkInitStruct.RTCClockSelection = RCC_RTCCLKSOURCE_HSE_DIV32;

  if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)

  {

   Error_Handler();

  }

Br,

gongw

IRakh.1
Associate III

Hi, thank you so much for your answer.

Can you a little clarity about - CFG_BLE_LSE_SOURCE  and CFG_RTC_ASYNCH_PRESCALER 

I don't have this setting in my CubeMX, please see the attached image. Do you know how I can fix it
_legacyfs_online_stmicro_images_0693W00000UnrDBQAZ.png?

gongw
Associate II

Hi,

First please use the latest CubeMX v6.6.1 and CubeWBv1.14.1.

Please go down to the middle position of Application parameters by scrolling the lightblue scrollbar
_legacyfs_online_stmicro_images_0693W00000UnsqYQAR.png​Br,

willee​

IRakh.1
Associate III

Hi Laura, thank you for your response, I did your recommendation, but still in my CubeMX don't have settings for CFG_BLE_LSE_SOURCE

if I correctly understand I can use the command in the code to fix it, how do you think?

#define CFG_BLE_LSE_SOURCE 1

and CubeWBv1.14.1 is it only examples of code, not more, yes?

gongw
Associate II

Hi,

For settings for CFG_BLE_LSE_SOURCE, you need to modify CFG_BLE_LSE_SOURCE as below after generated code.


_legacyfs_online_stmicro_images_0693W00000Uo8T6QAJ.png 

Br,

willee

Version history
Last update:
‎2021-11-01 12:05 PM