Flash

概述

Flash 闪存(Flash Memory)是一类非易失性存储器 NVM(Non-Volatile Memory),即使在供电电源关闭后仍能保持片内信息。

功能特性

  • Flash 模块支持常规镜像的烧录以及用户数据的保存。

  • Flash 模块支持程序 XIP,当然,也需要相关 cache 的支持,本文档仅描述 flash 相关操作。

  • 芯片包含两个 sfc 控制器,即分别控制两片 flash,用户在实际操作前,请先确认待操作的 sfc port。

用法流程

1 /** 从 sfc_port 口对应的 flash,flash 内部地址为 addr 处,读取数据量为 count 字节的数据到 buf 缓存*/
2 wq_flash_read(sfc_port,addr,buf,count);
1 /** 往 sfc_port 口对应的 flash,flash 内部地址为 addr 处写数据,待写的数据缓存为 buf,待写的数据量为 count 字节*/
2 wq_flash_write(sfc_port,addr,buf,count);
1 /** 将 sfc_port 口对应的 flash,flash 内部地址为 addr 所在的 secor 擦除,擦除大小为一个 sector(4K Byte),擦除后对应区域全为 0xFF*/
2wq_flash_erase(sfc_port,addr);
1 /** deinit sfc_port 口对应的 flash */
2 wq_flash_deinit(sfc_port);

API 介绍

Defines

WQ_FLASH_OTP_ADDR(id)

Flash OTP region address.

WQ_FLASH_OTP_PER_REGION_SIZE

Flash OTP per region size 512 Byte.

WQ_FLASH_LOCK_TASK_MODE

Flash lock mode, if use flash API in critical or isr context, switch to CRITICAL mode.

WQ_FLASH_LOCK_CRITICAL_MODE

Typedefs

typedef void (*wq_flash_pe_cb)(void)

Functions

WQ_RET wq_flash_erase_sector(WQ_SFC_PORT sfc_port, uint16_t sector_id)

This function is to erase flash sector according to the sector id.

参数:
  • sfc_port -- is flash sfc port

  • sector_id -- is flash sector id.

返回:

WQ_RET WQ_RET_INVAL or WQ_RET_OK,WQ_RET_OK for success else error.

WQ_RET wq_flash_erase(WQ_SFC_PORT sfc_port, uint32_t addr)

This function is to erase flash sector according to the sector addr.

参数:
  • sfc_port -- is flash sfc port

  • addr -- is erase flash addr

返回:

WQ_RET WQ_RET_INVAL or WQ_RET_OK,WQ_RET_OK for success else error.

WQ_RET wq_flash_erase_range(WQ_SFC_PORT sfc_port, uint32_t addr, uint32_t length)

This function is to erase flash sector according to the sector addr.

参数:
  • sfc_port -- is flash sfc port

  • addr -- is erase flash start addr. should align with SECTOR size

  • length -- is erase flash length. should align with SECTOR size

返回:

WQ_RET WQ_RET_INVAL or WQ_RET_OK,WQ_RET_OK for success else error.

WQ_RET wq_flash_chip_erase(WQ_SFC_PORT sfc_port)

This function is to chip erase flash.

参数:

sfc_port -- is flash sfc port

返回:

WQ_RET WQ_RET_INVAL or WQ_RET_OK,WQ_RET_OK for success else error.

WQ_RET wq_flash_read(WQ_SFC_PORT sfc_port, uint32_t addr, void *buf, size_t count)

This function is to read data from flash addr.

参数:
  • sfc_port -- is flash sfc port

  • addr -- is flash addr

  • buf -- is buffer for the data being read

  • count -- is buffer len

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error.

WQ_RET wq_flash_write(WQ_SFC_PORT sfc_port, uint32_t addr, const void *buf, size_t count)

This function is to write data into flash addr.

参数:
  • sfc_port -- is flash sfc port

  • addr -- is flash addr

  • buf -- is buffer ready write to flash

  • count -- is buffer len

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error.

WQ_RET wq_flash_write_without_erase(WQ_SFC_PORT sfc_port, uint32_t addr, const void *buf, size_t count)

This function is to wtite data into flash addr without erase.

参数:
  • sfc_port -- is flash sfc port

  • addr -- is flash addr

  • buf -- is buffer ready write to flash

  • count -- is buffer len

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error..

uint16_t wq_flash_get_id(WQ_SFC_PORT sfc_port)

This function is to get flash id.

参数:

sfc_port -- is flash sfc port

返回:

uint16_t 16 bytes of flash id.

WQ_RET wq_flash_init(WQ_SFC_PORT sfc_port)

This function is to init flash.

参数:

sfc_port -- is flash sfc port

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error..

void wq_flash_deinit(WQ_SFC_PORT sfc_port)

This function is to deinit flash.

参数:

sfc_port -- is flash sfc port

