2024-10-10 07:11 AM - last edited on 2024-10-10 08:15 AM by SofLit
Hi, I am trying to program a STM32L552ZEQ to use HSE instead of the default clock, but I am doing something wrong.
I attach the reference manual, as well as the user manual for my specific board. In the user manual, on page 24, it is stated that there is a HSE with 16 MHz clock frequency. I try to enable this by setting the HSEBYP and HSEON bits in `RCC->CR`, like so
```
```
Using GDB I observe the change to the register value happening as expected. After setting it, I am waiting for the hardware to set the HSERDY bit, indicating that everything went OK. But this bit is never set. I never seem to get out of this while-loop. I observe the bit not being set using e.g. GDB.
I looked at the reference manual and saw that MCO is fed to OSC_IN, which seems correct.
I then thought that it appears as if the MCO can be connected to several different sources, one of which being the HSE. I look at the reference manual, and find this
I modify my code to configure MCOSEL to have the value `0100`, to indicate that we should output the HSE to the MCO pin. I am using the CMSIS header files to access the correct addresses, and it seems as if the define for MCOSEL_2 carries the right value (4).
```
// the define is in the CMSIS header-file, but I paste it here for clarity
Solved! Go to Solution.
2024-10-11 08:45 AM
It looks like you have done the correct things with the hardware and software.
I wonder about R19 on the ST-LINK:
It looks like that would need to be present.
2024-10-10 07:13 AM
I should add that these clock configurations are the first things that are happening inside my main function.
2024-10-10 07:15 AM
I suggest that you start by doing this with CubeMX.
Even if you don't want to go forward with CubeMX, it should give you a starting point to work from ...
2024-10-10 07:21 AM
@krook wrote:In the user manual, on page 24, it is stated that there is a HSE with 16 MHz clock frequency. .
It also states that, by default, this is not implemented:
So have you made the necessary hardware changes?
2024-10-10 07:23 AM
I am not sure how to do it with CubeMX either, and I've failed to install CubeMX when I've tried. I'd rather understand why my code doesn't work. I don't think there is a lot missing, I've just misunderstood some minor detail.
2024-10-10 07:25 AM
I am not sure that I have. I've ever made modifications like this, where can I read more about that? I thought I could implement it in software.
2024-10-10 07:43 AM
I see now that there seems to be no HSE configuration available to me without modifying the board. What do you think I can do to get a more accurate and performant clock than the default MSI RC Oscillator 4 MHz?
2024-10-10 08:01 AM
I would connect the solder bridges to use the 8 MHz MCO from the ST-LINK.
2024-10-10 08:11 AM - edited 2024-10-10 08:21 AM
I think the default hardware configuration should be that the solder bridges are set for the 8MHz MCO from the ST-Link?
Correction: UM says it isn't (credit @Chris21 )
2024-10-10 08:17 AM