2021-02-11 02:45 AM
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
Solved! Go to Solution.
2021-02-12 07:31 AM
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
2021-02-12 07:31 AM
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