Skip to main content
Associate II
Jun 20, 2025 4:56 PM UTC
Solved

STM32N6 Inference LL_ATON_OSAL_WFE delaying PWM/timers

In the Cube AI documentation (stneuralart_api_and_stack.html) there is this code block 

/* Wait for next event */
if (ll_aton_rt_ret == LL_ATON_RT_WFE)
{ /*** subject to change to fit also user code requirements ***/
 LL_ATON_OSAL_WFE();
}

to wait for an event while an epoch is running. I looked into what WFE means and it turns out that it puts the CPU in a low power state and crucially gates all the clocks. The effect of this is that the 4 timers I have running generating PWMs all start getting delayed. I can see on the scope the period increasing up to 4-5x.

Is there another way to wait for the epoch to finish without going into a low power state? I am not currently using an RTOS but will switch to one later.

This topic has been closed for replies.
David SIORPAES
David SIORPAESBest answer
ST Employee
Jun 25, 2025 2:41 PM UTC

Hello,

Seems like the timer(s) you are using for PWM generation are disabled when entering in low power mode. This is default behavior. 

You can avoid this using __HAL_RCC_xxx_CLK_SLEEP_ENABLE macros, e.g.: for TIM2:

 

__HAL_RCC_TIM2_CLK_SLEEP_ENABLE()

 

 

If not concerned about power consumption, you can substitute LL_ATON_OSAL_WFE() with a __NOP() to avoid entering low power altogether.

Hope this helps,

David

 

2 replies

David SIORPAES
David SIORPAESBest answer
ST Employee
Jun 25, 2025 2:41 PM UTC

Hello,

Seems like the timer(s) you are using for PWM generation are disabled when entering in low power mode. This is default behavior. 

You can avoid this using __HAL_RCC_xxx_CLK_SLEEP_ENABLE macros, e.g.: for TIM2:

 

__HAL_RCC_TIM2_CLK_SLEEP_ENABLE()

 

 

If not concerned about power consumption, you can substitute LL_ATON_OSAL_WFE() with a __NOP() to avoid entering low power altogether.

Hope this helps,

David

 

neil1106Author
Associate II
Jun 25, 2025 2:50 PM UTC

Thanks that is exactly what I needed, enabling the clocks in sleep. The whole device is battery powered but the clocks are driving the CCD camera which runs constantly.