这是最新(主)开发分支的文档。如果您正在查找以前版本的文档,使用左侧的下拉菜单选择所需的版本。

Flash API

数据结构体

struct wm_drv_flash_info_t

flash infomation

Public Members

uint32_t flash_size

unit is byte

uint16_t sector_size

unit is byte

uint16_t page_size

unit is byte

uint8_t vendor_id

vendor ID

uint32_t unique_id[FLASH_UNIQUE_ID_SIZE / 4]

store flash unique id

相关API

int wm_drv_flash_write(wm_device_t *dev, uint32_t addr, uint8_t *wr_buf, uint32_t wr_len)

write data to flash without erase

警告

, must erase before call this API, othewise the write data maybe incorrert

参数:
  • dev[in] flash driver device

  • addr[in] begin address in flash that will be write

  • wr_buf[in] the source data address

  • wr_len[in] write data length

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_write_with_erase(wm_device_t *dev, uint32_t addr, uint8_t *wr_buf, uint32_t wr_len)

write data to flash with erase

警告

, donot poweroff or reboot system when excecute this API, othewise flash data maybe lost

参数:
  • dev[in] flash driver device

  • addr[in] begin address in flash that will be write

  • wr_buf[in] the source data address

  • wr_len[in] write data length

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_read(wm_device_t *dev, uint32_t addr, uint8_t *rd_buf, uint32_t rd_len)

read data from flash

参数:
  • dev[in] flash driver device

  • addr[in] begin address in flash that will be read

  • rd_buf[out] store read data address

  • rd_len[in] read data length

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_get_device_info(wm_device_t *dev, wm_drv_flash_info_t *flash_info)

get flash device information

参数:
  • dev[in] flash driver device, flash device information will store into dev->device_info

  • flash_info[out] store get information about this flash

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_erase_region(wm_device_t *dev, uint32_t addr, uint32_t erase_len)

erase flash begin with user’s specicy address

参数:
  • dev[in] flash driver device

  • addr[in] begin address in flash that will be erase

  • erase_len[in] erase length

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_erase_sector(wm_device_t *dev, uint32_t sector_idx, uint32_t sector_count)

erase flash by sector

参数:
  • dev[in] flash driver device

  • sector_idx[in] the start index will be erased

  • sector_count[in] erase sector number

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

int wm_drv_flash_erase_chip(wm_device_t *dev)

erase flash all region

参数:

dev[in] flash driver device

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed

wm_device_t *wm_drv_flash_init(char *dev_name)

Initialize flash driver.

参数:

dev_name[in] flash name will be inititaled

返回:

  • flash device poiniter: succeed

  • NULL: invalid argument or failed

int wm_drv_flash_deinit(wm_device_t *dev)

deinit flash driver

参数:

dev[in] flash driver device

返回:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed