这个页面的 最新开发版本 可能比这个发布的 2.4-rc 版本新。

Flash API

头文件

  • wm_iot_sdk/components/driver/include/wm_drv_flash.h

  • This header file can be included with:

#include "wm_drv_flash.h"

结构体

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

接口

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

警告

, Do not 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