This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to enable UART COM port on nRF52840 Dongle

Hi 

I am working on nRF52840 Dongle S140 SDK15.2.

i am developing BLE NUS application for dongle. but dongle is not supporting UART com port through USB connection.

What should be enabled to get COM Port over USB?

I tried to connect UART pin 10, 13 externally to get UART port. but we do not want to connect this way. we want to get UART console over USB itself.

Please guide.

Thanks

Rekha

Parents
  • Because all the answers about three years ago, I would like to add the example solution from sdk 1.7.1 + zephyr:

    Please have a look at example "/samples/subsys/usb/console": http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/usb/console/README.html?highlight=acm

    Flashing the device is nicely explained here: https://docs.zephyrproject.org/2.6.0/boards/arm/nrf52840dongle_nrf52840/doc/index.html

    ---

    1) After installing the toolchain successfully, or just use the docker container https://github.com/NordicPlayground/nrfconnect-chip-docker, connect the dongle with your pc.

    2) Bring it into bootloader mode by pressing the reset button (the red led LD2 will flash)

    3) build the sample project:

      west build -b nrf52840dongle_nrf52840 zephyr/samples/basic/blinky

    4) package the code for the bootloader:

      nrfutil pkg generate --hw-version 52 --sd-req=0x00 --application build/zephyr/zephyr.hex --application-version 1 usb_console_test.zip

    5) flash it to the device:

      nrfutil dfu usb-serial -pkg usb_console_test.zip -p /dev/ttyACM0

    if you use docker, you can use the --privileged flag to mount all devices with proper rights (this is unsafe but we just use it for flashing the device):

    docker run --rm -it -v <local_ncs>:/var/ncs --privileged nordicsemi/nrfconnect-chip:latest

    This should flash your dongle with the example application and you should be able to see some Hello World message via your favorite monitor.

    Or simply use: cat /dev/ttyACM0

    ---

    If we checkout the code, we see, that we need to enable the USB_UART_CONSOLE and bind it in the source code:

    prj.conf:

    CONFIG_USB=y
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
    CONFIG_USB_UART_CONSOLE=y
    
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
    

    main.c

    /*
     * Copyright (c) 2016 Intel Corporation.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <sys/printk.h>
    #include <sys/util.h>
    #include <string.h>
    #include <usb/usb_device.h>
    #include <drivers/uart.h>
    
    void main(void)
    {
    	const struct device *dev = device_get_binding(
    			CONFIG_UART_CONSOLE_ON_DEV_NAME);
    	uint32_t dtr = 0;
    
    	if (usb_enable(NULL)) {
    		return;
    	}
    
    	/* Poll if the DTR flag was set, optional */
    	while (!dtr) {
    		uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
    	}
    
    	if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) !=
    	    strlen("CDC_ACM_0") ||
    	    strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0",
    		    strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) {
    		printk("Error: Console device name is not USB ACM\n");
    
    		return;
    	}
    
    	while (1) {
    		printk("Hello World! %s\n", CONFIG_ARCH);
    		k_sleep(K_SECONDS(1));
    	}
    }
    

Reply
  • Because all the answers about three years ago, I would like to add the example solution from sdk 1.7.1 + zephyr:

    Please have a look at example "/samples/subsys/usb/console": http://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/zephyr/samples/subsys/usb/console/README.html?highlight=acm

    Flashing the device is nicely explained here: https://docs.zephyrproject.org/2.6.0/boards/arm/nrf52840dongle_nrf52840/doc/index.html

    ---

    1) After installing the toolchain successfully, or just use the docker container https://github.com/NordicPlayground/nrfconnect-chip-docker, connect the dongle with your pc.

    2) Bring it into bootloader mode by pressing the reset button (the red led LD2 will flash)

    3) build the sample project:

      west build -b nrf52840dongle_nrf52840 zephyr/samples/basic/blinky

    4) package the code for the bootloader:

      nrfutil pkg generate --hw-version 52 --sd-req=0x00 --application build/zephyr/zephyr.hex --application-version 1 usb_console_test.zip

    5) flash it to the device:

      nrfutil dfu usb-serial -pkg usb_console_test.zip -p /dev/ttyACM0

    if you use docker, you can use the --privileged flag to mount all devices with proper rights (this is unsafe but we just use it for flashing the device):

    docker run --rm -it -v <local_ncs>:/var/ncs --privileged nordicsemi/nrfconnect-chip:latest

    This should flash your dongle with the example application and you should be able to see some Hello World message via your favorite monitor.

    Or simply use: cat /dev/ttyACM0

    ---

    If we checkout the code, we see, that we need to enable the USB_UART_CONSOLE and bind it in the source code:

    prj.conf:

    CONFIG_USB=y
    CONFIG_USB_DEVICE_STACK=y
    CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
    CONFIG_USB_UART_CONSOLE=y
    
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_UART_LINE_CTRL=y
    CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
    

    main.c

    /*
     * Copyright (c) 2016 Intel Corporation.
     *
     * SPDX-License-Identifier: Apache-2.0
     */
    
    #include <zephyr.h>
    #include <sys/printk.h>
    #include <sys/util.h>
    #include <string.h>
    #include <usb/usb_device.h>
    #include <drivers/uart.h>
    
    void main(void)
    {
    	const struct device *dev = device_get_binding(
    			CONFIG_UART_CONSOLE_ON_DEV_NAME);
    	uint32_t dtr = 0;
    
    	if (usb_enable(NULL)) {
    		return;
    	}
    
    	/* Poll if the DTR flag was set, optional */
    	while (!dtr) {
    		uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
    	}
    
    	if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) !=
    	    strlen("CDC_ACM_0") ||
    	    strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0",
    		    strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) {
    		printk("Error: Console device name is not USB ACM\n");
    
    		return;
    	}
    
    	while (1) {
    		printk("Hello World! %s\n", CONFIG_ARCH);
    		k_sleep(K_SECONDS(1));
    	}
    }
    

Children
No Data
Related