From 5fd8ef1055efce53cedecef04750ae8adaac8562 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Tue, 18 Jul 2017 16:59:07 -1000 Subject: [PATCH] px4fmu-v2:Insure the discharge of the pins PWM pins on rest. On resets invoked from system (not boot) insure we establish a low output state (discharge the pins) on PWM pins before they become inputs. --- src/drivers/boards/px4fmu-v2/board_config.h | 2 + src/drivers/boards/px4fmu-v2/px4fmu2_init.c | 56 +++++++++++++++++---- 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/drivers/boards/px4fmu-v2/board_config.h b/src/drivers/boards/px4fmu-v2/board_config.h index 839b76c2b0..18fa37d899 100644 --- a/src/drivers/boards/px4fmu-v2/board_config.h +++ b/src/drivers/boards/px4fmu-v2/board_config.h @@ -295,6 +295,8 @@ /* This board provides a DMA pool and APIs */ #define BOARD_DMA_ALLOC_POOL_SIZE 5120 +#define BOARD_HAS_ON_RESET 1 + __BEGIN_DECLS /**************************************************************************************************** diff --git a/src/drivers/boards/px4fmu-v2/px4fmu2_init.c b/src/drivers/boards/px4fmu-v2/px4fmu2_init.c index d21c254ddc..30ac5085b7 100644 --- a/src/drivers/boards/px4fmu-v2/px4fmu2_init.c +++ b/src/drivers/boards/px4fmu-v2/px4fmu2_init.c @@ -152,6 +152,48 @@ __EXPORT void board_peripheral_reset(int ms) stm32_gpiowrite(GPIO_VDD_5V_PERIPH_EN, 0); } +/************************************************************************************ + * Name: board_on_reset + * + * Description: + * Optionally provided function called on entry to board_system_reset + * It should perform any house keeping prior to the rest. + * + * status - 1 if resetting to boot loader + * 0 if just resetting + * + ************************************************************************************/ + +__EXPORT void board_on_reset(int status) +{ + UNUSED(status); + /* configure the GPIO pins to outputs and keep them low */ + + stm32_configgpio(GPIO_GPIO0_OUTPUT); + stm32_configgpio(GPIO_GPIO1_OUTPUT); + stm32_configgpio(GPIO_GPIO2_OUTPUT); + stm32_configgpio(GPIO_GPIO3_OUTPUT); + stm32_configgpio(GPIO_GPIO4_OUTPUT); + stm32_configgpio(GPIO_GPIO5_OUTPUT); + + /* On resets invoked from system (not boot) insure we establish a low + * output state (discharge the pins) on PWM pins before they become inputs. + * + * We also delay the onset of the that 3.1 Ms pulse as boot. This has + * triggered some ESC to spin. By adding this delay here the reset + * is pushed out > 400 ms. So the ESC PWM input can not mistake + * the 3.1 Ms pulse as a valid PWM command. + * + * fixme:Establish in upstream NuttX an CONFIG_IO_INIT_STATE to + * the initialize the IO lines in the clock config. + * + */ + + if (status >= 0) { + up_mdelay(400); + } +} + /************************************************************************************ * Name: determin_hw_version * @@ -282,6 +324,11 @@ __EXPORT int board_get_hw_revision() __EXPORT void stm32_boardinitialize(void) { + board_on_reset(-1); + + /* configure LEDs */ + board_autoled_initialize(); + /* configure ADC pins */ stm32_configgpio(GPIO_ADC1_IN2); /* BATT_VOLTAGE_SENS */ @@ -300,19 +347,10 @@ stm32_boardinitialize(void) stm32_configgpio(GPIO_VDD_5V_HIPOWER_OC); stm32_configgpio(GPIO_VDD_5V_PERIPH_OC); - /* configure the GPIO pins to outputs and keep them low */ - stm32_configgpio(GPIO_GPIO0_OUTPUT); - stm32_configgpio(GPIO_GPIO1_OUTPUT); - stm32_configgpio(GPIO_GPIO2_OUTPUT); - stm32_configgpio(GPIO_GPIO3_OUTPUT); - stm32_configgpio(GPIO_GPIO4_OUTPUT); - stm32_configgpio(GPIO_GPIO5_OUTPUT); /* configure SPI interfaces */ stm32_spiinitialize(); - /* configure LEDs */ - board_autoled_initialize(); } /****************************************************************************