2023-08-24 07:10 AM
Board: STM32WB55
Software: STM32CubeIDE, STM32_WPAN BLE as Custom p2p server
Background: Have a test bench set up to check entering Standby Mode with additional features we want to use on our project before implementing it. Have been adding in our features and Standby Mode has been entered fine with good power consumption measured. I left the STM32_WPAN BLE package to last to add into the test project. This is my (edited) function WIP so far that is called when a button is pressed, using a flag system so not within the interrupt:
static void Enter_Standby_Mode() {
/* Flash Green LEDs to signal Shut Down and ensure all are off */
/* Specific procedure on STM32WB, in case of initial power-up and RF stack no started */
if((LL_PWR_IsActiveFlag_C1SB() == 0) || (LL_PWR_IsActiveFlag_C2SB() == 0)) {
/* Set the lowest low-power mode for CPU2: shutdown mode */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
}
/* Clear the RTC Wake UP (WU) flag */
__HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF);
/* Clear the Wake Up FLAG */
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
/* Set new RTC Wake Up Timer ~10s */
if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0x5AAA, RTC_WAKEUPCLOCK_RTCCLK_DIV16) != HAL_OK) {
Error_Handler();
}
/* Set CPU2 into Standby Mode */
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_STANDBY);
/* Allow Low-Power Manager to Enter Standby State?
* This links to a function calling UTIL_LPM_SetOffMode(1 << CFG_LPM_APP_BLE,
UTIL_LPM_ENABLE);*/
BLE_Enable_Standby();
/* Enter the Standby mode */
HAL_PWR_EnterSTANDBYMode();
/* Program should never reach this point (program restart when exiting from standby mode) */
Error_Handler();
}
Problem: This works fine, as per several examples, re-awakening form the RTC WU timer. However, simply adding in the STM32_WPAN package for BLE and generating the files with CubeMX, stops Standby Mode from working and it will now proceed to the Error_Handler.
I have scanned through app_conf.h for anything related and nothing seems to effect the outcome that is not the same in examples I have seen. I cannot seem to find the missing piece of this puzzle, I am not using debugger when expecting the power mode to change. The LPM and CPU2 are set into their respective low power states that should, as far as I am aware, allow the whole system to enter Standby. I have double checked registers during debugging and they are all set as expected in the reference manual,
Any clues would be much appreciated,
Thanks
2023-08-25 06:00 AM
Hi,
One possible reason could be that the BLE stack is preventing the MCU from entering Standby mode. The BLE stack might be running on the CPU2 and if it's not properly put into a low-power state, it can prevent the system from entering Standby mode. You mentioned that you're calling the function `BLE_Enable_Standby()`, which seems to be setting the low-power mode for the BLE stack. But it is not clear from your code snippet what this function does exactly.
Regards
2023-08-29 12:27 AM
Currently, this is the code to try and stop CPU2:
void BLE_Enable_Standby() {
/* Allow the Low-Power Manager of CPU2 to enter Standby */
Adv_Cancel();
UTIL_LPM_SetOffMode(1 << CFG_LPM_APP_BLE, UTIL_LPM_ENABLE);
HAL_Delay(5);
hci_reset();
return;
}
It seems to hang the process for around 10 seconds for my Wake Up Alarm to trigger, but when it triggers it continues from
HAL_PWR_EnterSTANDBYMode();
and enters the Error_Handler, instead of resetting as expected. This would imply the CPU2 is entering a lower power state but not Standby Mode, so the whole system is restricted to the lowest common denominator, I will look into this more today, any further advice would be appreciated,
Thanks