mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-18 22:05:17 +03:00
Add support for 2 softserial ports on PWM4+5/TIM3_CH1+2/PA6+PA7 and
PWM6+7/TIM3_CH3+4/PB0+PB1 Update software serial to monitor serial pins for signal changes instead of periodically sampling pin signals. When reading the data the timer used is syncronized to the falling edge of the start bit which allows for better syncronisation at higher speeds. The code has been tested OK from 1200 baud to 19200. 38400 baud was tested and partially usable but has been disabled because there are too many transmit and receive errors, especially when transmitting and receiving at the same time. Due to the way a single timer is used for transmitting and receiving, if data comes in while transmitting the system may incorrectly transmit a short or long bit. However at 19200 and below this didn't cause a problem in the limited testing I performed.
This commit is contained in:
parent
bd809bca1b
commit
c7de7d2ebc
9 changed files with 212 additions and 138 deletions
38
src/main.c
38
src/main.c
|
@ -30,8 +30,10 @@ int main(void)
|
|||
uint8_t i;
|
||||
drv_pwm_config_t pwm_params;
|
||||
drv_adc_config_t adc_params;
|
||||
serialPort_t* loopbackPort = NULL;
|
||||
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
serialPort_t* loopbackPort1 = NULL;
|
||||
serialPort_t* loopbackPort2 = NULL;
|
||||
#endif
|
||||
systemInit();
|
||||
#ifdef USE_LAME_PRINTF
|
||||
init_printf(NULL, _putc);
|
||||
|
@ -148,11 +150,19 @@ int main(void)
|
|||
serialInit(mcfg.serial_baudrate);
|
||||
|
||||
if (feature(FEATURE_SOFTSERIAL)) {
|
||||
setupSoftSerial1(mcfg.softserial_baudrate, mcfg.softserial_inverted);
|
||||
//mcfg.softserial_baudrate = 19200; // Uncomment to override config value
|
||||
|
||||
setupSoftSerialPrimary(mcfg.softserial_baudrate, mcfg.softserial_1_inverted);
|
||||
setupSoftSerialSecondary(mcfg.softserial_2_inverted);
|
||||
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
loopbackPort = (serialPort_t*)&(softSerialPorts[0]);
|
||||
serialPrint(loopbackPort, "LOOPBACK ENABLED\r\n");
|
||||
loopbackPort1 = (serialPort_t*)&(softSerialPorts[0]);
|
||||
serialPrint(loopbackPort1, "SOFTSERIAL 1 - LOOPBACK ENABLED\r\n");
|
||||
|
||||
loopbackPort2 = (serialPort_t*)&(softSerialPorts[1]);
|
||||
serialPrint(loopbackPort2, "SOFTSERIAL 2 - LOOPBACK ENABLED\r\n");
|
||||
#endif
|
||||
//core.mainport = (serialPort_t*)&(softSerialPorts[0]); // Uncomment to switch the main port to use softserial.
|
||||
}
|
||||
|
||||
if (feature(FEATURE_TELEMETRY))
|
||||
|
@ -169,11 +179,19 @@ int main(void)
|
|||
while (1) {
|
||||
loop();
|
||||
#ifdef SOFTSERIAL_LOOPBACK
|
||||
if (loopbackPort) {
|
||||
while (serialTotalBytesWaiting(loopbackPort)) {
|
||||
|
||||
uint8_t b = serialRead(loopbackPort);
|
||||
serialWrite(loopbackPort, b);
|
||||
if (loopbackPort1) {
|
||||
while (serialTotalBytesWaiting(loopbackPort1)) {
|
||||
uint8_t b = serialRead(loopbackPort1);
|
||||
serialWrite(loopbackPort1, b);
|
||||
//serialWrite(core.mainport, 0x01);
|
||||
//serialWrite(core.mainport, b);
|
||||
};
|
||||
}
|
||||
if (loopbackPort2) {
|
||||
while (serialTotalBytesWaiting(loopbackPort2)) {
|
||||
uint8_t b = serialRead(loopbackPort2);
|
||||
serialWrite(loopbackPort1, b);
|
||||
//serialWrite(core.mainport, 0x02);
|
||||
//serialWrite(core.mainport, b);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue