Skip to main content
SLevi.1
Associate III
Nov 8, 2023 4:30 PM UTC
Solved

STM32L452 LSE not starting

I have an STM32L452 rigged to use an external clock so we can keep the RTC running. Schematic attached.LSE_schem.png

X2 is a clock from SiTime, programmed to be 32.768kHz. C36 is a supercap acting as battery backup. I used STMCube to generate the startup code to feed into HAL_RCC_OscConfig. When I debug into this function, the LSE never becomes ready (RCC_BDCR_LSERDY bit always zero), and so the code returns HAL_TIMEOUT.

Do I have the correct circuit? Have I set the clock config correctly? It's the same if I run on a Nucleo board.

/** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure.
*/
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 2;
RCC_OscInitStruct.PLL.PLLN = 36;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV4;
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}

This topic has been closed for replies.
SLevi.1
SLevi.1Best answer
Associate III
Nov 16, 2023 8:16 AM UTC

Turns out that the wrong clock chip had been fitted - they'd used the low-power variant, so the swing on the clock signal was not sufficient for the processor to detect.

18 replies

gbm
Super User
Nov 8, 2023 4:59 PM UTC

Did you select BYPASS option in LSE configuration? I guess not -> check and correct.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
SLevi.1
SLevi.1Author
Associate III
Nov 8, 2023 5:25 PM UTC

I've tried LSE ON and LSE BYPASS; both give the same result. 

AScha.3
Super User
Nov 8, 2023 5:07 PM UTC

where is the vbat power coming from ?? CPHxx is a big cap - and empty. needs some diode or so from vdd -> cap, to charge it. otherwise the 32khz osc never gets power.

If you feel a post has answered your question, please click on " Best Answer ".
SLevi.1
SLevi.1Author
Associate III
Nov 8, 2023 5:32 PM UTC

My colleagure assures me he can see the 32768Hz clock on a scope. I use VBAT output to pwoer the supercap thus:

// Enable VBat output, which allows supercap to charge and external 32.678 clock to run
// thereby keeping RTC correct in 12v power loss
//
// Bit 9 VBRS: VBAT battery charging resistor selection
// 0: Charge VBAT through a 5 kOhms resistor
// 1: Charge VBAT through a 1.5 kOhms resistor
// Bit 8 VBE: VBAT battery charging enable
// 0: VBAT battery charging disable
// 1: VBAT battery charging enable
PWR->CR4 |= PWR_CR4_VBRS_Msk; // use 1.5kOhms, gives 3.02v out
PWR->CR4 |= PWR_CR4_VBE_Msk; // enable output

AScha.3
Super User
Nov 8, 2023 5:51 PM UTC

ok, so cap is charged by cpu internal 1k5.

so maybe you have to wait more time, until 32k osc signal "ok" .

or/and reset restart rtc , when signal "ok".

see .. about problems with rtc, when vbat was too low...

http://www.efton.sk/STM32/gotcha/index.html

 

If you feel a post has answered your question, please click on " Best Answer ".
gbm
Super User
Nov 8, 2023 7:10 PM UTC

At register level, it should be both, LSI_ON | LSI_BYPASS, not just one of them. In CubeMX - select Bypass option for LSE

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Tesla DeLorean
Guru
Nov 8, 2023 9:13 PM UTC

Wouldn't put a LED on PC15, it low current, and on the battery/low-power domain

RM suggests some sequencing is involved LSEON needs to be zero to enable LSEBYP.

You should be able to a) get the LSE out of a pin, b) measure the frequency with a TIM internally.

 

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
SLevi.1
SLevi.1Author
Associate III
Nov 9, 2023 8:43 AM UTC

I looked at the clock going into the RCC_OSC_In pin (3), and saw a 32.768 pulse. There only looked to be around 1v peak height. What sort of amplitude should it be? LSE.bmp

MM..1
Super User
Nov 9, 2023 2:17 PM UTC

I mean your config is wrong. For external active clock you in wizard ioc need config BYPASS and in config sysclock then is generated 

RCC_OscInitStruct.LSEState = RCC_LSE_BYPASS.

AAlis.23
Associate III
Mar 25, 2025 10:31 AM UTC

Schematic is wrong???. How is it going to work if you don’t have power on Vbat? You’ve placed a capacitor, and that’s it. You’re missing a diode to 3V3; otherwise, how is the capacitor going to charge?

Maybe that series has the diode integrated into the chip or a different system to provide power from the CPU to the external circuit?

MM..1
Super User
Mar 25, 2025 4:49 PM UTC

No diode, but switch internal. Read my forward up...