Skip to content

Commit

Permalink
Bidirectionnal DShot for H7 (#3253)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabien-B committed Apr 9, 2024
1 parent 6fb37f8 commit 15d8a63
Show file tree
Hide file tree
Showing 24 changed files with 3,280 additions and 328 deletions.
4 changes: 3 additions & 1 deletion conf/airframes/ENAC/quadrotor/cobraV2.xml
Expand Up @@ -30,7 +30,9 @@

<module name="telemetry" type="xbee_api"/>

<module name="actuators" type="dshot"/>
<module name="actuators" type="dshot">
<configure name="DSHOT_BIDIR" value="TRUE"/>
</module>
<module name="actuators" type="pwm"/>
<module name="switch" type="servo"/>
<define name="SWITCH_SERVO_ON_VALUE" value="SERVO_SWITCH_MAX"/>
Expand Down
3 changes: 3 additions & 0 deletions conf/boards/tawaki_2.0.makefile
Expand Up @@ -99,3 +99,6 @@ SBUS2_PORT ?= UART6
#
ACTUATORS ?= actuators_pwm


# Bidirectionnal DSHOT timer for input capture timeout
DSHOT1_GPT_TIM ?= 7
18 changes: 18 additions & 0 deletions conf/modules/actuators_dshot.xml
Expand Up @@ -8,8 +8,15 @@
Beware that servo output from the same timer cannot mix PWM and DSHOT.
It might be required to disable by hand some PWM output to avoid conflicts when they are activated by default on a board.
Currently only implemented over ChibiOS.

Configure DSHOT_BIDIR to TRUE to enable bidirectionnal DSHOT.
It overrides the rpm values from the UART dshot telemetry.
UART dshot telemetry is still usefull for current and voltage telemetry.

</description>
<configure name="DSHOT_BIDIR" value="FALSE" description="Bidirectionnal DSHOT for fast rpm feedback"/>
<define name="DSHOT_SPEED" value="600" description="DSHOT speed (150,300,600,1200)"/>
<configure name="DSHOT1_GPT_TIM" value="7" description="GPT driver used for telemetry timeout"/>
</doc>
<dep>
<depends>actuators,@commands</depends>
Expand All @@ -19,10 +26,21 @@
<file name="actuators_dshot.h"/>
</header>
<makefile>
<configure name="DSHOT_BIDIR" default="FALSE"/>
<file_arch name="actuators_dshot_arch.c"/>
<file_arch name="esc_dshot.c" cond="ifeq ($(RTOS),chibios)"/>
<file_arch name="hal_stm32_dma.c" dir="mcu_periph" cond="ifeq ($(RTOS),chibios)"/>
<test/>
</makefile>
<makefile cond="ifeq ($(DSHOT_BIDIR),TRUE)">
<define name="DSHOT_BIDIR" value="$(DSHOT_BIDIR)"/>
<define name="USE_GPT$(DSHOT1_GPT_TIM)" value="TRUE"/>
<define name="DSHOT1_BIDIR_GPT" value="GPTD$(DSHOT1_GPT_TIM)"/>
<file_arch name="dshot_rpmCapture.c"/>
<file_arch name="dshot_erps.c"/>
<file_arch name="input_capture_arch.c" dir="mcu_periph"/>
<file_arch name="timerDmaCache.c" dir="mcu_periph"/>
<test/>
</makefile>
</module>

5 changes: 5 additions & 0 deletions sw/airborne/arch/chibios/halconf.h
Expand Up @@ -91,8 +91,13 @@
* @brief Enables the GPT subsystem.
*/
#if !defined(HAL_USE_GPT) || defined(__DOXYGEN__)
#if USE_GPT5 || USE_GPT7 || USE_GPT8 || USE_GPT12 || USE_GPT13
#define HAL_USE_GPT TRUE
#define GPT_DRIVER_EXT_FIELDS void *user_data;
#else
#define HAL_USE_GPT FALSE
#endif
#endif

/**
* @brief Enables the I2C subsystem.
Expand Down
4 changes: 4 additions & 0 deletions sw/airborne/arch/chibios/mcu_periph/gpio_arch.c
Expand Up @@ -58,6 +58,10 @@ void gpio_setup_input_pulldown(ioportid_t port, uint16_t gpios)
chSysUnlock();
}

void gpio_setup_pin_af_pullup(ioportid_t port, uint16_t pin, uint8_t af) {
palSetPadMode(port, pin, PAL_MODE_ALTERNATE(af) | PAL_STM32_PUPDR_PULLUP);
}

void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output)
{
chSysLock();
Expand Down
6 changes: 6 additions & 0 deletions sw/airborne/arch/chibios/mcu_periph/gpio_arch.h
Expand Up @@ -72,6 +72,12 @@ extern void gpio_setup_input_pulldown(ioportid_t port, uint16_t gpios);
*/
extern void gpio_setup_pin_af(ioportid_t port, uint16_t pin, uint8_t af, bool is_output);

/**
* Setup a gpio for input pullup with alternate function.
* This is an STM32 specific helper funtion and should only be used in stm32 code.
*/
void gpio_setup_pin_af_pullup(ioportid_t port, uint16_t pin, uint8_t af);

/**
* Setup a gpio for analog use.
* @param[in] port
Expand Down

0 comments on commit 15d8a63

Please sign in to comment.