Event counter (32 bits) with ext. gate signal

H/W: Arduino Zero attached to two external events
IDE: 1.8.4

What I want is to have a 32 bits event/frequency counter that according to the datasheet, section 23. "EVSYS – Event System”, can do it without CPU intervention. Years ago I made this events/frequency counter for the Uno.

const byte gatePin = 3;
const byte freqPin = 5;

volatile uint32_t freqMulti = 0;

ISR(TIMER1_COMPA_vect)
{
    freqMulti++;
}

void GateEvent()
{
    uint32_t freq = (freqMulti << 16) + TCNT1;
    TCNT1 = 0;                                         // Reset count to zero
    freqMulti = 0;                                     // Reset mult to one

    Serial.println(freq);
}

void setup()
{
    Serial.begin(115200);

    pinMode(gatePin, INPUT);
    digitalWrite(gatePin, HIGH);                       // Enable pull up

    pinMode(freqPin, INPUT);                           // This is the frequency input
    TCCR1B = 0;                                        // Disable during setup
    TCCR1A = 0;                                        // Reset
    TCNT1 = 0;                                         // Reset counter
    TIFR1 = 1;                                         // Reset overflow
    TIMSK1 |= (1 << OCIE1A);

    freqMulti = 0;
    attachInterrupt(digitalPinToInterrupt(gatePin), GateEvent, RISING);
    TCCR1B = (1 << CS12) | (1 << CS11) | (1 << CS10);  // External trigger on Arduino D5
}

void loop() {}

It works flawlessly up to 43% of the clock frequency, i.e. limited by the Nyquist theorem and by the 16 bits counter in the Atmega328 thus the clock frequency kicks in. So far so good. But now I want to make a similar functionality in the Zero. I have experimented and searched high and low and the closest I have come is the below code found here: https://forum.arduino.cc/index.php?topic=396804.msg3078404#msg3078404 it uses the 24 bits TTC0 thus has a max frequency of 2^24-1 MHz using a gate period of 1 s and “uses the CPU”.

#define gatePin 5

void GateEvent()
{
    REG_TCC0_CTRLBSET = TCC_CTRLBSET_CMD_READSYNC;  // Trigger a read synchronization on the COUNT register
    while (TCC0->SYNCBUSY.bit.CTRLB);               // Wait for the CTRLB register write synchronization
    while (TCC0->SYNCBUSY.bit.COUNT);               // Wait for the COUNT register read sychronization

    int freq = REG_TCC0_COUNT;
    REG_TCC0_COUNT = 0;
    SerialUSB.println(freq, DEC);         // Print the result
}

