Showing results for 
Search instead for 
Did you mean: 

Timer Configuration causes Flash Error

user 143
Associate III

I've got a real strange error, and I really don't understand it.

I'm using a STM32F407VET6 Microcontroller. I also use CubeMX to generate the configurations.

But especially with the Timers, it's not possible to set every setting I need with Cube, so I added a custom timer init function for this. I'm using Timer 6, Timer 7 and Timer 13.

Additionally I use one Sector of the Flash as EEPROM. But since I added my custom Timer functions, the EEPROM erasing and writing isn't working anymore. I found out, that the Bits PGPERR and PGSERR in the Flash->SR register are set. But the strange thing is, the Bits are set after my Tming configuration function!

This is my configuration function:

TIM13->CR1 |= TIM_CR1_URS;

When I only configure one of the Timers, then the Flash Error bits are not set. And it's not matter which Timer, so long it's only one.

I also can configure Tim7 and Tim13 together, this gives also no Error Bits. But every combination with Tim6 causes the Error. But Tim6 alone is working.

The Erata Sheet has nothing about this.

Any ideas?



Doesn't look to configure much of anything. You service the interrupts properly? You clear the errors? You run without the debugger?​

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Alex R

Additional questions:

  • Is Vpp valid during programming? Could it be that when using the timers, other external peripherals are enable and Vpp is not valid.
  • Is the programming sequence followed? Note that Flash read will stall during Flash operations
  • Are you doing sector erase or mass erase?
  • Can you disable the timers (or at least Timer 6) during Flash Erasing /Programming? Note that the Flash erasing can be quite long (~1 seconds for a 64Kb sector), and the processor is basically stalled during that time.

user 143
Associate III

Thank you for your answers.

@Community member​ 

At this moment, the timer interrupts are not enabled. Only configured. I start the timers later in my application, but the flags in the register are set at the configuration. So far I didn't cleared the errors in the Flash register, but I try this next. I tested with and without debugger. I added a if() after every timer config and toggled a Pin. It doesn't matter if I use the debugger or not, the Error Flags are Set at the same position.

@Alex R​ 

  • I'm not using an external Vpp.
  • I'm not sore if I understand your 2nd point. Could you please explain it a bit more?
  • I'm doing a sector erase. I want to clear the 2nd sector with 16 kB (0x0800 4000 - 0x0800 7FFF)
  • The timers are not active at the Erasing/Programming. Only configured, but not enabled.

I also wrote an own Bootloader. This is placed in the first Sector of the Flash. In the 2nd Sector is my EEPROM. After that follows the User Code. My Bootloader is using the same HAL Functions for accessing the Flash (Erase and Programming) and works fine. A few months ago I implemented something similar with a F1 Microcontroller. There I'm using a 2kB page for the EEPROM and this works also fine with the HAL functions.

user 143
Associate III

I think I found my mistake. The HAL functions for initializing the timers are causing a update/interrupt of the timer. So after I was setting the Enable Interrupt Bit (TIM_DIER_UIE), the interrupt is executed immediately. But at this moment, one pointer in my ISR is not correct initialized and is showing somewhere in the Flash. And this causes the Error in the Flash Register. Clearing the Update Interrupt Flag in the SR Register of the Timers before setting the Enable Interrupt Flag solves the problem so far.