Skip to content

Commit

Permalink
fix: prevent generic module de-init if protocol is NONE
Browse files Browse the repository at this point in the history
Fixes #1898

De-initialising the external module while SBUS trainer is used on external module RX leads to the following sequence:
- `extmoduleStop()` is called, thus shutting down the timer DMA
- on certain targets, the timer DMA stream is the same as the external module RX DMA stream
- when this DMA stream is used by the SBUS trainer input, this leads to DMAFifo to return random bytes continuously
- thus driving `processSbusInput()` into an endless loop, which is run in the mixer task
- as the mixer task has the highest priority, it runs forever
- after some time the watchdog timer expires, and causes a reboot
  • Loading branch information
raphaelcoeffic committed Oct 11, 2022
1 parent 786fbcb commit d497534
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions radio/src/pulses/pulses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,9 @@ bool setupPulsesInternalModule(uint8_t protocol)

void stopPulsesInternalModule()
{
if (moduleState[INTERNAL_MODULE].protocol != PROTOCOL_CHANNELS_UNINITIALIZED) {
auto& proto = moduleState[INTERNAL_MODULE].protocol;
if (proto != PROTOCOL_CHANNELS_UNINITIALIZED &&
proto != PROTOCOL_CHANNELS_NONE) {
if (internalModuleDriver) {
internalModuleDriver->deinit(internalModuleContext);
internalModuleDriver = nullptr;
Expand All @@ -467,7 +469,7 @@ void stopPulsesInternalModule()
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
intmoduleStop();
}
moduleState[INTERNAL_MODULE].protocol = PROTOCOL_CHANNELS_NONE;
proto = PROTOCOL_CHANNELS_NONE;
}
}

Expand Down Expand Up @@ -766,8 +768,9 @@ void extmoduleSendNextFrame()

void stopPulsesExternalModule()
{
if (moduleState[EXTERNAL_MODULE].protocol !=
PROTOCOL_CHANNELS_UNINITIALIZED) {
auto& proto = moduleState[EXTERNAL_MODULE].protocol;
if (proto != PROTOCOL_CHANNELS_UNINITIALIZED &&
proto != PROTOCOL_CHANNELS_NONE) {
if (externalModuleDriver) {
externalModuleDriver->deinit(externalModuleContext);
externalModuleDriver = nullptr;
Expand All @@ -776,7 +779,7 @@ void stopPulsesExternalModule()
mixerSchedulerSetPeriod(EXTERNAL_MODULE, 0);
extmoduleStop();
}
moduleState[EXTERNAL_MODULE].protocol = PROTOCOL_CHANNELS_NONE;
proto = PROTOCOL_CHANNELS_NONE;
}
}

Expand Down

0 comments on commit d497534

Please sign in to comment.