This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to divert RTT logging to uart1 in Zephyr

I'm currently using Zephyr with Nordic Segger v5.50c.

Most of the code uses NRF_LOG, NRF_ERR statements which are printed to the Nordic Segger terminal.

I also configured the dts to use uart0, which is connected to a modem and is working fine.

I want to enable uart1 in the dts, and use it for RTT logging as well. For this I read:
https://docs.zephyrproject.org/latest/reference/logging/index.html

On the above they write about frontend and backend logging. But no reference to uart0 or uart1.
It looks like documentation how to write the code, but not how to configure the uart (might be Nordic documentation not Zephyr documentation)

I also found:
https://devzone.nordicsemi.com/f/nordic-q-a/73368/how-to-make-log_inf-and-log_err-print-over-uart0-in-nrf9160

But I don't understand chosen and the other parameters? Can it be this simple?

I also found:
https://devzone.nordicsemi.com/f/nordic-q-a/21189/how-to-enable-uart-or-rtt-logging-in-examples

But I don't see anywhere how to choose which uart to use? Is it uart0 by default?

I also noticed CONFIG_NRFX_UARTE0, but CONFIG_NRFX_UARTE1 does not exist? Maybe only uart0 is supported?
Do I have to reconfigure uart1 for the modem?

Parents Reply Children
  • Hi,

     

    My apologies for misunderstanding.

    ephimee said:
    because hello world uses printk and my project uses NRF_LOG?

    Do you mean LOG_INF? NRF_LOG is for nRF5 SDK.

    If you get output using printk(), then the serial output is in order.

     

    To enable LOG printing, in different modules, this is set explicitly in kconfig:

    https://docs.zephyrproject.org/latest/reference/logging/index.html#logging-kconfig

     

    here's the log subsys docs as well:

    https://docs.zephyrproject.org/latest/reference/logging/index.html

     

    First, to enable log, you need to add:

    CONFIG_LOG=y

    CONFIG_LOG_BACKEND_UART=y

     

    Then you set the desired level for the module you want to log from in kconfig as well.

     

    Kind regards,

    Håkon

  • Do you mean LOG_INF?

    Yes, sorry for the confusion, I meant LOG_INF.

    I still don't have logging.

    This is my main.c:

    #include <zephyr.h>
    #include <sys/printk.h>
    
    void main(void)
    {
    	printk("Hello World! %s\n", CONFIG_BOARD);
    }
    

    My overlay:

    / {
      
      chosen {
        zephyr,console = &uart0;
      };
    };
    
    &uart0 {
      compatible = "nordic,nrf-uarte";
      status = "okay";
      current-speed = <115200>;
      tx-pin = <33>;
      rx-pin = <34>;
    };
    

    My CMakeLists.txt:

    # SPDX-License-Identifier: Apache-2.0
      
    cmake_minimum_required(VERSION 3.13.1)
    
    # Set board folder
    set(BOARD_ROOT ${CMAKE_CURRENT_LIST_DIR})
    
    # Include the expansion board definition
    set(SHIELD overlay_folder)
    
    find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
    project(hello_world)
    
    target_sources(app PRIVATE src/main.c)
    

    My prj.conf:

    # Console
    CONFIG_UART_CONSOLE=n
    CONFIG_RTT_CONSOLE=n
    
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_USE_SEGGER_RTT=n
    
    # Logging
    CONFIG_LOG=y
    CONFIG_LOG_BACKEND_UART=y
    

  • Hi,

     

    printk uses the console backend for printing. You would want UART_CONSOLE set in this particular case, just to ensure that the pinout itself works as expected. It is very important to verify that the pinout and hardware connection is in order first, before jumping straight to the logging subsys configurations.

     

    Kind regards,

    Håkon

  • I now have:

    CONFIG_UART_CONSOLE=y
    

    And now hello world works.

    How do I make it work for uart1 in my "big" project?

    I tried to copy the same settings from hello world to my project, but I don't get any output.

    This is my prj.conf:

    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_NANO=n
    CONFIG_SIZE_OPTIMIZATIONS=y
    
    CONFIG_REBOOT=y
    CONFIG_MAIN_STACK_SIZE=2048
    CONFIG_HEAP_MEM_POOL_SIZE=32768
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
    CONFIG_STACK_SENTINEL=y
    
    CONFIG_LOG=y
    CONFIG_LOG_STRDUP_BUF_COUNT=32
    CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096
    CONFIG_I2C_LOG_LEVEL_OFF=y
    
    CONFIG_DEBUG=y
    CONFIG_ASSERT=y
    CONFIG_ASSERT_LEVEL=2
    CONFIG_LOG_BACKEND_UART=y
    CONFIG_LOG_BACKEND_RTT=n
    CONFIG_USE_SEGGER_RTT=n
    
    CONFIG_UART_CONSOLE=y
    CONFIG_RTT_CONSOLE=n
    
    CONFIG_I2C=y
    CONFIG_WATCHDOG=y
    CONFIG_NRFX_UARTE0=y
    CONFIG_NRFX_UARTE1=y
    CONFIG_NRFX_UARTE=y
    CONFIG_UART_ASYNC_API=y
    CONFIG_FLASH=y
    CONFIG_NETWORKING=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_OFFLOAD=y
    
    CONFIG_NET_IPV4=y
    CONFIG_NET_IPV6=n
    
    CONFIG_LWM2M=y
    CONFIG_LWM2M_RD_CLIENT_SUPPORT_BOOTSTRAP=y
    CONFIG_LWM2M_RD_CLIENT_ENDPOINT_NAME_MAX_LENGTH=64
    CONFIG_LWM2M_ENGINE_DEFAULT_LIFETIME=900
    CONFIG_LWM2M_COAP_BLOCK_SIZE=512
    CONFIG_COAP_INIT_ACK_TIMEOUT_MS=6000
    CONFIG_LWM2M_ENGINE_MAX_PENDING=10
    CONFIG_LWM2M_ENGINE_MAX_REPLIES=10
    
    CONFIG_LWM2M_DTLS_SUPPORT=y
    CONFIG_NET_SOCKETS_SOCKOPT_TLS=y
    CONFIG_NET_SOCKETS_OFFLOAD_TLS=n
    CONFIG_NET_SOCKETS_TLS_MAX_CONTEXTS=4
    CONFIG_NET_SOCKETS_ENABLE_DTLS=y
    CONFIG_MBEDTLS=y
    CONFIG_MBEDTLS_TLS_VERSION_1_2=y
    CONFIG_MBEDTLS_SSL_MAX_CONTENT_LEN=1500
    CONFIG_MBEDTLS_CIPHER_CCM_ENABLED=y
    CONFIG_MBEDTLS_KEY_EXCHANGE_RSA_ENABLED=n
    CONFIG_MBEDTLS_KEY_EXCHANGE_PSK_ENABLED=y
    CONFIG_LWM2M_CONN_MON_OBJ_SUPPORT=y
    

  • Hi,

     

    If you want uart1 to be the console output, you populate the my_application/boards/nrf52840dk_nrf52840.overlay file with this:

    / {
      chosen {
        zephyr,console = &uart1;
      };
    };
    
    &uart1 {
      compatible = "nordic,nrf-uarte";
      status = "okay";
      current-speed = <115200>;
      tx-pin = <33>;
      rx-pin = <34>;
    };

     

    Then re-configure and flash your project.

     

    Kind regards,

    Håkon

Related