NIOS II 软核中EPCS配置芯片的存储操作

EPCS4配置芯片除了存储FPGA配置信息和NIOS II程序外,还有很多存储空间剩余未使用,可以用来做用户配置信息存储。

ALTERA提供的HAL函数来调用EPCS相关的函数,在“altera_avalon_epcs_flash_controller.c”函数(路径为:\\altera\72\ip\sopc_builder_ip\altera_avalon_epcs_flash_controller\HAL\src)中。

一个老外写的关于NIOS II下CPCS器件操作的帖子,他是花了一个多月才摸索到怎么操作,然后给出了一个简单的例子。

先看一下这个简单程序

#include <stdio.h>

#include <unistd.h>

#include "system.h"

#include "alt_types.h"

#include "sys/alt_flash.h"

#include "sys/alt_flash_dev.h"

alt_u8 epcsbuf[32];

int ret_code;

flash_region *regions;
int number_of_regions;

alt_flash_fd* my_epcs;//定义句柄

main()

{

my_epcs = alt_flash_open_dev("/dev/epcs_controller");//打开FLASH器件,获取句柄

ret_code = alt_epcs_flash_get_info (my_epcs, &regions, &number_of_regions);//获取配置芯片信息

if(my_epcs) //信息获取成功

{

//example application, read general data from epcs address 0x70000

ret_code = alt_epcs_flash_erase_block(my_epcs, regions->offset+0x70000);//擦除第8块

ret_code = alt_epcs_flash_write(my_epcs, regions->offset+0x70000, epcsbuf, 32); //写32字节

ret_code = alt_epcs_flash_read(my_epcs, regions->offset+0x70000, epcsbuf, 32); //读32字节

}

while(1)

{

}

}

上面的程序就是对EPCS配置芯片操作的流程和方式。首先打开器件获取句柄my_epcs,然后的读写及擦除操作都是通过句柄my_epcs来操作的。“/dev/epcs_controller”中的“epcs_controller”是用户在配置NIOS核时自命名的,可以在system.h中查到,即“EPCS_CONTROLLER_NAME”。通过IDE调试的话可以查看my_epcs指向的FLASH相关参数。EPCS器件只有一个区(regions),EPCS4区内有8个块(block),每个块是65536字节。(注:只有EPCS1每个块32768字节,其余配置芯片是每块65536字节。

alt_epcs_flash_erase_block(my_epcs, regions->offset+0x70000);//擦除第8块

这个函数是擦除整块的函数,第一个参数是刚才获得的句柄,用于指示是对刚刚打开的FLASH进行擦除,第二个regions->offset的值其实是0,是由EPCS控制模块自己管理的。FPGA配置文件和NIOS核中的程序是从前边存储的,即从regions->offset+0x00000开始的地址。我的用掉不到4个块,还剩4个块可以用于自定义的存储。为便于将来进行功能扩展,尽量空余低块以备将来使用,优先使用高地址空间(第8块,起始地址为regions->offset+0x70000)进行用户配置信息存储。

alt_epcs_flash_write(my_epcs, regions->offset+0x70000, epcsbuf, 32); //写32字节

将epcsbuf数组中的连续32字节写入regions->offset+0x70000开始的EPCS4芯片内。如果是写入第6块的第0x100开始的地址,那么可用regions->offset+0x60100代替regions->offset+0x70000。

alt_epcs_flash_read(my_epcs, regions->offset+0x70000, epcsbuf, 32); //读32字节

从EPCS4中的第8段起点regions->offset+0x70000读取连续32字节存到epcsbuf数组内。

调试过程中可以在执行alt_epcs_flash_write前手动修改epcsbuf数组内的值,在执行alt_epcs_flash_read前再更改epcsbuf数组内的值为其他值,如果执行alt_epcs_flash_read后epcsbuf数组内的值恢复到执行alt_epcs_flash_write前的值,那么对EPCS芯片的读写操作已经成功了

注意:EPCS的擦写是针对整个块的,也可以不用擦写,直接写数据,因为重新写入时会发生覆盖。

与EPCS操作相关的头文件有以下:

#include "system.h"

#include "alt_types.h"

#include "sys/alt_flash.h"

#include "sys/alt_flash_dev.h"

当然系统还需要一些相关的标准头文件,执行一些操作。

其他参考程序:

1)First of all init the flash device and possibly get extra info about the flash device, like block size:

