bootM4() screws up my M7 TIM2 ETR functionality

i have tracked this down to booting the M4.
i was successfully using the M7 to take in a 10Mhz signal on pin PA0 which is the the TIM2 ETR pin. i was prescaling and dividing this down to make a nice accurate microsecond counter. the 10Mhz is the output from Chip Scale Atomic Clock (CSAC).

now i am trying to work the M4 into my project and if i simply create a blank sketch for the M4 with a while(1) loop in setup() as soon as i call bootM4() from the M7 it is somehow trampling the 10 Mhz on PA0. withe an oscope you can see everything is fine with the 10Mhz on PA0 until the moment i call bootM4(). here is the setup code for timer2 ETR functionality. and the interrupt routine.

any help is greatly appreciated!

void setupTIM2() {
  RCC->APB1LENR |= RCC_APB1LENR_TIM2EN;  // Enable TIM2 clock
  TIM2->CR1 = 0;                         // Reset control register
  TIM2->PSC = 4;                         // Prescaler set to 5 (PSC + 1)
  TIM2->ARR = 0xFFFFFFFF;                // Max auto-reload value (free-running)
  TIM2->CNT = 0;                         // Reset counter
  TIM2->DIER |= TIM_DIER_UIE;            // Enable update interrupt

  // Configure PA0 as Alternate Function (AF1 for TIM2_ETR)
  GPIOA->MODER &= ~(0b11 << (0 * 2));  // Clear mode bits
  GPIOA->MODER |= (0b10 << (0 * 2));   // Set to Alternate Function mode
  GPIOA->AFR[0] &= ~(0xF << (0 * 4));  // Clear AF selection
  GPIOA->AFR[0] |= (0x1 << (0 * 4));   // Set AF1 (TIM2_ETR)

  // Configure TIM2 to use external clock mode 1 on ETR (PA0)
  TIM2->SMCR = (7 << TIM_SMCR_SMS_Pos) |  // External Clock Mode 1
               (7 << TIM_SMCR_TS_Pos) |   // Trigger source = ETR (PA0)
               (1 << 12);                 // Set ETR prescaler to divide by 2

  // Ensure ETR is active high
  TIM2->SMCR &= ~(1 << 15);  // Clear ETP bit to select active high

  // Disable digital filtering on ETR
  //TIM2->SMCR &= ~(0b1111 << 8);  // Clear ETR filter bits

  TIM2->ARR = 999999;  // Set rollover to 1,000,000 counts
  TIM2->CR1 |= TIM_CR1_ARPE;

  //TIM2->EGR = TIM_EGR_UG;    // Manually trigger an update event
  TIM2->CR1 |= TIM_CR1_CEN;   // Enable the counter
  NVIC_EnableIRQ(TIM2_IRQn);  // Enable TIM2 interrupt in NVIC
}

extern "C" void TIM2_IRQHandler() {
  if (TIM2->SR & TIM_SR_UIF) {  // Check if update interrupt flag is set
    TIM2->SR &= ~TIM_SR_UIF;    // Clear the interrupt flag
    secondsCounter++;           // Increment seconds counter
    topSec = 1;
  }
}

Hi @jkobhome
I suspect this is due to PA_0 being dual pad with an analog switch. I see PWM for PA_0 has been disabled for TIM2(CM7) and TIM5(CM4)

but not for ADC

Looking at the ref man for this mcu, (SYSCFG_PMCR) page 586, the switch state can be changed.
Do you have the same issue if you bootM4, wait a moment, and then config TIM2?

Thanks for this Steve! i am also concerned that PA0 is involved with using the SDMMC. i think maybe the CMD pin on the uSD card slot. SDMMC2_CMD is one of the alternate functions of PA0. though i am also not sure which CMD line is used for th uSD slot on the portenta breakout board.
so i am wondering if this is all related to the microsecond ticker code. i am definitively willing to have live without the built in arduino micros() function on both cores since in essence i will have my own super accurate microseconds counter based on the CSAC 10Mhz output if this can all work. is the us_ticker compiled into the mbed lib or can i somehow leave this out on the arduino side of things. what is becomming more and more tricky is that i want to use and ETR pin and i want it to be on a 32bit general purpose timer. so i think that only leaves TIM2 and TIM5 and not very many pins can be ETR pins. i am reading from stm32h747ag.pdf starting on page 89 table 9 PortA alternate functions. if you flip through a few pages of these tables you see the available ETR pins and which timers they go to. the reason i am going after a 32bit timer is to be able to count to 1,000,000 before rolling over. maybe i am missing another way to do this.
in general i am still trying to understand what i can fiddle with on the arduino side "under the hood" or things that reside on my computer to get the board to behave how i need it versus what is going to require me to re-compile the libmbed.a library. things that compile when i hit compile button in the IDE versus things that are fixed in the mbed stuff.

also, do you know how or where i would look to see what resources the SDMMC card and sdmmcblockdevice library are required to use the uSD card slot from the M4 core?