From b20f98e99bd6623e56056d6b8ec047b71ac52fac Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 10 Jun 2020 23:07:40 +0200 Subject: [PATCH] boards/nrf52840dongle: enable automatic reset to bootloader --- boards/nrf52840dongle/Makefile.dep | 13 +++++----- boards/nrf52840dongle/Makefile.include | 2 ++ boards/nrf52840dongle/doc.txt | 11 ++++++--- boards/nrf52840dongle/reset.c | 33 ++++++++++++++++++++++++++ 4 files changed, 49 insertions(+), 10 deletions(-) create mode 100644 boards/nrf52840dongle/reset.c diff --git a/boards/nrf52840dongle/Makefile.dep b/boards/nrf52840dongle/Makefile.dep index 80e64005f1..18e5d17c60 100644 --- a/boards/nrf52840dongle/Makefile.dep +++ b/boards/nrf52840dongle/Makefile.dep @@ -5,13 +5,12 @@ endif ifeq (,$(filter-out stdio_cdc_acm,$(filter stdio_% slipdev_stdio,$(USEMODULE)))) # Use stdio_cdc_acm only if no other stdio is requested explicitly. USEMODULE += stdio_cdc_acm - # This does not *really* hinge on the choice of stdio, but this ensures - # compatibility with the test suite that uses stdio_null and would conflict - # with bootloader_nrfutil. - # (Having the feature in is generally a good thing because as an indicator - # that it the resulting program is meant to be flashed using nrfutil). - FEATURES_REQUIRED += bootloader_nrfutil endif -# ... and fall back to the UART-based stdio + +# enable bootloader reset over USB, requires USB bootloader to be used +ifneq (,$(filter stdio_cdc_acm,$(USEMODULE))) + FEATURES_REQUIRED += bootloader_nrfutil + USEMODULE += usb_board_reset +endif include $(RIOTBOARD)/common/nrf52/Makefile.dep diff --git a/boards/nrf52840dongle/Makefile.include b/boards/nrf52840dongle/Makefile.include index a26aaf1baf..b6e77101b7 100644 --- a/boards/nrf52840dongle/Makefile.include +++ b/boards/nrf52840dongle/Makefile.include @@ -18,6 +18,8 @@ ifeq (nrfutil,$(PROGRAMMER)) FLASHDEPS += $(HEXFILE).zip FLASHER = nrfutil FFLAGS = dfu usb-serial --port=${PORT} --package=$(HEXFILE).zip + + include $(RIOTMAKE)/tools/usb_board_reset.mk endif %.hex.zip: %.hex diff --git a/boards/nrf52840dongle/doc.txt b/boards/nrf52840dongle/doc.txt index 9f69622885..af82b30b31 100644 --- a/boards/nrf52840dongle/doc.txt +++ b/boards/nrf52840dongle/doc.txt @@ -28,9 +28,14 @@ The board is flashed using its on-board boot loader; the be installed. That can turn the binary into a suitable zip file and send it to the bootloader. -The process is automated in the usual `make flash` target. For that process to -complete, you need to enter the bootloader manually by pressing the board's -reset button. Readiness of the bootloader is indicated by LD2 pulsing in red. +The process is automated in the usual `make flash` target. + +If RIOT is already running on the board, it will automatically reset the CPU and enter +the bootloader. +If some other firmware is running or RIOT crashed, you need to enter the bootloader +manually by pressing the board's reset button. + +Readiness of the bootloader is indicated by LD2 pulsing in red. #### nrfutil installation diff --git a/boards/nrf52840dongle/reset.c b/boards/nrf52840dongle/reset.c new file mode 100644 index 0000000000..212c00ad0b --- /dev/null +++ b/boards/nrf52840dongle/reset.c @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2020 Benjamin Valentin + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup boards_nrf52840dongle + * @{ + * @file + * @brief Allows reboot into bootloader via hardware reset + * + * @author Benjamin Valentin + * + * @} + */ + +#ifdef MODULE_USB_BOARD_RESET + +#include "periph/gpio.h" + +/* P0.19 is connected to the RESET line */ +#define BSP_SELF_PINRESET_PIN GPIO_PIN(0, 19) + +void usb_board_reset_in_bootloader(void) +{ + gpio_init(BSP_SELF_PINRESET_PIN, GPIO_OUT); + gpio_clear(BSP_SELF_PINRESET_PIN); +} + +#endif /* MODULE_USB_BOARD_RESET */