Functions
Functions
Collaboration diagram for Functions:

Functions

sint8 spi_flash_erase (uint32 u32Offset, uint32 u32Sz)
 Erase a specified portion of SPI Flash.
. More...
 
uint32 spi_flash_get_size (void)
 Returns with uint32 value which is total flash size
. 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...
 

Detailed Description

Function Documentation

◆ spi_flash_erase()

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

#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;
}

Definition at line 616 of file spi_flash.c.

◆ spi_flash_get_size()

spi_flash_get_size ( void  )

Returns with uint32 value which is total flash size
.

Get size of SPI 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

Definition at line 654 of file spi_flash.c.

◆ spi_flash_read()

sint8 spi_flash_read ( uint8 pu8Buf,
uint32  u32Addr,
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.

Definition at line 505 of file spi_flash.c.

◆ spi_flash_write()

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.

Definition at line 539 of file spi_flash.c.



inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:18:00