【Sipeed 高云GW2A FPGA开发板】——ARM Cortex-M0软核处理器_点亮数码管
[复制链接]
ARMSOC-7SEG
该设计实现一个使用ARM Cortex-M0 DesignStart内核的SoC,集成一个7段数码管的驱动IP,对该IP的数据寄存器写入数据后,即可在IO引脚上输出对应的信号,从而在连接的7段数码管上显示对应的数字/字符。
4.5.1. FPGA硬件设计代码
创建对应的FPGA项目,将所需的文件添加到项目中,如图:
-
调整时钟分频,可直接运行在板载的27MHz时钟上,代码如下:
//CLOCK DIVIDER & RESET
ClockDiv #(
.CLOCK_DIV(1)
)
uClockDiv (
.CLK_I(CLK),
.CLK_O(HCLK)
);
-
由于原设计适配的Nexys3开发板上的4位7段数码管为共阳,且管选信号为PMOS驱动,seg/dp和an均为低电平有效,而本次试验使用的数码管为共阴、管选信号为NMOS,所以seg/dp和an均为高电平有效,因此需要将信号反相,修改AHBLITE_SYS.v代码如下:
wire [6:0] seg_n;
wire [3:0] an_n;
wire dp_n;
assign seg = ~seg_n;
assign an = ~an_n;
assign dp = ~dp_n;
//AHBLite Slave
AHB7SEGDEC uAHB7SEGDEC (
//AHBLITE Signals
.HSEL(HSEL_7SEG),
.HCLK(HCLK),
.HRESETn(HRESETn),
.HREADY(HREADY),
.HADDR(HADDR),
.HTRANS(HTRANS[1:0]),
.HWRITE(HWRITE),
// .HSIZE(HSIZE),
.HWDATA(HWDATA[31:0]),
.HRDATA(HRDATA_7SEG),
.HREADYOUT(HREADYOUT_7SEG),
//Sideband Signals
.seg(seg_n),
.an(an_n),
.dp(dp_n)
);
PS:在实验过程中,由于误输入,assign an = ~an; 导致出现显示异常的错误,排查了较长时间,逐一测试各个部分的代码,最后才纠正为assign an = ~an_n;
-
IO引脚约束,按照FPGA开发板与数码管接线方式,将IO引脚约束到Dock底板的2.54mm排母上,对应的引脚如下:
IO_LOC "dp" N8;
IO_PORT "dp" PULL_MODE=UP DRIVE=8;
IO_LOC "an[3]" D14;
IO_PORT "an[3]" PULL_MODE=UP DRIVE=8;
IO_LOC "an[2]" B14;
IO_PORT "an[2]" PULL_MODE=UP DRIVE=8;
IO_LOC "an[1]" B13;
IO_PORT "an[1]" PULL_MODE=UP DRIVE=8;
IO_LOC "an[0]" B12;
IO_PORT "an[0]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[6]" N7;
IO_PORT "seg[6]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[5]" D11;
IO_PORT "seg[5]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[4]" B11;
IO_PORT "seg[4]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[3]" L9;
IO_PORT "seg[3]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[2]" N9;
IO_PORT "seg[2]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[1]" N6;
IO_PORT "seg[1]" PULL_MODE=UP DRIVE=8;
IO_LOC "seg[0]" A11;
IO_PORT "seg[0]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[7]" P6;
IO_PORT "LED[7]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[6]" T6;
IO_PORT "LED[6]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[5]" L16;
IO_PORT "LED[5]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[4]" L14;
IO_PORT "LED[4]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[3]" N14;
IO_PORT "LED[3]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[2]" N16;
IO_PORT "LED[2]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[1]" A13;
IO_PORT "LED[1]" PULL_MODE=UP DRIVE=8;
IO_LOC "LED[0]" C13;
IO_PORT "LED[0]" PULL_MODE=UP DRIVE=8;
IO_LOC "RESETn" T10;
IO_PORT "RESETn" PULL_MODE=UP;
IO_LOC "CLK" H11;
IO_PORT "CLK" PULL_MODE=UP;
-
之后便直接综合、布局布线、时序、功耗分析,生成bitstream文件,下载运行即可。
4.5.2. 软件汇编代码的Keil编译和调试
打开Keil项目,无需更改直接编译即可得到所需的Cortex-M0所需的可执行代码,其源代码如下:
Reset_Handler PROC
GLOBAL Reset_Handler
ENTRY
LDR R1, =0x50000000
LDR R4, [R1]
AGAIN STR R4, [R1]
LDR R0, =0xFFFFF
Loop SUBS R0,R0,#1
BNE Loop
ADDS R4,R4,#1
B AGAIN
ENDP
使用Keil调试,在调试前设置0x50000000地址处的内存空间为可读可写(见前述),执行断点调试,即可看到AHB7SEGDEC数据寄存器0x500000000处的值在变化,如图:
4.5.3. 实际运行效果
用杜邦线连接好FPGA开发板和数码管,将FPGA项目编译后的fs文件下载到FPGA开发板后,可见数码管按照预期的数字累加,如图:
|