KDocs 研发资料库
  • 手表穿戴技术应用文档入口汇总
  • JL707N穿戴客述问题FAQ
  • 彩屏仓 硬件开发指南 与 量产作业流程规范
  • 彩屏仓 AC98N和JL701烧录升级注意事项
  • JL707 硬件开发资料
  • JL707 手表硬件设计注意事项 总结
  • 穿戴生产烧录OTA和key文件添加使用说明
  • JL707N-入门到进阶开发指导文档
  • 彩屏仓982相关
  • 彩屏仓耳机介绍
  • 杰理701_707双屏demo介绍
  • 707电子吧唧开发资料
  • GPIO相关
  • UART串口相关
  • SPI相关
  • nandflash相关
  • norflash相关
  • IIC相关
  • PWM相关
  • SD卡相关
  • 定时器TIMER
  • 文件系统接口设计说明文档
  • 音视频录像开发流程
  • rdec编码器
  • 穿戴功耗数据标准
  • 手表蓝牙开发文档
  • 701蓝牙PAN联网demo
  • BLE开发使用说明
  • 701手表2.0.0版本SDK EQ在线调试和离线调试方法 V1.1
  • JL707 手表喇叭输出声音大小评估方法 V1.0
  • JL707 手表音频EQ调试方法 V1.0
  • AC707N 手表通话写卡 软件配置方法
  • 录音功能
  • 701手表2.X.X系列SDK调试EQ配置方法及音频调试技巧V1.1
  • 701手表104版本SDK EQ在线调试和离线调试方法 V1.1
  • mic2dac示例
  • P11 SensorHub相关
  • 手表升级操作文档
  • AC707NGPU
  • DBI模块介绍
  • GPU模块介绍
  • 701N屏幕驱动配置说明
  • 701N_UI编辑工具用户手册
  • 支付宝资料
  • 支付宝硬件接入资料
  • 支付宝乘车码接入资料
  • CAT1 接入文档
  • 701N_WATCH_CAT1开发说明
  • Findmy功能
  • music模式相关
  • 707电池曲线
  • 707N内置FLASH挂载FAT文件系统251112_v1.2
  • AC707N_本地视频播放demo(AVI-MJPEG-PCM)
  • 光波导屏幕调试
  • 耳机研发和生产流程 指南
  • 707-NandFlash 代码和UI资源独立烧录方案
  • 彩屏仓时间同步补丁
  • 彩屏仓抖音点赞移植
  • 707LVGLv8双屏开发
  • 707N蓝牙互传图传demo
  • AVIPCM数据流接入AIVOICE
  • Flash分区操作demo
  • 手表发射问题
  • 701_707 双备份升级DEMO
  • 707_乘车码刷码失败问题_共性

707N内置FLASH挂载FAT文件系统251112_v1.2

📎 原始文档:https://www.kdocs.cn/l/chaAz3bVwllc

1、划分分区BASE地址和大小

image

2、配置挂载分区信息

image

3、添加挂载分区

image

4、打开宏TCFG_NOR_FAT

image

5、添加读写驱动ops

①、文件地址:

