为了让CSR867x的开发更容易,现与思度科技联合推出CSR867x学习板【淘宝链接:思度科技CSR开发板】。

技术交流QQ群号:743434463
开发板会员QQ群号:725398389(凭订单号入群,赠PPT、项目源码、视频教程)
——————————正文分割线———————————–

#1. 引言
项目需要CSR8675能够boot两个功放芯片内部的DSP。

为了满足这个需求,需要分几个步骤实现:

  1. 将2个20KB的bin文件存储在CSR8675的外部Flash中。
  2. 一边读取bin文件一边解析,并将解析得到的数据通过I2C写入功放芯片。

#2. 将文件存入外部Flash
##2.1. 外部Flash分区
创建分区文件:

ext_flash.ptn, File system

0, 1024K, RS, (erase) # Logical 0: Partition for DFU
1, 128K, RO, 2557_bin.xuv # Logical 1: Store 2557 bin file
2, 128K, RO, (erase) # Logical 2:

上述分区文件将外部Flash文件分为三段。0分区用于存储DFU升级文件,1分区用于存储bin文件,2分区暂时不用。

分区文件的写法可参考官方的nvscmd.chm。

##2.2. 打包bin文件
创建打包脚本ext_flash.ptn:

@echo offecho. *************************************
echo. Update external flash start
echo. *************************************:: set CSR install path
set adkpath=C:\ADK4.1
set dfutoolspath=%adkpath%\tools\bin:: set project path
set ReleaseVersion=lemon_ext_flash_V0.1
set projectpath=%adkpath%\apps\lemon\ext_flash
set releasepath=%projectpath%\%ReleaseVersion%
set releasefilepath=%releasepath%\ext_flash_files
set releasexuvpath=%releasepath%\ext_flash_xuvset debugtransport=SPITRANS=USB SPIPORT=0del /f /s /Q %releasepath%
mkdir %releasepath%
mkdir %releasefilepath%
mkdir %releasexuvpath%echo. *************************************
echo. Erase external flash
echo. *************************************
echo.call %dfutoolspath%\nvscmd.exe -usb 0 eraseecho. *************************************
echo. Package files into file system
echo. *************************************
echo.
copy /b %projectpath%\2557_tuning.bin
call %dfutoolspath%\packfile.exe %releasefilepath% %releasexuvpath%\2557_bin.xuv

打包文件前需要先调用nvscmd擦除Flash。packfile.exe会将指定文件夹路径中的文件打包成.xuv后缀的文件。

##2.3. 写入外部Flash
运行下述脚本后,bin文件会写入外部Flash内的分区1。

echo. *************************************
echo. Burn external flash
echo. *************************************
echo.
copy /b %projectpath%\ext_flash.ptn %releasexuvpath%\ext_flash.ptn
call %dfutoolspath%\nvscmd.exe -usb 0 burn %releasexuvpath%\ext_flash.ptn all

#3. VM读取Flash中的文件
##3.1. 加载Flash分区
VM只能一次读取一个分区,在读取前需先加载。参考代码如下:

#define MOUNT_FILE_SYSTEM_SECTION_INDEX 1/* mount sqif partition 1 */
if (!PartitionMountFilesystem(PARTITION_SERIAL_FLASH,MOUNT_FILE_SYSTEM_SECTION_INDEX,PARTITION_LOWER_PRIORITY))
{DEBUG_2557_ERR(("2557: Can't mount file system %d\n", MOUNT_FILE_SYSTEM_SECTION_INDEX));Panic();
}

##3.2. 读取Flash分区
VM中读取Flash中的文件需调用stream source API:

5.3 Source API


A source can be thought of as an infinite buffer divided into three sections:
Figure 5-2 Source buffer

■ The dropped section is data that the application has already processed and does not need the streams library to retain.
■ The readable section holds the data that the streams library has placed in the source and that the application is permitted to access.
■ The writeable section is where the library is still placing data.

In general, an application should only read from a source upon receipt of a MORE_DATA message. This indicates that there is data in the source which can be read. An application reading from a source must perform the following sequence:

  1. Get the amount of readable data in the source, using SourceSize
  2. Map the source into application memory, using SourceMap
  3. Process the data received
  4. Drop processed data, using SourceDrop If more data arrives at the source, the process is repeated.

