pylink icon indicating copy to clipboard operation
pylink copied to clipboard

Best method to erase code flash memory?

Open chanqueo opened this issue 3 years ago • 6 comments

Hi, On my device, flash memory is from 0x00000000 to 0x1fffffff. Flash allocated to source code is only from 0x00000000 to 0x00100000. erase() method will erase the whole flash memory. What it the best method to only clear flash dedicated to source code?

Here is the source code I am using. flash_address, flash_size = self.get_radio_board_flash_info() data = [0xFF] * flash_size self.jlink.flash_bytes(data, flash_address)

chanqueo avatar Nov 08 '22 16:11 chanqueo

Hm. I'm not sure what the best way is. What happens if you try the aforementioned?

hkpeprah avatar Nov 21 '22 16:11 hkpeprah

As you know, when a flash is erased, all the bits are set to 1. So writing 0xFF everywhere gives the same result as erase operation. self.get_radio_board_flash_info() returns the start address and size of the flash dedicated to source code. After running my source code, the flash contents is erased as expected but the execution takes very long.

  1. compare
  2. clear
  3. write

Instead of one erase operation. I'm surprised to be the only one concerned.

chanqueo avatar Nov 21 '22 17:11 chanqueo

Looks like #154 is related to this.

hkpeprah avatar Nov 23 '22 20:11 hkpeprah

I'm not sure. My question is, what is the best way to erase only part of the flash memory? The jlink.erase() method will erase the whole flash memory, and this is not what I want, because of bootloader...

chanqueo avatar Nov 24 '22 10:11 chanqueo

@chanqueo https://github.com/square/pylink/pull/155 should fix this. It causes flash to only erase the target area, leaving the bootloader (and other permanent data) untouched.

Also, apologies for opening a duplicate issue. I should've checked beforehand.

denravonska avatar Nov 25 '22 09:11 denravonska

Remedy should be available in v1.0.0 thanks to @denravonska.

hkpeprah avatar Dec 08 '22 19:12 hkpeprah