From a6e1e9e3395de280494e6d1b7a352c6336922ba8 Mon Sep 17 00:00:00 2001 From: Johann Fischer Date: Fri, 30 Jul 2021 16:01:03 +0200 Subject: [PATCH] zephyr: get CDC ACM UART device from devicetree Adapt to Zephyr OS changes to get CDC ACM UART device. Remove RECOVERY_UART_DEV_NAME Kconfig option and use DEVICE_DT_GET() in serial_adapter.c Signed-off-by: Johann Fischer --- boot/zephyr/Kconfig | 13 ----------- .../boards/nrf52840dongle_nrf52840.conf | 1 - boot/zephyr/dts.overlay | 7 ++++++ boot/zephyr/serial_adapter.c | 23 ++++++++++--------- 4 files changed, 19 insertions(+), 25 deletions(-) diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig index f612b6dc..1eb4f2a2 100644 --- a/boot/zephyr/Kconfig +++ b/boot/zephyr/Kconfig @@ -477,7 +477,6 @@ config BOOT_SERIAL_UART config BOOT_SERIAL_CDC_ACM bool "CDC ACM" select USB_DEVICE_STACK - select USB_CDC_ACM endchoice @@ -543,18 +542,6 @@ config BOOT_SERIAL_DETECT_DELAY Useful for powering on when using the same button as the one used to place the device in bootloader mode. -# Workaround for not being able to have commas in macro arguments -DT_CHOSEN_Z_CONSOLE := zephyr,console - -config RECOVERY_UART_DEV_NAME - string "UART Device Name for Recovery UART" - default "$(dt_chosen_label,$(DT_CHOSEN_Z_CONSOLE))" if HAS_DTS - default "UART_0" - depends on BOOT_SERIAL_UART - help - This option specifies the name of UART device to be used for - serial recovery. - config BOOT_ERASE_PROGRESSIVELY bool "Erase flash progressively when receiving new firmware" default y if SOC_FAMILY_NRF diff --git a/boot/zephyr/boards/nrf52840dongle_nrf52840.conf b/boot/zephyr/boards/nrf52840dongle_nrf52840.conf index 25dd6529..f4fbb39d 100644 --- a/boot/zephyr/boards/nrf52840dongle_nrf52840.conf +++ b/boot/zephyr/boards/nrf52840dongle_nrf52840.conf @@ -26,6 +26,5 @@ CONFIG_MULTITHREADING=y # USB CONFIG_USB_DEVICE_STACK=y CONFIG_USB_DEVICE_PRODUCT="MCUBOOT" -CONFIG_USB_CDC_ACM=y CONFIG_USB_COMPOSITE_DEVICE=n CONFIG_USB_MASS_STORAGE=n diff --git a/boot/zephyr/dts.overlay b/boot/zephyr/dts.overlay index 74d3dfbf..706d9542 100644 --- a/boot/zephyr/dts.overlay +++ b/boot/zephyr/dts.overlay @@ -3,3 +3,10 @@ zephyr,code-partition = &boot_partition; }; }; + +&zephyr_udc0 { + cdc_acm_uart0 { + compatible = "zephyr,cdc-acm-uart"; + label = "CDC_ACM_0"; + }; +}; diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c index 494dd095..18fab9b8 100644 --- a/boot/zephyr/serial_adapter.c +++ b/boot/zephyr/serial_adapter.c @@ -192,27 +192,28 @@ static int boot_uart_fifo_init(void) { #ifdef CONFIG_BOOT_SERIAL_UART - uart_dev = device_get_binding(CONFIG_RECOVERY_UART_DEV_NAME); + uart_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); #elif CONFIG_BOOT_SERIAL_CDC_ACM - uart_dev = device_get_binding(CONFIG_USB_CDC_ACM_DEVICE_NAME "_0"); - if (uart_dev) { - int rc; - rc = usb_enable(NULL); - if (rc) { - return (-1); - } - } + uart_dev = DEVICE_DT_GET_ONE(zephyr_cdc_acm_uart); #endif - uint8_t c; - if (!uart_dev) { + if (!device_is_ready(uart_dev)) { return (-1); } +#if CONFIG_BOOT_SERIAL_CDC_ACM + int rc = usb_enable(NULL); + if (rc) { + return (-1); + } +#endif + uart_irq_callback_set(uart_dev, boot_uart_fifo_callback); /* Drain the fifo */ if (uart_irq_rx_ready(uart_dev)) { + uint8_t c; + while (uart_fifo_read(uart_dev, &c, 1)) { ; }