AnsweredAssumed Answered

STM32F4 TIM causing FLASH PGPERR

Question asked by gookin.patrick on Jan 30, 2015
Latest reply on Feb 3, 2015 by gookin.patrick
Hey Everyone,

I'm using an STM32F405 on a custom board with the STM32CubeF4 library. Whenever I enable the TIM4 peripheral, the TIM4->DMAR register automatically changes from 0 to 1. This is causing the FLASH flags PGPERR and PGSERR to be set. If I manually set TIM4->DMAR = 0 and clear the FLASH flags, the flags go away. If I leave the TIM4->DMAR register alone and clear the FLASH flags, the flags come back seemingly instantaneously.

Anyone have an idea what might be causing the issue? Or do I have to keep using the band-aid I came up with?

Here's the code:
TIM_HandleTypeDef h_tim4;
 
__TIM4_CLK_ENABLE();
 
/*
 * APB1 Input clock is 84Mhz
 * prescaler is set to 84
 * Updated rate is 100 Hz
 * 1 ticks = 10ms
 */
h_tim4.Instance = TIM4;
h_tim4.Init.Period = (10 * 1000) - 1;
h_tim4.Init.Prescaler = 84 - 1;
h_tim4.Init.ClockDivision = 0;
h_tim4.Init.CounterMode = TIM_COUNTERMODE_UP;
h_tim4.Init.RepetitionCounter = 0;
 
// Initialize TIM4 Peripheral
HAL_TIM_Base_Init(&h_tim4);
 
// Setup TIM4 interrupt
HAL_NVIC_SetPriority(TIM4_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM4_IRQn);
HAL_TIM_Base_Start_IT(&h_tim4);
 
/* For some reason, TIM4->DMAR = 1 ???
 * This is causing FLASH flags PGPERR and PGSERR to be set.
 * Manually set TIM4->DMAR = 0
 */
TIM4->DMAR = 0;
 
// Clear pending FLASH flags
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR |
                FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR |
                FLASH_FLAG_PGPERR | FLASH_FLAG_PGSERR);

Outcomes