FLASH使用参考

Version 0.1


1. 概述

Onebin架构上线后,flash接口统一,nor flash与nand flash读写擦使用接口一致,根据product config中不同的指定去编译不同的flash驱动。

flash初始化流程已经加入rtos启动流程中,后续使用可直接根据应用需要调用对应的Flash API。

SDK默认使用NOR的配置,如果需要使用NAND,请修改相应product config选项为CONFIG_STORAGE_NAND_ONEBIN = TRUECONFIG_STORAGE_NOR_ONEBIN = FALSE,这个配置下将会编译nandflash驱动。

NOR FLASH驱动路径:rtk/proj/sc/driver/sysdriver/norflash

NAND FLASH驱动路径:rtk/proj/sc/driver/sysdriver/nandflash


2. API


2.1. Flash API

#include “mdrvFlash.h”

READ:

U32 MDRV_FLASH_read(U32 u32_bytes_offset, U32 u32_limit, U32 u32_address, U32 u32_size);

@u32_bytes_offset:The offset of the flash

@u32_limit:Limits the maximum read range

@u32_address:destination address

@u32_size:The size to read

@return:Failure returns 0,Success returns the size of the read

WRITE:

Will not skip bad block:

U32 MDRV_FLASH_write_pages(U32 u32_bytes_offset, U32 U32_address, U32 u32_size);

@u32_bytes_offset:The offset of the flash

@u32_address: source address

@u32_size:The size to write

@return:Failure returns 0,Success returns the size of the write

Should skip bad block:

U32 MDRV_FLASH_write_parts(U32 u32_bytes_offset, U32 u32_limit, U32 u32_address, U32 u32_size);

@u32_bytes_offset:The offset of the flash

@u32_limit:Limits the maximum write range

@u32_address: source address

@u32_size:The size to write

@return:Failure returns 0,Success returns the size of the write

ERASE:

U32 MDRV_FLASH_erase(U32 u32_bytes_offset, U32 u32_size);

@u32_bytes_offset:The offset of the flash

@u32_size:The size to write

@return:Failure returns 0,Success returns the size of the erase


#include “mdrvParts.h”

获取分区信息:

遍历pni,找到partition name相匹配的,并且是active
U8 MDRV_PARTS_get_active_part(U8 *pu8_PartName, PARTS_INFO_t *pst_PartInfo);

@pu8_PartName:Partition name

@pst_PartInfo:The location where partition information is stored

@return:Failure returns 0,Returns 1 on success

遍历pni,找到partition name相匹配的,并且Trubk匹配(名称相同时,使用Trubk区分)
U8 MDRV_PARTS_get_part(U8 *pu8_PartName, U8 u8_Trunk, PARTS_INFO_t *pst_PartInfo);

@pu8_PartName:Partition name

@pst_PartInfo:The location where partition information is stored

@u8_Trunk:partition ID

@return:Failure returns 0,Returns 1 on success

修改active Partition

void MDRV_PARTS_mark_active(U8 *pu8_PartName, U8 u8_Trunk);

@pu8_PartName:Partition name

@u8_Trunk:partition ID

PARTS write:

U32 MDRV_PARTS_program_part(PARTS_INFO_t *pst_PartInfo, U32 u32_address, U32 u32_size);

@pst_PartInfo:The location where partition information is stored

@u32_address:source address

@u32_size:The size to write

@return:Failure returns 0,Success returns the size of the write

2.2. 实例

内容:


3. 常见问题

问题:

flash读取时间太长

排查方法:

  1. 在flast_list.nri,检查是否enable quad mode,且最大clk是否设置86M,默认是54M

  2. 检查api入参,flash addr是否是16对齐,dram addr是否是64对齐。如果可以,两者都做64对齐,不行至少都做16对齐。