[Xilinx AX7103 MicroBalze study notes 3] MicroBlaze uses AXI GPIO to control LED lights

content

experimental task

Experimental block diagram

Hardware Design (Vivado part)

New Construction

Building Block Design

Add constraint information

Software design (SDK part)

New Construction

 code section

Board Level Verification

Summarize

Past series of blogs


experimental task

This experiment realizes the control of LED lights by using AXI GPIO IP.

This experiment is implemented based on Vivado 2018.2

Experimental block diagram

The experimental block diagram is as follows. Compared with the previous experimental project block diagram of Hello World, this experiment only adds the IP core of AXI GPIO. Both AXI GPIO and AXI UART are interconnected with the MicroBlaze through the AXI Interconnect module. The Microblaze processor outputs the control signal of the LED light and transmits it to the AXI GPIO module through the AXI Interconnect interconnection module. The AXI GPIO module parses the LED light control signal according to the AXI4-Lite protocol. , output to the LED pin of the FPGA, so as to control the LED light.

Hardware Design (Vivado part)

New Construction

Since most of the operations are similar to the experimental operations of Hello World, some unimportant steps are simplified.

Based on the Hello World experiment, click File->Project->Save As and rename the project to axi_gpio_led.

Building Block Design

Open Block Design, add the AXI GPIO block, and configure it.

Configure the bit width of GPIO to 4, because there are 4 LED lights to be controlled, the rest of the parameters can be kept as default.

Click Auto connect, the system will connect automatically.

重新 “Generate Output Products” 和 “Create HDL Wrapper”

Generate Output Products  mainly updates the IP parameters and connection information to the Project, and also checks for errors.

The role of Create HDL Wrapper  is to instantiate each module or code file into the top-level file.

Add constraint information

In this project, you need to bind the LED pins additionally, and bind them with your own development board pin constraints.

set_property PACKAGE_PIN T6 [get_ports reset_n]
set_property IOSTANDARD LVCMOS15 [get_ports reset_n]
set_property PACKAGE_PIN N15 [get_ports uart_txd]
set_property PACKAGE_PIN P20 [get_ports uart_rxd]
set_property IOSTANDARD LVCMOS33 [get_ports uart_rxd]
set_property IOSTANDARD LVCMOS33 [get_ports uart_txd]
set_property PACKAGE_PIN R4 [get_ports diff_clk_clk_p]
set_property IOSTANDARD DIFF_SSTL15 [get_ports diff_clk_clk_p]
create_clock -period 5.000 [get_ports diff_clk_clk_p]

set_property PACKAGE_PIN B13 [get_ports {LED_tri_io[0]}]
set_property PACKAGE_PIN C13 [get_ports {LED_tri_io[1]}]
set_property PACKAGE_PIN D14 [get_ports {LED_tri_io[2]}]
set_property PACKAGE_PIN D15 [get_ports {LED_tri_io[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {LED_tri_io[3]}]
set_property IOSTANDARD LVCMOS33 [get_ports {LED_tri_io[2]}]
set_property IOSTANDARD LVCMOS33 [get_ports {LED_tri_io[1]}]
set_property IOSTANDARD LVCMOS33 [get_ports {LED_tri_io[0]}]

Finally, generate a bitstream file, import it into the hardware, start the SDK, and enter the design of the software part.

Software design (SDK part)

New Construction

Like the previous Hello World experimental project, create a new project named axi_gpio_led, and add a new code file in the src folder named main.c.

 code section

Copy the code of the experiment into mian.c

#include "xparameters.h"
#include "xgpio.h"
#include "xil_printf.h"
#include "sleep.h"

#define GPIO_DEVICE_ID  XPAR_GPIO_0_DEVICE_ID
#define LED_CHANNEL 1
#define LED_DELAY   50000000

XGpio Gpio; 

int main(void)
{
	int Status;
	int i=0;

	//初始化gpio
	Status = XGpio_Initialize(&Gpio, GPIO_DEVICE_ID);
	if (Status != XST_SUCCESS) {
		xil_printf("Gpio Initialization Failed\r\n");
		return XST_FAILURE;
	}

	//设置数据方向  0为输出 1为输入
	XGpio_SetDataDirection(&Gpio, LED_CHANNEL, 0);

	//循环闪烁LED

	while (1) {
	//向指定通道写入数据,LED每0.5秒流转一次
	XGpio_DiscreteWrite(&Gpio, LED_CHANNEL, 0x01 << i);
	//循环计数,表示第几个灯亮
	if(i == 3)
	i = 0;
	else
	i = i + 1;
	//延时0.5秒
	usleep(500000);
	 }
	return 0;
}
//代码来源于正点原子 

The code design process is:

  1. Initialize GPIO first
  2. Set the direction of the data, because GPIO is used to control the LED, so it is defined as output
  3. In an infinite loop, write data to the channel, let the LED light form a flow

Board Level Verification

Burn the program into the board to verify the correctness of the program, and you can see that the LED lights flash in the form of flowing water.

Summarize

Compared with the Hello World experiment, this experiment has made a small change, only adding an AXI GPIO module to control the LED.

Past series of blogs

[Xilinx AX7103 MicroBalze Study Notes 1] Introduction to MicroBlaze

[Xilinx AX7103 MicroBalze study notes 2] MicroBlaze serial port sending Hello World experiment

Guess you like

Origin blog.csdn.net/m0_61298445/article/details/124026956