From 0b9e32ca3efb02be6fc7b12726997d5a4ef0a866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Roberto=20de=20Souza?= Date: Mon, 24 Jul 2017 14:15:44 -0700 Subject: [PATCH] aerofc: Reboot board when force bootloader pin is set This can help "unbrick" AeroFC when a bad firmware is loaded and it keeps rebooting or it spinning in some loop. No need to request to stay in booloader as it will stay in bootloader because the pin is set. --- src/drivers/boards/aerofc-v1/aerofc_init.c | 22 +++++++++++++++++++-- src/drivers/boards/aerofc-v1/board_config.h | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/drivers/boards/aerofc-v1/aerofc_init.c b/src/drivers/boards/aerofc-v1/aerofc_init.c index ed4fa212de..55480d5bc2 100644 --- a/src/drivers/boards/aerofc-v1/aerofc_init.c +++ b/src/drivers/boards/aerofc-v1/aerofc_init.c @@ -115,6 +115,19 @@ extern void led_on(int led); extern void led_off(int led); __END_DECLS +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +static int _bootloader_force_pin_callback(int irq, void *context) +{ + if (stm32_gpioread(GPIO_FORCE_BOOTLOADER)) { + board_reset(0); + } + + return 0; +} + /**************************************************************************** * Protected Functions ****************************************************************************/ @@ -128,15 +141,17 @@ __END_DECLS * * Description: * All STM32 architectures must provide the following entry point. This entry point - * is called early in the intitialization -- after all memory has been configured + * is called early in the initialization -- after all memory has been configured * and mapped but before any devices have been initialized. * ************************************************************************************/ __EXPORT void stm32_boardinitialize(void) { - /* configure LEDs */ + stm32_configgpio(GPIO_FORCE_BOOTLOADER); + _bootloader_force_pin_callback(0, NULL); + /* configure LEDs */ board_autoled_initialize(); /* turn sensors on */ @@ -159,6 +174,9 @@ __EXPORT int board_app_initialize(uintptr_t arg) { int result; + /* the interruption subsystem is not initialized when stm32_boardinitialize() is called */ + stm32_gpiosetevent(GPIO_FORCE_BOOTLOADER, true, false, false, _bootloader_force_pin_callback); + #if defined(CONFIG_HAVE_CXX) && defined(CONFIG_HAVE_CXXINITIALIZE) /* run C++ ctors before we go any further */ diff --git a/src/drivers/boards/aerofc-v1/board_config.h b/src/drivers/boards/aerofc-v1/board_config.h index 8da3ff8826..aa657f7567 100644 --- a/src/drivers/boards/aerofc-v1/board_config.h +++ b/src/drivers/boards/aerofc-v1/board_config.h @@ -64,6 +64,8 @@ #define GPIO_VDD_5V_SENSORS_EN (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN13) +#define GPIO_FORCE_BOOTLOADER (GPIO_INPUT|GPIO_PULLDOWN|GPIO_SPEED_50MHz|GPIO_PORTA|GPIO_PIN11|GPIO_EXTI) + /* * I2C busses *