Can't lock the RCC semaphore when exiting low power mode with BLE enabled
Hello everyone, for one of my projects, I am trying to use an STM32WB55 (RGV6) to read data from the ADC and notify a phone through BLE.
I have been able to read from the ADC, send the relevant data and enter shutdown mode, before waiting 64 seconds for an RTC alarm to wake up the system and start the system again.
It works fine, until I try to enable the low power mode in the advertising phase. According to what I found in another question (https://community.st.com/s/question/0D50X0000BzuU4fSQE/ble-low-power-mode-stop2), I should be able to enter STOP2 mode when entering the idle phase of the sequencer. I tried running the provided code, and a few other things to do just that, but I kept running into the same issue.
First, here is the code (in app_entry.c) that I tried to enter low power modes when idling :
void UTIL_SEQ_Idle( void )
{
#if ( CFG_LPM_SUPPORTED == 1)
UTIL_LPM_EnterLowPower();
#endif
//UTIL_LPM_SetStopMode(1U << CFG_LPM_APP, UTIL_LPM_ENABLE);
//UTIL_LPM_SetOffMode(1U << CFG_LPM_APP, UTIL_LPM_ENABLE);
UTIL_LPM_EnterLowPower();
//HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
return;
}
However, when I compiled and ran my project, it stopped advertising after a few packets. I tried to look at the power consumption to find out if I was getting stuck in STOP mode and unable to wake up, but this was not the case. The program was stuck in a loop after an arbitrary number of BLE advertising packets.
Here is a picture of that phenomenon, with spikes corresponding to resets of the device.
To find more details on what was happening, I used the debugger to see what the program was doing, and what I found was that the program was getting stuck when exiting low power mode, more specifically at this line in smp32_lpm_if.c in the ExitLowPower function :
while( LL_HSEM_1StepLock( HSEM, CFG_HW_RCC_SEMID) );
I tried to disable this line, to make it a 2-step lock, but nothing so far has corrected the issue. All other uses of the CFG_HW_RCC_SEMID are in the same file, and are followed not far away by a release of the lock.
In the end, I have not yet been able to find what was preventing the lock operation from being completed, and have no more ideas on what to look for.
Thank you in advance for any tip or idea, if you need to, you can find the code for the whole project here : https://github.com/BabdCatha/STM32-ECG/tree/main/STM32WB55RGV6/STM32-ECG