void setup()
{
    SerialUSB.begin(115200);
    while (!SerialUSB); 

    REG_PM_APBCMASK |=  PM_APBCMASK_EVSYS;    // Switch on the event system peripheral
    PM->APBCMASK.reg |= PM_APBCMASK_TCC0;     // Enable TCC0 Bus clock (Timer counter control clock)

    REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN |         // Enable the generic clock...
                       GCLK_CLKCTRL_GEN_GCLK0 |     // .... on GCLK0...
                       GCLK_CLKCTRL_ID_EIC;         // ... to feed the GCLK0 to EIC peripheral
    while (GCLK->STATUS.bit.SYNCBUSY);              // Wait for synchronization

    REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN |         // Enable the generic clock...
                       GCLK_CLKCTRL_GEN_GCLK0 |     // ....on GCLK0...
                       GCLK_CLKCTRL_ID_TCC0_TCC1;   // ... to feed the GCLK5 to TCC0 and TCC1 peripheral
    while (GCLK->STATUS.bit.SYNCBUSY);              // Wait for synchronization

    // Select event input pin
    PORT->Group[PORTA].PMUX[19 >> 1].reg |= PORT_PMUX_PMUXO_A;     // Connect PA19 pin to peripheral A (EXTINT[3])
    PORT->Group[PORTA].PINCFG[19].reg |= PORT_PINCFG_PMUXEN;       // Enable pin peripheral multiplexation

    // Setup the External Interrupt Controller (EIC)
    REG_EIC_EVCTRL |= EIC_EVCTRL_EXTINTEO3;         // Enable event from pin on external interrupt 3 (EXTINT03)
    REG_EIC_CONFIG0 |= EIC_CONFIG_SENSE3_RISE;      // Set event on rising edge of signal
    REG_EIC_CTRL |= EIC_CTRL_ENABLE;                // Enable EIC peripheral
    while (EIC->STATUS.bit.SYNCBUSY);               // Wait for synchronization

    // Configure the event user       SerialUSB.println("Configuración EVE_SYS_CHANNEL realizada");
    REG_EVSYS_USER = EVSYS_USER_CHANNEL(1) |                                // Attach the event user (receiver) to channel n=0 (n + 1)
                     EVSYS_USER_USER(EVSYS_ID_USER_TCC0_EV_0);              // Set the event user (receiver) as timer TCC0, event 1

    REG_EVSYS_CHANNEL = EVSYS_CHANNEL_EDGSEL_NO_EVT_OUTPUT |                // No event output edge detection
                        EVSYS_CHANNEL_PATH_ASYNCHRONOUS |                   // Set event path as asynchronous
                        EVSYS_CHANNEL_EVGEN(EVSYS_ID_GEN_EIC_EXTINT_3) |    // Set event generator (sender) as external interrupt 3
                        EVSYS_CHANNEL_CHANNEL(0);                           // Attach the generator (sender) to channel 0

    // Setup Timer/Counter TCC0
    REG_TCC0_CTRLA &= ~TCC_CTRLA_ENABLE;            // Disable TCC0 peripheral
    while (TCC0->SYNCBUSY.bit.ENABLE);            // Wait for synchronization

    REG_TCC0_CTRLBCLR |= TCC_CTRLBCLR_DIR;          // Clear DIR bit to count up
    while (TCC0->SYNCBUSY.bit.CTRLB);               // Wait for (write) synchronization

    REG_TCC0_EVCTRL |= TCC_EVCTRL_TCEI0 |           // Enable the TCC event 0 input
                       TCC_EVCTRL_EVACT0_COUNT;     // Set up TCC timer/counter to count on event

    REG_TCC0_CTRLA |= TCC_CTRLA_ENABLE;             // Enable TCC0
    while (TCC0->SYNCBUSY.bit.ENABLE);              // Wait for synchronization

    attachInterrupt(gatePin, GateEvent, RISING);
}

void loop() {}

So far I have managed to get to this non working code. Being stuck I am looking for some guidance. I am in no risk of running into an overflow when using 32 bits vs the used gate periode.

#define gatePin 5

void GateEvent()
{
    while (TC4->COUNT32.STATUS.bit.SYNCBUSY);                              // Wait for sync
    int freq = REG_TC4_COUNT32_CC0;
    REG_TC4_COUNT32_CC0 = 0;
    
    SerialUSB.println(freq);
}

void setup()
{
    SerialUSB.begin(115200);
    while (!SerialUSB);

    // Config peripheral that is to act as event generator, 23.6.2.1 + 23.6.2.4
    PORT->Group[PORTA].PMUX[7 >> 1].reg |= PORT_PMUX_PMUXO_A;             // Connect A1 to peripheral A (TC4)
    PORT->Group[PORTA].PINCFG[7].reg |= PORT_PINCFG_PMUXEN;               // Enable pin peripheral muxing

    // Configure the event user, 23.6.2.1.1
    REG_EVSYS_USER = EVSYS_USER_CHANNEL(1) |                              // The channel to be connected to a user, ~.1
                     EVSYS_USER_USER(EVSYS_ID_USER_TC4_EVU);              // The user to connect the channel, ~.2

    // Configure the channel, 23.6.2.1.2
    REG_EVSYS_CHANNEL = EVSYS_CHANNEL_CHANNEL(0) |                        // The event generator, ~.1
                        EVSYS_CHANNEL_PATH_ASYNCHRONOUS |                 // The path to be used, ~.2 + 23.6.2.3
                        EVSYS_CHANNEL_EDGSEL_NO_EVT_OUTPUT |              // The channel to be configured, ~.3
                        EVSYS_CHANNEL_EVGEN(EVSYS_CHANNEL_EVGEN_Pos);     // The type of edge detection to use on the channel, ~.4

    // Enable EVSYS, 23.6.2.2 (says "always enabled"?)
    REG_PM_APBCMASK |= PM_APBCMASK_EVSYS;

    attachInterrupt(gatePin, GateEvent, RISING);
}

void loop() {}

From the datasheet, Table A6/A-8, I understand that the event counter should be able to run up to 48 MHz.

TIA
MikD