Guidelines for Developing a Nios II HAL Device Driver

ID 683146
Date 6/12/2015
Document Table of Contents Altera Logging Usage

You enable Altera logging with the hal.log_port BSP setting by setting the logging level with ALT_LOG_FLAGS. This setting causes the SBT to define ALT_LOG_ENABLE in

You can add Altera logging diagnostic messages to your code by invoking ALT_LOG_PRINTF(), a macro that handles most printf() formatting options.

Writes to the Altera logging device are blocking. Therefore, when hal.log_port is set to a component instance of type altera_avalon_jtag_uart, you must run an application to accept the Altera logging output in order for the Nios II application to complete initialization. Otherwise, the application pends on an ALT_LOG_PRINTF() statement until the Altera logging device's output buffer can be drained.

You can handle the JTAG UART logging output in either of the following ways:

  • Run your application in the Nios II SBT for Eclipse. JTAG UART logging output appears in the Nios II Console view.
  • Run your application from the Nios II Command Shell, with the nios2-download command. From another Nios II Command Shell, run nios2-terminal to accept the JTAG UART logging output.

You can disable the Altera logging feature by setting the hal.log_port setting in the BSP to none. This is the default setting. In the example BSP, hal_my_uart, the create-this-bsp script initially sets hal.log_port to jtag_uart. You can enable and disable it in the BSP Editor. After regenerating a BSP, you can check the value of hal.log_port in summary.html, located in the bsp/hal_my_uart folder.

Disabling Altera logging has the effect of leaving ALT_LOG_ENABLE undefined in bsp/hal_my_uart/ When this feature is disabled, the application does not pend on ALT_LOG_PRINTF() statements, even when no terminal capable of receiving Altera logging output is connected.

You can leave your ALT_LOG_PRINTF() debugging statements in the final source code version intended for production release, provided you set hal.log_port to none. With this setting, the definition of ALT_LOG_PRINTF() is empty, and so the compiler effectively removes these macro invocations. They have no impact on code footprint or performance unless you re-enable Altera logging.

For complete information about using the Altera logging functions, refer to "Using Character-Mode Devices" section in the "Developing Programs Using the Hardware Abstraction Layer" chapter in the Nios II Software Developer's Handbook.

Did you find the information on this page useful?

Characters remaining:

Feedback Message