STM32CubeWBA BLE Timing Profiling

Revision as of 15:50, 10 July 2024 by Registered User (→‎How to set the DRIFT_TIME)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

1. Introduction

The goal of this wiki page is to describe how the STM32WBA works to meet RF timing requirements and how to profile the system and link layer timing. These timing needs to be profile to avoid any RF missed event and to optimize the device power consumption.

To schedule a RF event, the BLE Link Layer (LL) starts a timer based on the event anchor point and on the LL process duration. In run mode, when this timer expired, the radio IRQ (HW signal) fired to execute three LL processes to manage the radio activity event. These LL processes are executed in ISR.

The margin M1 between the end of Hash IRQ handler and the radio activity allows the application / system to preempt the LL processes. Based on STM32CubeWBA v1.4.0 release, the application / system can preempt the LL processes up to 200 us. A preemption longer than 200 us might lead to an event missed (no radio activity on this event).

Constraints:

  • The sum of interrupts with priority lower than RADIO_INTR_PRIO_HIGH = 0 must not last more than 40us.
  • The sum of interrupts with priority lower than RADIO_INTR_PRIO_LOW = 5 must not last more than 200us.
Radio activity event management in run mode
Connectivity:Connectivity : Radio activity management run mode.png

2. Stop 1 low power mode

When stop1 low power mode is used, an additional system process need to be considered in addition of LL processes, it’s called the stop1 exit in the diagram above. The stop1 exit allows to restore the clock configuration when the system wakes up from stop1 low power mode and it’s performed under critical section. The critical section duration depends on the application, if using the system clock manager (SCM) or not, the code optimization… and delayed the process of the radio IRQ handler.

In BLE applications available in STM32CubeWBA package, the system clock manager (SCM) is used to restore the clock configuration. When exiting from stop1, the system is running on HSI at 16 MHz, thanks to the SCM module the execution of the application continue on HSI instead of waiting for HSE ready and then switch to HSE when it’s ready. In this case the duration of the critical section is very short and doesn’t impact the RF requirement timing.

But, if the application has a long critical section, for example if the SCM is not used and the wait for HSE ready is performed inside the critical section. The radio IRQ Handler will be delayed too much which can lead to BLE missed event. To avoid missed event, the critical section duration need to be considered in the DRIFT_TIME to meet RF requirement timing.

The DRIFT_TIME corresponds to the time between the Radio IRQ and the beginning of the LL Process 3. Find out in the next section how to profile and configure it.

Radio activity event management in stop1 low power mode
Connectivity:Connectivity : Radio activity management stop1 mode.png

2.1. GPIO configuration to measure the DRIFT_TIME

To profile the DRIFT_TIME, the following GPIO are needed:

  • RADIO_IRQ DTB – PA6: CN3 pin 30 on NUCLEO-WBA55CG
  • TX_ON DTB – PA1: CN3 pin 34 on NUCLEO-WBA55CG
  • DBG_IO_PROFILE_END_DRIFT_TIME debug GPIO of the RT Debug module

With STM32CubeWBA v1.4.0 release, follow these steps to enable the GPIO:

  • To enable the DTB signals (RADIO_IRQ and TX_ON) set to 1 the following define in app_conf.h file:
#define CFG_RT_DEBUG_DTB                 (1)
  • To enable DBG_IO_PROFILE_END_DRIFT_TIME debug GPIO of the RT Debug module, set to 1 the following define in app_conf.h file:
#define CFG_RT_DEBUG_GPIO_MODULE                              (1)

Then choose the GPIO you want to use (PA0 in this example) in debug_config.h file and enable it:

#define USE_RT_DEBUG_PROFILE_END_DRIFT_TIME                   (1)
#define GPIO_DEBUG_PROFILE_END_DRIFT_TIME                     {GPIOA, GPIO_PIN_0}  // CN3 pin 38 on NUCLEO-WBA55CG
Radio activity event management in stop1 low power mode
Connectivity:Connectivity radio activity management stop1 mode GPIO conf.png

2.2. How to measure the DRIFT_TIME

Depending on the device role, the DRIFT_TIME can be measured:

  • During an advertising event for broadcaster role
  • Before a scan window for observer role
  • During a connection event for peripheral and central role

