FPGA读取NandFlash的ID
最近在工作上碰到NandFlash烧录器,自己又在学习FPGA,就打算自己做个简易的烧录器。
为了确保可行性,偷偷把公司的烧录器拆开看了一下(放心,早就过了保修期),Altera的FPGA加单片机。果然不出所料,可行。又在淘宝上找找有没有带NandFlash的FPGA开发板,毕竟只是想做软件而已,没必要自己焊线。也顺便看看,有没有附带NandFlash的FPGA程序。可惜找了好久没发现,有一家做了带NandFlash扩展板,不过没有程序。最后想来想去,还是在原本的FPGA开发板上跳线吧,因为手头上有个NandFlash烧录座子,所以跳线还是很好跳的,就电源地还有十几根控制数据线而已。以现在FPGA的基础,能把NandFlash几个常用操作搞掂就算不错了。说干就干,先从读取ID开始。
NandFlash的硬件连接,我就接了3.3V和GND,其他信号线全部连接到FPGA的IO口,所有都没有上拉。因为ReadID不需要,等以后其他操作需要在考虑。NandFlash的信号线什么意思我就不多说了,百度谷歌多的是。
FPGA NandFlash控制器网上发表的文档也很多,可惜verilog编写的程序少之又少,可能都当宝吧。难得找到一些,可惜看不懂,对于菜鸟的我,甚是伤心。无奈之下,决定自己重头开始写,慢慢下吧。慢慢写都花了两天时间,伤不起啊。为此,分享一下,就当铺路吧。
我用的是HY27UF(08_16)2G2B 这款NandFlash,命令ReadID时序图如下
reg [7:0] Cnt;
reg [7:0] FID;
reg [7:0] DID;
reg [7:0] ID_detail_1;
reg [7:0] ID_detail_2;
reg [7:0] ID_detail_3;
output CE_n;
output WE_n;
output RE_n;
output ALE;
output CLE;
output WP_n;
inout [7:0] DATA;
input R_B_n;
always @ (negedge reset or posedge clkin)//clkin尝试达到24MHZ都可以,可能这和跳线有关系吧
if (!reset)
begin
Led = 3'b001;
Cnt<=0;
WP_n<=1;
CE_n<=1;
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;
end
else
begin
Cnt<=Cnt+1;
test=~test;
case(Cnt)
1://初始化
begin
Led = 3'b011;
CE_n<=0;
en<=1;
end
2://发送readid命令
begin
CLE<=1;
ALE<=0;
WE_n<=0;//low
RE_n<=1;
data_reg<=8'h90;
end
3:
begin
CLE<=1;
ALE<=0;
WE_n<=1;//high
RE_n<=1;
end
4://发送地址
begin
CLE<=0;
ALE<=1;
WE_n<=0;//low
RE_n<=1;
data_reg<=8'h00;
end
5:
begin
CLE<=0;
ALE<=1;
WE_n<=1;//high
RE_n<=1;
end
6:;//delay 1 time
7://读取FID
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=0;//low
en=0;
end
8:
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;//high
end
9:
begin
FID=DATA;
end
10://读取DID
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=0;//low
end
11:
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;//high
end
12:
begin
DID=DATA;
end
13://读取ID_detail_1
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=0;//low
end
14:
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;//high
end
15:
begin
ID_detail_1=DATA;
end
16://读取ID_detail_2
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=0;//low
end
17:
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;//high
end
18:
begin
ID_detail_2=DATA;
end
19://ID_detail_3
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=0;//low
end
20:
begin
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;//high
end
21:
begin
ID_detail_3=DATA;
end
22://结束
begin
WP_n<=1;
CE_n<=1;
CLE<=0;
ALE<=0;
WE_n<=1;
RE_n<=1;
Cnt<=22;
Led = 3'b111;
end
default:;
endcase
end
assign DATA=en?data_reg:8'bzzzz_zzzz;
写都花了两天时间,伤不起。所以ID都能正确读取,我用的是数码管显示,有图为证。事实证明,焊接功夫必须够硬,而且焊接的线路要分明,最起码让人看得舒服,最好就是把它当成艺术品去做,这样才会赏心悦目。臭美啦,哈哈!
转载记得留点痕迹。
QQ交流方式:350352197
用户403664 2013-8-20 15:25