2020-08-04 01:22 AM
I want to switch clock source for decreasing power consumption(WakeUp->MSI->HSE->MSI->STOP2->WakeUp->MSI->...). I use HSE(12MHz) for SYSCLK through PLL(24MHz).
MSI is set 24MHz.
I have three probrems.
First:
Switching MSI to HSE is always successful. Each time I don't disable MSI.
Switching HSE to MSI and disabling PLL also seems successful. Because this code(HAL_RCC_ClockConfig()) returns HAL_OK.
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
// switching to MSI before disabling HSE
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
_dbgTurnOn_LED();
for (int i = 0; i < 1000000; ++i) {
}
_dbgTurnOff_LED();
for (int i = 0; i < 1000000; ++i) {
}
// Returns HAL_OK
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
{
Error_Handler();
}
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;
// RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_OFF;
// Returns HAL_OK
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
/* Initialization Error */
Error_Handler();
}
_dbgTurnOn_LED();
for (int i = 0; i < 1000000; ++i) {
}
_dbgTurnOff_LED();
for (int i = 0; i < 1000000; ++i) {
}
HAL_RCCEx_EnableMSIPLLMode();
Add:I confirmed that HSEON, HSEBYP, PLLON, and PLLRDY was reset after above code excuted(debug using ST-Link and CubeIDE). Only HSERDY bit remained SET.
But when I disable HSE using this code, HAL_RCC_OscConfig() returns HAL_TIMEOUT.
In HAL driver, this func rerutns HAL_TIMEOUT when HSERDY don't reset in 100ms.
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_OFF;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) == HAL_TIMEOUT)
{
// MCU enters here each time
_dbgTurnOn_LED();
for (int i = 0; i < 10000000; ++i) {
}
_dbgTurnOff_LED();
for (int i = 0; i < 10000000; ++i) {
}
/* Initialization Error */
Error_Handler();
}
Add:I confirmed that HSEON, HSEBYP, PLLON, and PLLRDY was reset after above code excuted(debug using ST-Link and CubeIDE). Only HSERDY bit remained SET.
So I think my method disabling HSE is wrong. Following problems should occur with same cause.
If I don't switch to HSE, all procedure(WakeUp->MSI->HSE->MSI->STOP2->WakeUp->MSI->...) successfully works.
2023-10-24 07:36 AM
The post is quiet old but we are facing a similar problem at the moment. When we work with the internal HSI RC oscillator we have no problem to wakeup from the stop mode. But as soon as we switch to the HSE we have the problem that we got stuck in the sleep mode.
Have you found a solution for your problem?