FLASH (eFLASH控制器)

简介

Flash 控制器可管理任何主设备通过 AXI 接口对 Flash 进行读取、编程操作,并实施读取和编程/擦除保护机制。

Flash 接口可管理 CPU 通过 APB 接口对 Flash Main 空间进行擦除。

功能概述

  • PFLASH 存储容量为 512 KB,分为 512 个扇区,每个扇区1024字节

  • 支持ECC (Error Code Correction)

  • 支持双字、字、半字和字节读操作

  • 支持双字编程操作

  • 支持扇区擦除、片擦除

  • 支持 Flash Main 读/写/擦保护功能

  • 支持全片安全擦除保护功能

  • 支持总线预取功能,预期深度为128字节

  • 支持 Flash 低功耗模式

  • PFLASH 支持双存储区同时操作

  • PFLASH 支持存储区交换

  • DFLASH 存储容量为 128KB,分为 128 个扇区,每个扇区1024字节

BANK SWAP功能

BANK SWAP功能允许用户通过软件配置交换PFLASH的两个存储区的位置。启用BANK SWAP后,原先的存储区A将映射到高地址区域,而存储区B将映射到低地址区域。 这对于某些应用场景,如固件升级或双重引导系统,提供了更大的灵活性和安全性。

详细信息请参阅: Flash功能配置

备注

该功能只在支持双Bank的芯片上有效,如ET6001、ET6002、ET6039等,不支持双Bank的芯片如ET6015x、ET6013x等

软件配置流程

  1. 解锁寄存器 调用 FLASH_unlockRegister() 进行寄存器写保护解锁

  2. 失能写保护 调用 FLASH_disableWriteProtect() 进行写保护失能

  3. 擦除

    备注

    注意代码存储位置,若擦除到代码区域,会导致代码无法正常运行

  4. 写数据 调用 FLASH_programming() 传入相关参数

  5. 操作结束,重新上锁 调用 FLASH_enableWriteProtect() 传入PFLASHx进行写保护; 调用 FLASH_lockRegister() 传入PFLASHx进行寄存器上锁

注意

当Flash进入到DPD模式后,软件需禁止对Flash Main 空间的读写操作。建议进入DPD模式后,使能FLash写保护。

应用示例

API Reference

Header File

Functions

DRV_Status FLASH_unlockRegister(FLASH_Type *FLASHx)

unlock flash register

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status FLASH_lockRegister(FLASH_Type *FLASHx)

lock pflash register

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status

DRV_Status FLASH_enableWriteProtect(FLASH_Type *FLASHx)

lock flash data write protect

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status

DRV_Status FLASH_disableWriteProtect(FLASH_Type *FLASHx)

unlock flash data write protect

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status

bool FLASH_isBusy(FLASH_Type *FLASHx)

Wait for the operation to complete, and get the status when completed.

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

DRV_Status FLASH_eraseChip(FLASH_Type *FLASHx)

Perform a chip erase,for the flash which needs to be operated.

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

DRV_Status FLASH_eraseSector(FLASH_Type *FLASHx, uint32_t sectorNum, bool retry)

Perform sector erase.

参数:
  • FLASHx – for the flash which needs to be operated

  • sectorNum – sector number (0-511,when pflash; 0-127,when dflash)

  • retry – use retry erase or not

DRV_Status FLASH_programming(FLASH_Type *FLASHx, uint64_t *addr, uint64_t *data, uint32_t len)

Write dword to flash.

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • addr – start address to write data, Addr must be align by 8

  • data – data to write to flash

  • len – write data length(dword),be careful not to exceed the data range in data

返回:

Operation success or fail

bool FLASH_isSectorBlank(FLASH_Type *FLASHx, uint32_t sectorNum)

Check whether flash sector is blank.

参数:
  • FLASHx – Pointer to the FLASH peripheral.

  • sectorNum – sector index

返回:

bool blank or not

bool FLASH_getRedundancySectorStatus(FLASH_Type *FLASHx, FLASH_SectorRDNIdx index, uint32_t *sectorNum)

whether the rdn sector replaces unusable flash sector

参数:
  • FLASHx – controller of Corresponding pflash

  • index – rdn sector number

  • sectorNum – output parameter,if return value is EFC_RDN_REPLACE.

返回:

bool false:rdn sector is not in use; true: rdn sector is in used

DRV_Status FLASH_setRedundancySector(FLASH_Type *FLASHx, FLASH_SectorRDNIdx index, uint32_t sectorNum)

replace flash sector with redundancy sector

参数:
  • FLASHx – controller of Corresponding pflash

  • index – the redundancy sector index (0 or 1)

  • sectorNum – the sector num to be replaced

返回:

DRV_Status DRV_OK: success; DRV_ERROR: failure

void FLASH_enableCache(FLASH_Type *FLASHx)

Enable cache of flash.

参数:

FLASHx – Pointer to the FLASH peripheral.

void FLASH_disableCache(FLASH_Type *FLASHx)

Disable cache of flash.

参数:

FLASHx – Pointer to the FLASH peripheral.

void FLASH_enableInterrupt(FLASH_Type *FLASHx, uint32_t ITmask)

Enable flash interrupt.

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • ITmask – Interrupt type selection

