From 82648f325218a6f5cb88e8f299370347f688d03e Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Thu, 3 Dec 2020 08:58:16 -0800 Subject: [PATCH 1/3] Add GPIO and Pin functions --- src/main/drivers/io.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/drivers/io.h b/src/main/drivers/io.h index 9c20347a10..0bddea2276 100644 --- a/src/main/drivers/io.h +++ b/src/main/drivers/io.h @@ -131,3 +131,6 @@ void IOInitGlobal(void); typedef void (*IOTraverseFuncPtr_t)(IO_t io); void IOTraversePins(IOTraverseFuncPtr_t func); + +GPIO_TypeDef* IO_GPIO(IO_t io); +uint16_t IO_Pin(IO_t io); From 74df0ca92cb96a08492437dec71351f05a61c452 Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Thu, 3 Dec 2020 08:59:00 -0800 Subject: [PATCH 2/3] Optimize pin reconfiguration for H7 --- src/main/drivers/pwm_output_dshot_hal.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index db9fabfe93..002b1de5c0 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -117,13 +117,25 @@ FAST_CODE static void pwmDshotSetDirectionInput( timer->ARR = 0xffffffff; #ifdef STM32H7 - IOConfigGPIO(motor->io, GPIO_MODE_OUTPUT_PP); + // Configure pin as GPIO output to avoid glitch during timer configuration + uint32_t pin = IO_Pin(motor->io); + LL_GPIO_SetPinMode(IO_GPIO(motor->io), pin, LL_GPIO_MODE_OUTPUT); + LL_GPIO_SetPinSpeed(IO_GPIO(motor->io), pin, LL_GPIO_SPEED_FREQ_LOW); // Needs to be low + LL_GPIO_SetPinPull(IO_GPIO(motor->io), pin, LL_GPIO_PULL_NO); + LL_GPIO_SetPinOutputType(IO_GPIO(motor->io), pin, LL_GPIO_OUTPUT_PUSHPULL); #endif LL_TIM_IC_Init(timer, motor->llChannel, &motor->icInitStruct); #ifdef STM32H7 - IOConfigGPIOAF(motor->io, motor->iocfg, timerHardware->alternateFunction); + // Configure pin back to timer + LL_GPIO_SetPinMode(IO_GPIO(motor->io), IO_Pin(motor->io), LL_GPIO_MODE_ALTERNATE); + if (IO_Pin(motor->io) & 0xFF) { + LL_GPIO_SetAFPin_0_7(IO_GPIO(motor->io), IO_Pin(motor->io), timerHardware->alternateFunction); + } + else { + LL_GPIO_SetAFPin_8_15(IO_GPIO(motor->io), IO_Pin(motor->io), timerHardware->alternateFunction); + } #endif motor->dmaInitStruct.Direction = LL_DMA_DIRECTION_PERIPH_TO_MEMORY; From b46971f1f0bc604e770182868f67da280ce06d65 Mon Sep 17 00:00:00 2001 From: Martin Luessi Date: Wed, 9 Dec 2020 05:43:51 -0800 Subject: [PATCH 3/3] Fix style --- src/main/drivers/pwm_output_dshot_hal.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/drivers/pwm_output_dshot_hal.c b/src/main/drivers/pwm_output_dshot_hal.c index 002b1de5c0..5788c27e0e 100644 --- a/src/main/drivers/pwm_output_dshot_hal.c +++ b/src/main/drivers/pwm_output_dshot_hal.c @@ -132,8 +132,7 @@ FAST_CODE static void pwmDshotSetDirectionInput( LL_GPIO_SetPinMode(IO_GPIO(motor->io), IO_Pin(motor->io), LL_GPIO_MODE_ALTERNATE); if (IO_Pin(motor->io) & 0xFF) { LL_GPIO_SetAFPin_0_7(IO_GPIO(motor->io), IO_Pin(motor->io), timerHardware->alternateFunction); - } - else { + } else { LL_GPIO_SetAFPin_8_15(IO_GPIO(motor->io), IO_Pin(motor->io), timerHardware->alternateFunction); } #endif