NOTE: There is a strict limit on how big the readable section can grow, so applications should drop data as soon as possible. Failing to do so eventually chokes off the supply of new data. Even if the source is a data block in the firmware or the read-only filing system, only a limited amount (currently about 3 kB) can exist in the application address space at one time.

通过使用source API,我们可以得到1个最大3kB的内存窗口。利用这个窗口,可以实现bin文件一边读取一边解析,参考代码如下:

/* find 2557.bin file in file system */
file = FileFind(FILE_ROOT, file_name, strlen(file_name));
if (file == FILE_NONE)
{DEBUG_2557_ERR(("2557: Can't find bin file: %s\n",file_name));Panic();
}pTAS2557->source = StreamFileSource(file);
if (pTAS2557->source == NULL)
{DEBUG_2557_ERR(("2557: Can't find stream source\n"));Panic();
}file_len = SourceSize(pTAS2557->source);
pData = (uint8_t *)SourceMap(pTAS2557->source);
pDataStart = pData;/* PLL Name */
pDataBuf = malloc(64);
memcpy(pDataBuf, pData, 64);
DEBUG_2557(("2557: PLL Name = %s\n", pDataBuf));
free(pDataBuf);
pData += 64;/* PLL Description */
n = strlen((const char *)pData);
pDataBuf = malloc(n+1);
memcpy(pDataBuf, pData, n+1);
DEBUG_2557(("2557: PLL Description = %s\n", pDataBuf));
free(pDataBuf);
pData += n+1;SourceDrop(pTAS2557->source, (pData - pDataStart));

程序最后调用SourceDrop将已使用的数据段丢弃,在此调用SourceMap时,返回的指针指向下一个未使用的数据。循环往复得调用SourceMap和SourceDrop,并且正确丢弃已用数据,即可实现大于3KB的bin文件的连续处理了。

##3.3. 卸载Flash分区
读取完Flash分区后,即可卸载Flash分区。

if (!PartitionUnmountFilesystem(PARTITION_SERIAL_FLASH, MOUNT_FILE_SYSTEM_SECTION_INDEX))
{DEBUG_2557_ERR(("2557: Unmount file system fail\n"));Panic();
}

#4. 从内部Flash读取文件
其实CSR8675内部的Flash也可以存储bin文件,方法是将bin文件放在工程的image路径下,工程在编译时会自动打包这个文件。VM可在运行时直接通过source API调用,无需加载外部Flash分区。

这种方法的缺点是导致image文件变大,增大了DFU文件,使OTA升级耗时变长。

也许有人会问,为什么不将bin文件以.h文件的形式保存在CSR8675的程序段的const区呢?因为CSR8675的const区只有24KB,无法存放40KB这样的bin文件。并且考虑到const区一般存储一些常用的数据表和debug打印字符串,留给bin文件的空间更少了。参考《VM Memory Mapping and Memory Usage》:

2.1.3 Constants region
The constants region maps to ROM/Flash memory used to store constant data that is required to persist for the duration of the program.
The constants region is limited to a maximum of 24 K words and is used for:
■ Constant global variables
■ String literals e.g. “Hello world”
■ Jump tables for switch statements
■ Initializers for non-constant global variables
The linker produces an error message if the 24 K limit is exceeded.

#5. 总结

在掌握了从外部Flash读取文件的方法后,可以实现很多有意义的功能。包括boot外部DSP,读取电话簿,播放特定音频文件等。

#6. 参考文档

  1. CS-227835-AN-4-Using external FLASH on ADK.pdf
  2. nvscmd.chm
  3. Implementing sources in bluecore applications
  4. ADK Audio Prompts Application Note
  5. VM Memory Mapping and Memory Usage

