1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-17 13:25:30 +03:00

Fix board wedging if motor DMA is undefined for Dshot.

This commit is contained in:
mikeller 2019-08-11 21:16:16 +12:00
parent b310f9b348
commit a77f658b22
5 changed files with 35 additions and 25 deletions

View file

@ -179,22 +179,26 @@ motorDevice_t *dshotPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idl
const ioTag_t tag = motorConfig->ioTags[motorIndex]; const ioTag_t tag = motorConfig->ioTags[motorIndex];
const timerHardware_t *timerHardware = timerAllocate(tag, OWNER_MOTOR, RESOURCE_INDEX(motorIndex)); const timerHardware_t *timerHardware = timerAllocate(tag, OWNER_MOTOR, RESOURCE_INDEX(motorIndex));
if (timerHardware == NULL) { if (timerHardware != NULL) {
/* not enough motors initialised for the mixer or a break in the motors */ motors[motorIndex].io = IOGetByTag(tag);
dshotPwmDevice.vTable.write = motorWriteNull; IOInit(motors[motorIndex].io, OWNER_MOTOR, RESOURCE_INDEX(motorIndex));
dshotPwmDevice.vTable.updateComplete = motorUpdateCompleteNull;
/* TODO: block arming and add reason system cannot arm */ if (pwmDshotMotorHardwareConfig(timerHardware,
return NULL; motorIndex,
motorConfig->motorPwmProtocol,
motorConfig->motorPwmInversion ? timerHardware->output ^ TIMER_OUTPUT_INVERTED : timerHardware->output)) {
motors[motorIndex].enabled = true;
continue;
}
} }
motors[motorIndex].io = IOGetByTag(tag); /* not enough motors initialised for the mixer or a break in the motors */
IOInit(motors[motorIndex].io, OWNER_MOTOR, RESOURCE_INDEX(motorIndex)); dshotPwmDevice.vTable.write = motorWriteNull;
dshotPwmDevice.vTable.updateComplete = motorUpdateCompleteNull;
pwmDshotMotorHardwareConfig(timerHardware, /* TODO: block arming and add reason system cannot arm */
motorIndex, return NULL;
motorConfig->motorPwmProtocol,
motorConfig->motorPwmInversion ? timerHardware->output ^ TIMER_OUTPUT_INVERTED : timerHardware->output);
motors[motorIndex].enabled = true;
} }
return &dshotPwmDevice; return &dshotPwmDevice;

View file

@ -161,7 +161,7 @@ motorDmaOutput_t *getMotorDmaOutput(uint8_t index);
bool isMotorProtocolDshot(void); bool isMotorProtocolDshot(void);
void pwmWriteDshotInt(uint8_t index, uint16_t value); void pwmWriteDshotInt(uint8_t index, uint16_t value);
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output); bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output);
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
bool pwmStartDshotMotorUpdate(void); bool pwmStartDshotMotorUpdate(void);
#endif #endif

View file

@ -205,7 +205,7 @@ static void motor_DMA_IRQHandler(dmaChannelDescriptor_t *descriptor)
} }
} }
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output) bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output)
{ {
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
#define OCINIT motor->ocInitStruct #define OCINIT motor->ocInitStruct
@ -247,7 +247,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
#endif #endif
if (dmaRef == NULL) { if (dmaRef == NULL) {
return; return false;
} }
motorDmaOutput_t * const motor = &dmaMotors[motorIndex]; motorDmaOutput_t * const motor = &dmaMotors[motorIndex];
@ -423,6 +423,8 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
} }
#endif #endif
motor->configured = true; motor->configured = true;
return true;
} }
#endif #endif

View file

@ -181,7 +181,7 @@ static void motor_DMA_IRQHandler(dmaChannelDescriptor_t* descriptor)
} }
} }
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output) bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output)
{ {
#ifdef USE_DSHOT_TELEMETRY #ifdef USE_DSHOT_TELEMETRY
#define OCINIT motor->ocInitStruct #define OCINIT motor->ocInitStruct
@ -215,7 +215,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
#endif #endif
if (dmaRef == NULL) { if (dmaRef == NULL) {
return; return false;
} }
motorDmaOutput_t * const motor = &dmaMotors[motorIndex]; motorDmaOutput_t * const motor = &dmaMotors[motorIndex];
@ -381,5 +381,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
} }
#endif #endif
motor->configured = true; motor->configured = true;
return true;
} }
#endif #endif

View file

@ -233,7 +233,7 @@ static void motor_DMA_IRQHandler(dmaChannelDescriptor_t* descriptor)
} }
} }
void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output) bool pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t motorIndex, motorPwmProtocolTypes_e pwmProtocolType, uint8_t output)
{ {
dmaResource_t *dmaRef = NULL; dmaResource_t *dmaRef = NULL;
uint32_t dmaChannel; uint32_t dmaChannel;
@ -266,7 +266,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
#endif #endif
if (dmaRef == NULL) { if (dmaRef == NULL) {
return; return false;
} }
motorDmaOutput_t * const motor = &dmaMotors[motorIndex]; motorDmaOutput_t * const motor = &dmaMotors[motorIndex];
@ -298,7 +298,7 @@ void pwmDshotMotorHardwareConfig(const timerHardware_t *timerHardware, uint8_t m
if (result != HAL_OK) { if (result != HAL_OK) {
/* Initialization Error */ /* Initialization Error */
return; return false;
} }
} }
@ -334,7 +334,7 @@ P - High - High -
if (result != HAL_OK) { if (result != HAL_OK) {
/* Configuration Error */ /* Configuration Error */
return; return false;
} }
// DMA setup // DMA setup
@ -347,7 +347,7 @@ P - High - High -
if (!configureTimer) { if (!configureTimer) {
motor->configured = true; motor->configured = true;
return; return false;
} }
} else } else
#endif #endif
@ -418,7 +418,7 @@ P - High - High -
if (result != HAL_OK) { if (result != HAL_OK) {
/* Initialization Error */ /* Initialization Error */
return; return false;
} }
dmaIdentifier_e identifier = dmaGetIdentifier(dmaRef); dmaIdentifier_e identifier = dmaGetIdentifier(dmaRef);
@ -444,9 +444,11 @@ P - High - High -
if (result != HAL_OK) { if (result != HAL_OK) {
/* Starting PWM generation Error */ /* Starting PWM generation Error */
return; return false;
} }
motor->configured = true; motor->configured = true;
return true;
} }
#endif #endif