Microchip® Advanced Software Framework

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

Functions

sint8 spi_flash_erase (uint32 u32Offset, uint32 u32Sz)
 Erase a specified portion of 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.

References FLASH_PAGE_SZ, M2M_DBG, M2M_ERR_FAIL, M2M_PRINT, M2M_SUCCESS, MAX_ATTEMPT_STATUS_READ, MAX_PROG_CNT, MAX_RETRY, spi_flash_read_status_reg(), spi_flash_sector_erase(), and spi_flash_write_enable().

Referenced by m2m_flash_erase_sector(), and update_control_structure().