1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-19 06:15:16 +03:00

[G4] BB-DSHOT support (TIM1/TIM8 limited version)

This commit is contained in:
jflyper 2020-06-06 22:34:12 +09:00
parent de35df8e07
commit 35bad24c55
3 changed files with 65 additions and 8 deletions

View file

@ -79,6 +79,9 @@ dshotBitbangStatus_e bbStatus;
#elif defined(STM32H7)
#define BB_OUTPUT_BUFFER_ATTRIBUTE DMA_RAM
#define BB_INPUT_BUFFER_ATTRIBUTE DMA_RAM
#elif defined(STM32G4)
#define BB_OUTPUT_BUFFER_ATTRIBUTE DMA_RAM_W
#define BB_INPUT_BUFFER_ATTRIBUTE DMA_RAM_R
#endif
BB_OUTPUT_BUFFER_ATTRIBUTE uint32_t bbOutputBuffer[MOTOR_DSHOT_BUFFER_SIZE * MAX_SUPPORTED_MOTOR_PORTS];
@ -101,6 +104,25 @@ const timerHardware_t bbTimerHardware[] = {
DEF_TIM(TIM1, CH2, NONE, TIM_USE_NONE, 0, 1),
DEF_TIM(TIM1, CH3, NONE, TIM_USE_NONE, 0, 1),
DEF_TIM(TIM1, CH4, NONE, TIM_USE_NONE, 0, 0),
#elif defined(STM32G4)
// XXX TODO: STM32G4 can use any timer for pacing
// DMA request numbers are duplicated for TIM1 and TIM8:
// - Any pacer can serve a GPIO port.
// - For quads (or less), 4 pacers can cover the worst case scenario of
// 4 motors scattered across 4 different GPIO ports.
// - For hexas (and larger), more channels may become necessary,
// in which case the DMA request numbers should be modified.
DEF_TIM(TIM8, CH1, NONE, TIM_USE_NONE, 0, 0, 0),
DEF_TIM(TIM8, CH2, NONE, TIM_USE_NONE, 0, 1, 0),
DEF_TIM(TIM8, CH3, NONE, TIM_USE_NONE, 0, 2, 0),
DEF_TIM(TIM8, CH4, NONE, TIM_USE_NONE, 0, 3, 0),
DEF_TIM(TIM1, CH1, NONE, TIM_USE_NONE, 0, 0, 0),
DEF_TIM(TIM1, CH2, NONE, TIM_USE_NONE, 0, 1, 0),
DEF_TIM(TIM1, CH3, NONE, TIM_USE_NONE, 0, 2, 0),
DEF_TIM(TIM1, CH4, NONE, TIM_USE_NONE, 0, 3, 0),
#else
#error MCU dependent code required
#endif
};
@ -649,6 +671,8 @@ motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t
useDshotTelemetry = motorConfig->useDshotTelemetry;
#endif
memset(bbOutputBuffer, 0, sizeof(bbOutputBuffer));
for (int motorIndex = 0; motorIndex < MAX_SUPPORTED_MOTORS && motorIndex < motorCount; motorIndex++) {
const unsigned reorderedMotorIndex = motorConfig->motorOutputReordering[motorIndex];
const timerHardware_t *timerHardware = timerGetByTag(motorConfig->ioTags[reorderedMotorIndex]);
@ -679,7 +703,7 @@ motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t
bbMotors[motorIndex].output = output;
#if defined(STM32F4) || defined(STM32F3)
bbMotors[motorIndex].iocfg = IO_CONFIG(GPIO_Mode_OUT, GPIO_Speed_50MHz, GPIO_OType_PP, bbPuPdMode);
#elif defined(STM32F7)
#elif defined(STM32F7) || defined(STM32G4)
bbMotors[motorIndex].iocfg = IO_CONFIG(GPIO_MODE_OUTPUT_PP, GPIO_SPEED_FREQ_VERY_HIGH, bbPuPdMode);
#endif