zephyr: selectable serial device for recovery

This commit adds a choice for the device to use for serial recovery.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>

fixup
diff --git a/boot/zephyr/Kconfig b/boot/zephyr/Kconfig
index 3502481..4b8801e 100644
--- a/boot/zephyr/Kconfig
+++ b/boot/zephyr/Kconfig
@@ -127,6 +127,23 @@
 
 if MCUBOOT_SERIAL
 
+choice
+	prompt "Serial device"
+	default BOOT_SERIAL_UART if !BOARD_NRF52840_PCA10059
+	default BOOT_SERIAL_CDC_ACM if BOARD_NRF52840_PCA10059
+
+config BOOT_SERIAL_UART
+	bool "UART"
+	# SERIAL and UART_INTERRUPT_DRIVEN already selected
+
+config BOOT_SERIAL_CDC_ACM
+	bool "CDC ACM"
+	select USB
+	select USB_DEVICE_STACK
+	select USB_CDC_ACM
+
+endchoice
+
 config BOOT_MAX_LINE_INPUT_LEN
 	int "Maximum command line length"
 	default 512
diff --git a/boot/zephyr/main.c b/boot/zephyr/main.c
index ca30bb5..234ad4c 100644
--- a/boot/zephyr/main.c
+++ b/boot/zephyr/main.c
@@ -20,6 +20,7 @@
 #include <misc/__assert.h>
 #include <flash.h>
 #include <drivers/system_timer.h>
+#include <usb/usb_device.h>
 #include <soc.h>
 
 #include "target.h"
@@ -66,6 +67,10 @@
                                      rsp->br_hdr->ih_hdr_size);
     irq_lock();
     sys_clock_disable();
+#ifdef CONFIG_BOOT_SERIAL_CDC_ACM
+    /* Disable the USB to prevent it from firing interrupts */
+    usb_disable();
+#endif
     __set_MSP(vt->msp);
     ((void (*)(void))vt->reset)();
 }
diff --git a/boot/zephyr/serial_adapter.c b/boot/zephyr/serial_adapter.c
index 92aa6c6..fc39f71 100644
--- a/boot/zephyr/serial_adapter.c
+++ b/boot/zephyr/serial_adapter.c
@@ -188,7 +188,11 @@
 static int
 boot_uart_fifo_init(void)
 {
+#ifdef CONFIG_BOOT_SERIAL_UART
 	uart_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME);
+#elif CONFIG_BOOT_SERIAL_CDC_ACM
+	uart_dev = device_get_binding(CONFIG_CDC_ACM_PORT_NAME);
+#endif
 	u8_t c;
 
 	if (!uart_dev) {