cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_ERROR in HAL_RCC_OscConfig()

Andres Cao
Associate III
Posted on September 29, 2017 at 18:13

Hi all!

I have an STM32L0 using the HSI to clock at 6MHz, and a LSE for the RTC.

Devices goes to sleep (STOP mode) and wakes up just fine.

But if I activate the RTC Alarm A interrupt, while restoring clocks I get a HAL_ERROR in the HAL_RCC_OscConfig() function.

More precisely here:

/* Check if the PLL is used as system clock or not */

if(__HAL_RCC_GET_SYSCLK_SOURCE() != RCC_SYSCLKSOURCE_STATUS_PLLCLK)

{

   .....

}

else

{

   return HAL_ERROR;

}

Any clues into this? 

Thanks!!!
3 REPLIES 3
Posted on September 29, 2017 at 18:19

Decode the RCC state before that, make sure the HSI is clocking, the PLL is locked and sourced correctly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andres Cao
Associate III
Posted on October 03, 2017 at 13:06

Thank you

Turvey.Clive.002

for the suggestions.

I have gotten a little bit deeper and realized that the device is actually not going to sleep, and this happens sometimes every couple of minutes, or could be a couple of days. If the HAL_RCC_OscConfig() is calledwhen the device is awake then it fails and goes to the Error_Handler();. Of course, it shouldn't be called when the device is awake, but this would happen if the device fails to go to sleep.

I have the following function to go to sleep:

void enterStopMode(void){

if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 9, RTC_WAKEUPCLOCK_CK_SPRE_16BITS) != HAL_OK) {

TRACE_DBG_H('HAL ERROR -> HAL_RTCEx_SetWakeUpTimer_IT\n');

}

HAL_CRC_DeInit(&hcrc);

HAL_I2C_DeInit(&hi2c1);

HAL_I2C_DeInit(&hi2c2);

HAL_I2C_DeInit(&hi2c3);

isSleep=true;

TRACE_DBG_H('STOP\n');

HAL_UART_DeInit(&hlpuart1);

__HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU);

__HAL_RCC_WAKEUPSTOP_CLK_CONFIG(RCC_STOP_WAKEUPCLOCK_MSI);

HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);

}

Sometimes this function doesn't go to sleep at all and code continues execution, where the HAL_RCC_OscConfig() is called and it fails as expected.

I noticed that in the Reference Manual (

http://www.st.com/content/ccc/resource/technical/document/reference_manual/2f/b9/c6/34/28/29/42/d2/DM000957pdf/files/DM000957pdf/jcr:content/translations/en.DM000957pdf

) page 161, Table 37, it says:

Note: To enter the Stop mode, all EXTI Line pending bits (in Section 5.6: EXTI pending register (EXTI_PR)), all peripherals interrupt pending bits, the RTC Alarm (Alarm A and Alarm B), RTC wakeup, RTC tamper, and RTC time-stamp flags, must be reset. Otherwise, the Stop mode entry procedure is ignored and program execution continues.

The only interrupt is the SysTick one. Could this be a race condition inside the

HAL_PWR_EnterSTOPMode that there's just an interrupt event before entering stop and makes it fail as per the note above?

void HAL_PWR_EnterSTOPMode(uint32_t Regulator, uint8_t STOPEntry)

{

uint32_t tmpreg = 0U;

/* Check the parameters */

assert_param(IS_PWR_REGULATOR(Regulator));

assert_param(IS_PWR_STOP_ENTRY(STOPEntry));

/* Select the regulator state in Stop mode ---------------------------------*/

tmpreg = PWR->CR;

/* Clear PDDS and LPDS bits */

CLEAR_BIT(tmpreg, (PWR_CR_PDDS | PWR_CR_LPSDSR));

/* Set LPSDSR bit according to PWR_Regulator value */

SET_BIT(tmpreg, Regulator);

/* Store the new value */

PWR->CR = tmpreg;

/* Set SLEEPDEEP bit of Cortex System Control Register */

SET_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);

/* Select Stop mode entry --------------------------------------------------*/

if(STOPEntry == PWR_STOPENTRY_WFI)

{

/* Request Wait For Interrupt */

__WFI();

}

else

{

/* Request Wait For Event */

__SEV();

__WFE();

__WFE();

}

/* Reset SLEEPDEEP bit of Cortex System Control Register */

CLEAR_BIT(SCB->SCR, SCB_SCR_SLEEPDEEP_Msk);

}

I'm not entirely sure if this could be the case. Any opinions?

Thanks all for your input.

Andrés

Andres Cao
Associate III
Posted on October 04, 2017 at 11:20

Hi all!

Can anyone help me as to how to avoid this Stop mode entry ignored? I checked EXTI_PR and it is 0, but still Stop mode is ignored due to the Systick timer, I think. 

Note: To enter the Stop mode, all EXTI Line pending bits (in Section 13.5.6: EXTI pending register (EXTI_PR)), all peripherals interrupt pending bits, the RTC Alarm (Alarm A and Alarm B), RTC wakeup, RTC tamper, and RTC time-stamp flags, must be reset. Otherwise, the Stop mode entry procedure is ignored and program execution continues.

Thanks in advance!

Andrés