SpiFlashOpResult spi_flash_write(uint32 des_addr, uint32 *src_addr, uint32 size);
SpiFlashOpResult spi_flash_read(uint32 src_addr, uint32 *des_addr, uint32 size);
Here flash address is just uint32, but the memory side pointer (src_addr in write or des_addr in read) is pointer to uint32.
Why is that? Doe this mean the memory buffer has to be integer (32-bit) aligned?
Can the addr in flash side be any non-integer-aligned address?
This seems odd.
In rboot posted by rburton, he has this:
// esp8266 built in rom functions
extern uint32 SPIRead(uint32 addr, void *outptr, uint32 len);
extern uint32 SPIEraseSector(int);
extern uint32 SPIWrite(uint32 addr, void *inptr, uint32 len);
Note here both memory pointers are void *.
Can folks at Espressif please clarify this.
If memory side does not be integer-aligned, please fix the prototypes.
Yes. Attempting to read/write from a Flash address that is not on a 32-bit boundary or using a buffer that is not 32-bit word aligned will (almost certainly) result in an exception. It is a simple matter to write helper routines that take arbitrary addresses and arbitrarily aligned buffers and perform properly aligned read/write operations.derekh wrote:Doe this mean the memory buffer has to be integer (32-bit) aligned?
As for your comment about the void * parameters, a void pointer might be 32-bit aligned or not. Similarly, a uint32_t pointer might be 32-bit aligned or not depending on compiler directives. It is up to the programmer to ensure that the proper alignment is used for any call. The provider's responsibility is to clearly describe what the requirements are.
Beaverton, OR, USA
Thanks for the reply. I check the SDK doc again and did see it also clearly states that pointers must be int-aligned. I would
assume length must be multiples of 4-byte as well.
But I thought NOR flash is byte addressable and can be read/written on any boundary, length?
That is correct. I apologize for omitting that.derekh wrote:I would assume length must be multiples of 4-byte as well.
For reading, yes. For writing, most/many chips have a minimum size (a "page") that must be written. If you want to write fewer bytes than the page size you must do a read-modify-write. Some Flash chips are byte-writeable - you must read the datasheet for the chip to learn what the particulars are.derekh wrote:But I thought NOR flash is byte addressable and can be read/written on any boundary, length?
Be that as it may, I believe the the size, address alignment and data alignment restrictions arise due to the way that the Flash chip is mapped into the ESP8266 address space.
Beaverton, OR, USA
Who is online
Users browsing this forum: No registered users and 10 guests
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
We also have a RTOS version and a MESH version too!
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!