bool wq_flash_is_init(WQ_SFC_PORT sfc_port)

This function is to check if flash is inited.

参数:

sfc_port -- is flash sfc port

返回:

bool true or false

void wq_flash_set_io_map(WQ_SFC_PORT sfc_port, uint32_t map)

This function is to set flash io map.

参数:
  • sfc_port -- is flash sfc port

  • map -- is flash io map

void wq_flash_enable_quad_mode(WQ_SFC_PORT sfc_port)

This function is to enable flash's quad mode.

参数:

sfc_port -- is flash sfc port

void wq_flash_enable_qpp_mode(WQ_SFC_PORT sfc_port)

This function is to enable flash's qpp mode.

参数:

sfc_port -- is flash sfc port

WQ_RET wq_flash_otp_write(WQ_SFC_PORT sfc_port, WQ_FLASH_OTP_REGION_ID id, uint32_t addr, const void *buf, size_t count)

This function is to write data into flash through otp certification.

参数:
  • sfc_port -- is flash sfc port

  • id -- is flash otp region id

  • addr -- is otp region inter addr

  • buf -- is buffer ready write into flash

  • count -- is data buffer lenth

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error.

WQ_RET wq_flash_otp_read(WQ_SFC_PORT sfc_port, WQ_FLASH_OTP_REGION_ID id, uint32_t addr, void *buf, size_t count)

This function is to read data from flash through otp certification.

参数:
  • sfc_port -- is flash sfc port

  • id -- is flash otp region id

  • addr -- is otp region inter addr

  • buf -- is buffer for the data being read

  • count -- is buffer len

返回:

WQ_RET WQ_RET_OK or WQ_RET_INVAL,WQ_RET_OK for success else error.

void wq_flash_otp_lock(WQ_SFC_PORT sfc_port, WQ_FLASH_OTP_REGION_ID id)

This function is to lock flsh region through otp certification.

参数:
  • sfc_port -- is flash sfc port

  • id -- is Flash otp region id

WQ_RET wq_flash_otp_erase(WQ_SFC_PORT sfc_port, WQ_FLASH_OTP_REGION_ID id)

This function is to erase flsh region through otp certification.

参数:
  • sfc_port -- is flash sfc port

  • id -- is Flash otp region id

返回:

WQ_RET WQ_RET_OK.

void wq_flash_set_cache_mode(WQ_SFC_PORT sfc_port)

This function is to set flash cache mode.

参数:

sfc_port -- is flash sfc port

uint32_t wq_flash_get_size(WQ_SFC_PORT sfc_port)

This function is to get flash size.

参数:

sfc_port -- is flash sfc port

返回:

uint32_t flash size.

uint32_t wq_flash_get_vendor(WQ_SFC_PORT sfc_port)

This function is to get vendor id.

参数:

sfc_port -- is flash sfc port

返回:

uint32_t vendor id.

void wq_flash_disable_qpp_mode(WQ_SFC_PORT sfc_port)

This function is to disable QPP mode.

参数:

sfc_port -- is flash sfc port

uint32_t wq_flash_get_version(WQ_SFC_PORT sfc_port)

This function is to get flash's version.

参数:

sfc_port -- is flash sfc port

返回:

uint32_t is flash version.

WQ_RET wq_flash_register_pe_callback(WQ_SFC_PORT sfc_port, wq_flash_pe_cb cb)

This function is to register program/erase's callback function.

参数:
  • sfc_port -- is flash sfc port

  • cb -- is the callback.

返回:

WQ_RET WQ_RET_OK for success else error.

WQ_RET wq_flash_unregister_pe_callback(WQ_SFC_PORT sfc_port)

This function is to unregister program/erase's callback function.

参数:

sfc_port -- is flash sfc port

返回:

WQ_RET WQ_RET_OK for success else error.

bool wq_flash_is_pe_in_progress(WQ_SFC_PORT sfc_port)

This function is to get wheter program/erase is in progress.

参数:

sfc_port -- is flash sfc port

返回:

bool is true when run program/erase command.

void wq_flash_set_deep_power_down_mode(WQ_SFC_PORT sfc_port)

This function is to set deep power down mode for power save.

参数:

sfc_port -- is flash sfc port

void wq_flash_exit_deep_power_down_mode(WQ_SFC_PORT sfc_port)

This function is to release deep power down mode for power save.

参数:

sfc_port -- is flash sfc port

void wq_flash_wait_wip(WQ_SFC_PORT sfc_port)

This function is to wait flash wip done.

参数:

sfc_port -- is flash sfc port

uint8_t wq_flash_lock_mode_get(void)

This function is to get flash lock mode.

返回:

return current lock mode

void wq_flash_lock_mode_set(uint8_t lock_mode)

This function is to release deep power down mode for power save.

参数:

lock_mode -- is seting flash lock mode