From 0201893f7cbccfa1dcc0a948b34339bfe608baea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Jul 2018 20:47:48 +1000 Subject: [PATCH] HAL_ChibiOS: fixed peripheral power-up on fmuv5 we need to do the powerup before we initialise the UARTs --- libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp | 6 +++--- libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp b/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp index b2885bfe26..1a06afda42 100644 --- a/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp +++ b/libraries/AP_HAL_ChibiOS/HAL_ChibiOS_Class.cpp @@ -153,7 +153,9 @@ static THD_FUNCTION(main_loop,arg) #endif ChibiOS::Shared_DMA::init(); - + + peripheral_power_enable(); + hal.uartA->begin(115200); #ifdef HAL_SPI_CHECK_CLOCK_FREQ @@ -177,8 +179,6 @@ static THD_FUNCTION(main_loop,arg) schedulerInstance.hal_initialized(); - peripheral_power_enable(); - g_callbacks->setup(); hal.scheduler->system_initialized(); diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c index 57e2645281..23f4b9353d 100644 --- a/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c +++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stm32_util.c @@ -254,14 +254,24 @@ void set_fast_reboot(enum rtc_boot_magic v) /* enable peripheral power if needed This is done late to prevent - problems with RTS causing SiK radios to stay in the bootloader + problems with CTS causing SiK radios to stay in the bootloader. A + SiK radio will stay in the bootloader if CTS is held to GND on boot */ void peripheral_power_enable(void) { +#if defined(HAL_GPIO_PIN_nVDD_5V_PERIPH_EN) || defined(HAL_GPIO_PIN_nVDD_5V_HIPOWER_EN) + // we don't know what state the bootloader had the CTS pin in, so + // wait here with it pulled up from the PAL table for enough time + // for the radio to be definately powered down + for (uint8_t i=0; i<100; i++) { + // use a loop as this may be a 16 bit timer + chThdSleep(MS2ST(1)); + } #ifdef HAL_GPIO_PIN_nVDD_5V_PERIPH_EN palWriteLine(HAL_GPIO_PIN_nVDD_5V_PERIPH_EN, 0); #endif #ifdef HAL_GPIO_PIN_nVDD_5V_HIPOWER_EN palWriteLine(HAL_GPIO_PIN_nVDD_5V_HIPOWER_EN, 0); #endif +#endif }