Skip to content

Commit c513b10

Browse files
authored
FIX: Invalid references when neither DSHOT nor PWM_OUTPUT is defined. (betaflight#14135)
1 parent 07e4b4f commit c513b10

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

src/main/drivers/motor.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -317,26 +317,31 @@ bool isMotorProtocolBidirDshot(void)
317317

318318
void motorDevInit(const motorDevConfig_t *motorDevConfig, uint16_t idlePulse, uint8_t motorCount)
319319
{
320-
memset(motors, 0, sizeof(motors));
321-
320+
#if defined(USE_PWM_OUTPUT) || defined(USE_DSHOT)
322321
bool useUnsyncedPwm = motorDevConfig->useUnsyncedPwm;
322+
#else
323+
UNUSED(idlePulse);
324+
UNUSED(motorDevConfig);
325+
#endif
323326

324327
if (isMotorProtocolEnabled()) {
325-
if (!isMotorProtocolDshot()) {
326-
motorDevice = motorPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
327-
}
328+
do {
329+
if (!isMotorProtocolDshot()) {
330+
#ifdef USE_PWM_OUTPUT
331+
motorDevice = motorPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
332+
#endif
333+
break;
334+
}
328335
#ifdef USE_DSHOT
329-
else {
330336
#ifdef USE_DSHOT_BITBANG
331337
if (isDshotBitbangActive(motorDevConfig)) {
332338
motorDevice = dshotBitbangDevInit(motorDevConfig, motorCount);
333-
} else
334-
#endif
335-
{
336-
motorDevice = dshotPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
339+
break;
337340
}
338-
}
339341
#endif
342+
motorDevice = dshotPwmDevInit(motorDevConfig, idlePulse, motorCount, useUnsyncedPwm);
343+
#endif
344+
} while(0);
340345
}
341346

342347
if (motorDevice) {

src/platform/APM32/pwm_output_apm32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static motorVTable_t motorPwmVTable = {
155155

156156
motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
157157
{
158+
memset(motors, 0, sizeof(motors));
159+
158160
motorPwmDevice.vTable = motorPwmVTable;
159161

160162
float sMin = 0;

src/platform/AT32/dshot_bitbang.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ motorDevice_t *dshotBitbangDevInit(const motorDevConfig_t *motorConfig, uint8_t
756756
IOHi(io);
757757
}
758758

759-
// Fill in motors structure for 4way access (XXX Should be refactored)
759+
// Fill in motors structure for 4way access (TODO: Should be refactored)
760760
motors[motorIndex].io = bbMotors[motorIndex].io;
761761
}
762762

src/platform/AT32/pwm_output_at32bsp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ static motorVTable_t motorPwmVTable = {
151151

152152
motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
153153
{
154+
memset(motors, 0, sizeof(motors));
155+
154156
motorPwmDevice.vTable = motorPwmVTable;
155157

156158
float sMin = 0;

src/platform/STM32/pwm_output.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ static motorVTable_t motorPwmVTable = {
183183

184184
motorDevice_t *motorPwmDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8_t motorCount, bool useUnsyncedPwm)
185185
{
186+
memset(motors, 0, sizeof(motors));
187+
186188
motorPwmDevice.vTable = motorPwmVTable;
187189

188190
float sMin = 0;

0 commit comments

Comments
 (0)