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

Do not permit MSP on softserial ports as the load on the CPU is too great (#13303)

Do not permit MSP or serial RX, or baud rates above 19200 on softserial ports as the load on the CPU is too great
This commit is contained in:
Steve Evans 2024-01-18 04:34:22 +00:00 committed by GitHub
parent 926ef34476
commit 42267349db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 4 deletions

View file

@ -229,7 +229,7 @@ static void validateAndFixConfig(void)
}
#endif
if (!isSerialConfigValid(serialConfig())) {
if (!isSerialConfigValid(serialConfigMutable())) {
pgResetFn_serialConfig(serialConfigMutable());
}

View file

@ -28,6 +28,7 @@
#include "cli/cli.h"
#include "common/maths.h"
#include "common/utils.h"
#include "drivers/time.h"
@ -324,9 +325,8 @@ serialPort_t *findSharedSerialPort(uint16_t functionMask, serialPortFunction_e s
#define ALL_FUNCTIONS_SHARABLE_WITH_MSP (FUNCTION_BLACKBOX | FUNCTION_VTX_MSP)
#endif
bool isSerialConfigValid(const serialConfig_t *serialConfigToCheck)
bool isSerialConfigValid(serialConfig_t *serialConfigToCheck)
{
UNUSED(serialConfigToCheck);
/*
* rules:
* - 1 MSP port minimum, max MSP ports is defined and must be adhered to.
@ -341,6 +341,19 @@ bool isSerialConfigValid(const serialConfig_t *serialConfigToCheck)
for (int index = 0; index < SERIAL_PORT_COUNT; index++) {
const serialPortConfig_t *portConfig = &serialConfigToCheck->portConfigs[index];
#ifdef USE_SOFTSERIAL
if ((portConfig->identifier == SERIAL_PORT_SOFTSERIAL1) ||
(portConfig->identifier == SERIAL_PORT_SOFTSERIAL2)) {
// Ensure MSP or serial RX is not enabled on soft serial ports
serialConfigToCheck->portConfigs[index].functionMask &= ~(FUNCTION_MSP | FUNCTION_RX_SERIAL);
// Ensure that the baud rate on soft serial ports is limited to 19200
serialConfigToCheck->portConfigs[index].gps_baudrateIndex = constrain(portConfig->gps_baudrateIndex, BAUD_AUTO, BAUD_19200);
serialConfigToCheck->portConfigs[index].blackbox_baudrateIndex = constrain(portConfig->blackbox_baudrateIndex, BAUD_AUTO, BAUD_19200);
serialConfigToCheck->portConfigs[index].telemetry_baudrateIndex = constrain(portConfig->telemetry_baudrateIndex, BAUD_AUTO, BAUD_19200);
}
#endif
if (portConfig->functionMask & FUNCTION_MSP) {
mspPortCount++;
} else if (portConfig->identifier == SERIAL_PORT_USB_VCP) {
@ -423,6 +436,13 @@ serialPort_t *openSerialPort(
serialPort_t *serialPort = NULL;
#ifdef USE_SOFTSERIAL
if (((identifier == SERIAL_PORT_SOFTSERIAL1) || (identifier == SERIAL_PORT_SOFTSERIAL2)) && (baudRate > 19200)) {
// Limit baud rate on soft serial ports
baudRate = 19200;
}
#endif
switch (identifier) {
#ifdef USE_VCP
case SERIAL_PORT_USB_VCP:

View file

@ -157,7 +157,7 @@ void serialInit(bool softserialEnabled, serialPortIdentifier_e serialPortToDisab
void serialRemovePort(serialPortIdentifier_e identifier);
uint8_t serialGetAvailablePortCount(void);
bool serialIsPortAvailable(serialPortIdentifier_e identifier);
bool isSerialConfigValid(const serialConfig_t *serialConfig);
bool isSerialConfigValid(serialConfig_t *serialConfig);
const serialPortConfig_t *serialFindPortConfiguration(serialPortIdentifier_e identifier);
serialPortConfig_t *serialFindPortConfigurationMutable(serialPortIdentifier_e identifier);
bool doesConfigurationUsePort(serialPortIdentifier_e portIdentifier);