User external HSE on nucleo board bypass bit (HSEBYP) acts weird
Hi, I am trying to use an external frequency to drive my STM32F303RE, using a nucleo board (NUCLEO-F303RE). There is a lot of confusion going on right now.
First of all, I was provided a nucleo board with an external oscillator that was already soldered on there. But to use the oscillator, I DISABLE the HSEBYP bit in my code. The reference manual states for this bit:
0: HSE crystal oscillator not bypassed
1: HSE crystal oscillator bypassed with external clock
I would think I need to set the bit to 1 to see the external oscillator frequency (24 MHz) and not the HSE frequency (8 MHz). But when I set the bit to 1 (RCC->CR |= RCC_CR_HSEBYP;) I see the HSE is not bypassed and the microcontroller uses the provided 8 MHz clock. If I set the bit to 0 (RCC->CR &=~ RCC_CR_HSEBYP; ) is see the 24 MHz user external oscillator as a result.
Also I noticed that the bit has no impact on a microcontroller on a nucleo board, where no external oscillator is soldered. According the the Nucleo Datasheet, there are a few solder bridges to remove, in order to use the external oscillator. Even with those solder bridges adjusted in the way the datasheet states, playing around with the HSEBYP bit is giving me weird results.
I would expect that on a Nucleo with no external oscillator and with the solder bridges set up for an external oscillator, I would not get a working code when I try to bypass the HSE (since there is just no clock provided). But in this case, the HSEBYP bit just changes the "frequency stability". If the bit is set, I have my 8 MHz. If the bit is deleted, I see 7.57 Mhz. This indicates, that in the HSEBYP=1 case I use the HSE but when I set it to 0, the microcontroller tries to find an external oscillator, does not find one and uses HSI or something, which is not exactly 8 MHz. And if this is the case, it would endorse the fact that I have to set the HSEBYP to 0 to bypass the HSE, as described above.
Then there is the whole HSERDY story. The HSERDY bit description from the reference manual states:
0: HSE oscillator not ready
1: HSE oscillator ready
After choosing the HSEBYP bit, I enable the HSE (RCC->CR |= RCC_CR_HSEON;) and then I wait for the HSERDY bit to become 1 (while !(RCC->CR & RCC_CR_HSERDY);). If I am not using an external oscillator and all solder bridges are default (brand new nucleo board), the code has no problems at this point, regardless of the HSEBYP bit (which doesn’t do anything). If I use my provided nucleo board with an external oscillator on there, the code only works if I choose the external oscillator (24 MHz, HSEBYP = 0). Waiting for the HSERDY bit does not work, if I want to use the HSE. Weirdly enough, I can still use the HSE (even though I soldered an external oscillator and the HSERDY bit is not set) if I just don’t wait for the HSERDY bit.
Last case: If I have the solder bridges set up for an external oscillator but there is none, the HSERDY flag is never set, regardless of the HSEBYP bit. So kinda what I was expecting but I am still able to use the HSE if I just ignore the HSE flag?!
This brings us to my actual problem. I am trying to use the system clock of one microcontroller via the MCO output on pin PA8 as an OSC_IN input at the next microcontroller on pin PF0 to synchronize the microcontrollers. My idea was to use the OSC_IN pin while the OSC_OUT pin is not used and left in HIGH-Z state, just as the data sheet describes. But when I try to read the input frequency on the OSC_IN pin by setting the HSE up to bypass mode, nothing really happens. I see 8 MHz and not the 4 MHz, I put on OSC_IN for testing purposes.
I gave my best to make this as little confusing as possible, I'd be grateful for answers!
