cancel
Showing results for 
Search instead for 
Did you mean: 

How to set STM32F051K8 custom board HSE with RTC?

JLee.161
Associate III

Hi,

I've developed a custom PCB for STM32F051K8 connected to an external crystal oscillator (8Mhz - nx3225gd from NDK). I think I have set everything correct on CubeMX and managed to get a working firmware going. I set up a 100Hz timer for ADC through setting system clock source to HSE on CubeMx, and the ADC timing seems to be correct (1000 samples take roughly 10 seconds).

My issue is that when I try to clock the RTC with the HSE, the timing seems to be consistently off by a factor of 8 or something close to that - Instead of showing 20secs it shows 2min 40secs.

When I change the clock source to LSI on the CubeMX clock configuration tab, the timing seems to be closer when I store the timing results same as above - with the LSI, it shows about 22secs.

Supposing that I have set the load capacitors of the external correctly, is there anything else I should do to make it work? especially with the RTC (as it seems that the system clock is working fine with the external crystal as the source)

1 ACCEPTED SOLUTION

Accepted Solutions
berendi
Principal

Neither CubeMX nor the HAL library can handle all possible hardware configurations and use cases.

Read the Clock and prescalers and the RTC initialization and configuration sections under RTC functional description in the reference manual, and follow the procedures described there to configure the RTC registers directly.

View solution in original post

2 REPLIES 2
berendi
Principal

Neither CubeMX nor the HAL library can handle all possible hardware configurations and use cases.

Read the Clock and prescalers and the RTC initialization and configuration sections under RTC functional description in the reference manual, and follow the procedures described there to configure the RTC registers directly.

JLee.161
Associate III

Thanks for the tip berendi! I managed to solve the issue following your directions. Calculating the correct value for the prescalers to give 1Hz for the calendar update clock gave correct timing for the results.

One thing to add though, it turns out these prescaler values can be changed in the RTC tab of CubeMX under 'General' in 'Parameter Settings' or they can be just changed in the firmware code it self.

Thanks for the help, it was much appreciated!