Guidelines for Developing a Nios II HAL Device Driver

ID 683146
Date 6/12/2015
Public
Document Table of Contents

1.2.3. Configuring the Altera_Avalon_UART Component

In this section, you configure the Altera_Avalon_UART hardware component in Qsys. Perform the following steps:

  1. Start the Quartus II software. In the File menu, click Open Project.
  2. Browse to <my_design>.
  3. Select the Quartus II project file AN459.qpf, and click Open.
  4. In the Tools menu, click Qsys and open system.qsys.
  5. In Qsys, in the Module Name column, double-click on uart1.
  6. In the UART (RS-232 Serial Port) - uart1 dialog box, verify the baud rate is set to 115200 bps, as shown in the figure below.
    Figure 1. Verify UART Baud Rate
  7. Click Finish.
  8. In the System Contents tab of Qsys, verify the value for the UART base address.

    This design example uses a value of 0x80 for the UART’s register base address. If you use a hardware design other than the design example accompanying this application note, the value of the UART's register base address might be different. Open Qsys and find the UART base address for your board. The "uart1 Peripheral Register Base Address" figure shows the base address for the UART used in this example.

  9. Click Generate HDL in Qsys to regenerate the system.
  10. Recompile the Quartus II project.
  11. In the Quartus II software, in the Tools menu, click Programmer.
  12. To program the AN459.sof image to the development board, ensure that Program/Configure is turned on and click Start.
  13. In Qsys, on the Tools menu, click Nios II Command Shell.
  14. Change the directory to <my_design> /software_examples/app/bit_bang_uart.
    Figure 2. uart1 Peripheral Register Base Address
  15. Run the create-this-app script as follows:

    ./create-this-app

    This step might take several minutes to complete.

    The create-this-app script specifies the BSP named hal_my_uart. The hal_my_uart BSP associates the component instance uart1 with the software driver my_uart_driver, as shown in the summary.html excerpt in the "Driver Mapping in summary.html" figure. The create-this-bsp script for the hal_my_uart BSP selects component instance uart1 for the stdio device. Build messages are stored in bsp/hal_my_uart/hal_my_uart_build_log.txt.

    The compiler might report a small number of harmless warnings when you build bit_bang_uart. For a list of expected warnings, refer to the <my_design> /readme.txt file, extracted from an459-design-files.zip.

  16. Change the directory to <my_design> /software_examples/bsp/hal_my_uart.
  17. Edit alt_sys_init.c in your favorite editor. The vi editor is available from the Nios II Command Shell.
    Figure 3. Driver Mapping in summary.html
  18. Disable the automatic invocation of the HAL UART device driver initialization function by commenting out invocations of the following macros in alt_sys_init.c:
    • ALTERA_AVALON_UART_INSTANCE()
    • ALTERA_AVALON_UART_INIT()
  19. Save alt_sys_init.c.
  20. Rebuild the bit_bang_uart project by changing the directory back to <my_design> /software_examples/app/bit_bang_uart, and executing make.
  21. Connect a serial cable from the 9-pin console port on the Nios II development board to an RS-232 serial port on your development host computer.
  22. Ensure that your host serial port is configured with the following settings:
    Figure 4. Tera Term Serial Settings