Lab05 External IO Control Xilinxaccess.ee.ntu.edu.tw/course/soc2004/version 3/lab05... ·...

19
Contents 5. External I/O Control .................................................................................. 5-1 5.1. 實驗目的............................................................................................ 5-1 5.2. 實驗原理............................................................................................ 5-1 5.2.1. About the GPIO unit .................................................................. 5-1 5.2.2. GPIO Overview ......................................................................... 5-2 5.2.3. Programmer’s model .................................................................. 5-3 5.3. 引導實驗............................................................................................ 5-4 5.3.1. 檔案說明.................................................................................... 5-4 5.3.2. 實驗步驟.................................................................................... 5-5 5.4. 實驗要求.......................................................................................... 5-17 5.5. 問題與討論...................................................................................... 5-18 5.6. 參考文件.......................................................................................... 5-18 說明 1. 本實驗所需設備:ARM Integrator AP、CM、LM (Xilinx)、ARM Multi-ICE、 麵包版、LED、文字型 LCD;本實驗所需軟體:ARM Developer Suite、Xilinx ISE。 2. 本實驗需用到 LM 中的 FPGA 。規劃 LM FPGA 的方法在另一個實驗「ASIC Logic」中提及,故授課教師可依實際狀況將本實驗安排在「ASIC Logic」實 驗之後。

