From 892ae1436c3bea351a65f258253f109dffc8ee4e Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Tue, 27 Jun 2017 12:53:30 -1000 Subject: [PATCH] px4fmu-v4pro::Insure the discharge of the PWM pins on rest. As done on fmuV4 on resets invoked from system (not boot) insure we establish a low output state (discharge the pins) on PWM pins before they become inputs as a result of the pending reset. We also delay the reset by 400 MS to insure the 3.1 Ms pulse is not too close to the last PWM pulse. --- .../boards/px4fmu-v4pro/board_config.h | 1 + src/drivers/boards/px4fmu-v4pro/px4fmu_init.c | 54 ++++++++++++++++--- 2 files changed, 47 insertions(+), 8 deletions(-) diff --git a/src/drivers/boards/px4fmu-v4pro/board_config.h b/src/drivers/boards/px4fmu-v4pro/board_config.h index 4e76e5a67e..29cea37495 100644 --- a/src/drivers/boards/px4fmu-v4pro/board_config.h +++ b/src/drivers/boards/px4fmu-v4pro/board_config.h @@ -366,6 +366,7 @@ #define BOARD_DMA_ALLOC_POOL_SIZE 5120 +#define BOARD_HAS_ON_RESET 1 __BEGIN_DECLS /**************************************************************************************************** diff --git a/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c b/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c index 607cfe0f92..a863cfb3f0 100644 --- a/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c +++ b/src/drivers/boards/px4fmu-v4pro/px4fmu_init.c @@ -156,6 +156,47 @@ __EXPORT void board_peripheral_reset(int ms) stm32_gpiowrite(GPIO_VDD_5V_HIPOWER_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: stm32_boardinitialize * @@ -169,7 +210,12 @@ __EXPORT void board_peripheral_reset(int ms) __EXPORT void stm32_boardinitialize(void) { + /* Reset all PWM to Low outputs */ + + board_on_reset(-1); + /* configure LEDs */ + board_autoled_initialize(); /* Start with Power off */ @@ -201,13 +247,6 @@ stm32_boardinitialize(void) stm32_configgpio(GPIO_8266_RST); stm32_configgpio(GPIO_BTN_SAFETY_FMU); - /* 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 * is deferred to board_app_initialize @@ -215,7 +254,6 @@ stm32_boardinitialize(void) * out adding a delay */ - stm32_usbinitialize(); }