cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H742AG Flash Erase Bank 2 issues

kip18
Associate III

Hello,

I am trying to erase flash bank 2 and then re-write with an incoming application. This appears to work that when I read back some of this sector it's changed to 0xFFFFFFFF, however when I restart or connect with STLINK it reads out as 0x00000000.

I only get errors if I try to write too fast after erasing flash and on POR the flash is read back as 0x00000000


I have tried unlocking flash and relocking after with

HAL_FLASHEx_Unlock_Bank2();
// erase
HAL_FLASHEx_Lock_Bank2();

// and or 
HAL_FLASH_Unlock();
// erase here
HAL_FLASH_Lock();


voltage range is correct. 

FLASH_EraseInitTypeDef erase_init;
erase_init.TypeErase = FLASH_TYPEERASE_SECTORS;
erase_init.Sector = 0;
erase_init.NbSectors = 1;
erase_init.Banks = FLASH_BANK_2;
erase_init.VoltageRange = FLASH_VOLTAGE_RANGE_3;
HAL_FLASHEx_Erase(&erase_init, &sector_error);

 

any suggestions or help would be appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

> when I restart or connect with STLINK it reads out as 0x00000000

Can you show a screenshot of where/how you're reading this out? 0 may indicate an error during reading rather than the actual value being read. Perhaps an ECC error.

HAL_FLASHEx_Erase returns HAL_OK?

No bank swapping enabled? SWAP_BANK=0?

The code presented looks fine.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
TDK
Super User

> when I restart or connect with STLINK it reads out as 0x00000000

Can you show a screenshot of where/how you're reading this out? 0 may indicate an error during reading rather than the actual value being read. Perhaps an ECC error.

HAL_FLASHEx_Erase returns HAL_OK?

No bank swapping enabled? SWAP_BANK=0?

The code presented looks fine.

If you feel a post has answered your question, please click "Accept as Solution".
kip18
Associate III

Hi TDK,

I thought it was resolved by disabling an ISR, as it worked 1 time. But now appears to fail again

I check memory in cortex-debug memory view and STLINK

if I step through the code memory appears to erase and write correctly in cortex-debug. But when I disconnect and open STLINK it reads all 0x00000000 (I'm erasing sector 0 in bank 2)

But I am starting to think it's just STLINK failing to read for some reason as when I restart and read out the memory in code it appears to be correct.

kip18_0-1764284299023.png