From d24e9bde26230f5364fbea8fc8a5052a693b7790 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Redon?= Date: Sat, 7 Jul 2018 14:56:43 +0200 Subject: DFU: re-enable UART after testing forced bootloader The qmod does not have a separate force button as simtrace has. Instead it check is TX and RX of UART are shorted using PIO. If the pins are not set back to the UART peripheral, the TRACE/debug console output will not work anymore. Change-Id: Id434b49909d6395a2f93a00f39d2d770a5725466 --- firmware/libboard/qmod/source/board_qmod.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'firmware/libboard') diff --git a/firmware/libboard/qmod/source/board_qmod.c b/firmware/libboard/qmod/source/board_qmod.c index dd6e616..0eda1ef 100644 --- a/firmware/libboard/qmod/source/board_qmod.c +++ b/firmware/libboard/qmod/source/board_qmod.c @@ -261,20 +261,32 @@ static int uart_has_loopback_jumper(void) /* Configure UART pins as I/O */ PIO_Configure(uart_loopback_pins, PIO_LISTSIZE(uart_loopback_pins)); + /* Send pattern over UART TX and check if it is received on RX + * If the loop doesn't get interrupted, RxD always follows TxD and thus a + * loopback jumper has been placed on RxD/TxD, and we will boot + * into DFU unconditionally + */ + int has_loopback_jumper = 1; for (i = 0; i < 10; i++) { /* Set TxD high; abort if RxD doesn't go high either */ PIO_Set(&uart_loopback_pins[1]); - if (!PIO_Get(&uart_loopback_pins[0])) - return 0; + if (!PIO_Get(&uart_loopback_pins[0])) { + has_loopback_jumper = 0; + break; + } /* Set TxD low, abort if RxD doesn't go low either */ PIO_Clear(&uart_loopback_pins[1]); - if (PIO_Get(&uart_loopback_pins[0])) - return 0; + if (PIO_Get(&uart_loopback_pins[0])) { + has_loopback_jumper = 0; + break; + } } - /* if we reached here, RxD always follows TxD and thus a - * loopback jumper has been placed on RxD/TxD, and we will boot - * into DFU unconditionally */ - return 1; + + /* Put pins back to UART mode */ + const Pin uart_pins[] = {PINS_UART}; + PIO_Configure(uart_pins, PIO_LISTSIZE(uart_pins)); + + return has_loopback_jumper; } int board_override_enter_dfu(void) -- cgit v1.2.3