Nios® II Software Developer Handbook

ID 683525
Date 8/28/2023
Public
Document Table of Contents

7.7.6.1. Enabling Logging

Logging is enabled by setting hal.log_port to a JTAG UART or a UART device. The setting allows the HAL to send log messages to the specified device.

Once hal.log_port is set, ALT_LOG_ENABLE is defined in public.mk and the ALT_LOG_FLAGS flag is set to 0, the default value.
Note: You can set ALT_LOG_FLAGS to any value from 1 to 4, to determine the level of output.
Note: If hal.log_port is not set, then ALT_LOG_ENABLE and ALT_LOG_FLAGS do not appear in public.mk.

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 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 logging device stalls in ALT_LOG_PRINTF() until the characters are read from the logging device’s output buffer. To ensure that the Nios® II application completes initialization, run the nios2-terminal command from the Nios® II Command Shell to accept the logging output.