XIAO how to write and read PWM pulse duration (period) using timers

What I need is simple; but after spending a week on this it is time to find some help, because my head is starting to spin.

XIAO sending the square wave:

  • Generate (on pin D10) a square wave that is running independently of the loop() call
  • Modify the frequency of the square wave within the loop() call

XIAO reading the square wave:

  • Read on pin D10 (independently of the loop() call) the duration (period) of the square wave
  • Assign the read value to a variable

I asked the same question in more detail here.