Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Functions

Functions

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...
 

sint8 spi_flash_erase ( uint32  u32Offset,
uint32  u32Sz 
)

Erase a specified portion of SPI Flash.
.

Parameters
[in]u32OffsetAddress (Offset) to erase from the SPI flash.
[in]u32SzTotal number of bytes required to be erased.
Note
It is blocking function
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for writing to SPI flash.
  • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode
See Also
m2m_wifi_download_mode, spi_flash_get_size
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.

Example

* #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;
* }
*
Parameters
[in]u32OffsetAddress (Offset) to erase from the SPI flash.
[in]u32SzSize of SPI flash required to be erased.
Note
It is blocking function
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for writing to SPI flash.
    • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode
    • It is blocking function
See Also
m2m_wifi_download_mode, spi_flash_get_size
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
uint32 spi_flash_get_size ( void  )

Get size of SPI Flash.

Returns with uint32 value which is total flash size
.

Returns
Size of Flash
Note
Returned value in Mb (Mega Bit).
Returns
SPI flash size in case of success and a ZERO value in case of failure.
Size of Flash
Author
M.S.M
Version
1.0
sint8 spi_flash_read ( uint8 pu8Buf,
uint32  u32offset,
uint32  u32Sz 
)

Read a specified portion of data from SPI Flash.
.

Parameters
[out]pu8BufPointer to data buffer which will be filled with data in case of successful operation.
[in]u32AddrAddress (Offset) to read from at the SPI flash.
[in]u32SzTotal size of data to be read in bytes
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for reading from SPI flash.
  • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode
Note
  • It is blocking function
See Also
m2m_wifi_download_mode, spi_flash_get_size
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
Parameters
[out]pu8BufPointer to data buffer which will fill in with data in case of successful operation.
[in]u32AddrAddress (Offset) to read from at the SPI flash.
[in]u32SzTotal size of data to be read in bytes
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for reading from SPI flash.
  • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode
Note
  • It is blocking function
See Also
m2m_wifi_download_mode, spi_flash_get_size
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
sint8 spi_flash_write ( uint8 pu8Buf,
uint32  u32Offset,
uint32  u32Sz 
)

Write a specified portion of data to SPI Flash.
.

Parameters
[in]pu8BufPointer to data buffer which contains the data to be written.
[in]u32OffsetAddress (Offset) to write at the SPI flash.
[in]u32SzTotal number of size of data bytes
Note
  • It is blocking function
  • It is user's responsibility to verify that data has been written successfully by reading data again and comparing it with the original.
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for writing to SPI flash.
  • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode.
  • Before writing to any section, it is required to erase that section first.
See Also
m2m_wifi_download_mode, spi_flash_get_size, spi_flash_erase
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.
Parameters
[in]pu8BufPointer to data buffer which contains the required to be written.
[in]u32OffsetAddress (Offset) to write at the SPI flash.
[in]u32SzTotal number of size of data bytes
Note
  • It is blocking function
  • It is user's responsibility to verify that data has been written successfully by reading data again and compare it with the original.
Warning
  • Address (offset) plus size of data must not exceed flash size.
  • No firmware is required for writing to SPI flash.
  • In case of there is a running firmware, it is required to pause your firmware first before any trial to access SPI flash to avoid any racing between host and running firmware on bus using m2m_wifi_download_mode.
  • Before writing to any section, it is required to erase it first.
See Also
m2m_wifi_download_mode, spi_flash_get_size, spi_flash_erase
Returns
The function returns M2M_SUCCESS for successful operations and a negative value otherwise.