2019-01-30 11:04 PM
Hi all i'm developing a bootloader on a stm32f407. I want to erase all the flash sectors except of the first 3 which i have the bootloader code. The problem is that to erase a sector it takes 1 second and i have an external watchdog on the board that has to be toggled at least every 600 msec. What i have relized is that while a sector is erased the mcu does not execute any line of code :\ I used these 2 functions to erase the flash
HAL_FLASHEx_Erase_IT(&FLASH_EraseInitStruct)
HAL_FLASHEx_Erase(&FLASH_EraseInitStruct, &SectorError)
But both functions use this function
FLASH_Erase_Sector(pEraseInit->Sector, pEraseInit->VoltageRange)
which takes 1 second long to execute. I measure the time of a function by toggling a pin before and after execution and measuring the pin with a scope.
Any help will be very useful , thanks in advance
Solved! Go to Solution.
2019-01-31 11:07 PM
> ... and i have an external watchdog on the board that has to be toggled at least every 600 msec.
Then , this is a design fault.
Flash erase can take several seconds under worst conditions.
Either use a dual bank MCU, execute the Flash routines from RAM, or keep the watchdog off when in the bootloader.
You digged that hole.
BTW, the IAR Workbench has direct support for running code (functions) from RAM. Perhaps you can use that as template.
2019-01-30 11:13 PM
If you need to execute code during FLASH erasing/programming, that code has to run from RAM. This includes the interrupt vector table and all interrupts which are running (unless you disable interrupts before programming starts).
JW
2019-01-30 11:29 PM
Develop your code around the fact that Flash erase takes as long as it takes.
Take the maximum given in the datasheet into account.
Run from RAM, as waclawek.jan suggested, and/or do not enable a watchdog.
2019-01-31 01:19 AM
Thank for the answer, can you give me a direction how to run code from RAM, so i can figure out how to do it.
2019-01-31 01:20 AM
:pensive_face: wathdog has no enable..
2019-01-31 10:10 PM
If you're roadblocked, try another part that has dual flash banks, e.g. STM32F42xxx or STM32F43xxx, and see note on page 70 of RM0090 Rev 17.
2019-01-31 11:07 PM
> ... and i have an external watchdog on the board that has to be toggled at least every 600 msec.
Then , this is a design fault.
Flash erase can take several seconds under worst conditions.
Either use a dual bank MCU, execute the Flash routines from RAM, or keep the watchdog off when in the bootloader.
You digged that hole.
BTW, the IAR Workbench has direct support for running code (functions) from RAM. Perhaps you can use that as template.
2019-02-01 01:00 AM
I agrre with you, it was a design fault.
The only choice i have is messing with RAM, cant turn the watchdog off and changing the MCU is not a realistic choice.
I tried the __ramfunc extended keyword on functions and they do run from RAM. I'm using IAR BTW did not mention it before.
2024-01-05 06:41 AM
So how does this work?
2024-01-05 08:12 AM
please start a new thread, stating your hardware/software, and what is the problem: what is the expected behaviour and how is the observed behaviour different from it.
JW