When I run the example, if a full erase has been triggered, it will still fail, but it appears to read and write with an offset. This may be related to the erase error:
Thanks for sharing the code which has given bit more context on this issue.
Key points from this flash device datasheet
Uniform 4 KByte erasable sectors with eight 8KByte parameters.
Also, it has two 32 KByte and 30 64 KByte erasableoverlay blocks.
This flash device erasable sector sizes are not uniform and differ based on an address which is requested in erase() API
In Mbed OS, SPIFBlockDevice::get_erase_size() API returns the minimum erase size supported by this flash, which is 4KB when there is no address argument. In your application, erase() API is using get_erase_size() for in_size argument which becomes 4KB. But erase() API implementation contains an internal pre-erase check that compares the requested erase size (4KB) with the specific get_erase_size(addr) (32KB or 64KB) and finds that they don’t match, which might be a reason for the error observed.
We are recommending to use this get_erase_size(bd_addr_t addr) API and addr argument should be the same as the one passed to erase() API and to see whether that helps.
@kyle_spinnaker So, in the example you call spif.erase(0, ...) at address 0. Similarly could you replace spif.get_erase_size() with spif.get_erase_size(0) and please let us know if the issue goes away? Thanks in advance!
Edit: If this doesn’t work, could you help us to identify which line SPIF_BD_ERROR_INVALID_ERASE_PARAMS is reported? (There are three in in SPIFBlockDevice.cpp.)
Thanks for the response. That did not fix the issue.
After looking at this on a logic analyzer, we think it actually may have to do with the use of dummy bytes on the driver, some of the data certain reads is being dropped due to the driver sending a dummy byte when none is expected.
We believe the issue may be with the following lines in SPIFBlockDevice.cpp around line 480.
// Write Dummy Cycles Bytes
for (uint32_t i = 0; i < dummy_bytes; i++) {
_spi.write(dummy_byte);
}
// Read Data
for (bd_size_t i = 0; i < size; i++) {
buffer[i] = _spi.write(0);
}
Looking at the logic analyzer, it seems that the spif is sending the first byte of data on some reads in response to the dummy byte, causing offset problems and I believe also a problem getting the regions from the chip.
You seem to have encountered a different issue. As we do not support your flash device, we cannot offer you more support. As an open-source project, we welcome fixes to Mbed OS, so if you find an issue with the SPIFBlockDevice and would like to contribute a fix then we would very much welcome that.
I have similar issues with this flash chip. I unfortunately cannot afford to debug this issue and would like to use another flash chip instead. Do you maintain a list of tested flash chips with Mbed OS?
@boraozgen Hi, built-in flash chips on our supported targets are tested, and chips from the same series as an on-board flashes (e.g. with different capacities) are mostly likely to work too.
We were able to identify the problem and create a custom port. It appears that the mbed driver incorrectly inserts dummy bytes into certain read operations, causing data the be dropped.