2025-03-24 3:48 PM
Hello
I'm trying to make an application with BLE using this video tutorial https://www.youtube.com/watch?v=CKYWy7LKL68&ab_channel=STMicroelectronics.
I also found an example of entering standby mode using RTC wake-up (PWR_STANDBY_RTC in the example projects). I rewrote the program so that wake-up works on alarm. The program seems to work fine, but only if I enter standby mode before BLE initialization in CPU2 using MX_APPE_Init();.
As far as I understand, I have to turn off BLE and de-initialize RF the stack? How do I stop the second core from running?
I found this function in my BLE code: Adv_Cancel(); but it doesn't help.
Here is the main part of my code:
int main(void)
{
HAL_Init();
MX_APPE_Config();
SystemClock_Config();
PeriphCommonClock_Config();
MX_IPCC_Init();
MX_RF_Init();//sets alarm for 5 sec
MX_GPIO_Init();
MX_SPI1_Init();
MX_ADC1_Init();
MX_I2C3_Init();
MX_TIM17_Init();
MX_TIM16_Init();
MX_RTC_Init();
if( (__HAL_PWR_GET_FLAG(PWR_FLAG_SB) != RESET)
&& (__HAL_PWR_GET_FLAG(PWR_FLAG_C2SB) != RESET)
)
{
HAL_GPIO_TogglePin(LED2_GPIO_Port, LED2_Pin);
HAL_Delay(1000); // Мигаем светодиодом 1 секунду
// Clear Standby flag
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_SB);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_C2SB);
}
MX_APPE_Init();
Adv_Cancel();
EnterStandBy();
while (1)
{
/* USER CODE END WHILE */
//MX_APPE_Process();
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
void EnterStandBy(void)
{
HAL_NVIC_SetPriority(RTC_Alarm_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(RTC_Alarm_IRQn);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
HAL_NVIC_DisableIRQ(RTC_WKUP_IRQn);
HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);
__HAL_RTC_ALARM_CLEAR_FLAG(&hrtc, RTC_FLAG_ALRAF);
if ((LL_PWR_IsActiveFlag_C1SB() == 0) || (LL_PWR_IsActiveFlag_C2SB() == 0))
{
LL_C2_PWR_SetPowerMode(LL_PWR_MODE_SHUTDOWN);
}
HAL_PWR_EnterSTANDBYMode();
}
Let me know if more information is needed.
I also found this example https://github.com/stm32-hotspot/STM32WB-BLE-standby/tree/main but I can't find anything in it related to turning off the second core.
I also tried removing the commands that were commented out as specific to cpu1 when cpu2 was not initialized.
I also saw some messages about resetting the HCI but my board freezes when I do it.
In some developer chats, there are legends about problems with sleep for the second core, which the developer of Flipper Zero had. Also, from some comments in his code, it becomes clear that this was a sore subject for them.
Help, please. I will be immensely grateful for your help.
2025-03-25 2:20 AM
Hello,
the wireless stack manages CPU2 low power mode on its own. Please have a look here.
How to build wireless applications with STM32WB MCUs - Application note section 4.6
I'm also attaching modified STM32WB-BLE-Standby example. The MCU can be woken up by grounding PC5 pin or automatically in 10 s using RTC wakeup. You should be able to measure around 2 uA (IDLE) with STM32WB55 Nucleo board removing JP2. Also please remove all from JP5 and disconnect USB cable from ST-Link.
Best regards,
Filip Kremen