cancel
Showing results for 
Search instead for 
Did you mean: 

Reading clock input on OSC_IN

treguy
Associate II

Hi,

  I have an stm32g473 which use the clock of another system as external clock on PF0 / OSC_IN. This clock is them multiplied by 74 through the PLL. I need to synchronize my code with the external clock (i.e. wait for it to rise).

  What is the simplest way to do this? Can I use PF0 both as OSC_IN and as an GPIO in input mode to generate an event on the rising edge? or should I root the clock to both OSC_IN and another GPIO?

  Are there other possibilities did not find in the reference manual (e.g. using the HSE as a trigger to one of the timer or an event I could WFE on ?)

Thanks.

5 REPLIES 5
TDK
Super User

> I need to synchronize my code with the external clock

To what extent, specifically?

If you just need to wait for it to go high, set PF0 as an input and wait for it to go high, then start the clock after that.

If you feel a post has answered your question, please click "Accept as Solution".
treguy
Associate II

I need a more precise synchronization than this would provide, I will do bus sniffing (and even on the fly modification) of the data bus timed by my input clock.

I probably will need to resync my code to the input clock rising edge just in case my code do not execute in constant cycle code (always hard to say with nowadays MCUs), but I hope to reduce jitter (and have it null every time my code run in expected amount of cycles) by using the external clock and a PLL. So switch the pin function is not an option.

TDK
Super User

Trying to get tick-level precision by reading an input pin will not work. If you need that sort of precision, consider something using a timer.

If you feel a post has answered your question, please click "Accept as Solution".
treguy
Associate II

Using a timer is also a possibility (at least something I will try and what makes me try using the target clock + a PLL), but I will still need to find a way to sync the timer with the non-PLLed clock. And for now I don't know how to do that without using an additional pin (and I already don't have enough pins left)

On STM32G473, PF0 (OSC_IN) is dedicated to the HSE oscillator and cannot be used at the same time as GPIO, EXTI, or timer input.
For precise edge‑synchronous timing, you typically feed the external clock to PF0 (for HSE/PLL) and to a second pin that is used as an EXTI or timer input.