diff --git a/boards/common/particle-mesh/Makefile.dep b/boards/common/particle-mesh/Makefile.dep index b68127eea4..b03de54da5 100644 --- a/boards/common/particle-mesh/Makefile.dep +++ b/boards/common/particle-mesh/Makefile.dep @@ -2,5 +2,9 @@ ifneq (,$(filter saul_default,$(USEMODULE))) USEMODULE += saul_gpio endif +ifeq (1,$(PARTICLE_MONOFIRMWARE)) + USEMODULE += usb_board_reset +endif + # include common nrf52 dependencies include $(RIOTBOARD)/common/nrf52/Makefile.dep diff --git a/boards/common/particle-mesh/Makefile.include b/boards/common/particle-mesh/Makefile.include index 6e7387215c..683ab4a972 100644 --- a/boards/common/particle-mesh/Makefile.include +++ b/boards/common/particle-mesh/Makefile.include @@ -18,6 +18,10 @@ ifeq (1,$(PARTICLE_MONOFIRMWARE)) FFLAGS = -d 0x2B04:0xD00E -a 0 -s 0x30000:leave -D $(FLASHFILE) PROGRAMMER = dfu-util include $(RIOTMAKE)/tools/dfu.inc.mk + # If CDC-ACM is *not* enabled, any pre-flash resets will just not work -- but + # then again nothing can be done in that case anyway, and the preflash + # routines fall through without erring. + include $(RIOTMAKE)/tools/usb_board_reset.mk else # This board uses a DAP-Link programmer # Flashing support is provided through pyocd (default) and openocd. diff --git a/boards/common/particle-mesh/reset.c b/boards/common/particle-mesh/reset.c new file mode 100644 index 0000000000..2e964623b8 --- /dev/null +++ b/boards/common/particle-mesh/reset.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2020 Christian Amsüss + * + * 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. + */ + +/** + * @{ + * + * @brief Management of bootloader resets + * + * This implements a reset procedure read from the code of the particle device + * OS at https://github.com/particle-iot/device-os/ (version + * c21d5b8f39c8a013e19f904800808673f369c6e3), primarily from + * hal/inc/syshealth_hal.h and its linker script. + * + * @file + * @author Christian Amsüss + * + * @} + */ + +#include +#include "cpu.h" + +/* from the eSystemHealth definition of hal/inc/syshealth_hal.h */ +#define ENTER_DFU_APP_REQUEST (0xEDFA) + +/* Start of the backup registers as per + * build/arm/linker/nrf52840/platform_ram.ld and hal/src/nRF52840/core_hal.c */ +#define BACKUP_REGISTERS ((volatile int32_t*)0x2003f380) + +void usb_board_reset_in_bootloader(void) +{ + /* This *is* a write into an arbitrary memory location -- as RIOT does not + * use any of the Particle system interrupt handlers any more, it's not + * abiding by its RAM layout either. The write immediately preceding the + * reboot should not have any effect on being-restarted system, but leaves + * the flag in memory for the starting-up system to introspect. + * */ + BACKUP_REGISTERS[0] = ENTER_DFU_APP_REQUEST; + /* Going with a hard reset rather than a pm_off, as that might be altered + * to do *anything* -- which is not safe any more now that we've forsaken + * the RAM content */ + NVIC_SystemReset(); +}