cancel
Showing results for 
Search instead for 
Did you mean: 

HSERDY doesn't RESET on STM32L432KC when I wanna disable HSE after SYSCLK switch from HSE to MSI for power consumption

nebusokuu
Associate II

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.

  1. HSERDY doesn't RESET when disabling HSE
  2. After entering STOP2, the flowing current is abnormally high.
  3. Never wakeup from STOP2(use RTC WakeUp)

​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.

I​n 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.

  1. After entering STOP2, the flowing current is abnormally high.
    1. On this board, when STOP2, usually 100uA, but now 700uA
  2. Never wakeup from STOP2

If I don't switch to HSE, all procedure(WakeUp->MSI->HSE->MSI->STOP2->WakeUp->MSI->...) successfully works.

1 REPLY 1
gigerueli
Associate

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?