Skip to main content
Visitor II
January 31, 2019
Solved

Flash sector erase is taking too long

  • January 31, 2019
  • 4 replies
  • 3743 views

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

    This topic has been closed for replies.
    Best answer by AvaTar

    > ... 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.

    4 replies

    Super User
    January 31, 2019

    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

    tdAuthor
    Visitor II
    January 31, 2019

    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.

    Visitor II
    January 31, 2019

    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.

    tdAuthor
    Visitor II
    January 31, 2019

    :pensive_face: wathdog has no enable..

    AvaTarAnswer
    Visitor II
    February 1, 2019

    > ... 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.

    Explorer
    February 1, 2019

    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.

    Super User
    January 5, 2024

    @mrx23,

    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