Using USB as virtual com as log with zephyr

Hi to all,

I'm developing a beacon application on the nRF52840-DK starting from the example that I found in the VS Code (Zephyr).

I'm designing a custom board with only the nRF onboard (without the interface MCU).

If I insert a USB cable in the USB connector of the nRF micro I cannot see any virtual COM on my PC.

How could I use the USB peripheral of the nRF micro as virtual COM for logging purpose in the Zephyr OS?

Thanks in advance.

Parents Reply
  • Hi,

    When testing the CDC ACM USB sample, I saw that the log is printed on the UART port, but only if the USB is connected. I suspect this is not what you want to achieve, so I made a sample that only uses nRF USB, which I have attached here. It is the Hello World sample from Zephyr, and I only added support for CDC ACM USB, so it is very simple and should be straightforward to incorporate into other projects.

    This is what the prj.conf looks like:

    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_REMOTE_WAKEUP=n
    CONFIG_USB_DEVICE_PRODUCT="My USB device"
    CONFIG_USB_CDC_ACM=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_USB_DEVICE_PID=0x0001
    CONFIG_USB_CDC_ACM_LOG_LEVEL_OFF=y
    
    CONFIG_LOG=y

    And the devicetree overlay:

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

    In main,c you need to include the usb_device.h file and enable USB with usb_enable():

    #include <zephyr/kernel.h>
    #include <zephyr/usb/usb_device.h>
    #include <zephyr/logging/log.h>
    
    LOG_MODULE_REGISTER(app);
    
    int main(void)
    {
    	usb_enable(NULL);
    	printf("Hello World! %s\n", CONFIG_BOARD);
    	while(true){
    		LOG_INF("Hello World\n");
    		/* Wait 100ms for the host to do all settings */
    		k_msleep(100);
    	}
    	return 0;
    }
    

    hello_world_usb.zip

    Please let me know if this makes it so you can get logs from the USB/COM13 or not Slight smile

    Best regards,
    Marte

Children
No Data
Related