[CDC ACM USB Example] DTR Issue

Hello,

I am programming BLE with the nRF52840-DK. [Toolchain Manager: v1.3.0, IDE: Visual Studio Code (VSCode), SDK: ncs v2.6.0, window11 pro]

I'm studying the CDC_ACM Example to increase the data rate between the PC and nRF52840dk. However, I'm facing an issue.

There was an issue in the original example( CDC_ACM Example )where it doesn't execute properly.

I can't seem to get out of the while loop below. I can't understand why. Please help :( 

while (true) {
		uint32_t dtr = 0U;
		ret = uart_line_ctrl_get(uart_dev, UART_LINE_CTRL_DTR, &dtr);
		LOG_INF("uart_line_ctrl_get >>> err:%d", ret);
		if (dtr) {
			break;
		} else {
			k_sleep(K_MSEC(100));
		}
	}

- Here is Main.c:

#include <stdio.h>
#include <string.h>
#include <zephyr/device.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/kernel.h>
#include <zephyr/sys/ring_buffer.h>
#include <zephyr/usb/usb_device.h>
#include <zephyr/usb/usbd.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(cdc_acm_echo, LOG_LEVEL_INF);
const struct device *const uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart);
#define RING_BUF_SIZE 1024
uint8_t ring_buffer[RING_BUF_SIZE];
struct ring_buf ringbuf;

int main(void){
	int ret;
	if (!device_is_ready(uart_dev)) {
		LOG_ERR("CDC ACM device not ready");
		return 0;
	}
	ret = usb_enable(NULL);
	LOG_INF("usb_enable >>>> err:%d",ret);
	ring_buf_init(&ringbuf, sizeof(ring_buffer), ring_buffer);
	LOG_INF("Wait for DTR");
	while (true) {
		uint32_t dtr = 0U;
		ret = uart_line_ctrl_get(uart_dev, UART_LINE_CTRL_DTR, &dtr);
		LOG_INF("uart_line_ctrl_get >>> err:%d", ret);
		if (dtr) {
			break;
		} else {
			k_sleep(K_MSEC(100));
		}
	}
	LOG_INF("DTR set");
	return 0;
}

- Here is prj.conf

CONFIG_STDOUT_CONSOLE=y
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=n


- Debugging result in PuTTY:

*** Booting nRF Connect SDK v3.5.99-ncs1 ***

[00:00:00.253,570] <inf> cdc_acm_echo: usb_enable >>>> err:0

[00:00:00.253,570] <inf> cdc_acm_echo: Wait for DTR

[00:00:00.253,570] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.353,637] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.453,735] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.553,833] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.653,930] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.754,028] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

[00:00:00.854,125] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0

-  PuTTY Configuration:

- Here is Device Manager(Connecting between IMCU USB of nRF52840dk and PC USB):

Parents
  • Hi!

    1) Make sure that you have connect the USB cable to USB port on the long side of the DK named "nRF USB".

    2) COM10 is wrong, since that's the J-link port.

    It should be the USB Serial Device, that have Bus reported device description "Zephyr CDC ACM sample"

  • thank you for answer! I feel that your help is invaluable.
    but.. In my case, COM11 was identified as 'Zephyr CDC ACM sample'. I connected to COM11 using PuTTY and set the log debugging to COM6. Despite this, I couldn't get past the while loop.

    -Blow is log debugging:

    *** Booting nRF Connect SDK v3.5.99-ncs1 ***
    [00:00:00.250,518] <inf> cdc_acm_echo: Device name: cdc_acm_uart0
    [00:00:00.250,549] <inf> cdc_acm_echo: Device config address: 0x20000438
    [00:00:00.250,549] <inf> cdc_acm_echo: Device API address: 0xbae4
    [00:00:00.250,579] <inf> cdc_acm_echo: Device state address: 0x2000026c
    [00:00:00.250,579] <inf> cdc_acm_echo: Device private data address: 0x20000000
    [00:00:00.250,762] <inf> cdc_acm_echo: usb_enable >>>> err:0
    [00:00:00.250,762] <inf> cdc_acm_echo: Wait for DTR
    [00:00:00.250,793] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.250,793] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.254,791] <inf> usb_cdc_acm: Device suspended
    [00:00:00.350,860] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.350,891] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.352,874] <inf> usb_cdc_acm: Device resumed
    [00:00:00.450,958] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.450,958] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.551,055] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.551,055] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.587,097] <inf> usb_cdc_acm: Device configured
    [00:00:00.651,153] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.651,153] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.751,251] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.751,281] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.851,348] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.851,348] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:00.951,446] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:00.951,446] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:01.051,544] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:01.051,544] <inf> cdc_acm_echo: DTR >>>:0
    [00:00:01.151,641] <inf> cdc_acm_echo: uart_line_ctrl_get >>> err:0
    [00:00:01.151,641] <inf> cdc_acm_echo: DTR >>>:0
     

    - Blow is Device Manager:

  • Ok, so now you are interfacing with the right COM port. Do you see any difference if you change flow control setting in PuTTy?

Reply Children
Related