Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

spi_flash.h File Reference

spi_flash.h File Reference

WINC1500 SPI Flash. More...

Go to the source code of this file.

Functions

uint32 spi_flash_get_size (void)
 Returns with uint32 value which is total flash size
.
sint8 spi_flash_read (uint8 *pu8Buf, uint32 u32Addr, uint32 u32Sz)
 Read a specified portion of data from SPI Flash.
.
sint8 spi_flash_write (uint8 *pu8Buf, uint32 u32Offset, uint32 u32Sz)
 Write a specified portion of data to SPI Flash.
.
sint8 spi_flash_erase (uint32 u32Offset, uint32 u32Sz)
 Erase a specified portion of SPI Flash.
.

Detailed Description

WINC1500 SPI Flash.

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

Copyright (c) 2016-2017 Atmel Corporation. All rights reserved.

Example

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

 {.c}
                    #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;
    
                        ret = m2m_wifi_download_mode();
                        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;
                    }

Definition in file spi_flash.h.