2022-10-01 03:52 AM
In my STM32L496 MCU I saw that if I activate timer1(PWM channel1) is not possible to use internal flash because FLASH_SR_PGSERR go up just after initialization (Hal_Init).
while, if I disable the timer (in cube) and regenerate code, flash works as expected.
So my question is: is it a problem to use timer1 and flash together?
Thanks in advance
Solved! Go to Solution.
2022-10-02 02:30 PM
Hi hs2,
I did a test project using Cube without write a single line of code and the problem is present.
But finally I found what cause it. In timebase source I set tim17 because normally I use freertos and it is strongly recommended to do not use systick.
If I change tim17 with another timer (I tried tim8) the problem disappear.
So now I'm happy because I found how to fix this problem, but I would like to know why the combination of using tim17 as timebase source and activating tim1 cause internal flash FLASH_SR_PGSERR.
In any case thanks for your help.
2022-10-02 07:01 AM
A timer is not related to flash or the flash controller. I bet your timer1 code / ISR is buggy and tries to write to a flash address instead of a RAM address probably due to an uninitialized variable (null pointer ?) or handle.
2022-10-02 02:30 PM
Hi hs2,
I did a test project using Cube without write a single line of code and the problem is present.
But finally I found what cause it. In timebase source I set tim17 because normally I use freertos and it is strongly recommended to do not use systick.
If I change tim17 with another timer (I tried tim8) the problem disappear.
So now I'm happy because I found how to fix this problem, but I would like to know why the combination of using tim17 as timebase source and activating tim1 cause internal flash FLASH_SR_PGSERR.
In any case thanks for your help.
2022-10-03 12:44 AM
As far as I remember I had the issue explained before in some init code and encountered flash error FLASH_SR_PGSERR later on and was also wondering ;)
I used a debugger stepping through the (init) code watching flash controller status reg and found the bug.
2022-10-03 01:02 AM
Few days ago I did the same things and I found in the Init code the step in which this error happens... something related with priority if I remember correctly (sorry today is Monday and my brain is still in the weekend :-))
I'll try again to debug in order to understand where the bug is.
Thanks again
2022-10-03 02:23 AM
The problem happens in this functions
HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority)
in this line
HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM17_IRQn);
Not sure but I'm starting thinking that timer17 is based in timer1 and changing/activating timer1 this will cause some changes in timer17. So maybe timer17 speed is no correct and read/write operation in flash memory are not possible. That's my idea but I'm not so expert, if you have an explanation please explain to me.
In any case I'll stop to use tim17 as timebase source.