Carte Basys 3

Pour programmer cette carte vous avez besoin de l'environnement Vivado.

Manuel d'utilisation de la carte

Fichier Xdc de la carte

Utilisation de XADC



Exmple: Create a microblaze project using Basys 3

Create a MicroBlaze project (Version 2018.2)

1- Create Block Diagram

2- Add « microBlaze »

3- Run block automation (then local memory 16KB)

4- Add « AXI GPIO »

5- Run connection automatic

6- Activate just AXI-GPIO_0

7- Double click on « Clocking wizard » (then in the tab « clocking option », in the primary « input clock » select « single ended clock …» ; in the tab « output Clock » uncheck « reset »

8- Add a constant block (double click, and check that the width and val are set to 1) => (connect the constant output to the ext_resest_in and aux_reset_in of the block « processor system reset ».

9- Right click on the « clk_in » of the block « Clocking Wizard » and select « make external »

10- Double click on AXI_GPIO and see that the GPIO is connected to the switches

11- Add another « AXI_GPIO » and double click on it and then select the LEDs

12- Run connection automation and activate axi_gpio_1

13- Check the design (you should receive « validation successful »)

Now we are going to assign the pins. Because we already selected the basys 3 board, the LEDs and the Switches are already done.

14- In the small « block design » window, select the tab « sources » then right click on design_1 and select « create HDL wrapper »

15- In « Flow Navigator », in the « RTL ANALYSIS » click on « open Elaborated Design » (this make some times to be completed!)

16- In the “layout” menu, select “I/O Planning”. In the bottom window, go to the tab “I/O Port” and select “LVCMOS33” pour “clk_in1_0”, and select “W5” as Package pin (which is 100 MHz clock)

17- You can see that the pins for LEDs and switches are already assigned.

18- Click on “generate bitstream”. Choose a file name when prompted.

Now everything is ok and the bit stream contains the circuit. We will go the software parts.

19- In the “File” menu “export” then “export hardware”, activate the inclusion of bitstream.

20- Lunch SDK

In SDK, we are going to program in C.

21- Menu “File” -> new -> application project; the give a name (“test” for example), then “next” and “empty application”.

22- In the project explorer window at the left, right click on test -> src, ten select "new source file", put a name with extension c: for example “main.c”.

23- In the main.c file include two .h files using #include "xparameters.h" and #include "xgpio.h"

24- Define as global two objects of XGpio class as : XGpio gpio_led, gpio_sw;

25- Then create the main program: int main() { …

26- Initialize the two objects such as they represent the two GPIO ports:

          XGpio_Initialize(&gpio_sw, XPAR_AXI_GPIO_0_DEVICE_ID);
          XGpio_Initialize(&gpio_led, XPAR_AXI_GPIO_1_DEVICE_ID);
      

27- For the output port define the data direction

          XGpio_SetDataDirection(&gpio_led,1,0);
    

28- Define a u16 variable : u16 sw;

29- In an infinite loop, read the state of the swithes and write it on the leds:

      while(1){
          sw = XGpio_DiscreteRead(&gpio_sw,1);
          XGpio_DiscreteWrite(&gpio_led,1,sw);
      }

30- Then just return 1 and close the main program with “}”

31- In the menu “run” go  to “run configuration” =>; double click on Xilinx C/C++ application (system debugger)

32- In the tab “Target setup” select “standalone” in “debug type”, then check the “reset entire system” check box.

33- In the tab “application” check the box in the “download” column

34- Apply and then Run

35- Menu “Xilinx” ->program FPGA

36- Menu “Run” or "debug"


Note about the channels in AXI GPIO

If you create in one AXI-GPIO two ports, for example one is connected to the SWs and the other to the LEDs, then the first one is the channel one and the seconde one is the channel 2. You can not to use the XGpio functions and directly work with memory. So for example if the SWs are channel one and the LEDs are channel 2, you can read the switches and write to the LEDs using:

      int *hex;
      int sw;
      int main{
        init_platform();
        hex = (int *)XPAR_AXI_GPIO_0_BASEADDR;
        sw = *hex; //(reading from channel 1)
        hex = hex + 2; //(here the address is incremented by 8 because we are using int, so 32 bits)
        *hex = sw;  //(writing to channel 2)
        cleanup_platform();
        return 0;
      }
      

In genertal, you can read or write directly from GPIO ports, by using pointers to memory without using the gpio functions.

There are also two functions that are defined to read from and write to memory using xgpio.h.

          sw = Xil_In32(XPAR_AXI_GPIO_0_BASEADDR); // to read from memory
          Xil_Out32(XPAR_AXI_GPIO_0_BASEADDR+8,sw);  // to write to memory