技术标签: fpga
大多数FPGA内部不具有掉电存储程序的功能,所以都是外置flash存储器来存储程序,上电后加载flash中的程序到FPGA中,在运行。外置flash不仅可以作为存储程序使用,也可以存储任何你想存储的用户数据,这样可以更有效的利用flash的存储空间,本文不讲其寄存器及原理,这个网上很多。
flash_spi:
`timescale 1ns / 1ps
//
// Company:
// Engineer: QSJ
//
// Create Date: 2021/03/26 9:02:44
// Design Name:
// Module Name: flash_spi
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module flash_spi(
input wire sys_clk,
input wire i_rst_n,
// ---------- spi port ---------
output wire o_spi_clk,
output wire o_spi_cs,
output wire o_spi_mosi,
input wire i_spi_miso,
// --------- data port -----------
input wire [7:0] iv_write_data ,
output reg o_wr_1_byte_ok ,
input wire [15:0] iv_write_num,
input wire [15:0] iv_read_num,
input wire [3:0] iv_cmd_type,
output reg o_flash_done,
input wire [7:0] iv_flash_cmd,
input wire [31:0] iv_flash_addr,
output reg [7:0] ov_read_data,
output wire o_read_data_vld
);
wire spi_clk;
reg spi_cs;
reg spi_mosi;
wire spi_miso;
assign o_spi_clk = spi_clk;
assign o_spi_cs = spi_cs;
assign o_spi_mosi = spi_mosi;
assign spi_miso = i_spi_miso;
reg read_data_vld;
reg [7:0] read_data;
reg [2:0] spi_state;
reg spi_clk_en=1'b0;
reg data_come;
assign o_read_data_vld=read_data_vld;
assign spi_clk=spi_clk_en?sys_clk:0;
parameter IDLE = 3'b000;
parameter CMD_SEND = 3'b001;
parameter ADDRESS_SEND = 3'b010;
parameter READ_WAIT = 3'b011;
parameter WRITE_DATA = 3'b101;
parameter FINISH_DONE = 3'b110;
reg [7:0] cmd_reg;
reg [31:0] address_reg;
reg [7:0] wr_bit_cnt;
reg [15:0] write_cnt;
reg [7:0] rd_bit_cnt;
reg [15:0] read_cnt;
reg [15:0] read_num_inner;
reg read_finish;
always @(negedge sys_clk)
begin
if(!i_rst_n)
begin
spi_cs<=1'b1;
spi_state<=IDLE;
cmd_reg<=0;
address_reg<=0;
spi_clk_en<=1'b0;
wr_bit_cnt<=0;
write_cnt<=0;
read_num_inner<=0;
o_flash_done<=1'b0;
data_come<=1'b0;
o_wr_1_byte_ok <= 1'b0;
end
else
begin
case(spi_state)
IDLE: begin
spi_clk_en<=1'b0;
spi_cs<=1'b1;
spi_mosi<=1'b1;
cmd_reg<=iv_flash_cmd;
address_reg<=iv_flash_addr;
o_flash_done<=1'b0;
if(iv_cmd_type[3]==1'b1)
begin
spi_state<=CMD_SEND;
wr_bit_cnt<=7;
write_cnt<=0;
read_num_inner<=0;
end
end
CMD_SEND:
begin
spi_clk_en<=1'b1;
spi_cs<=1'b0;
if(wr_bit_cnt>0)
begin
spi_mosi<=cmd_reg[wr_bit_cnt];
wr_bit_cnt<=wr_bit_cnt-1'b1;
end
else
begin
spi_mosi<=cmd_reg[0];
if ((iv_cmd_type[2:0]==3'b001) | (iv_cmd_type[2:0]==3'b100))
begin
spi_state<=FINISH_DONE;
end
else if (iv_cmd_type[2:0]==3'b011)
begin
spi_state<=READ_WAIT;
wr_bit_cnt<=7;
read_num_inner<=1;
end
else if (iv_cmd_type[2:0]==3'b000)
begin
spi_state<=READ_WAIT;
wr_bit_cnt<=7;
read_num_inner<=17;
end
else
begin
spi_state<=ADDRESS_SEND;
wr_bit_cnt<=31;
end
end
end
ADDRESS_SEND:
begin
if(wr_bit_cnt>0)
begin
spi_mosi<=address_reg[wr_bit_cnt];
wr_bit_cnt<=wr_bit_cnt-1;
end
else begin
spi_mosi<=address_reg[0];
if(iv_cmd_type[2:0]==3'b010)
begin
spi_state<=FINISH_DONE;
end
else if (iv_cmd_type[2:0]==3'b101)
begin
spi_state<=WRITE_DATA;
wr_bit_cnt<=7;
end
else begin
spi_state<=READ_WAIT;
read_num_inner<=iv_read_num;
end
end
end
READ_WAIT:
begin
if(read_finish)
begin
spi_state<=FINISH_DONE;
data_come<=1'b0;
end
else
data_come<=1'b1;
end
WRITE_DATA:
begin
if(write_cnt<iv_write_num)
begin
if(wr_bit_cnt>0)
begin
spi_mosi<=iv_write_data[wr_bit_cnt];
wr_bit_cnt<=wr_bit_cnt-1'b1;
o_wr_1_byte_ok <= 1'b0;
end
else
begin
spi_mosi<=iv_write_data[0];
wr_bit_cnt<=7;
o_wr_1_byte_ok <= 1'b1;
write_cnt<=write_cnt+1'b1;
end
end
else
begin
spi_state<=FINISH_DONE;
spi_clk_en<=1'b0;
o_wr_1_byte_ok <= 1'b0;
write_cnt <= 0;
end
end
FINISH_DONE:
begin
spi_cs<=1'b1;
spi_mosi<=1'b1;
spi_clk_en<=1'b0;
o_flash_done<=1'b1;
spi_state<=IDLE;
end
default:spi_state<=IDLE;
endcase
end
end
always @(posedge sys_clk)
begin
if(!i_rst_n)
begin
read_cnt<=0;
rd_bit_cnt<=0;
read_finish<=1'b0;
read_data_vld<=1'b0;
read_data<=0;
ov_read_data<=0;
end
else
if(data_come)
begin
if(read_cnt<read_num_inner)
begin
if(rd_bit_cnt<7)
begin
read_data_vld<=1'b0;
read_data<={
read_data[6:0],spi_miso};
rd_bit_cnt<=rd_bit_cnt+1'b1;
end
else
begin
read_data_vld<=1'b1;
ov_read_data<={
read_data[6:0],spi_miso};
rd_bit_cnt<=0;
read_cnt<=read_cnt+1'b1;
end
end
else begin
read_cnt<=0;
read_finish<=1'b1;
read_data_vld<=1'b0;
end
end
else
begin
read_cnt<=0;
rd_bit_cnt<=0;
read_finish<=1'b0;
read_data_vld<=1'b0;
read_data<=0;
end
end
endmodule
flash_cmd:
`timescale 1ns / 1ps
//
// Company:
// Engineer: QSJ
//
// Create Date: 2021/03/26 9:04:02
// Design Name:
// Module Name: flash_cmd
// Project Name:
// Target Devices:
// Tool Versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//
module flash_cmd(
input sys_clk,
input i_rst_n,
input i_wr_flash_start,
input i_rd_flash_start,
input i_rd_device_id_start,
input i_subsector_erase_start,
input wire [7:0] iv_write_data ,
output wire o_wr_1_byte_ok ,
input wire [15:0] iv_write_num,
input wire [15:0] iv_read_num,
input wire [31:0] iv_base_addr ,
output o_spi_clk ,
output o_spi_cs ,
output o_spi_mosi ,
input i_spi_miso ,
output [7:0] ov_rd_data,
output o_rd_data_vld
);
reg [7:0] flash_cmd_def;
reg [3:0] cmd_type;
wire flash_done;
wire [7:0] read_data;
wire read_data_vld;
reg [4:0] curr_state = 'd15;
always @ ( posedge sys_clk )
begin
if( !i_rst_n ) begin
curr_state <= 'd15;
flash_cmd_def <= 8'd0;
cmd_type <= 4'b0000;
end
else
begin
case( curr_state )
'd0://idle
if(i_wr_flash_start) curr_state <= 'd8 ;
else if(i_rd_flash_start) curr_state <= 'd13;
else if(i_rd_device_id_start) curr_state <= 'd1 ;
else if(i_subsector_erase_start) curr_state <= 'd3 ;
else curr_state <= 'd0;
// -------------- read device ID ------------------
'd1://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd2;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd2:// Read Device ID:9FH
if( flash_done )
begin
flash_cmd_def <= 8'h00;
if(read_data == 8'hFF) // if the device id is error
curr_state <= 'd1;
else
curr_state <= 'd0;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h9f;
curr_state <= curr_state;
cmd_type <= 4'b1000;
end
// -------------- Erase ------------------
'd3://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd4;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd4://Write Enable:06H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd5;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h06;
curr_state <= curr_state;
cmd_type <= 4'b1001;
end
'd5://4-byte address mode Sector Erase:DCH Subsector Erase:21H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd6;
cmd_type<=4'b0000;
end
else
begin
flash_cmd_def <= 8'h21;
curr_state <= curr_state;
cmd_type <= 4'b1010;
end
'd6://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd7;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd7://Write disable: 04H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd0;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h04;
cmd_type <= 4'b1100;
end
// -------------- write Data ------------------
'd8://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd9;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd9://Write Enable:06H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd10;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h06;
cmd_type <= 4'b1001;
end
'd10://4-byte address page program: write data to flash
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd11;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h12;
cmd_type <= 4'b1101;
end
'd11://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd12;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd12://Write disable: 04H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd0;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h04;
cmd_type <= 4'b1100;
end
// -------------- read Data ------------------
'd13://Read Status Register:05H
if( flash_done ) begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd14;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd14://4-byte address read flash data
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd0;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h13;
cmd_type <= 4'b1110;
end
// -------------- enter 4-byte mode ------------------
'd15://Read Status Register:05H
if( flash_done ) begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd16;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd16://Write Enable:06H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd17;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h06;
cmd_type <= 4'b1001;
end
'd17://Enter 4-byte address mode:B7H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd18;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'hB7;
cmd_type <= 4'b1001;
end
'd18://Read Status Register:05H
if( flash_done )
begin
if (read_data[0]==1'b0)
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd19;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
end
else
begin
flash_cmd_def <= 8'h05;
cmd_type <= 4'b1011;
end
'd19://Write disable: 04H
if( flash_done )
begin
flash_cmd_def <= 8'h00;
curr_state <= 'd1;
cmd_type <= 4'b0000;
end
else
begin
flash_cmd_def <= 8'h04;
cmd_type <= 4'b1100;
end
endcase
end
end
reg [31:0] base_addr;
always @ ( posedge sys_clk)
begin
if( !i_rst_n ) begin
base_addr <= 'd0;
end
else
begin
if(curr_state == 0)
begin
if(i_wr_flash_start|i_rd_flash_start|i_subsector_erase_start) base_addr <= iv_base_addr ;
else base_addr <= 'd0;
end
else base_addr <= base_addr ;
end
end
flash_spi U_flash_spi(
.sys_clk( sys_clk ),
.i_rst_n( i_rst_n ),
.o_spi_clk ( o_spi_clk ),
.o_spi_cs ( o_spi_cs ),
.o_spi_mosi ( o_spi_mosi ),
.i_spi_miso ( i_spi_miso ),
.iv_write_data ( iv_write_data ),
.o_wr_1_byte_ok ( o_wr_1_byte_ok ),
.iv_write_num ( iv_write_num ),
.iv_read_num ( iv_read_num ),
.iv_cmd_type ( cmd_type ),
.o_flash_done ( flash_done ),
.iv_flash_cmd ( flash_cmd_def ),
.iv_flash_addr ( base_addr ),
.ov_read_data ( read_data ),
.o_read_data_vld( read_data_vld )
);
assign ov_rd_data = read_data;
assign o_rd_data_vld = (curr_state == 'd14) ? read_data_vld : 0;
endmodule
以上就是全部内容,仅做个人记录,若需要对flash进行更多操作,可阅读flash对应的datasheet。
有完整的VIVADO FPGA测试工程。
工程未经过全面的调试,有问题请指正!
文章浏览阅读64次。朋友曾经给我推荐了一个有关代码优化的pdf文档《让你的软件飞起来》,看完之后,感受颇深。为了推广其,同时也为了自己加深印象,故将其总结为word文档。下面就是其的详细内容总结,希望能于己于人都有所帮助。速度取决于算法同样的事情,方法不一样,效果也不一样。比如,汽车引擎,可以让你的速度超越马车,却无法超越音速;涡轮引擎,可以轻松超越音障,却无法飞出地球;如果有火箭发动机,就可以到达火..._bao.yuv
文章浏览阅读2.5k次,点赞3次,收藏33次。文章目录前言一、载具设置二、电机接线三、PWM输出设置四、航点设置前言一个人可以走的更快,一群人才能走的更远,交流学习加qq:2096723956更多保姆级PX4+ROS学习视频:https://b23.tv/ZeUDKqy分享知识,传递正能量,如有疏漏或不当之处,恳请指出.PX4固件版本:1.10.0硬件:淘宝竞速船或者打窝船实验录屏https://www.bilibili.com/video/BV1wA411c7p3?spm_id_from=333.999.0.0一、载具设置单电机_在px4固体中如何设置差速船
文章浏览阅读370次。每天都有大量的快递单号需要查询,如果一个个手动查询,不仅费时费力,还容易出错。为了解决这个问题,我们教您如何批量查询快递单号,并将快递物流信息进行备份并共享,实现高效管理。弹出一个对话框,文件名和保存类型不变,直接点“保存”,会提示备份成功,那么这个数据库就备份在电脑上了,也可以用第三方工具发送到其他电脑上。第四步,查询速度很快,我们就可以在主页面看到该批单号的运件信息了,比如:发出时间,状态,最后更新的物流时间,等等。第二步,在弹出来的文件框里,将需要查询的德邦快递单号都一一导入,并点击保存。_批量快递查询
文章浏览阅读7.7k次,点赞6次,收藏61次。敏捷开发(scrum)是一种软件开发的流程,强调快速反应、快速迭代、价值驱动。Scrum的英文意思是橄榄球运动的一个专业术语,表示“争球”的动作;运用该流程,你就能看到你团队高效的工作。一、四大价值观(特点)敏捷开发的特点就是下面4句话:「个体与交互」胜过「过程与工具」「可以工作的软件」胜过「面面俱到的文挡」「客户协作」胜过「合同谈判」「响应变化」胜过「遵循计划」说明:(1)敏捷开发(scrum)适用于竞争激烈,快速变化的市场。 敏捷的客户协作观念,快速迭代能帮助团队以最小成本,最快速_敏捷开发
文章浏览阅读3.5k次。首先我们看一下man string 里面的内容:可见,strings 头文件中包含了部分函数,没有在 string.h 中出现的。上图的环境是 macOS Sierra 版本号为:10.12.6包括; index, rindex, strcasecmp, strncasecmp 这四个函数。为了一探这个头文件是不是只有macos 这种 Unix-like 系统中才出现。我在Linu..._strings.h
文章浏览阅读4.3k次,点赞21次,收藏48次。本文将带领大家了解 jQuery 的定义,它有什么作用,我们为什么要学它,以及如何使用它,它的语法是什么,最后对比了 jQuery 对象和 DOM 对象的区别。_jquery
文章浏览阅读464次。布局管理器提供相关的类对界面组件进行布局管理能够自动排布窗口中的界面组件窗口变化后自动更新界面组件的大小QLayoutQLayout 是Qt 中布局管理器的抽象基类通过继承QLayout实现了功能各异且互补的布局管理器Qt中可以根据需要自定义布局管理器布局管理器不是界面部件,而是界面部件的定位策略QBoxLayout 布局管理器以水平或者垂直的方式管理界面组件水平:QHBoxLayout 水平布局管理器垂直:QVBoxLayout 垂直布局管理器sizePolicy:QSize_qt layout可以嵌套layout吗
文章浏览阅读2.6k次。error MSB6006 rc exe 已退出,代码为 5_vs2010报警 error msb6006: “rc.exe”已退出,代码为 5。
文章浏览阅读6.2k次。对于人数不多的小型初创企业、工作室、SOHO人群来说,能够拥有自有的协同办公系统无疑是提高工作效率的好方法,同时将文件放在自己的服务器中,显然会更加安心,不用担心重要内容的泄露问题。因此,大家有没有这样想过,自己动手搭一套私有的、云端化的协同办公系统,搞定文件异地同步的同时,实现云端化的办公软件,并提升数据安全性。理想虽好,不过要亲手搞定这样的协同办公系统一定很困难吧?如果你真这样
文章浏览阅读33次。输出描述:一行,一个字符,A或B或E,输出A表示A得票数多,输出B表示B得票数多,输出E表示二人得票数相等。输入描述:一行,字符序列,包含A或B,输入以字符0结束。
文章浏览阅读2.2k次,点赞2次,收藏2次。BeanFactory和ApplicationContext有什么区别? BeanFactory和ApplicationContext是Spring的两大核心接口,都可以当做Spring的容器。其中ApplicationContext是BeanFactory的子接口。(1)BeanFactory:是Spring里面最底层的接口,包含了各种Bean的定义,读取bean配置文档,管理..._beanfactory和applicationcontext是干什么的
文章浏览阅读4.5k次。转贴:http://blog.csdn.net/shiqiang1234/archive/2006/10/12/1331725.aspxMaven简介Maven最初的目的是在Jakarta Turbine项目中使构建处理简单化。几个项目之间使用到的Ant build文件差异很小,各个JAR都存入CVS。因此希望有一个标准的方法构建各个工程,清晰的定义一个工程的组成,一个容易的方法去发布项目_apt fml fr