flash_region *regions;
int numRegions;
int error = 0;
pFlashDevice = alt_flash_open_dev(FLASH_CONTROLLER_NAME);
if (pFlashDevice <= 0)
error = -1;
if (!error)
error = alt_epcs_flash_get_info(pFlashDevice, &regions, &numRegions);
if (!error)

{flash_block_size = regions->block_size;
flash_max_addr = regions->region_size;
This is for erasing a single block:
alt_epcs_flash_erase_block(pFlashDevice, block_address);
This is for writing any data to a previously erased area:
int buf[10] = { 1, 2,3,4,5,6,7,8,9,10 };
rv = alt_epcs_flash_write_block(pFlashDevice, block_address,
data_offset_inside_block , buf, 10);
Then, read back data with:
alt_epcs_flash_read(pFlashDevice, addr, buf, len);

 

问题:

First of all init the flash device and possibly get extra info about the flash device, like block size:

flash_region *regions;
int numRegions;
int error = 0;
pFlashDevice = alt_flash_open_dev(FLASH_CONTROLLER_NAME);
if (pFlashDevice <= 0)
error = -1;
if (!error)
error = alt_epcs_flash_get_info(pFlashDevice, &regions, &numRegions);
if (!error) {
flash_block_size = regions->block_size;
flash_max_addr = regions->region_size;

i am using cfi, is it the same? besides, my pFlashDevice is <= 0. i dunno why. is it sth to do with reset vector as my reset vector is sdram.

This is for writing any data to a previously erased area:
int buf[10] = { 1, 2,3,4,5,6,7,8,9,10 };
rv = alt_epcs_flash_write_block(pFlashDevice, block_address,
data_offset_inside_block , buf, 10);

why need rv when write data?

Then, read back data with:
alt_epcs_flash_read(pFlashDevice, addr, buf, len);

where is the data when we read it from the flash? like i want to print out the data.
please help me with the ques in bold. thanks!

回答:

why need rv when write data?
This is not mandatory, but recommended to check if data has been written correctlywhere is the data when we read it from the flash? like i want to print out the data.
???
What's the problem? The buf array contains your data.
Maybe this way is clearer:
int buf[10];
alt_flash_read(pFlashDevice, addr, buf, 10);Remark:
remove epcs_ from the previous post. I copied and pasted from a project using epcs instead of parallel flash and forgot to change function names.

注:此程序为altera论坛问答帖子,如何在DE2上使用flash的问题,具体链接地址为,http://www.alteraforum.com/forum/archive/index.php/t-27526.html

NIOS II 软核中EPCS配置芯片的存储操作相关推荐

  1. [转贴]NIOS II 软核中EPCS配置芯片的存储操作

    最近用CYCLONE FPGA做的视频图像叠加板需要存储一些用户配置信息,而EPCS4配置芯片除了存储FPGA配置信息和NIOS II程序外,还有很多存储空间剩余未使用,刚好可以用来做用户配置信息存储 ...

  2. NIOS II软核处理器

    前不久,Altera 正式推出了Nios II系列32位RSIC嵌入式处理器.Nios II系列软核处理器是Altera的第二代FPGA嵌入式处理器,其性能超过200DMIPS,在Altera FPG ...

  3. [笔记].Nios II 软核性能基准

    一些表格 表1 Nios II处理器系统的最大时钟频率(tMAX)(MHz) 表2 Nios II处理器系统的MIPS(每秒钟一百万个指令)   表3 在不同设备家族上的Nios II处理器系统的MI ...

  4. PYNQ-Z2调试笔记:在Microblaze软核中编程运行C程序

    本篇主要介绍,通过Jupyter在Microblaze Subsystems上使用C语言编程,实现一些简单的功能. 目录 前言 正文 一.软核PMODA.PMODB.RPI.ARDUINO 二.在软核 ...

  5. nios 双核 烧录_FPGA烧写NIOS ii程序至FLASH(epcs)中

    硬件平台:黑金开发板 软件平台:quartus 11.0  NIOS II 11.0IDE FPGA芯片:EP4CE6F17C8N 1.      新建工程,bdf文件,这些不做具体说明了,网络资料详 ...

  6. [原创].使用Nios II 9.1中的Flash Programmer无法固化程序到EPCS上

    情况描述 自从装了91,就发现通过NII的Flash Programmer编程后,上电无法正常复位,也就是说无法固化程序到EPCS中(或其他Flash器件).本来我以为是我的EPCS出问题了,但是在Q ...

  7. SecureCrt配置之自动存储操作日志

    日志自动存储配置 我填写的log file name D:\SecureCrt-log\%H\%Y%M%D\%S  %H  %Y-%M-%D %h%m%s.log 防止连接中断配置 每300秒会在命令 ...

  8. 【连载】【FPGA黑金开发板】NIOS II那些事儿--串口实验(六)

    声明:本文为原创作品,版权归本博文作者所有,如需转载,请注明出处http://www.cnblogs.com/kingst/ 简介 这一节,我们来说说RS232,俗称串口.大家对这东西应该很了解,没什 ...

  9. NIOS II程序Flash固化

    目录 NIOS II 程序flash固化 第一部分 EPCS flash固化 第二部分 CFI Flash程序固化 NIOS II 程序flash固化 这两天尝试着NIOS II程序固化,遇到很多问题 ...

最新文章

  1. R语言使用pROC包绘制ROC曲线并使用smooth函数绘制平滑的ROC曲线(方法包括:binormal、density、fitdistr、logcondens、logcondens.smooth)
  2. 给 Android 初学者的 Gradle 知识普及
  3. 地图上显示div点位
  4. MySQL中的索引详讲
  5. c语言时钟报告,C语言图形时钟课程设计实验报告
  6. plsql如何执行单个语句_在单个try-with-resources语句中仔细指定多个资源
  7. 玩转LiteOS组件:玩转Librws
  8. NYOJ-58 最少步数
  9. Centos7 PXE服务器部署
  10. ssm oracle mysql_ssm连接oracle数据库
  11. 长春技师学院计算机系,长春技校排名前五十
  12. linux里centos7开放端口,linux centos7 防火墙及端口开放相关命令
  13. easydatasource能删除吗_面试官:能跟我说一下rm删除文件之后,空间都发生了什么吗?
  14. VS运行程序时遇到0xc0150002的问题
  15. 基于五种机器算法的信用风险评估
  16. 案例分析|戴森如何以DTC全渠道营销打造百亿规模增长
  17. 计算机恢复原始桌面图标,如何将电脑界面上的图标恢复到原始样子?
  18. Webpack是什么?(webpack初学简单易理解)
  19. 黄奇帆:消费互联网垄断、杀熟等不讲道理的盈利模式行不通
  20. 科学计算机 百分号,普通计算器上百分号(%)有什么用?

热门文章

  1. Linux-线程(LWP)
  2. halide 资源整理
  3. VMWare网络模式(Centos7)
  4. Windows 生物统计框架结构简介(WBF) (指纹识别技术)
  5. 华为 FTTB(大ONU)修改同时节目观看数
  6. python列表过滤的方法
  7. 实验:GNS3中创建PC机与连接交换机实现互联互通
  8. Exchange Server2010系列之六:监控用户邮件
  9. 数据库 (基础数据库知识 )
  10. ajax tool works,,AJAX TOOLS.