AM261x MCU+ SDK: Flash

| AM261x MCU+ SDK 26.00.00 |

Flash

The Flash driver provides API to read and write to xSPI based flash devices present in the board.

The driver takes care of all sequencing necessary to perform writes across pages and the application need not take care of the programming intricacies.

# Features Supported

- APIs to read and write to a flash offset
- Provides API to return flash attributes like block size, page size etc
- API for block erases
- Supports Nand Flash

# SysConfig Features

Note
  It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

- Option to select flash type based on board
- Supported flash devices
  - IS25LX256
  - W25N01GVZEJ

# Features NOT Supported

- DMA for NAND FLASH

# Important Usage Guidelines

- Typically before writing to an offset, erase the block which corresponds to the offset
- Flashes support multiple erase sizes, conditionally. We provide 2 APIs for this cause in case the flash supports 2 different erase sizes:
  - Flash_eraseBlk()
  - Flash_eraseSector() The larger size can be thought of as a 'block' and the smaller size as a 'sector'. In a flash where both are supported, one can make use of both. In some flashes, the sector configuration has to be fixed before-hand. In such cases the way erase sizes supported will be subject to this configuration. Take care in the flash configuration and the application to make sure the erase APIs are called only with the right configuration.
- Flash writes can only be done to a page size aligned offset, otherwise the write API returns an error
- The `sbl_ospi` will be typically flashed at location 0x00000000 in the flash memory. So applications using flash should refrain from using this offset. Similarly, the starting of the last block of the flash is used for storing attackVector patterns later used for PHY tuning. So avoid using this offset as well.

# Example Usage

Include the below file to access the APIs

#include <board/flash.h>

Flash Read API

uint32_t offset;
/* Set offset to read from */
offset = 0;
/* Do the read */
status = Flash_read(handle, offset, buffer, 100);
DebugP_assert(SystemP_SUCCESS == status);

Flash Write API

uint32_t offset;
/* Set offset to write to */
offset = 0;
/* Do the write */
status = Flash_write(handle, offset, buffer, 100);
DebugP_assert(SystemP_SUCCESS == status);

Flash Erase API

uint32_t offset, blk, page;
/* Set offset to erase */
offset = 0;
/* Find the block number corresponding to the offset */
status = Flash_offsetToBlkPage(handle, offset, &blk, &page);
DebugP_assert(SystemP_SUCCESS == status);
/* Erase the block */
status = Flash_eraseBlk(handle,blk);
DebugP_assert(SystemP_SUCCESS == status);

# API

APIs for FLASH APIs for FLASH

Flash_offsetToBlkPage
int32_t Flash_offsetToBlkPage(Flash_Handle handle, uint32_t offset, uint32_t *block, uint32_t *page)
Utility API to convert offset in bytes to (Block Num, Page Num)
SystemP_SUCCESS
#define SystemP_SUCCESS
Return status when the API execution was successful.
Definition: SystemP.h:56
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:187
Flash_eraseBlk
int32_t Flash_eraseBlk(Flash_Handle handle, uint32_t blockNum)
Erase a block from flash.
Flash_write
int32_t Flash_write(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)
Write to flash.
flash.h
Flash_read
int32_t Flash_read(Flash_Handle handle, uint32_t offset, uint8_t *buf, uint32_t len)
Read data from flash.