Once the GPIO configured and the scenario executed, the DRIFT_TIME can be profiled as described below:

  • Identify the RF activity of the scenario and identify the foregoing RADIO_IRQ as shown below.
  • Start the measure at the rising edge of the RADIO_IRQ signal
  • Stop the measure at the falling edge of the DBG_IO_PROFILE_END_DRIFT_TIME signal
DRIFT_TIME measurement
Connectivity:Connectivity stop1 drift time measurement.png

2.3. How to set the DRIFT_TIME

Once the DRIFT_TIME measured in microseconds, the value will be computed to have the number of cycles required for the DRIFT_TIME, using the following formula:

V_drift_time = CEIL(T_drift_time / T_cycle) + V_margin

With:

  • V_drift_time: the value to set in the Link Layer and corresponds to the number of cycles required for the DRIFT_TIME.
  • T_drift_time: the DRIFT_TIME duration measured previously in microsecond.
  • T_cycle: the duration of the Radio sleep timer clock cycle (~30.52us for LSE clock at 32.768kHz)
  • V_margin: the number of cycles added to allow preemption of Link Layer process. The minimum margin recommended is 6 cycles (~183.1us).

Then with STM32CubeWBA v1.4.0 release call the following API in ll_sys_reset function to set the new DRIFT_TIME value:

ll_intf_config_schdling_time( &event_time );

With the following parameters:

Evnt_timing_t event_time;
event_time.drift_time = xx;    // xx is the drift time measured in number of cycles (default value in v1.4.0 is 14)
event_time.exec_time = 14;     // Should be set to 14, default value in v1.4.0
event_time.schdling_time = 20; // Should be set to 20, default value in v1.4.0


Warning white.png Warning
System interface to set the drift time value and a user section to call the API need to be implemented for v1.5.0 (Internal ticket)


3. Standby low power mode

When standby low power mode is used, additional processes need to be considered in addition of LL processes, called the standby exit and the LL deep sleep exit in the diagram above. When exiting from standby, the system needs to wake up earlier to restore the CPU context, the clock configuration, to reinitialize the peripherals and to exit from deep sleep the RF IP. To do that, the radio sleep timer used to schedule the radio IRQ is reprogrammed to considered the duration of standby exit and LL deep sleep exit processes. These duration are considered through CFG_LPM_STDBY_WAKEUP_TIME define in app_conf.h file. This define is equal to the sum of standby exit duration (duration X) and deep sleep exit duration (duration Y).

The standby exit is performed under critical section and its duration depends on the application: the clock used, if the SCM is use or not, the number of peripheral to restore… The LL deep sleep exit depends only on the system clock frequency.

In BLE applications available in STM32CubeWBA package, the CFG_LPM_STDBY_WAKEUP_TIME define is set at a default value equal to 1500 us when standby is enabled (CFG_LPM_STDBY_SUPPORTED set to 1).
The default value has been set to 1500 to support all the configuration and include some margin, to reduce the device power consumption this value should be profile and set to the right value according to the application.

Warning white.png Warning
By default if standby is disable, CFG_LPM_STDBY_WAKEUP_TIME is set to 0 in v1.4.0. This value need to be always set to 1500 (Internal ticket for v1.5.0)


Radio activity event management in standby low power mode
Connectivity:Connectivity radio activity management standby.png


If the value in CFG_LPM_STDBY_WAKEUP_TIME macro is:

  • Too small: can lead to miss the radio activity event
  • Too big: Increase the device power consumption, the system goes back in stop1 low power mode and then wakes up again to manage the radio activity as shown in the diagram below:
Radio activity event management in standby low power mode not optimized
Connectivity:Connectivity radio activity management standby no optim.png

3.1. GPIO configuration to measure the CFG_LPM_STDBY_WAKEUP_TIME

To profile the CFG_LPM_STDBY_WAKEUP_TIME macro, the following GPIO are needed:

  • RADIO_IRQ DTB – PA6: CN3 pin 30 on NUCLEO-WBA55CG
  • DBG_IO_LOW_POWER_STANDBY_MODE_EXIT debug GPIO of the RT Debug module
  • DBG_IO_SCHDLR_HNDL_NXT_TRACE debug GPIO of the RT Debug module
  • DBG_IO_LLHWC_CMN_LW_ISR debug GPIO of the RT Debug module

