<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Console output over USB</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/107615/console-output-over-usb</link><description>I&amp;#39;m a bit confused on the USB pins of the nRF5340 and how to use them. I have the USB D+/D- pins from my nRF5340 connected to the associated pins on a microUSB connector. I would like to get the console output from my application over the USB to a terminal</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 02 Feb 2024 19:49:01 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/107615/console-output-over-usb" /><item><title>RE: Console output over USB</title><link>https://devzone.nordicsemi.com/thread/467437?ContentTypeID=1</link><pubDate>Fri, 02 Feb 2024 19:49:01 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:5fe2d4df-1fe8-4d04-acdf-bb6fb87e7a6a</guid><dc:creator>KevinG</dc:creator><description>&lt;p&gt;Thanks for the great information.&amp;nbsp; Using the example in the link, I was able to use the USB for console output by making the following changes:&lt;/p&gt;
&lt;p&gt;prj.conf&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_LOG=y
CONFIG_LOG_BACKEND_SHOW_COLOR=y
CONFIG_LOG_MODE_DEFERRED=y
CONFIG_USB_DEVICE_STACK_NEXT=y
CONFIG_STDOUT_CONSOLE=y
CONFIG_UART_LINE_CTRL=y
CONFIG_USBD_CDC_ACM_CLASS=y
CONFIG_USBD_LOG_LEVEL_WRN=y
CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y
CONFIG_UART_CONSOLE=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Added to my dts for my custom board, but could be added to an overlay for a DK:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	chosen {
		...
		zephyr,console = &amp;amp;cdc_acm_uart0;
	};
	
	&amp;amp;usbd {
	status = &amp;quot;okay&amp;quot;;
	cdc_acm_uart0: cdc_acm_uart0 {
		compatible = &amp;quot;zephyr,cdc-acm-uart&amp;quot;;
	};
};&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;And in my&amp;nbsp;main.c file:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#include &amp;lt;zephyr/kernel.h&amp;gt;
#include &amp;lt;zephyr/device.h&amp;gt;
#include &amp;lt;zephyr/devicetree.h&amp;gt;
#include &amp;lt;zephyr/logging/log.h&amp;gt;
#include &amp;lt;zephyr/usb/usb_device.h&amp;gt;
#include &amp;lt;zephyr/usb/usbd.h&amp;gt;
#include &amp;lt;zephyr/drivers/uart.h&amp;gt;

...


BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart), &amp;quot;Console device is not ACM CDC UART device&amp;quot;);

USBD_CONFIGURATION_DEFINE(usbd_config_1, USB_SCD_SELF_POWERED, 200);

USBD_DESC_LANG_DEFINE(usb_lang);
USBD_DESC_MANUFACTURER_DEFINE(usb_mfr, &amp;quot;CompanyName&amp;quot;);
USBD_DESC_PRODUCT_DEFINE(usb_product, &amp;quot;ProjectName&amp;quot;);
USBD_DESC_SERIAL_NUMBER_DEFINE(usb_sn, &amp;quot;1234SERIALNUMBER&amp;quot;);

USBD_DEVICE_DEFINE(my_usbd, DEVICE_DT_GET(DT_NODELABEL(usbd)), 0x2fe3, 0x0001);

static int enable_usb_device_next(void)
{
	int err;

	err = usbd_add_descriptor(&amp;amp;my_usbd, &amp;amp;usb_lang);
	if (err) {
		return err;
	}

	err = usbd_add_descriptor(&amp;amp;my_usbd, &amp;amp;usb_mfr);
	if (err) {
		return err;
	}

	err = usbd_add_descriptor(&amp;amp;my_usbd, &amp;amp;usb_product);
	if (err) {
		return err;
	}

	err = usbd_add_descriptor(&amp;amp;my_usbd, &amp;amp;usb_sn);
	if (err) {
		return err;
	}

	err = usbd_add_configuration(&amp;amp;my_usbd, &amp;amp;usbd_config_1);
	if (err) {
		return err;
	}

	err = usbd_register_class(&amp;amp;my_usbd, &amp;quot;cdc_acm_0&amp;quot;, 1);
	if (err) {
		return err;
	}

	err = usbd_init(&amp;amp;my_usbd);
	if (err) {
		return err;
	}

	err = usbd_enable(&amp;amp;my_usbd);
	if (err) {
		return err;
	}

	return 0;
}
//End Logging Setup


int main(void)
{

    ...
    
     //Init USB Console
    enable_usb_device_next();
    const struct device *const usbDevice = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
	uint32_t dtr = 0;

    ...
    
    while(1) {
        //obviously change this to work for your needs
        if(!dtr) {
            uart_line_ctrl_get(usbDevice, UART_LINE_CTRL_DTR, &amp;amp;dtr);
        }

		k_msleep(SLEEP_TIME_MS);
    }&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Console output over USB</title><link>https://devzone.nordicsemi.com/thread/465275?ContentTypeID=1</link><pubDate>Mon, 22 Jan 2024 11:18:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:13342860-3b0d-442e-b7d8-99a09668c755</guid><dc:creator>H&amp;#229;kon Alseth</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Logging over USB uses CDC, which enumerates as a COM-port in the OS even though all communication is USB.&lt;/p&gt;
&lt;p&gt;To route a CDC ACM to the console, you can have a look at the zephyr/samples/subsys/usb/console sample, specifically in the app.overlay file:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/subsys/usb/console/app.overlay"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/main/samples/subsys/usb/console/app.overlay&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Kind regards,&lt;/p&gt;
&lt;p&gt;Håkon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>