AnsweredAssumed Answered

faliing to migrate trivial example from TIM6 to TIM5

Question asked by belomutskiy.andrey on Apr 15, 2014
Latest reply on Apr 15, 2014 by belomutskiy.andrey
I have a snippet which works, it blinks blue LED on stm32f4discovery:

void TIM6_DAC_IRQHandler() {
    if (TIM6->SR)
        GPIOD->ODR ^= (1 << 15);   // Toggle D15
    TIM6->SR &= ~1;   // Interrupt has been handled
}
 
int main(void) {
    TIM_TypeDef *TIM = TIM6;
 
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;   // Enable GPIOD clock
    GPIOD->MODER |= GPIO_MODER_MODER15_0;   // Enable output mode for D15
 
    RCC->APB1ENR |= RCC_APB1ENR_TIM6EN;   // Enable TIM6 clock
    NVIC_EnableIRQ(TIM6_DAC_IRQn);   // Enable TIM6 IRQ
    TIM->DIER |= TIM_DIER_UIE;   // Enable interrupt on update event
    TIM->PSC = 41999;   // Set prescaler to 41999
    TIM->ARR = 999;   // Set auto-reload to 999
    TIM->CR1 |= TIM_CR1_CEN;   // Enable TIM counter
 
    while (1) {
        // do nothing
    }
}

I am trying to move this logic to TIM5 - I want to use 32 bit counter. Well, it's embarrassing - this snipped does not work. What am I missing?

void TIM5_IRQHandler() {
    if (TIM5->SR)
        GPIOD->ODR ^= (1 << 15);   // Toggle D15
    TIM5->SR &= ~1;   // Interrupt has been handled
}
 
int main(void) {
    TIM_TypeDef *TIM = TIM5;
 
    RCC->AHB1ENR |= RCC_AHB1ENR_GPIODEN;   // Enable GPIOD clock
    GPIOD->MODER |= GPIO_MODER_MODER15_0;   // Enable output mode for D15
 
    RCC->APB1ENR |= RCC_APB1ENR_TIM5EN;   // Enable TIM5 clock
    NVIC_EnableIRQ(TIM5_IRQn);   // Enable TIM5 IRQ
    TIM->DIER |= TIM_DIER_UIE;   // Enable interrupt on update event
    TIM->PSC = 41999;   // Set prescaler to 41999
    TIM->ARR = 999;   // Set auto-reload to 999
    TIM->CR1 |= TIM_CR1_CEN;   // Enable TIM counter
 
    while (1) {
        // do nothing
    }
}




Outcomes