12.3 Read/Write/Erase Operations

SPI Flash can be accessed to be read, written and erased.

It is required to change the WINC’s mode to Download mode first before attempting to access the SPI Flash by calling:

sint32 m2m_wifi_download_mode();

All SPI Flash functions are blocking. A return of M2M_SUCCESS indicates that the requested operation is successfully completed.

The following is a list of Flash functions that may be used:

  • Query the size of the SPI Flash:
uint32 spi_flash_get_size();

This function returns with the size of the SPI Flash in Mb.

  • Read data from the SPI Flash:
sint8 spi_flash_read(uint8 *pu8Buf, uint32 u32offset, uint32 u32Sz)

Where the size of data is limited by the SPI Flash size.

  • Erase sectors in the SPI Flash:
sint8 spi_flash_erase(uint32 u32Offset, uint32 u32Sz)
Note: The size is limited by the SPI Flash size.

Prior to writing to any sector, erase this sector first. If some data needs to be changed within a sector, it is advised to read the sector first, modify the data and then erase and write the whole sector again.

  • Write data to the SPI Flash:
sint8 spi_flash_write(uint8* pu8Buf, uint32 u32Offset, uint32 u32Sz)

If the application wants to write any number of bytes within any sector, it has to erase the entire sector first. It may be necessary to read the entire sector, erase the sector and then write back with modifications. It is also recommended to verify that data is written after it returns success by reading data again and compare it with the original.