Microchip® Advanced Software Framework

spi_flash.h File Reference

WINC1500 SPI Flash.

This file describe SPI flash APIs, how to use it and limitations with each one.

Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.

Example

This example illustrates a complete guide of how to use these APIs.

#include "spi_flash.h"
#define DATA_TO_REPLACE "THIS IS A NEW SECTOR IN FLASH"
int main()
{
uint8 au8FlashContent[FLASH_SECTOR_SZ] = {0};
uint32 u32FlashTotalSize = 0;
uint32 u32FlashOffset = 0;
if(M2M_SUCCESS != ret)
{
printf("Unable to enter download mode\r\n");
}
else
{
u32FlashTotalSize = spi_flash_get_size();
}
while((u32FlashTotalSize > u32FlashOffset) && (M2M_SUCCESS == ret))
{
ret = spi_flash_read(au8FlashContent, u32FlashOffset, FLASH_SECTOR_SZ);
if(M2M_SUCCESS != ret)
{
printf("Unable to read SPI sector\r\n");
break;
}
memcpy(au8FlashContent, DATA_TO_REPLACE, strlen(DATA_TO_REPLACE));
ret = spi_flash_erase(u32FlashOffset, FLASH_SECTOR_SZ);
if(M2M_SUCCESS != ret)
{
printf("Unable to erase SPI sector\r\n");
break;
}
ret = spi_flash_write(au8FlashContent, u32FlashOffset, FLASH_SECTOR_SZ);
if(M2M_SUCCESS != ret)
{
printf("Unable to write SPI sector\r\n");
break;
}
u32FlashOffset += FLASH_SECTOR_SZ;
}
if(M2M_SUCCESS == ret)
{
printf("Successful operations\r\n");
}
else
{
printf("Failed operations\r\n");
}
while(1);
return M2M_SUCCESS;
}
*

Macros

#define FLASH_SECTOR_SZ   (4 * 1024UL)
 

Functions

sint8 spi_flash_enable (uint8 enable)
 
sint8 spi_flash_erase (uint32 u32Offset, uint32 u32Sz)
 Erase a specified portion of SPI Flash.
. More...
 
uint32 spi_flash_get_size (void)
 Get size of SPI Flash. More...
 
sint8 spi_flash_read (uint8 *pu8Buf, uint32 u32Addr, uint32 u32Sz)
 Read a specified portion of data from SPI Flash.
. More...
 
sint8 spi_flash_write (uint8 *pu8Buf, uint32 u32Offset, uint32 u32Sz)
 Write a specified portion of data to SPI Flash.
. More...
 

#define FLASH_SECTOR_SZ   (4 * 1024UL)

Sector Size in Flash Memory

Referenced by m2m_ota_host_file_read_spi(), and spi_flexible_flash_find_section().