2023-12-02 07:05 AM - edited 2023-12-02 07:20 AM
Hi,
as I understand it:
I can activate the low power manager in CubeIDE. This will automatically add code, so each time the Sequencer has nothing to do, the system enters low power mode.
So far, this works. I can see it in the current consumption.
What I don´t understand: Is the HSE deactivated during sleep? I think it has to be, otherwise the current consumption should be much higher. But I cannot confirm it, when I use a scope and set test point in the code.
If I go to the file stm32_lpm_if.c and edit:
static void EnterLowPower(void)
{
/**
* This function is called from CRITICAL SECTION
*/
HAL_GPIO_WritePin(testpin_GPIO_Port, testpin_Pin, 0);
...
and
static void ExitLowPower(void)
{
HAL_GPIO_WritePin(testpin_GPIO_Port, testpin_Pin, 1);
/* Release ENTRY_STOP_MODE semaphore */
...
then I can see that each 100 ms (advertising interval), the microcontroller wakes up (current spike and test pin goes high)
and then goes back to sleep (test pin goes low).
static void Switch_On_HSI(void)
{
HAL_GPIO_WritePin(testpin_GPIO_Port, testpin_Pin, 0);
...
and here
static void ExitLowPower(void)
{
/* Release ENTRY_STOP_MODE semaphore */
LL_HSEM_ReleaseLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0);
while(LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
if(LL_RCC_GetSysClkSource() == LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
{
/* Restore the clock configuration of the application in this user section */
/* USER CODE BEGIN ExitLowPower_1 */
HAL_GPIO_WritePin(testpin_GPIO_Port, testpin_Pin, 1);
LL_RCC_HSE_Enable( );
__HAL_FLASH_SET_LATENCY(FLASH_LATENCY_1);
while(!LL_RCC_HSE_IsReady( ));
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
while (LL_RCC_GetSysClkSource( ) != LL_RCC_SYS_CLKSOURCE_STATUS_HSE);
/* USER CODE END ExitLowPower_1 */
}
...
then I observe, that the HSE is only turned on each 2,4 seconds.
I thought the procedure is:
Switch to HSI, go to sleep,
wakeup, turn on HSE, wait till it is ready, send advertisement package
swtich to HSI, go to sleep and so on.
From the readings on the oscilloscope, I cannot confirm that the HSE is turned on each 100 ms, as I would suppose it would be.
Also, when I monitor the MCO output (I output the HSE to a pin), it shows the HSI clock during sleep, but during the advertising there seems to be no clock signal on MCO pin (with prescaler = 16).
Btw. all these measurements are done during debugging.
Sorry for the bad quality of the oscilloscope, I am using relatively simple equipment and an improvised test setup.
Kind regards
René
2024-01-24 02:23 AM
In the datasheet of the STM32WBXX you find the different sleep modes and what peripherals are active during these sleep modes. Usually, if you are using the low power manager (from CubeIDE), the HSE is deactivated in STOP1 mode I think.
But how do you want to use UART during sleep? To send something, you would have to wake up, activate HSE, do your stuff like:
static void ExitLowPower(void)
{
/* Release ENTRY_STOP_MODE semaphore */
LL_HSEM_ReleaseLock(HSEM, CFG_HW_ENTRY_STOP_MODE_SEMID, 0);
while(LL_HSEM_1StepLock(HSEM, CFG_HW_RCC_SEMID));
if(LL_RCC_GetSysClkSource() == LL_RCC_SYS_CLKSOURCE_STATUS_HSI)
{
/* Restore the clock configuration of the application in this user section */
/* USER CODE BEGIN ExitLowPower_1 */
LL_RCC_HSE_Enable( );
__HAL_FLASH_SET_LATENCY(FLASH_LATENCY_1);
while(!LL_RCC_HSE_IsReady( ));
LL_RCC_SetSysClkSource(LL_RCC_SYS_CLKSOURCE_HSE);
//LL_RCC_SetSMPSClockSource(LL_RCC_SMPS_CLKSOURCE_HSE);
//LL_RCC_SetADCClockSource(LL_RCC_ADC_CLKSOURCE_SYSCLK);
while (LL_RCC_GetSysClkSource( ) != LL_RCC_SYS_CLKSOURCE_STATUS_HSE);
/* USER CODE END ExitLowPower_1 */
}
else
{
/* If the application is not running on HSE restore the clock configuration in this user section */
/* USER CODE BEGIN ExitLowPower_2 */
/* USER CODE END ExitLowPower_2 */
}
/* Release RCC semaphore */
LL_HSEM_ReleaseLock(HSEM, CFG_HW_RCC_SEMID, 0);
return;
}