With STM32CubeWBA v1.4.0 release, follow these steps to enable the GPIO:

  • To enable the DTB signals (RADIO_IRQ and TX_ON) set to 1 the following define in app_conf.h file:
#define CFG_RT_DEBUG_DTB                 (1)
Warning white.png Warning
In v1.4.0 need to call Standby_Restore_GPIO before RT_DEBUG_DTBInit in PWR_EnterOffMode and remove the call to Standby_Restore_GPIO in PWR_ExitOffMode (Internal ticket for v1.5.0)


  • To enable DBG_IO_LOW_POWER_STANDBY_MODE_EXIT, DBG_IO_SCHDLR_HNDL_NXT_TRACE and DBG_IO_LLHWC_CMN_LW_ISR debug GPIO of the RT Debug module, set to 1 the following define in app_conf.h file:
#define CFG_RT_DEBUG_GPIO_MODULE                              (1)

Then choose the GPIO you want to use in debug_config.h file and enable it:

#define USE_RT_DEBUG_LOW_POWER_STANDBY_MODE_EXIT              (1)
#define GPIO_DEBUG_LOW_POWER_STANDBY_MODE_EXIT                {GPIOA, GPIO_PIN_2}   // CN3 pin 32 on NUCLEO-WBA55CG 
#define USE_RT_DEBUG_SCHDLR_HNDL_NXT_TRACE                    (1)
#define GPIO_DEBUG_SCHDLR_HNDL_NXT_TRACE                      {GPIOB, GPIO_PIN_5}   // CN4 pin 35 on NUCLEO-WBA55CG
#define USE_RT_DEBUG_LLHWC_CMN_LW_ISR                         (1)
#define GPIO_DEBUG_LLHWC_CMN_LW_ISR                           {GPIOA, GPIO_PIN_12}  // CN4 pin 17 on NUCLEO-WBA55CG
Radio activity event management in standby low power mode
Connectivity:Connectivity radio activity management standby mode GPIO conf.png

3.2. How to measure the CFG_LPM_STDBY_WAKEUP_TIME

Once the GPIO are configured, the CFG_LPM_STDBY_WAKEUP_TIME can be profile by adding the duration of the following processes:

  • Standby Exit (Duration X):
    • The rising edge of the DTB Radio IRQ
    • The falling edge of the Low power standby exit: GPIO_DEBUG_LOW_POWER_STANDBY_MODE_EXIT
  • Deep Sleep exit (Duration Y):
    • The rising edge of the HASH IRQ Handler: GPIO_DEBUG_LLHWC_CMN_LW_ISR
    • The rising edge of Handle next event: GPIO_DEBUG_SCHDLR_HNDL_NXT_TRACE
CFG_LPM_STDBY_WAKEUP_TIME measurement
Connectivity:Connectivity CFG LPM STDBY WAKEUP TIME measurement.png

3.3. How to set the CFG_LPM_STDBY_WAKEUP_TIME

Once the value has been measured, add the duration of standby exit process and LL Deep Sleep exit process:

CFG_LPM_STDBY_WAKEUP_TIME = Standby exit duration + LL Deep Sleep exit duration

If you are using STM32CubeMX tool, set the value in us through STM32_WPAN interface in configuration panel. Else set the value directly in the code through CFG_LPM_STDBY_WAKEUP_TIME define in app_conf.h file.

4. Backup

4.1. Link Layer Timing

To adjust the BLE Link Layer timing with the right value, it requires a profile of specific timings called the DRIFT_TIME and EXEC_TIME.

The DRIFT_TIME corresponds to the time between the Radio IRQ and the beginning of the Link Layer event setup. It can be impacted by the system process and the active clock frequency.

The EXEC_TIME corresponds to the time required by the Link Layer to prepare the system to configure the next radio event. Please find below the step to follow to configure the DRIFT_TIME and EXEC_TIME values.

4.1.1. GPIO and signals setup