void FLASH_disableInterrupt(FLASH_Type *FLASHx, uint32_t ITmask)

Disable flash interrupt.

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • ITmask – Interrupt type selection

void FLASH_setInterruptMask(FLASH_Type *FLASHx, uint32_t ITmask)

mask flash interrupt

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • ITmask – Interrupt type selection

void FLASH_clearInterruptStatus(FLASH_Type *FLASHx, uint32_t ITmask)

Clear flash interrupt.

参数:

ITmask – Interrupt type selection

void FLASH_clearInterruptMask(FLASH_Type *FLASHx, uint32_t ITmask)

clear flash interrupt

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • ITmask – Interrupt type selection

uint32_t FLASH_getInterruptStatus(FLASH_Type *FLASHx)

Get flash interrupt status.

返回:

uint32_t Interrupt type selection

DRV_Status FLASH_unlockNVRRegister(FLASH_Type *FLASHx)

unlock nvr zone register

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status FLASH_lockNVRRegister(FLASH_Type *FLASHx)

lock nvr zone register

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

返回:

DRV_Status

DRV_Status FLASH_eraseNVRSector(uint32_t sectorNum, bool retry)

Perform nvr sector erase.

参数:
  • sectorNum – sector number (0-11)

  • retry – use retry erase or not

返回:

DRV_Status DRV_OK: success; DRV_ERROR: failure

DRV_Status FLASH_programmingNVRSector(uint32_t addr, uint64_t *data, uint32_t len)

Write DoubleWord to dflash nvr sector.

参数:
  • addr – start address to write data,Address must be divisible by 8

  • data – data address

  • len – write data length(DoubleWord),be careful not to exceed the data range in dataAddr

返回:

Operation success or fail

DRV_Status FLASH_readNVRSector(uint32_t addr, uint64_t *data, uint32_t len)

Read DoubleWord from dflash nvr sector.

参数:
  • addr – start address to Read data,Address must be divisible by 8

  • data – Output parameter,which hold the data you read.

  • len – Read data length(DoubleWord),be careful not to exceed the data range in data

返回:

Operation success or fail

void FLASH_enableECC(FLASH_Type *FLASHx, FLASH_Zone area)

Enable Flash ECC function.

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • area – FLASH area

    • FLASH_ZONE_MAIN

    • FLASH_ZONE_NVR

void FLASH_disableECC(FLASH_Type *FLASHx, FLASH_Zone area)

Disable Flash ECC function.

参数:
  • FLASHx – Flash peripheral[PFLASH0,PFLASH1, DFLASH]

  • area – FLASH area

    • FLASH_ZONE_MAIN

    • FLASH_ZONE_NVR

void FLASH_enableECCTest(FLASH_Type *FLASHx, FLASH_ECCConfigParams *eccErrorInit)

Enable Manual ECC error injection.

参数:
  • FLASHx – Flash peripheral[PFLASH0:1, DFLASH]

  • eccErrorInit – ECC error inject struct

void FLASH_disableECCTest(FLASH_Type *FLASHx)

Disable Manual ECC error injection.

参数:

FLASHx – Flash peripheral[PFLASH0,PFLASH1,DFLASH]

Structures

struct FLASH_ECCConfigParams

FLASH ECC Inject Init Struct.

Macros

PFLASH0_START_ADDR
PFLASH1_START_ADDR
DFLASH_START_ADDR
PFLASH_SEC_NUM
DFLASH_SEC_NUM
DFLASH_NVR_SEC_NUM
FLASH_SECTOR_SIZE
FLASH_ALIGN_SIZE
FLASH_IT_ERASE_DONE_MASK

EFC interrupt bit mask define.

FLASH_IT_RETRY_ERASE_DONE_MASK
FLASH_IT_NVR_WR_DONE_MASK
FLASH_IT_WRP_ERR_MASK
FLASH_IT_PGS_ERR_MASK
FLASH_IT_STRB_ERR_MASK
FLASH_IT_INC_ERR_MASK
FLASH_IT_NVR_ECC_1BIT_ERR_MASK
FLASH_IT_NVR_ECC_2BIT_ERR_MASK
FLASH_IT_ECC_1BIT_ERR_MASK
FLASH_IT_ECC_2BIT_ERR_MASK
FLASH_IT_BOOT_TIMEOUT_MASK
FLASH_IT_GATING_APB_ERR_MASK
FLASH_IT_RST_APB_ERR_MASK
FLASH_IT_GATING_AXI_ERR_MASK
FLASH_IT_RST_AXI_ERR_MASK
FLASH_IT_AXI_CMD_ERR_MASK

Enumerations

enum FLASH_Zone

Flash zone type. DFLASH have two zones.

Values:

enumerator FLASH_ZONE_MAIN
enumerator FLASH_ZONE_NVR
enum FLASH_SectorRDNIdx

Flash RDN sector Number. Each Flash has 2 redundant sectors.

Values:

enumerator FLASH_SECTOR_RDN_IDX0
enumerator FLASH_SECTOR_RDN_IDX1
enum FLASH_ECCErrorType

FLASH ECC error type.

Values:

enumerator FLASH_ECC_1BIT_ERROR
enumerator FLASH_ECC_2BIT_ERROR
enumerator FLASH_ECC_MULT_BIT_ERROR