CSR8675学习笔记:从外部Flash读取bin文件相关推荐

  1. 点云学习笔记19——使用pcl将bin文件转化为pcd文件

    从KITTI下载的数据是二进制bin格式,但是pcl似乎只能读取pcd文件,为了可视化,先将bin文件转换为pcd文件. 在home下,新建文件夹PointCloud(我建在这里,大家随意),在Poi ...

  2. ffmpeg4.4 学习笔记 -(2)读取视频文件并用SDL 显示

    使用SDL 2.0.20 Simple DirectMedia Layer - SDL version 2.0.20 (stable)https://www.libsdl.org/release/SD ...

  3. STATA学习笔记:外部命令

    STATA学习笔记:外部命令 1.设置外部命令存储地址 //在电脑里设置好文件夹以备存储外部命令 //Set location where packages will be installed //方 ...

  4. Flash读取XML文件出现的中文乱码问题 flash读取外部中文时显示乱码的问题

    Flash读取XML文件出现的中文乱码问题    原因:中文乱码,不用说都是编码惹的祸.Flash是使用UTF-8编码的.而一般我们保存文本文件时(也就是XML文件),用的编码是GB2321.ANSI ...

  5. R语言小白学习笔记3—R语言读取数据

    R语言小白学习笔记3-R语言读取数据 笔记链接 想说的话 学习笔记3-R语言读取数据 3.1 读取CSV文件 3.1.1 read_delim函数 3.1.2 fread函数 3.2 读取Excel数 ...

  6. FPGA学习笔记之Altera FPGA使用JIC文件配置固化教程

    FPGA学习笔记之Altera FPGA使用JIC文件配置固化教程 很多做过单片机的朋友都知 道,我们在对MCU烧写完程序固件后,那么该程序固件就存储在了该MCU内部.即使MCU断电了再重新上电,程序 ...

  7. Python 学习笔记(3)对txt文件的读与写操作(下)

    上一章节我们讨论了如何对txt文本文件进行读写操作,这一张将讨论如何进行二进制文件的写与读.<Python 学习笔记(3)对txt文件的读与写操作(上)>的链接如下https://blog ...

  8. oracle 怎么看监听文件,【学习笔记】Oracle11G关于监听文件位置与监听文件大小限制...

    [学习笔记]Oracle11G关于监听文件位置与监听文件大小限制 时间:2016-11-07 21:21   来源:Oracle研究中心   作者:HTZ   点击: 次 天萃荷净 Oracle研究中 ...

  9. Java NIO 学习笔记(五)----路径、文件和管道 Path/Files/Pipe

    目录: Java NIO 学习笔记(一)----概述,Channel/Buffer Java NIO 学习笔记(二)----聚集和分散,通道到通道 Java NIO 学习笔记(三)----Select ...

最新文章

  1. javascript中replace使用方法总结
  2. 部署篇01:Linux 安装配置JDK
  3. python装饰器实例-Python装饰器原理与简单用法实例分析
  4. 微软算法100题26 左旋转字符串
  5. 成为技术大牛,只能靠天赋吗?
  6. django_form表单的提交
  7. Object类和String类
  8. Kenai.com 将与 java.net 合并
  9. Spring Cloud 2020年路线图发布,涵盖Spring Boot 2.3、2.4,Spring Cloud Ilford等重磅内容!
  10. (71)信号发生器DDS方波设计 (一)(第15天)
  11. 【Luogu】P2634聪聪可可(树形DP)
  12. 图论--最短路径--观光旅游
  13. C#使用Parallel处理数据同步写入Datatable并使用BulkInsert批量导入数据库
  14. http://www.spiceworks.com
  15. nx显示服务器错误,ug6.0软件打开出现nx许可证错误的解决办法
  16. 华中科技大学计算机课程学什么,华中科技大学计算机专业课程表
  17. 多少秒算长镜头_什么是长镜头画面(电影里的长镜头有哪些分类)
  18. 【coq】函数语言设计 笔记 11 - rel
  19. 邓俊辉数据结构学习心得系列——如何正确衡量一个算法的好坏
  20. 将Jetson XavierNX的Ubuntu系统迁移至到nvme固态硬盘上

热门文章

  1. Python学习关键tip记录
  2. 计算机财务管理系统的目标,计算机财务管理之计算机财务管理系统的建立课件.ppt...
  3. 实验六图的应用(通信网络)
  4. 喵喵机打印机各系列通过USB数据线连接电脑打印
  5. 招聘:量化策略研究员(股票、期货、机器学习)
  6. 基于MODIS数据的大气水汽反演
  7. 俄罗斯、乌克兰程序员薪资大曝光!
  8. WEB免费打印控件推荐(转载)
  9. LintCode入门题目
  10. USB gadget(1)----controller driver