实验现象:
1、先烧写FPGA程序,再烧写ARM程序,ARM程序烧写完毕后即开始读写RAM测试,测试成功,绿色ARM·LED亮,测试失败,红色ARM·LED闪烁。
2、测试成功,ARM通过映射寄存器来控制FPGA三色LED循环点亮。
核心代码:
int main(void)
{ /* USER CODE BEGIN 1 */
int i; /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */
SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */
MX_GPIO_Init();
MX_FMC_Init(); /* USER CODE BEGIN 2 */
for(i = ;i < ;i ++){
fpga_write(i, * i);
}
for(i = ;i < ;i ++){
if(fpga_read(i) != *i){
while(){
LED_RED_ON;
HAL_Delay();
LED_RED_OFF;
HAL_Delay();
}
}
}
LED_GREEN_ON;
/* USER CODE END 2 */ /* Infinite loop */
/* USER CODE BEGIN WHILE */
while ()
{
/* USER CODE END WHILE */ /* USER CODE BEGIN 3 */
FPGA_LED_RED_ON;
FPGA_LED_GREEN_OFF;
FPGA_LED_BLUE_OFF;
HAL_Delay(); FPGA_LED_RED_OFF;
FPGA_LED_GREEN_ON;
FPGA_LED_BLUE_OFF;
HAL_Delay(); FPGA_LED_RED_OFF;
FPGA_LED_GREEN_OFF;
FPGA_LED_BLUE_ON;
HAL_Delay();
}
/* USER CODE END 3 */ }
//-----------------------Module fsmc_ctrl-----------------------//
module fsmc_ctrl(
input clk_100m,
input rst_n,
input [:]ab,
inout [:]db,
input wr_n,
input rd_n,
input cs0,
input nadv,
output led_red,
output led_green,
output led_blue
); wire wr,rd;
wire [:]out_data;
//-------------------------wr & rd-----------------------------//
assign wr = cs0 | wr_n;
assign rd = cs0 | rd_n; //-------------------------address-----------------------------//
reg [:]address;
always@(posedge nadv or negedge rst_n)
if(!rst_n)
address <= 'd0;
else
address <= {ab,db}; //锁存地址 //----------------------------clk------------------------------//
reg wr_clk1,wr_clk2;
always@(posedge clk_100m or negedge rst_n)
if(!rst_n)
begin
wr_clk1 <= 'd1;
wr_clk2 <= 'd2;
end
else
{wr_clk2,wr_clk1} <= {wr_clk1,wr}; wire clk = (!wr_clk2 | !rd); assign db = !rd ? out_data:'hzzzz; //----------------------------ram------------------------------//
ram u1(
.address(address),
.clock(clk),
.data(db),
.wren(!wr),
.rden(!rd),
.q(out_data)
); //----------------------------led_ctrl-------------------------//
reg led[:];
always@(posedge wr or negedge rst_n)
if(!rst_n)
begin
led[] <= 'd1;
led[] <= 'd0;
led[] <= 'd1;
end
else
begin
case(address) //映射寄存器地址
'd10:led[0] <= db;
'd11:led[1] <= db;
'd12:led[2] <= db;
endcase
end assign led_red = led[];
assign led_green = led[];
assign led_blue = led[]; endmodule
源代码下载链接:
链接:http://pan.baidu.com/s/1nvkhPWl 密码:7x76
iCore4链接: