Guidelines for Developing a Nios II HAL Device Driver

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

1.12. Debugging the HAL UART Device Driver

For the next set of debugging examples, you must create a new application. For these examples, create the hello_world_my_uart application and import it to the Nios II SBT for Eclipse. Next, regenerate the files which make up the hal_my_uart BSP. This time, instead of commenting out the invocation of the macros ALTERA_AVALON_UART_INSTANCE() and ALTERA_AVALON_UART_INIT(), let the alt_sys_init() function install the Altera Avalon UART HAL device driver, after which you can inspect its operation.

The following sections show examples of placing breakpoints and watchpoints in HAL device driver source code to analyze component instance behavior.

To create and import the hello_world_my_uart project, perform the following steps:

  1. Delete the generated file from the hal_my_uart BSP. Enter the following command in the Nios II Command Shell:

    rm <my_design>/software_examples/bsp/hal_my_uart/

    Deleting these files causes the next build to regenerate the hal_my_uart BSP files, including alt_sys_init.c.

  2. Create the hello_world_my_uart application by invoking its create-this-app script. Enter the following commands:

    cd <my_design>/software_examples/app/hello_world_my_uart r ./create-this-app

    This action accomplishes several tasks:

    • Invokes the create-this-bsp script for the hal_my_uart BSP.
    • In the BSP, deletes and rebuilds generated files and object files from the previous build.
    • Builds the libhal_bsp.a BSP library in the

      <my_design> /software_examples/bsp/hal_my_uart directory.

    • Builds the hello_world_my_uart.elf file in the

      <my_design> /software_examples/app/hello_world_my_uart directory.

    • Generates a new file.
    • Sets the software device descriptors stdout, stderr, and stdin to uart1. The <my_design> /software_examples/bsp/hal_my_uart/create-this-bsp script sets up these software device descriptors by calling nios2-bsp.
    • Creates the software device driver, my_uart_driver, in the <my_design> /ip/my_uart directory, and associates it with the Altera_Avalon_UART device. The <my_design> /ip/my_uart/my_uart_sw.tcl script creates the driver and associates it with its device.
    • Sets the software device driver called my_uart_driver to the component instance named uart1. The <my_design> /software_examples/bsp/hal_my_uart/ hal_my_uart.tcl script, passed to nios2-bsp, sets the driver to uart1.
    • Regenerates alt_sys_init.c by invoking of ALTERA_AVALON_UART_INIT().
      Note: You can invoke nios2-bsp with the --debug parameter, which displays verbose information about the construction steps in this section. The --debug parameter can be very useful for finding errors in the construction of the relevant Tcl scripts and command shell scripts.
  3. Import the hello_world_my_uart application to the Nios II SBT for Eclipse as described in the section Importing Projects in Steps 2 through 8, substituting the hello_world_my_uart application for the bit_bang_uart application. It is not necessary to re-import the BSP.

Did you find the information on this page useful?

Characters remaining:

Feedback Message