Skip to main content
Visitor II
February 11, 2021
Solved

HAL_FLASHEx_Erase does not work for STM32L496VE due to incorrect FLASH_BANK_SIZE and FLASH_BANK_2 being declared

  • February 11, 2021
  • 1 reply
  • 1015 views

We have designed a custom bootloader solution that works on multiple STM32 devices, however when we attempted to use it on STM32L496VE we realised HAL_FLASHEx_Erase did not clear the flash, even though it returned HAL_OK.

On further investigation, it was found that the HAL library assumes any stm32L4xx has 2 banks, with each bank having half the FLASH_SIZE. This meant that FLASH_SIZE is set to 512KB, and FLASH_BANK_SIZE is set to 256KB for STM32L496VE, whereas the datasheet states that this IC has 1 bank of 512KB.

Note - we have modified the defines to ensure STM32L496VE has only 1 bank in the HAL Library, however HAL_FLASHEx_Erase still does not work. Potentially the assumption that the device has 2 banks causes a lot of ripples throughout all the other libraries for the same device.

Is there any assistance you can provide with this please?

Regards,

Kaz

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

    Update - After lots of experimentation, the answer was found. Posting here for any others that encounter this issue.

    STM32L496VE IS a dual bank device with 256KB in each bank. Even though the datasheet states that bank sizes are 512KB.

    When programming a double word, the sequential address numbers can be used, however when erasing a page there is a 128 page offset between bank 1 and bank 2.

    See - Table 9, page 98 of https://www.st.com/resource/en/reference_manual/dm00083560-stm32l47xxx-stm32l48xxx-stm32l49xxx-and-stm32l4axxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

    Therefore, when erasing any page in bank 2 using HAL_FLASHEx_Erase , add 128 to the page number, and the correct page will be erased.

    Regards,

    Kaz

    1 reply

    KazAuthorAnswer
    Visitor II
    February 12, 2021

    Update - After lots of experimentation, the answer was found. Posting here for any others that encounter this issue.

    STM32L496VE IS a dual bank device with 256KB in each bank. Even though the datasheet states that bank sizes are 512KB.

    When programming a double word, the sequential address numbers can be used, however when erasing a page there is a 128 page offset between bank 1 and bank 2.

    See - Table 9, page 98 of https://www.st.com/resource/en/reference_manual/dm00083560-stm32l47xxx-stm32l48xxx-stm32l49xxx-and-stm32l4axxx-advanced-armbased-32bit-mcus-stmicroelectronics.pdf

    Therefore, when erasing any page in bank 2 using HAL_FLASHEx_Erase , add 128 to the page number, and the correct page will be erased.

    Regards,

    Kaz