Specifications
printed in response to several conditions. Altera logging can be enabled and disabled independently of
any normal stdio output, making it a powerful debugging tool.
When Altera logging is enabled, your software can print extra messages to a specified port with HAL
function calls. The logging port, specified in the BSP, can be a UART or a JTAG UART device. In its
default configuration, Altera logging prints out boot messages, which trace each step of the boot process.
Note: Avoid setting the Altera logging device to the device used for stdout or stderr. If Altera logging
output is sent to stdout or stderr, the logging output might appear interleaved with the stdout
or stderr output
Several logging options are available, controlled by C preprocessor symbols. You can also choose to add
custom logging messages.
Note: Altera logging changes system behavior. The logging implementation is designed to be as simple as
possible, loading characters directly to the transmit register. It can have a negative impact on
software performance.
Altera logging functions are conditionally compiled. When logging is disabled, it has no impact on code
footprint or performance.
Note: The Altera reduced device drivers do not support Altera logging.
Enabling Altera Logging
The Nios II SBT has a setting to enable Altera logging. The setting is called hal.log_port. It is similar to
hal.stdout, hal.stdin, and hal.stderr. To enable Altera logging, you set hal.log_port to a JTAG UART or
a UART device. The setting allows the HAL to send log messages to the specified device when a logging
macro is invoked.
When Altera logging is enabled, the Nios II SBT defines ALT_LOG_ENABLE in public.mk to enable log
messages and sets ALT_LOG_FLAGS to 0. The build tools also set the ALT_LOG_PORT_TYPE and
ALT_LOG_PORT_BASE values in system.h to point to the specified device.
When Altera logging is enabled without special options, the HAL prints out boot messages to the selected
port. For typical software that uses the standard alt_main.c (such as the Hello World software example),
the messages appear as in the following example.
Example 6–5. Default Boot Logging Output
[crt0.S] Inst & Data Cache Initialized.
[crt0.S] Setting up stack and global pointers.
[crt0.S] Clearing BSS
[crt0.S] Calling alt_main.
[alt_main.c] Entering alt_main, calling alt_irq_init.
[alt_main.c] Done alt_irq_init, calling alt_os_init.
[alt_main.c] Done OS Init, calling alt_sem_create.
[alt_main.c] Calling alt_sys_init.
[alt_main.c] Done alt_sys_init. Redirecting IO.
[alt_main.c] Calling C++ constructors.
[alt_main.c] Calling main.
[alt_exit.c] Entering _exit() function.
[alt_exit.c] Exit code from main was 0.
[alt_exit.c] Calling ALT_OS_STOP().
[alt_exit.c] Calling ALT_SIM_HALT().
[alt_exit.c] Spinning forever.
Note:
A write operation to the Altera logging device stalls in ALT_LOG_PRINTF() until the characters are
read from the Altera logging device’s output buffer. To ensure that the Nios II application
6-8
Enabling Altera Logging
NII5V2
2015.05.14
Altera Corporation
Developing Programs Using the Hardware Abstraction Layer
Send Feedback