raspberrypi / pico-sdk

BSD 3-Clause "New" or "Revised" License
3.74k stars 932 forks source link

flash_range_program will not work if flash is not erased #650

Closed MohamedGhardallou closed 3 months ago

MohamedGhardallou commented 3 years ago

flash_range_erase must be called before calling flash_range_program. Otherwise flash_range_program will not work.

To test this behavior , just comment line 40 in flash_program example.

Could you please add a comment in the header file rp2_common/hardware_flash/include/hardware/flash.h to indicate this.

This is not obvious and it may save a lot of time to a lot of people.

Thanks

dshadoff commented 3 years ago

Are you commenting on the behaviour of flash memory itself ? Or is there some different behaviour / error code sent back by the SDK ?

For regular flash chips, the behaviour is:

MohamedGhardallou commented 3 years ago

@dshadoff Thank you for your response. Yes i was asking about the behavior of flash memory itself. I was not aware of this behavior and when i discovered it , i thought we may add a comment to the header file to highlight this. But then this is not necessarily as we can also program the flash without erasing if that sector bits are already ones. So no need to change the header.

Thank you again.

savejeff commented 2 years ago

just stumbled over the same unexpected behavior. a hint in the header of fash.h would be nice for people not familiar with how flash cells work

LucaOverflow commented 1 year ago

Jup. Spent half a day because it's not documented. It would be very nice if it's not just a note in the header but contained in the online documentation.

kilograham commented 1 year ago

re-opened to add documentation to header

jaguilar commented 5 months ago

One option here would be to assert in debug mode like

for (int i = 0; i < write_size; ++i) {
  assert(!(writebuf[i] & ~existingbuf[i]));
}

for all bytes to be programmed. It could easily prevent accidental misuse and serve as a hint to users. I'm not sure how much the overhead y'all tolerate on debug-mode vs. release-mode builds.

lurch commented 3 months ago

Fixed by #1772