Skip to content

Commit

Permalink
Merge pull request #10383 from mluessi/ml_h7_dshot_opt
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeller committed Dec 9, 2020
2 parents 34e6a83 + b46971f commit 57c9c12
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/main/drivers/io.h
Expand Up @@ -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);
15 changes: 13 additions & 2 deletions src/main/drivers/pwm_output_dshot_hal.c
Expand Up @@ -117,13 +117,24 @@ 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;
Expand Down

0 comments on commit 57c9c12

Please sign in to comment.