The latest development version of this page may be more current than this released 2.4-rc version.

Flash API

Data Structures

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 Reference

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

Warning

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

Parameters:
  • 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

Returns:

  • 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 The non-written data in the erased sector block will be read out first. This data will be combined with the data to be written, and then they will be written together after the sector is erased.

Warning

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

Parameters:
  • 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

Returns:

  • 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

Parameters:
  • 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

Returns:

  • 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

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

  • flash_info[out] store get information about this flash

Returns:

  • 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

Parameters:
  • dev[in] flash driver device

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

  • erase_len[in] erase length

Returns:

  • 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

Parameters:
  • dev[in] flash driver device

  • sector_idx[in] the start index will be erased

  • sector_count[in] erase sector number

Returns:

  • 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

Parameters:

dev[in] flash driver device

Returns:

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

Parameters:

dev_name[in] flash name will be inititaled

Returns:

  • flash device poiniter: succeed

  • NULL: invalid argument or failed

int wm_drv_flash_deinit(wm_device_t *dev)

deinit flash driver

Parameters:

dev[in] flash driver device

Returns:

  • WM_ERR_SUCCESS: succeed

  • WM_ERR_INVALID_PARAM: invalid argument

  • others: failed