MartinL,
An old post I asked the moderators to kindly bump up so I could ask some questions.
I'm a retired hardware designer with no in-depth software experience (apart from Sinclair / Amstrad CPC Basic from my childhood days

). I'm self teaching myself "C" on the Arduino - and for sure its making me feel VERY VERY stupid.
So I'm working on a hardware design where I need to confirm that a couple of external "Clock" inputs are within a correct frequency range - anywhere from say 30KHz to 100MHz... So I need the system MCU to act as a frequency counter when an signal is sensed on 1 or 2 inputs.
Please understand I'm a real beginner here with C so please go easy with me and I hope I dont shame myself too much!
I plan to use the SAMD51 (in QFN64 pin package) - the SAM range of MCU's have the FREQM clock which you implemented on the Audafruit Metro M4. Unfortunately I have the bigger Audafruit Metro M4 Grand Central (for testing, before I design my own PCB) which used the larger 128pin QFN ATSAMD51P20A and I could not get any output from your "Adafruit Metro M4 SAMD51's frequency meter peripheral" code, No 30MHz output on any pin, and it appears to "freeze" at:-
Line 61 while (GCLK->SYNCBUSY.bit.GENCTRL7); // Wait for synchronization
One would assume its waiting endlessly for "synchronization" - which as I have no 30MHz clock / any clock connected to the input its "waiting" with no escape

... (no input/ output as I my Grand central ports dont match up with your code)
I did managed to get your earlier code for the Adafruit Feather M4 (using the microcontroller's Timer Counter TC0) to output atleast the "30MHz" clock on PA18 D35 on the Metro M4 Grand Central. But I could not find any of the Grand Central GPIO inputs that would be the Frequency input....
What I dont understand is why the Clock is outputted on the Grand Central's Port PA18 (not Port PA20 as you defined for your smaller Audafruit Metro M4) - I know theboards use different packaged IC's, but surely from a software perspective the hardware ports remain the same??? (where common / available between the different packages).
Also, your using some very crypt "command syntax" in your code to setup the internal hardware clock blocks of the Atmel SAMD51's where did you get this info from? - I have very vague idea its maybe specified by ARM CMSIS - but I could find no documentation - help etc.... (maybe I'm wrong about CMSIS)!!!
GCLK->PCHCTRL[TCC0_GCLK_ID].reg = GCLK_PCHCTRL_CHEN | // Enable the TCC1 perhipheral channel
GCLK_PCHCTRL_GEN_GCLK0; // Connect 120MHz generic clock 0 to TCC0
etc etc...
Could you please post a link to the relent documents / info?
Also, I measured the "30MHz" output with a "real" frequency meter and as you suspected its A: Very jittery - like VERY jittery!!! and B: a Massive PPM Offset... It would be interesting to see how accurate the FREQM can be made to function with a decent external reference clock to the MCU (you mentioned 4Hz)... which would be decent... understandably related to the Input / Reference clock ratio and counter length...
It would be something I'd like to try with some software help from you

... I'll have no problem with the hardware - but OMG, self learning C is a pig, and not helped when having to work at such a complex level for a true beginner (Setting up up the Atmel SAMD internal Clock blocks / ARM CMSIS etc.)
My hardware will have an Ultra precise 48MHz external Clock, which I'd like to use as the SAM reference clock... Once I can get to grips with configuring its clock blocks / C etc

!!!
Any help (I understand this is a old thread) would be very much appreciated - hopefully making my pending Christmas period "programming" somewhat less frustrating and painful - I dread both C and configuring the SAM clock blocks!!!