The DTB RADIO_IRQ, TX_ON and the debug IO of the RT Debug module DBG_IO_PROFILE_END_DRIFT_TIME and DBG_IO_SCHDLR_EXEC_EVNT_PROFILE.

  • The RADIO_IRQ GPIO indicates the beginning of the DRIFT_TIME
  • The DBG_IO_PROFILE_END_DRIFT_TIME indicates the end of the DRIFT_TIME.
  • The TX_ON GPIO indicates the RF activity. As the DRIFT_TIME to measure, is the one which occurs just before the RF Activity (TX_ON) (cf. figure 1)
  • The DBG_IO_SCHDLR_EXEC_EVNT_PROFILE rising edge indicates the beginning of the EXEC_TIME and the falling edge indicates the end of the EXEC_TIME.

(Please refer to the XXX note to setup configure those GPIOs)


4.1.2. Run Bluetooth scenario

For broadcaster role, the DRIFT_TIME and EXEC_TIME can be measured during an Advertising event.

For observer role, the DRIFT_TIME and EXEC_TIME can be measured before a Scan window.

For other roles, the DRIFT_TIME and EXEC_TIME can be measured during a connection event.

4.1.3. Measure the DRIFT_TIME duration

Once the GPIO configured and the scenario executed, the DRIFT_TIME can be profiled as described below.

  • Identify the RF activity of the scenario (detailed in the point 2.) and identify the foregoing RADIO_IRQ as shown in the figure 1.
  • Start the measure at the rising edge of the RADIO_IRQ signal
  • Stop the measure at the falling edge of the DBG_IO_PROFILE_END_DRIFT_TIME signal
Connectivity:STM32CubeWBA BLE Timing Profiling 1717763978699.png

Figure 1 : Signal identification

Connectivity:STM32CubeWBA BLE Timing Profiling 1717763990124.png

Figure 2 : DRIFT_TIME measurement


4.1.4. Define the DRIFT_TIME value

Once the DRIFT_TIME measured in microseconds, the value will be computed to have the number of cycles required for the DRIFT_TIME, using the following formula:

With:

-       T_drift_time is the DRIFT_TIME duration measured previously in microsecond.

-       T_cycle is the duration of the Link Layer sleep clock cycle ~30.52us (clock at 32.768kHz)

-       V_drift_time is the value to set in the Link Layer and corresponds to the number of cycles required for the DRIFT_TIME.

-       V_margin is the number of cycles added to allow preemption of the Link Layer setup. The minimum margin recommended is 7 cycles (~183.1us).

4.1.5. Measure the EXEC_TIME duration

Once the GPIO configured and the scenario executed, the EXEC_TIME can be profiled as described below.

- Identify the RF activity of the scenario (detailed in the point 2.).

- Start the measure at the rising edge of the DBG_IO_SCHDLR_EXEC_EVNT_PROFILE signal

- Stop the measure at the falling edge of the DBG_IO_SCHDLR_EXEC_EVNT_PROFILE signal

Connectivity:STM32CubeWBA BLE Timing Profiling 1717764026129.png

Figure 3: EXEC_TIME measurement

4.1.6. Define the EXEC_TIME value

Once the EXEC_TIME measured in microseconds, the value will be computed to have the number of cycles required for the EXEC_TIME, using the following formula:

With:

-       T_exec_time is the EXEC_TIME duration measured previously in microsecond.

-       T_cycle is the duration of the Link Layer sleep clock cycle ~30.52us (clock at 32.768kHz)

-       V_exec_time is the value to set in the Link Layer and corresponds to the number of cycles required for the EXEC_TIME.

Note: No margin needed for exec_time.

4.1.7. Set the DRFIT_TIME and EXEC_TIME

Call the XXX function with V_drift_time and V_exe _time as parameter in the ll_sys_reset function.

4.1.8. Example

For an application which supports Central or Peripheral Role :

Connectivity:STM32CubeWBA BLE Timing Profiling 1717763978699.png
Connectivity:STM32CubeWBA BLE Timing Profiling 1717764026129.png
  • T_drift_time = 186us
  • V_drift_time = CEIL(186 / 30.52) + 6 = 13
  • T_exec_time = 445us
  • V_exec_time = CEIL(445 / 30.52) = 15

Call the XXX function to set the new DRIFT_TIME value.

 void ll_sys_reset( void )
 {
 XXX( 10 );
 } 

Note :

  • Add note on default value.
  • problem with STOP MODE impact ?
No categories assignedEdit