Hi all,
Currently, I am working on an application that requires a UART interface that can talk with a machine running on the UART. I am able to run a demo code that can transmit and receive over UART1.
Next, I added the Zephyr, Console over &cdc_acm_uart0 for debugging and logging. The application build was successful but when I tried to run the code it stuck in the uart_callback_set() function. During debugging, I found that the dev->API copied to the uart_callback_set() function gets NULL and that is why it fails.
So, in conclusion, I cannot able to run the UART1 and cdc_acm_uart0 together. below is my prj.conf, overlay, and main code. Kindly suggest a suitable way to have these options together.
- prj.conf
CONFIG_SERIAL=y
CONFIG_UART_ASYNC_API=y
CONFIG_UART_INTERRUPT_DRIVEN=y
CONFIG_USB_DEVICE_STACK=y
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
CONFIG_USB_DEVICE_PID=0x0004
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
CONFIG_CONSOLE=y
CONFIG_UART_CONSOLE=y
CONFIG_UART_LINE_CTRL=y
- overlay
/ {
chosen {
zephyr,console = &cdc_acm_uart0;
};
};
&uart1{
status = "okay";
};
&zephyr_udc0 {
cdc_acm_uart0: cdc_acm_uart0 {
compatible = "zephyr,cdc-acm-uart";
};
};
- Main()
BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
"Console device is not ACM CDC UART device");
const struct device *uart_dev = DEVICE_DT_GET(DT_NODELABEL(uart1));
int main()
{
const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
uint32_t dtr = 0;
if (usb_enable(NULL)) {
return 0;
}
while (!dtr) {
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
/* Give CPU resources to low priority threads. */
k_sleep(K_MSEC(100));
}
if (!device_is_ready(uart_dev)){
printk("UART device not ready\r\n");
return 1 ;
}
ret = uart_callback_set(uart_dev, uart_cb, NULL);
if (ret) {
return 1;
}
ret = uart_tx(uart_dev, tx_buf, sizeof(tx_buf), SYS_FOREVER_US);
if (ret) {
return 1;
}
ret = uart_rx_enable(uart_dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
if (ret) {
return 1;
}
while(1)
{
uart_tx(uart_dev, transm, strlen(transm), SYS_FOREVER_US);
printk("Hello World! %s\n", CONFIG_ARCH);
}
}
Setup info:
Environment: Ubuntu 20.04 LTS
ncs: v2.4.0 nrf SDK
Device: nrf52840_dk