Dear All,
I am working with an STM32U599NJHxQ mcu. Reading about this module I see that it has 4 Mbytes of Flash divided in 2 banks. So far I have been successful in reading and writing data to the first bank, but accessing the second has been a complete failure.
ased on the sample in STM32Cube_FW_U5_V1.6.0\Projects\STM32U5x9J-DK\Examples\FLASH\FLASH_EraseProgram packet, in order to write to the flash you need to disable the icache, unlock the flash, determine the page you need to write to, the number of pages where to write and finally the bank where these pages are located. Then you erase the pages that you have determined and write the data in the address in the flash where the page starts. Finally you lock the flash and enable back the icache.
In the example there is a limited number of pages where you can actually write to. Furthermore, the bank is also hard-coded. For my use case, I need to be able to write to the last pages of the flash.
If I understand things correctly, since there are 2 banks and since the size of all pages is 8kB there 512 pages in total.
The starting address of each page is 0x08000000 + (n * 0x2000), where n is the number of the page.
So, if I want to write a few bytes on page 254 of the second bank, I would need to populate the FLASH_EraseInitTypeDef like this:
FLASH_EraseInitTypeDef erase_init =
{
.TypeErase = FLASH_TYPEERASE_PAGES,
.Banks = FLASH_BANK_2,
.Page = 254,
.NbPages = 1};
Then after erasing the page, if I want to write to it, I will need to calculate the address of the page based on the formula from before 0x08000000 + (510 * 0x2000) = 0x83fc000.
But when I call the HAL_FLASH_Program, I am getting a hardfault at the point, shown in the Failure_point.png attachement, because I am trying to write to write to the address calculated above.
If I try the same sequence for page 254, bank 1 then the code works just fine.
Is there any limitation on accessing the second bank? Is there any step that I am missing?
Is there any relevant configuration using the option bytes?
Thanks a lot in advance.