Arm Mbed OS support forum

How to erase only a portion of Flash when writing code to flash?

Currently my target Debug flags are set to erase the entire flash module before flashing the application to the board.

In Mbed Studio “Manage Custom Targets” => Debug flags this is:
–target mimxrt1050_hyperflash --erase=chip

However, I’d like to erase all but the last sector of the flash because I’m using the last sector for persistent storage of configuration data.

I know that in pyOCD I can do something like this:
pyocd erase --target mimxrt1050_hyperflash --sector 0x60400000-0x63FC0000
I’m not sure if the above command line is 100% correct. But the idea is to only erase sectors 0x60400000-0x63FC0000 which leaves the last sector not erased.

How do I set this up in Mbed Studio in the Debug flags?

Hello Jim,

To minimize flash wear-out, a (solid) programmer software usually by default erases only sectors to be flashed with the program’s code. It isn’t exactly what you want (erase all but the last sector) but it will keep the last sector provided the program fits into the chip’s flash but last sector. So I’d suggest to try removing --erase=chip from the Mbed Studio “Manage Custom Targets” debug flags.

Thank you. I thought the chip had to be erased before programming.