Flash sector erase is taking too long
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Labels:
-
Flash
-
STM32F4 Series
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-31 1: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-01-31 1:20 AM
:pensive_face: wathdog has no enable..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2019-02-01 1: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-05 6:41 AM
So how does this work?
FLASH_Erase_Sector(idx, FLASH_VOLTAGE_RANGE_3);
done = FLASH_WaitForLastOperation(NVI_ERASE_TOUT_MS) == HAL_OK;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2024-01-05 8: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
