Skip to main content
Graduate
February 21, 2024
Solved

STM32U575VGT HAL_FLASHEx_Erase() not working (page is not erased)

  • February 21, 2024
  • 7 replies
  • 3943 views

Hello all,

this code snippet is not working: the page is not erased, although the HAL does not report errors.

No RTOS is running.

 

if (HAL_ICACHE_Disable() != HAL_OK) {

Error_Handler();

}

 

status = HAL_FLASH_Unlock();

if (status != HAL_OK) {

Error_Handler();

}

 

erase_init_struct.TypeErase = FLASH_TYPEERASE_PAGES;

erase_init_struct.Banks = FLASH_BANK_1;

erase_init_struct.Page = 127;

erase_init_struct.NbPages = 1;

 

status = HAL_FLASHEx_Erase(&erase_init_struct, &page_error);

if (status != HAL_OK) {

Error_Handler();

}

 

Any suggestion?

 

 

 

    This topic has been closed for replies.
    Best answer by Adriano Melis

    Hello all,

    I found the source of the problem: the DUALBANK bit in FLASH_OPTR was set to 1.

    On this device this arranges the FLASH page access in two banks of 64 pages each.

     

    7 replies

    Super User
    February 21, 2024

    How are you verifying the page is not erased? What tool and memory addresses are you looking at?

    Graduate
    February 21, 2024

    I am monitoring the page content using the Memory renderer of STM32Cube Ide, there are values different from the erased value 0xFFFFFFFF

    Graduate
    February 21, 2024

    AdrianoMelis_0-1708528531593.png

     

    ST Employee
    February 21, 2024

    Hello @Adriano Melis 

    The page 127 in bank1 is in 0x080F E000 - 0x080F FFFF 

    the screenshot you showed, does not show page 127 

    SarraS_0-1708530176754.png

     

     

    Graduate
    February 21, 2024

    AdrianoMelis_0-1708530610222.png

     

    Graduate
    February 21, 2024

    my bad. this is an actual screenshot: Flash erase has been executed, FLASH content is unchanged.

    (status value is HAL_OK)

     

    ST Employee
    February 21, 2024

    Hello @Adriano Melis

    I tried to reproduce your issue using the FLASH_EraseProgram example in STM32U5CubeFW, however, page 127 was erased successfully and I couldn't reproduce it 

    Maybe share a minor project to reproduce it on my side. 

    Graduate
    February 22, 2024

    hello, these are additional info:

    • the MCU is STM32U575VGT6 on a proprietary board clocked at 100 MHz: are there known problems on this particular device? The same code is OK on the Nucleo STM32U575ZI-Q
    • FLASH erase on a single page works fine from Cube Programmer
    • when the page is pre-erased with Cube Programmer writing data is successful
    ST Employee
    February 22, 2024

    Hello @Adriano Melis 

    I suppose you're setting Flash latency to 3WS? 

    Graduate
    February 22, 2024

    Attached two cube projects, mcb-fw-FLASH-IAP is for U575VGT (NOT working), IAP is for U575ZI (working on the Nucleo board).

    As you can see the code is the same.

     

    Adriano MelisAuthorAnswer
    Graduate
    February 23, 2024

    Hello all,

    I found the source of the problem: the DUALBANK bit in FLASH_OPTR was set to 1.

    On this device this arranges the FLASH page access in two banks of 64 pages each.