2023-11-08 08:30 AM
I have an STM32L452 rigged to use an external clock so we can keep the RTC running. Schematic attached.
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();
}
Solved! Go to Solution.
2023-11-08 11:29 AM
Is RCC PWR enabled ? Read STM32 L4 VBAT internal battery charging - STMicroelectronics Community
2023-11-08 11:50 AM
Tried setting RCC pwr on, before setting PWR->CR4: Still no joy.
SET_BIT(RCC->APB1ENR1, RCC_APB1ENR1_PWREN);
PWR->CR4 |= PWR_CR4_VBRS_Msk; // use 1.5kOhms, gives 3.02v out
PWR->CR4 |= PWR_CR4_VBE_Msk; // enable output
2023-11-08 12:17 PM - edited 2023-11-08 12:18 PM
i would do a simple test now: connect a 3v batt, cr2032 typ. , to vbat . (no super-cap)
without any problems from charging etc. you should get rtc working (as everybody -- like me is doing.)
then - if you see this working, try with only the cap again.
2023-11-08 01:13 PM
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.
2023-11-09 12:43 AM
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?
2023-11-09 06:17 AM - edited 2023-11-09 06:17 AM
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.
2023-11-16 12:16 AM
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.