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 <johann.fischer@nordicsemi.no>
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index f612b6d..1eb4f2a 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -477,7 +477,6 @@
config BOOT_SERIAL_CDC_ACM
bool "CDC ACM"
select USB_DEVICE_STACK
- select USB_CDC_ACM
endchoice
@@ -543,18 +542,6 @@
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 25dd652..f4fbb39 100644
--- a/boot/zephyr/boards/nrf52840dongle_nrf52840.conf
+++ b/boot/zephyr/boards/nrf52840dongle_nrf52840.conf
@@ -26,6 +26,5 @@
# 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 74d3dfb..706d954 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 494dd09..18fab9b 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -192,27 +192,28 @@
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)) {
;
}