why spi_flash_read/spi_flash_write requires uint32 *

derekh
Posts: 4
Joined: Thu Aug 13, 2015 1:47 pm

why spi_flash_read/spi_flash_write requires uint32 *

Postby derekh » Tue Sep 29, 2015 9:40 am

In SDK:

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.

Thanks!

derek

dkinzer
Posts: 52
Joined: Fri Jul 31, 2015 7:37 am

Re: why spi_flash_read/spi_flash_write requires uint32 *

Postby dkinzer » Tue Sep 29, 2015 10:47 am

derekh wrote:Doe this mean the memory buffer has to be integer (32-bit) aligned?
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.

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.
Don Kinzer
Beaverton, OR, USA

derekh
Posts: 4
Joined: Thu Aug 13, 2015 1:47 pm

Re: why spi_flash_read/spi_flash_write requires uint32 *

Postby derekh » Wed Sep 30, 2015 4:01 am

Hi Don,

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?

Thanks!

derek

dkinzer
Posts: 52
Joined: Fri Jul 31, 2015 7:37 am

Re: why spi_flash_read/spi_flash_write requires uint32 *

Postby dkinzer » Wed Sep 30, 2015 6:26 am

derekh wrote:I would assume length must be multiples of 4-byte as well.
That is correct. I apologize for omitting that.

derekh wrote:But I thought NOR flash is byte addressable and can be read/written on any boundary, length?
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.

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.
Don Kinzer
Beaverton, OR, USA

Who is online

Users browsing this forum: No registered users and 7 guests