Having issues with serial debugging with cdc_acm_uart0 on the Particle Xenon board.

CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM sample"
CONFIG_USB_DEVICE_PID=0x0001
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
CONFIG_SERIAL=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y

CONFIG_USB_CDC_ACM=y
CONFIG_UART_CONSOLE=n
CONFIG_LOG=y
CONFIG_USB_DRIVER_LOG_LEVEL_DBG=y
CONFIG_USB_CDC_ACM_LOG_LEVEL_DBG=y  # Explicitly enable CDC ACM logging
CONFIG_UART_LINE_CTRL=y

Here is my code:

#include <zephyr/kernel.h>

#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/logging/log.h>

LOG_MODULE_REGISTER(meat);
#include <zephyr/drivers/uart.h>

void main(void)
{
    //     const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
    // uint32_t dtr = 0;

    if (usb_enable(NULL))
    {
        return;
    }

    while (1)
    {
        printk("HELLO\n");
        k_sleep(K_MSEC(100));
    }

    return 0;
}


My issue is I am trying to get logging to happen over USB using the cdc acm with the Particle XENON board.
https://docs.particle.io/reference/discontinued/hardware/xenon-datasheet/

I can get the com port to show up with this code.  However when I connect to it via putty it does not print anything.  Also I am not sure how to set the default baud rate when using the cdc acm.  Perhaps I am not understanding how this works exactly.  Is it that the usb cdc acm just connects the uart to a usb serial port profile?  Meaning you are still using one of the uart ports available on this soc?

If anyone has any ideas on why this is happening I would really appreciate it !


Thanks!

  • Hi,

     

    You need to have a overlay with the following:

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

     

    Here the prj.conf that I used:

    CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM sample"
    CONFIG_USB_DEVICE_PID=0x0001
    CONFIG_LOG=y
    CONFIG_SERIAL=y
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=y
    CONFIG_USB_DEVICE_STACK=y
    
    CONFIG_USB_CDC_ACM=y
    CONFIG_UART_CONSOLE=y
    CONFIG_LOG=y
    CONFIG_UART_LINE_CTRL=y
    

     

    When you have USB_DEVICE_INITIALIZE_AT_BOOT set, calling usb_enable will fail, so you should add a if condition around it:

    #include <zephyr/kernel.h>
    
    #include <zephyr/usb/usb_device.h>
    #include <zephyr/usb/usbd.h>
    #include <zephyr/logging/log.h>
    
    LOG_MODULE_REGISTER(meat);
    #include <zephyr/drivers/uart.h>
    
    int main(void)
    {
        //     const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
        // uint32_t dtr = 0;
    	LOG_INF("Hi");
        #if !defined(CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT)
        if (usb_enable(NULL))
        {
    		LOG_INF("usb already enabled");
    		k_msleep(1000);
            return 0;
        }
        #endif
        while (1)
        {
            printk("HELLO\n");
            k_sleep(K_MSEC(100));
        }
    
        return 0;
    }

     

    Kind regards,

    Håkon

  • Happy to help. Hope you have a wonderful day!

     

    Kind regards,

    Håkon

Related