How to use USB_CDC and Segger RTT at the same time?

Hello,

I am working on NCS v2.2.0. Currently, I am able to use USB CDC ACM on my development board. But, If I set CONFIG_LOG=y, I am seeing LOG_INF and printk function's messages at the RTT Viewer. If I set CONFIG_LOG=n, I am not seeing RTT messages on RTT terminal but I am able to see printk messages on the UART terminal.

My aim is this I want to use USB_CDC and RTT at the same time. I want to use LOG_INF for RTT and printk for UART terminal. Is this possible?

Thanks.

Parents
  • Hi

    How have you set CONFIG_LOG_PRINTK in your application, by default it is enabled, and will log printk messages unconditionally. If you disable this they will not, and RTT logging should behave as expected.

    Then you're free to set up printk to output wherever you like in your .overlay file with the zephyr,console. An example is how it's done in the nRF52 Dongle overlay files, where the UART0 instance is set up with the USB CDC ACM.

     / {
     	chosen {
     		zephyr,console = &cdc_acm_uart0;
    		};
    };
    
    &zephyr_udc0 {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    		label = "CDC_ACM_0";
    	};
    };

    Best regards,

    Simon

Reply
  • Hi

    How have you set CONFIG_LOG_PRINTK in your application, by default it is enabled, and will log printk messages unconditionally. If you disable this they will not, and RTT logging should behave as expected.

    Then you're free to set up printk to output wherever you like in your .overlay file with the zephyr,console. An example is how it's done in the nRF52 Dongle overlay files, where the UART0 instance is set up with the USB CDC ACM.

     / {
     	chosen {
     		zephyr,console = &cdc_acm_uart0;
    		};
    };
    
    &zephyr_udc0 {
    	cdc_acm_uart0: cdc_acm_uart0 {
    		compatible = "zephyr,cdc-acm-uart";
    		label = "CDC_ACM_0";
    	};
    };

    Best regards,

    Simon

Children
  • Hi  

    Thanks for your quick response. My overlay file is like you show me. This is my conf file.

    # Enable DK LED and Buttons library
    CONFIG_DK_LIBRARY=y
    ####
    
    # Config
    CONFIG_ASSERT=n
    CONFIG_REBOOT=n
    CONFIG_RESET_ON_FATAL_ERROR=n
    CONFIG_CPLUSPLUS=y
    CONFIG_MAIN_STACK_SIZE=4096
    CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    ####
    
    # Config LOGGER
    CONFIG_LOG=y
    CONFIG_RTT_CONSOLE=y
    CONFIG_USE_SEGGER_RTT=y
    CONFIG_LOG_BACKEND_RTT=y
    CONFIG_LOG_MODE_IMMEDIATE=y
    CONFIG_NEWLIB_LIBC=y
    CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y
    CONFIG_CBPRINTF_FP_SUPPORT=y
    
    CONFIG_LOG_PRINTK=n
    CONFIG_LOG_BACKEND_UART=n
    # to see DBG messages
    #CONFIG_LOG_DEFAULT_LEVEL=4
    ####
    
    # Console
    # Enable USB CDC ACM
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_DRIVER=y
    CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
    CONFIG_USB_DEVICE_MANUFACTURER="Nordic Semiconductor ASA"
    CONFIG_USB_DEVICE_VID=0x1915
    CONFIG_USB_DEVICE_PID=0x0100
    
    CONFIG_UART_LINE_CTRL=y
    #CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=n
    #CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
    #CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
    ####
    
    # Module UART
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_UART_CONSOLE=y
    ####
    
    # Config GPIO
    CONFIG_GPIO=y
    CONFIG_GPIO_NRFX=y
    ####

    I defined CONFIG_LOG_PRINTK as "n". But, printk and LOG_INF is working similar. Both function's messages are appear on RTT viewer. If I set CONFIG_LOG=n, printk starts sending message to UART terminal. However, I am not able to see RTT logs if I set CONFIG_LOG=n.

    Thanks.

Related