i've got this code that works great on TIM2 and PA0 but i just found a conflict with this pin when using the SDMMC card. can anyone help locate an available ETR pin that is somewhat accessible on and arduino PortentaH7 docked to a Portenta breakout board? i use document stm32h747ag.pdf starting on Page 89 Table 9. PortA alternate functions but am having trouble find a pin that doesn't get trampled on by some mbed code or i am assume that is what is doing the trampling.
here is my code and ISR
volatile uint32_t secondsCounter = 0;
volatile uint8_t topSec = 0;
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;
}
}