Transcript of Lab05 External IO Control Xilinxaccess.ee.ntu.edu.tw/course/soc2004/version 3/lab05... ·...

  • Contents 5. External I/O Control .................................................................................. 5-1

    5.1. 實驗目的............................................................................................ 5-1 5.2. 實驗原理............................................................................................ 5-1

    5.2.1. About the GPIO unit .................................................................. 5-1 5.2.2. GPIO Overview ......................................................................... 5-2 5.2.3. Programmer’s model.................................................................. 5-3

    5.3. 引導實驗............................................................................................ 5-4 5.3.1. 檔案說明.................................................................................... 5-4 5.3.2. 實驗步驟.................................................................................... 5-5

    5.4. 實驗要求.......................................................................................... 5-17 5.5. 問題與討論...................................................................................... 5-18 5.6. 參考文件.......................................................................................... 5-18

    說明

    1. 本實驗所需設備:ARM Integrator AP、CM、LM (Xilinx)、ARM Multi-ICE、麵包版、LED、文字型 LCD;本實驗所需軟體:ARM Developer Suite、Xilinx

    ISE。

    2. 本實驗需用到 LM 中的 FPGA。規劃 LM 的 FPGA 的方法在另一個實驗「ASIC Logic」中提及,故授課教師可依實際狀況將本實驗安排在「ASIC Logic」實驗之後。

  • External I/O control

    教育部 SoC 聯盟教材 5-1

    5. External I/O Control --Using the GPIO Unit to Control the External I/O Devices

    5.1. 實驗目的

    In this Lab, you will learn (1) the operation mechanism of a GPIO (General Purpose Input/Output) unit, (2) the method of connecting an external I/O device to the ARM Integrator Platform, and (3) how to employ the GPIO to control the external I/O device.

    5.2. 實驗原理

    5.2.1. About the GPIO unit

    The GPIO (General Purpose Input/Output) unit is an AMBA slave module that connects to the APB. It has 16 bits of programmable input/output organized as two 8-bit ports, port A and port B. Pins of both ports can be configured as either inputs or outputs. The GPIO unit interface with input/output pad cells using a data input, data output and output enable line per pad. Figure 5-1 illustrates the GPIO interfaces, and Figure 5-2 shows the GPIO block diagram.

    Figure 5-1. GPIO interfaces.

  • External I/O control

    教育部 SoC 聯盟教材 5-2

    Figure 5-2. GPIO block diagram

    5.2.2. GPIO Overview

    GPIO provides 16 inputs/outputs organized as two 8-bit groups, port A and port B. The CPU reads and writes data and control/status information to and from GPIO via the AMBA APB interface. Each port has an associated data direction register and a data register.

    Data direction register The data direction register is 8 bits wide, and is programmed to select whether each individual input/output pin is configured as an input or an output.

    Data register The data register is 8 bits wide, and is used to read the value input on those

    GPIO lines that are configured as inputs, and to program the value output on those GPIO line that are configured as outputs.

    AMBA APB interface

    The AMBA APB groups narrow-bus peripherals to avoid loading the system bus, and provides an interface using memory-mapped registers which are accessed

  • External I/O control

    教育部 SoC 聯盟教材 5-3

    under programmed control. The AMBA APB interface generate read and write decodes for accesses to the control register and data register for each input/output port.

    5.2.3. Programmer’s model

    The GPIO registers are shown in Table 5-1.

    Table 5-1. GPIO register summary

    GPIOPADDR is the port A data direction register. Bits set in GPIOPADDR will set the corresponding pin in PORT A to be an output. Clearing a bit configures the pin to be an input. GPIOPBDDR is the port B data direction register. Bits cleared in GPIOPBDDR will set the corresponding pin in PORT B to be an output. Setting a bit configures the pin to be an input.

    The base address of the PrimeCell GPIO is not fixed, and may be different for any particular system implementation. However, the offset of any particular register from the base address is fixed. In this Lab, the GPIO unit is implemented in the FPGA of LM, and the base address of GPIO is selected as 0xC2100000.

  • External I/O control

    教育部 SoC 聯盟教材 5-4

    Figure 5-3. Memory map of Logic Module

    5.3. 引導實驗

    In this Lab, you will implement a GPIO in the FPGA of the logic module. The port A and port B of the GPIO unit will be assigned to those FPGA pins that connected to the prototyping grids such that the ports of GPIO can be accessed via the prototyping grids on the logic module. You will use the GPIO to control the flashing of LEDs on a breadboard. In the exercise, you are asked to employ the GPIO unit to control a text LCD display.

    5.3.1. 檔案說明

    The associated Verilog files include AHBAPBSys.v

    AHBAHBTop.v

    AHB2APB.v

    AHBDecoder.v

    AHBDefaultSlave.v

    AHBMuxS2M.v

    AHBZBTRAM.v

  • External I/O control

    教育部 SoC 聯盟教材 5-5

    APBIntcon.v

    APBRegs.v

    GPIO060.v

    APBMuxP2B.v

    You can find the Verilog files in the directory Codes/HW/Xilinx/GPIO/Verilog. Also, you can find a testbench for simulating the GPIO unit in the directory Codes/HW/Xilinx/GPIO/Testbench. The associated software source codes can be found in the directory Codes/SW/GPIO. The associated reference documents, such as ARM PrimeCell™ General Purpose Input/Output (PL060)Technical Reference Manual, the document of the LM PCB layout, and documents for text LCD display, can be found in the directory Doc/Ref.

    5.3.2. 實驗步驟

    1. Pin Assignment We want the input/output ports of GPIO to be connected to the prototyping grids

    in the logic module such that we can access the input/output ports of GPIO via the prototyping grids. From the document lm_xcv600e_revc.pdf (in “\Program Files\ARM\Logic Modules\LM-XCV600E\schematics\lm_xcv600e_revc.pdf”), you can find the schematic diagram of the LM PCB. Figure 5-4 shows part of the pin names of prototyping grids in the logic module, and Figure 5-5 shows the Bank-0 pin names of the FPGA. You can see that many Bank-0 pins of FPGA are wired to the prototyping grids in the logic module. You have to modify the file xxx.ucf(\Codes\HW\Xilinx\GPIO\PnR\AHBAHBTop.ucf)such that the pins of the GPIO are assigned to the appropriate pins of the FPGA that are connected to the prototyping grids. In the following, we will assign the port A of GPIO to row 2 of prototyping grid, and assign port B to row 3 of the prototyping grid.

  • External I/O control

    教育部 SoC 聯盟教材 5-6

    Figure 5-4. Pin names of prototyping grids in the logic module

    Figure 5-5. The Bank-0 pin names of the FPGA (XCV600E)

    (2) Add the pin assignment into ***.ucf (AHBAHBTop.ucf)as following: NET GPIO1XPA LOC=b20;

    NET GPIO1XPA LOC=a21;

    NET GPIO1XPA LOC=b21;

    NET GPIO1XPA LOC=a22;

    NET GPIO1XPA LOC=b22;

    NET GPIO1XPA LOC=c22;

    NET GPIO1XPA LOC=d22;

    NET GPIO1XPA LOC=e22;

    NET GPIO1XPB LOC=a23;

  • External I/O control

    教育部 SoC 聯盟教材 5-7

    NET GPIO1XPB LOC=b23;

    NET GPIO1XPB LOC=c23;

    NET GPIO1XPB LOC=d23;

    NET GPIO1XPB LOC=e23;

    NET GPIO1XPB LOC=a24;

    NET GPIO1XPB LOC=b24;

    NET GPIO1XPB LOC=c24;

    2. Logic Synthesis (1) Start Xilinx ISE 6.1 from the start menu and then you will see Figure 5-6.

    Figure 5-6 (2)Create a New Project

    (a)Input the project name (b)Assign the project location (see Figure 5-7)

  • External I/O control

    教育部 SoC 聯盟教材 5-8

    Figure 5-7 (3)Choose your device and then press next button (see Figure 5-8)

    (a) Device Family: VirtexE (b) Device: xcv2000e (c) Package: fg680 (d) Speed Grade: -6

  • External I/O control

    教育部 SoC 聯盟教材 5-9

    Figure 5-8 (4)Press next button (see Figure 5-9)

    Figure 5-9

  • External I/O control

    教育部 SoC 聯盟教材 5-10

    (5) Project→add source File(s) (\Codes\HW\Xilinx\GPIO\Verilog\*.v)

    Figure 5-10 (6)Then you can see Figure 5-11

  • External I/O control

    教育部 SoC 聯盟教材 5-11

    Figure 5-11 (7) Press the next button (you will see Figure 5-12)

    Figure 5-12

  • External I/O control

    教育部 SoC 聯盟教材 5-12

    (8)Press finish button (you will see Figure 5-13)

    Figure 5-13 (9)Add AHBAHBTop.ucf file to this project associate with AHBAHBTop.

    ( choose Project --->Add sources ,see Figure 5-14 ) (\Codes\HW\Xilinx\GPIO\PnR)

  • External I/O control

    教育部 SoC 聯盟教材 5-13

    Figure 5-14 (10)Generate the Binary Bitstreams (a) Select Top module (AHBAHBTop)

    (b) Double click the Generate Programming File (see Figure 5-15)

    Figure 5-15

  • External I/O control

    教育部 SoC 聯盟教材 5-14

    NOTE: (1) To ensure that Xilinx generate a file that operates correctly with logic module,

    you use some setting (reference “Integrator/LM-XCV600E+ User Guide” “Integrator/LM-EP20K600E+ User Guide” CHAPTER 5 Configuring Xilinx Logic Modules at page 5-1), and then compile your design to generate .bit file.

    (2) Be careful !! Before programming the FPGA, you must generate a *.ucf file and then compile your design. Then, Xilinx will generate .bit file.

    3. Porting the Bit file (AHBAHBTop.bit) to the Logic Module (1) Create a BRD file as below [General]

    Name = AHB XCV2000E -> flash (addr 0x0)

    Priority = 1

    [ScanChain]

    TAPs = 2

    TAP0 = XCV2000E

    TAP1 = XC9572XL

    [Program]

    SequenceLength = 3

    Step1Method = Virtex

    Step1TAP = 0

    Step1File = lmxcv600e_72c_xcv2000e_via_reva_build0.bit

    Step2Method = IntelFlash

    Step2TAP = 0

    Step2File = ahbahbtop.bit

    Step3Method = IntelFlashVerify

    Step3TAP = 0

    Step3File = ahbahbtop.bit

    Save the file and rename it as GPIO.brd. (2) Copy the file progcard.exe (in \Program Files\ARM\Logic\Modules\LM-XCV600E\configure\) to your working directory (3) Make sure that the Integrator is power off. (4) Adjust the logic module into Flash Program Mode as follows:

    (i) Let the CONFIG LINK be shorted.

  • External I/O control

    教育部 SoC 聯盟教材 5-15

    (ii) Close the switch S1[4] (the switch is pull down).. (5) Connect the Multi-ICE unit to the Logic Module. (6) Power on the Integrator. (7) Run the ARM Multi-ICE Server (/Programs/ARM Multi-ICE v2.2/Multi-ICE Server) (Figure 5-16).

    Figure 5-16. Multi-ICE Server

    (8)Check if the three files lmxcv600e_72c_xcv2000e_via_reva_build0.bit , AHBAHBTop.bit , GPIO.brd, and progcard.exe exist in the working directory. Execute progcard.exe (Figure 5-17). This step will download the design into the flash of LM.

  • External I/O control

    教育部 SoC 聯盟教材 5-16

    Figure 5-17. Execute the progcard.exe to download the design into the flash.

    (9)Shutdown the Integrator. (10)Adjust the logic module into the User Mode as follows:

    (i) Adjust the CONFIG Link as open; (ii) Adjust the S1[4] as open (pull up).

    (11) Adjust the switch S1[1] as closed (down) and switch S1[3] as open (up) to select flash image 0. 4. Running the application program An application example that employs the GPIO implemented in LM FPGA to control the LED is given in the directory Codes/SW/GPIO.

    (1) Connect Row 2 and Row 3 of the prototyping grid to the LEDs in a breadboard (Figure 5-18).

    Note: We should series the LEDs with protective resistances to limit the current.

  • External I/O control

    教育部 SoC 聯盟教材 5-17

    Figure 5-18. Connect the prototype grids to the LEDs in a breadboard

    (2) Connect Multi-ICE to the Core Module (3) Start the Multi-ICE Server (4) Start CodeWarrior. Create a new project, and add the files in the directory

    Codes/SW/GPIO to the project. Build this project. (5) Run the AXD and you will see the LEDs connected on the breadboard are

    flashing.

    5.4. 實驗要求

    1. Understand the Verilog codes of GPIO and the source codes of the application program, and try to modify the application program such that the LEDs flash in a different way.

    2. Modify the application program such that you can use the GPIO unit to control an external text LCD such that you can display an arbitrary string in the LCD.

  • External I/O control

    教育部 SoC 聯盟教材 5-18

    5.5. 問題與討論

    1. Read the ARM PrimeCell General Purpose Input/Output (PL061) Technical Reference Manual and compare the differences between GPIO PL060 and GPIO PL061.

    5.6. 參考文件

    1. ARM PrimeCell General Purpose Input/Output (PL060) Technical Reference Manual (ARM DDI 0142B).

    2. Zong-xin Lin, “Design of an ARM-based System-on-Chip for Real-time QRS Detection in Electrocardiogram,” master thesis, Department of Electrical Engineering, Chang Gung University, Taiwan, June 2003.

    3. Xilinx Logic Module Schematics : lm_xcv600e_revc.pdf