D:\working_space\707N_watch_git\watch_git_ 250109\SDK\apps\common\include\norflash_sfc.h 新增:
extern const struct device_operations inside_norflash_fat_fs_dev_ops ;
image ②、文件地址:
D:\working_space\707N_watch_git\watch_git_ 250109\SDK\apps\common\device\storage_device\norflash\inside_norflash.c
整个inside_norflash.c文件进行替换
将以下内容直接覆盖到上述文件路径,进行整文件的替换
【金山文档 | WPS云文档】 inside_norflash(250711_v1 . 1)
https://www.kdocs.cn/l/chL3Z5sX5NJ7
image #include "includes .h "
#include "app_config .h "
#include "norflash_sfc .h "
#include "tzflash_api .h "
#undef LOG_TAG_CONST
#define LOG_TAG " [FLASH_INDIDE] "
#define LOG_ERROR_ENABLE
#define LOG_INFO_ENABLE
#include "debug .h "
/* extern void sfc_protect_lock(u8 index) ; /
/
extern void sfc_protect_release(u8 index) ; */
#define norflash_mutex_init() //
#define norflash_mutex_enter() //sfc_protect_lock(0)
#define norflash_mutex_exit() //sfc_protect_release(0)
extern void ble_busy_wait_idle(u8 type) ;
static struct list_head head = LIST_HEAD_INIT(head) ;
#define USER_FAT_DEBUG_ENABLE 0
#if USER_FAT_DEBUG_ENABLE
#define debug_printf( . . .) printf( VA_ARGS )
#else
#define debug_printf( . . .)
#endif //endif USER_FAT_DEBUG_ENABLE struct norflash_partition {​
struct list_head entry;
const char *name ;
u32 start_addr ;
image u32 size ;
u8 igore_overlaps; //忽略分区检查
struct device device ;
​} ;
static OS_MUTEX inside_norflash_mutex;
#define inside_nor_flash_mutex_init() os_mutex_create(&inside_norflash_mutex) ;#define inside_norflash_mutex_lock() os_mutex_pend(&inside_norflash_mutex , 0) ;
#define inside_norflash_mutex_unlock() os_mutex_post(&inside_norflash_mutex) ; static struct norflash_partition *norflash_find_part(const char *name)
{​
struct norflash_partition *p , *n ;
local_irq_disable() ;
list_for_each_entry_safe(p , n , &head , entry) {​
if (!strcmp(p->name , name)) {​
local_irq_enable() ;
return p ;
​}
​}
local_irq_enable() ;
return NULL ;​}
static struct norflash_partition *norflash_new_part(const char *name , u32 addr , u32 size , u8 igore_overlap)
{​
struct norflash_partition *part = zalloc(sizeof(struct norflash_partition)) ; ASSERT(part , "norflash_partition malloc err ") ;
part->name = name ;
part->start_addr = addr ;
part->size = size ;
part->igore_overlaps = igore_overlap ;
local_irq_disable() ;
list_add_tail(&part->entry , &head) ;
local_irq_enable() ;
return part ;​}
static void norflash_delete_part(const char *name)
{​
struct norflash_partition *p , *n ;
local_irq_disable() ;
list_for_each_entry_safe(p , n , &head , entry) {​
if (!strcmp(p->name , name)) {​
list_del(&p->entry) ;
free(p) ;
local_irq_enable() ;
return ;
​}
​}
local_irq_enable() ;
return ;​}
static int norflash_verify_part(struct norflash_partition *p){​
image if (p->igore_overlaps) {​
return 0 ;​}
struct norflash_partition *part , *n ;
local_irq_disable() ;
list_for_each_entry_safe(part , n , &head , entry) {​
if (part->igore_overlaps) {​
continue ;
​}
if ((p->start_addr >= part->start_addr) && (p->start_addr < part-> start_addr + part->size)) {​
if (strcmp(p->name , part->name) != 0) {​
return -1;
​}
​}
​}
local_irq_enable() ;
return 0 ;​}
extern u32 sdfile_flash_addr2cpu_addr(u32 offset) ;
extern u32 sdfile_cpu_addr2flash_addr(u32 offset) ;
static int _norflash_init(const char *name , struct norflash_sfc_dev_platform_data *pdata)
{​
log_info( "norflash_sfc_init >>>> ") ;
if (pdata->path) {​
FILE *fp = fopen((const char *)pdata->path , " r ") ;
if (!fp) {​
log_error( "fopen err :%s \n " , pdata->path) ;
ASSERT(0) ;
return false ;
​}
struct vfs_attr attr = {​0​} ;
fget_attrs(fp , &attr) ;
u32 part_addr = attr .sclust ;
u32 part_len = attr .fsize ;
part_addr = sdfile_cpu_addr2flash_addr(part_addr) ;
ASSERT(pdata->start_addr == part_addr , "%x %x\n " , pdata->start_addr , part_addr) ;
ASSERT(part_len <= pdata->size , "%x ,%x\n " , pdata->start_addr , part_addr) ;
fclose(fp) ;​}
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {​
part = norflash_new_part(name , pdata->start_addr , pdata->size , pdata-> igore_overlaps) ;
ASSERT(part , "not enough norflash partition memory in array\n ") ;
image ASSERT(norflash_verify_part(part) == 0 , "norflash partition %s overlaps\n " , name) ;
log_info( "norflash new partition %s\n " , part->name) ;​} else {​
ASSERT(0 , "norflash partition name already exists\n ") ;​}
return 0 ;​}
static int norflash_sfc_fs_dev_init(const struct dev_node *node , void *arg){​
struct norflash_sfc_dev_platform_data *pdata = arg ;
return _norflash_init(node->name , pdata) ;​}
static int norflash_sfc_fs_dev_open(const char *name , struct device **device , void *arg)
{​
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {​
log_error( "no norflash partition is found\n ") ;
return -ENODEV;​}
*device = &part->device ;
(*device)->private_data = part ;
if (atomic_read(&part->device . ref)) {​
return 0 ;​}
return 0;//_norflash_open(arg) ;​}
static int norflash_sfc_fs_dev_close(struct device *device){​
return 0;//_norflash_close() ;​}
static int norflash_sfc_fs_dev_read(struct device *device , void *buf , u32 len , u32 offset)
{​
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
int reg ;
struct norflash_partition *part ;
part = (struct norflash_partition *)device->private_data;
if (!part) {​
log_error( "norflash partition invalid\n ") ;
return -EFAULT;​}
if (offset + len > part->size) {​
log_error( " func %s %x %x %x\n " , func , rets , offset , len) ;
ASSERT(0) ;​}
image offset += part->start_addr ;
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;///20250217
u32 cpu_addr = sdfile_flash_addr2cpu_addr(offset) ;
memcpy((u8 *)buf , (u8 *)cpu_addr , len) ;
inside_norflash_mutex_unlock() ;///20250217
norflash_mutex_exit() ;
return len ;​}
static int norflash_sfc_fs_dev_write(struct device *device , void *buf , u32 len , u32 offset)
{​
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
int reg = 0 ;
// printf( "norflash_sfc_fs_dev_write %x %x %x\n " , rets , offset , len) ;
struct norflash_partition part = device->private_data;
if (!part) {​
log_error( "norflash partition invalid\n ") ;
return -EFAULT;​}
if (offset + len > part->size) {​
log_error( " func %s %x %x %x\n " , func , rets , offset , len) ;
ASSERT(0) ;​}
offset += part->start_addr ;
/
norflash_mutex_enter() ; /
ASSERT(!cpu_in_irq()) ;
ASSERT(!cpu_irq_disabled()) ;
reg = tzflash_write(buf , len , offset);//写操作里面已经集合的互斥,这里仅仅检查中断
/
norflash_mutex_exit() ; */
return reg ;
​}
static bool norflash_sfc_fs_dev_online(const struct dev_node *node){​
return 1;​}
static int norflash_sfc_fs_dev_ioctl(struct device *device , u32 cmd , u32 arg){​
u32 rets;// , reti ;
asm volatile( "%0 = rets " : "= r " (rets)) ;
debug_printf( "%s , decvice 0000 = %x , cmd = %x , arg = %x\n " , func , device , cmd , arg) ;
struct norflash_partition *part = device->private_data;
debug_printf( "%s , decvice 1111 = %x , cmd = %x , arg = %x\n " , func , device , cmd , arg) ;
struct sfc_no_enc_wr *no_enc_wr ;
int reg = 0 ;
if (!part) {​
log_error( "norflash partition invalid\n ") ;
return -EFAULT;​}
debug_printf( "cmd = %d\n " , cmd) ;
image switch (cmd) {​
case IOCTL_GET_PART_INFO:
u32 *info = (u32 *)arg ;
u32 *start_addr = &info [0 ] ;
u32 *part_size = &info [ 1 ] ;
*start_addr = part->start_addr ;
*part_size = part->size ; break;
case IOCTL_GET_CAPACITY :

  • (u32 *)arg = part->size ;
    break;
    case IOCTL_ERASE_PAGE :
    ASSERT(!cpu_in_irq()) ;
    ASSERT(!cpu_irq_disabled()) ;
    //写操作里面已经集合的互斥,这里仅仅检查中断
    #if TCFG_FLASH_ERASE_WAIT_BLE
    //擦除前需等待ble idle
    ble_busy_wait_idle(IOCTL_ERASE_PAGE) ;#endif
    return tzflash_ioctl(cmd , arg + part->start_addr) ;
    break;
    case IOCTL_ERASE_SECTOR :
    if ((arg * 1) + 4096 > part->size) {​
    log_error( " func %s %x %x %x\n " , func , rets , arg , 1) ; ASSERT(0) ;
    ​}
    ASSERT(!cpu_in_irq()) ;
    ASSERT(!cpu_irq_disabled()) ;#if TCFG_FLASH_ERASE_WAIT_BLE
    //擦除前需等待ble idle
    ble_busy_wait_idle(IOCTL_ERASE_SECTOR) ;#endif
    //写操作里面已经集合的互斥,这里仅仅检查中断
    return tzflash_ioctl(cmd , arg + part->start_addr) ;
    break;
    case IOCTL_ERASE_BLOCK :
    if ((arg * 1) + (64 * 1024) > part->size) {​
    log_error( " func %s %x %x %x\n " , func , rets , arg , 1) ; ASSERT(0) ;
    ​}
    ASSERT(!cpu_in_irq()) ;
    ASSERT(!cpu_irq_disabled()) ;#if TCFG_FLASH_ERASE_WAIT_BLE
    //擦除前需等待ble idle
    ble_busy_wait_idle(IOCTL_ERASE_BLOCK) ;#endif
    //写操作里面已经集合的互斥,这里仅仅检查中断
    return tzflash_ioctl(cmd , arg + part->start_addr) ;
    break;
    #if 0
    case IOCTL_SFC_NORFLASH_READ_NO_ENC:
    no_enc_wr = (struct sfc_no_enc_wr *)arg ;
    norflash_mutex_enter() ;
    u32 cpu_addr = sdfile_flash_addr2cpu_addr(no_enc_wr->addr) ;
    image memcpy((u8 *)no_enc_wr->buf , (u8 *)cpu_addr , no_enc_wr->len) ;
    norflash_mutex_exit() ;
    reg = 0 ;
    break;
    case IOCTL_SFC_NORFLASH_WRITE_NO_ENC:
    no_enc_wr = (struct sfc_no_enc_wr )arg ;
    /
    norflash_mutex_enter() ; /
    ASSERT(!cpu_in_irq()) ;
    ASSERT(!cpu_irq_disabled()) ;
    //写操作里面已经集合的互斥,这里仅仅检查中断
    reg = tzflash_write(no_enc_wr->buf , no_enc_wr->len , no_enc_wr->addr) ;
    /
    norflash_mutex_exit() ; */
    break;
    #endif
    case IOCTL_FLUSH :
    break;
    default :
    return tzflash_ioctl(cmd , arg) ;
    ​}
    return reg ;​}

//按1字节单位读写

const struct device_operations inside_norflash_fs_dev_ops = {​
.init = norflash_sfc_fs_dev_init ,
.online = norflash_sfc_fs_dev_online ,
.open = norflash_sfc_fs_dev_open ,
. read = norflash_sfc_fs_dev_read ,
.write = norflash_sfc_fs_dev_write ,
.ioctl = norflash_sfc_fs_dev_ioctl ,
.close = norflash_sfc_fs_dev_close ,​} ;
#define FLASH_CACHE_ENABLE 1
#if FLASH_CACHE_ENABLE
static u32 flash_cache_addr ;
static u8 *flash_cache_buf = NULL ; //缓存4K的数据,与flash里的数据一样。
static u8 flash_cache_is_dirty;
static u16 flash_cache_timer ;
#define FLASH_CACHE_SYNC_T_INTERVAL 60
#endif
static int norflash_fat_fs_dev_init(const struct dev_node *node , void *arg){​
inside_nor_flash_mutex_init() ;
struct norflash_sfc_dev_platform_data *pdata = arg ;
int ret = _norflash_init(node->name , pdata) ;
return ret ;​}
image static int norflash_fat_fs_dev_open(const char *name , struct device **device , void *arg)
{​
struct norflash_partition *part ;
part = norflash_find_part(name) ;
if (!part) {​
log_error( "no norflash partition is found\n ") ;
return -ENODEV;​}
*device = &part->device ;
(device)->private_data = part ;
if (atomic_read(&part->device . ref)) {​
return 0 ;
​}#if FLASH_CACHE_ENABLE
/
ASSERT(flash_cache_buf , "flash_cache_buf is not only\n ") ; */
if(!flash_cache_buf){​
flash_cache_buf = (u8 *)malloc(4096) ;
flash_cache_addr = 4096;//先给一个大于4096的数​}
norflash_sfc_fs_dev_read(*device , flash_cache_buf ,4096 ,0) ;
flash_cache_addr = 0 ;#endif
return 0;//_norflash_open(arg) ;​}
static int norflash_fat_fs_dev_close(struct device device){​
#if FLASH_CACHE_ENABLE
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;
if (flash_cache_is_dirty) {​
flash_cache_is_dirty = 0 ;
norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ; norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
/
_norflash_sfc_ioctl_eraser(IOCTL_ERASE_SECTOR , flash_cache_addr) ; /
/
_norflash_write_pages(flash_cache_addr , flash_cache_buf , 4096) ; /
​}
inside_norflash_mutex_unlock() ;
norflash_mutex_exit() ;
/
free(flash_cache_buf) ; /
/
flash_cache_buf = NULL ; */
#endif
image static int norflash_fat_fs_dev_read(struct device *device , void buf , u32 len , u32 addr)
{​
int org_len = len ;#if FLASH_CACHE_ENABLE
addr = addr * 512 ;
len = len * 512 ;
debug_printf( "norflash_fat_fs_dev_read 000000000000 %x %x\n " , addr , len) ;
norflash_mutex_enter() ;
inside_norflash_mutex_lock() ;
debug_printf( "norflash_fat_fs_dev_read 1111111111111111 %x %x\n " , addr , len) ; u32 r_len = 4096 - (addr % 4096) ;
if ((addr >= flash_cache_addr) && (addr < (flash_cache_addr + 4096))) {​ if (len <= r_len) {​
memcpy(buf , flash_cache_buf + (addr - flash_cache_addr) , len) ;
/
int ret = len ; /
inside_norflash_mutex_unlock() ;
norflash_mutex_exit() ;
goto exit ;
​} else {​
memcpy(buf , flash_cache_buf + (addr - flash_cache_addr) , r_len) ;
addr += r_len ;
buf += r_len ;
len - = r_len ;
​}
​}
inside_norflash_mutex_unlock() ;
debug_printf( "norflash_fat_fs_dev_read 222222222222222 %x %x\n " , addr , len) ; norflash_mutex_exit() ;
norflash_sfc_fs_dev_read(device , buf , len ,addr) ;
#else
norflash_sfc_fs_dev_read(device , buf , len ,addr) ;#endif
exit :
return org_len ;​}
#if FLASH_CACHE_ENABLE
static void _norflash_cache_sync_timer(struct device device){​
norflash_mutex_enter() ;
debug_printf( "%s 000000000000 \n " , func ) ;
inside_norflash_mutex_lock() ;
debug_printf( "%s 11111111111 \n " , func ) ;
int reg = 0 ;
if (flash_cache_is_dirty) {​
flash_cache_is_dirty = 0 ;
/
reg = _norflash_sfc_ioctl_eraser(IOCTL_ERASE_SECTOR , flash_cache_addr) ; /
debug_printf( "aaaaaaaaaaaaaaaa ") ;
image reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
debug_printf( "bbbbbbbbbbbbbbb ") ;
if (reg == -EFAULT) {​
goto exit ;
​}
debug_printf( "cccccccccccccccccc ") ;
/
reg = _norflash_write_pages(flash_cache_addr , flash_cache_buf , 4096) ;
/
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
debug_printf( "ddddddddddddddd ") ;
​}
if (flash_cache_timer) {​
sys_timeout_del(flash_cache_timer) ;
flash_cache_timer = 0 ;
​}
exit :
inside_norflash_mutex_unlock() ;
debug_printf( "%s 22222222222 \n " , func ) ;
norflash_mutex_exit() ;
return ;
​}
#endif
struct device *device_test ;
static int norflash_fat_fs_dev_write(struct device *device , void *buf , u32 len , u32 addr)
{​
norflash_mutex_enter() ;
debug_printf( "%s 000000000000 \n " , func ) ;
inside_norflash_mutex_lock() ;
debug_printf( "%s 111111111111 \n " , func ) ;
int org_len = len ;#if FLASH_CACHE_ENABLE
u8 *w_buf = (u8 )buf;
u32 w_len = len * 512 ;
addr = addr * 512 ;
// len = len * 512 ;
int reg ;
u32 align_addr = addr / 4096 * 4096 ;
u32 align_len = 4096 - (addr - align_addr) ;
align_len = w_len > align_len ? align_len : w_len ;
device_test = device ;
if (align_addr != flash_cache_addr) {​
if (flash_cache_is_dirty) {​
flash_cache_is_dirty = 0 ;
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
if (reg == -EFAULT) {​
line_inf;
goto exit ;
​}
image /
reg = _norflash_write_pages(flash_cache_addr , flash_cache_buf ,
4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,flash_cache_addr) ;
if (reg != 4096) {​
line_inf;
goto exit ;
​}
​}
/
fat_sfc_norflash_read(align_addr , flash_cache_buf , 4096 , 0) ; /
norflash_sfc_fs_dev_read(device ,flash_cache_buf ,4096 ,align_addr) ;
flash_cache_addr = align_addr ;
​}
memcpy(flash_cache_buf + (addr - align_addr) , w_buf , align_len) ;
if ((addr + align_len) % 4096) {​
flash_cache_is_dirty = 1;
if (flash_cache_timer) {​
sys_timer_re_run(flash_cache_timer) ;
​} else {​
flash_cache_timer = sys_timeout_add(device_test ,
_norflash_cache_sync_timer , FLASH_CACHE_SYNC_T_INTERVAL) ;///12343
​}
​} else {​
flash_cache_is_dirty = 0 ;
/
reg = norflash_sfc_fs_dev_ioctl(IOCTL_ERASE_SECTOR , align_addr) ; /
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , align_addr) ; if (reg == -EFAULT ) {​
line_inf;
goto exit ;
​}
/
reg = _norflash_write_pages(align_addr , flash_cache_buf , 4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,align_addr) ; if (reg != 4096) {​
line_inf;
goto exit ;
​}
​}
addr += align_len ;
w_buf += align_len ;
w_len - = align_len ;
while (w_len) {​
u32 cnt = w_len > 4096 ? 4096 : w_len ;
/
fat_sfc_norflash_read(addr , flash_cache_buf , 4096 , 0) ; /
norflash_sfc_fs_dev_read(device ,flash_cache_buf ,4096 ,align_addr) ;
flash_cache_addr = addr ;
memcpy(flash_cache_buf , w_buf , cnt) ;
if ((addr + cnt) % 4096) {​
flash_cache_is_dirty = 1;
if (flash_cache_timer) {​
sys_timer_re_run(flash_cache_timer) ;
​} else {​
flash_cache_timer = sys_timeout_add(device_test ,_norflash_cache_sync_timer , FLASH_CACHE_SYNC_T_INTERVAL) ;
​}
​} else {​
flash_cache_is_dirty = 0 ;
image /
reg = norflash_sfc_fs_dev_ioctl(IOCTL_ERASE_SECTOR , addr) ; /
reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , addr) ; if (reg == -EFAULT) {​
line_inf;
goto exit ;
​}
/
reg = _norflash_write_pages(addr , flash_cache_buf , 4096) ; /
reg = norflash_sfc_fs_dev_write(device , flash_cache_buf ,4096 ,addr) ; if (reg != 4096) {​
line_inf;
goto exit ;
​}
​}
addr += cnt ;
w_buf += cnt ;
w_len - = cnt ;
​}
#else
/
reg = _norflash_write_pages(addr , w_buf , w_len) ; */
reg = norflash_sfc_fs_dev_write(device , w_buf ,w_len ,addr) ;#endif
exit :
inside_norflash_mutex_unlock() ;
debug_printf( "%s 222222222222 \n " , func ) ;
norflash_mutex_exit() ;
return org_len ;​}
static bool norflash_fat_fs_dev_online(const struct dev_node *node){​
return 1;​}
static int norflash_fat_fs_dev_ioctl(struct device *device , u32 cmd , u32 arg){​
struct norflash_partition *part = device->private_data;
switch(cmd){​
case IOCTL_GET_STATUS:

  • (u32 )arg = 1;
    break;
    case IOCTL_ERASE_SECTOR :
    int reg = norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , arg
    512) ;
    return reg ;
    break;
    case IOCTL_FLUSH :
    norflash_mutex_enter() ;
    inside_norflash_mutex_lock() ;
    if (flash_cache_is_dirty) {​
    flash_cache_is_dirty = 0 ;
    norflash_sfc_fs_dev_ioctl(device , IOCTL_ERASE_SECTOR , flash_cache_addr) ;
    image norflash_sfc_fs_dev_write(device ,
    flash_cache_buf ,4096 ,flash_cache_addr) ;
    ​}
    inside_norflash_mutex_unlock() ;
    norflash_mutex_exit() ;
    return 0 ;
    break;
    case IOCTL_GET_CAPACITY :
  • (u32 )arg = part->size / 512 ;
    /
    * (u32 *)arg = part->size ; */
    break;
    case IOCTL_GET_BLOCK_SIZE :
  • (u32 *)arg = 512 ;
    break;
    case IOCTL_CMD_RESUME :
    break;
    case IOCTL_CMD_SUSPEND :
    break;
    case IOCTL_CHECK_WRITE_PROTECT :
  • (u32 *)arg = 0 ;
    break;
    default :
    reg = -EINVAL ;
    break;​}
    return 0 ;​}
    //按512字节单位读写
    const struct device_operations inside_norflash_fat_fs_dev_ops = {​
    .init = norflash_fat_fs_dev_init ,
    .online = norflash_fat_fs_dev_online ,
    .open = norflash_fat_fs_dev_open ,
    . read = norflash_fat_fs_dev_read ,
    .write = norflash_fat_fs_dev_write ,
    .ioctl = norflash_fat_fs_dev_ioctl ,
    .close = norflash_fat_fs_dev_close ,​} ;

6、生成镜像带FAT文件系统的bin文件

image p.s.
11.txt中内容为“11“
33.txt中内容为“33Π

7、配置生成的镜像文件,烧录至内置flash

image

8、读写操作

imageimage log_info( "APP_MODE_POWERON\n ") ;
char buf [ 32] = {​0​} ;
FILE *test_fd = fopen( "storage/fat_nor/C/11 .txt " , " r ") ; if(!test_fd){​
log_info( "inside falsh fat open file fail\n ") ;​}else{​
log_info( "inside falsh fat open file success , ready read\n ") ; int len = fread((void *)buf , 16 , 1 , test_fd) ;
log_info( " read file %d %s\n " , len , buf) ;​}
fclose(test_fd) ;
test_fd = NULL ;
FILE *test_fd1 = fopen( "storage/fat_nor/C/33 .txt " , "w+ ") ; if(!test_fd1){​
image log_info( "inside falsh fat open file fail\n ") ;​}else{​
log_info( "inside falsh fat open file success , ready read\n ") ;
int len = fread((void *)buf , 16 , 1 , test_fd1) ;
log_info( " read file %d %s\n " , len , buf) ;​}
fclose(test_fd1) ;
test_fd1 = NULL ;
FILE *test_fd2 = fopen( "storage/fat_nor/C/22 .txt " , "w+ ") ; if(!test_fd2){​
log_info( "inside falsh fat open file fail\n ") ;​}else{​
u8 str [] = "This is a test string . " ;
int len = fwrite(str , sizeof(str) , 1 , test_fd2) ;
fclose(test_fd2) ;
test_fd2 = NULL ;
test_fd2 = fopen( "storage/fat_nor/C/22 .txt " , "w+ ") ;
if(!test_fd2){​
log_info( "inside falsh fat open file fail\n ") ;​}else{​
log_info( "inside falsh fat open file success , ready read\n ") ; len = fread((void *)buf , sizeof(str) , 1 , test_fd2) ;
log_info( " read file %d %s\n " , len , buf) ;​}
​}
fclose(test_fd2) ;
test_fd2 = NULL ;

9、测试结果

image

10、文档版本记录

时间版本号修改内容
2502171.0新增文档,包含读写互斥锁
2507111.1IOCTL新增107 108命令码返回值
2511121.2新增250711文件改动后的源码.c

本文档包含以下子页面

Prev
707电池曲线
Next
AC707N_本地视频播放demo(AVI-MJPEG-PCM)