Skip to content

Commit 842ff0a

Browse files
committed
fix MF_SerialUART
1 parent 0c80871 commit 842ff0a

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/madflight/hal/RP2040/MF_SerialPIO_RP2040.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class MF_SerialPIO : public MF_Serial {
2121

2222
xTaskCreate( MF_SerialPIO_task, // The function that implements the task
2323
taskname, // Human readable name for the task
24-
configMINIMAL_STACK_SIZE, // Stack size (in words!)
24+
configMINIMAL_STACK_SIZE, // Stack size (in words!) (configMINIMAL_STACK_SIZE=256)
2525
(void*)this, // Task parameter
2626
uxTaskPriorityGet(NULL), // The priority at which the task is created
2727
NULL ); // No use for the task handle
@@ -44,6 +44,7 @@ class MF_SerialPIO : public MF_Serial {
4444
}
4545

4646
int write(uint8_t *buf, int len) override {
47+
if(len <= 0) return 0;
4748
if(availableForWrite() < len) return 0;
4849
return xStreamBufferSend( xStreamBuffer, (const void *)buf, len, 0 ); //0 = no wait
4950
}

src/madflight/hal/RP2040/MF_SerialUART_RP2040.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,14 @@ class MF_SerialUART : public MF_Serial {
1414
StreamBufferHandle_t xStreamBuffer = NULL;
1515

1616

17-
1817
MF_SerialUART(SerialUART *_serial, const char* taskname) {
1918
this->_serial = _serial;
2019

2120
xStreamBuffer = xStreamBufferCreate(256, 1); // length, triggerlevel
2221

2322
xTaskCreate( MF_SerialUART_task, // The function that implements the task
2423
taskname, // Human readable name for the task
25-
configMINIMAL_STACK_SIZE, // Stack size (in words!)
24+
configMINIMAL_STACK_SIZE, // Stack size (in words!) (configMINIMAL_STACK_SIZE=256)
2625
(void*)this, // Task parameter
2726
uxTaskPriorityGet(NULL), // The priority at which the task is created
2827
NULL ); // No use for the task handle
@@ -45,6 +44,7 @@ class MF_SerialUART : public MF_Serial {
4544
}
4645

4746
int write(uint8_t *buf, int len) override {
47+
if(len <= 0) return 0;
4848
if(availableForWrite() < len) return 0;
4949
return xStreamBufferSend( xStreamBuffer, (const void *)buf, len, 0 ); //0 = no wait
5050
}

src/madflight/hal/RP2040/hal_RP2040_cpp.h

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
#include "RP2040_PWM.h" //Servo and oneshot
3232
#include "../MF_I2C.h"
3333
#include "../MF_Serial.h"
34-
//#include "RP2040_SerialIRQ.h" //Replacement high performance serial driver (did not work very well...)
34+
#include "RP2040_SerialIRQ.h" //Replacement high performance serial driver (did not work very well...)
3535
#include "MF_SerialUART_RP2040.h" //MF_Serial wrappers for SerialUART with task based TX buffer
3636
#include "MF_SerialPIO_RP2040.h" //MF_Serial wrappers for SerialPIO with task based TX buffer
3737

@@ -166,8 +166,7 @@ void hal_print_pin_name(int pinnum) {
166166
}
167167

168168

169-
170-
169+
//* MF_SerialUART version - works for sbus & ublox
171170

172171
//create/get Serial bus (late binding)
173172
//Serial BUS (&Serial, &Serial1, &Serial2) - ser0 &Serial is used for CLI via uart->USB converter
@@ -278,9 +277,11 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
278277
return hal_ser[bus_id];
279278
}
280279

280+
//*/
281281

282282

283-
/* //SerialUART version - works
283+
284+
/* //SerialUART version - works for sbus, not for gps because of lacking TX buffer
284285
285286
//create/get Serial bus (late binding)
286287
//Serial BUS (&Serial, &Serial1, &Serial2) - ser0 &Serial is used for CLI via uart->USB converter
@@ -344,23 +345,14 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
344345
}
345346
346347
347-
*/
348+
//*/
348349

349350

350351

351352

352353

353-
/*
354-
//uncomment one: SerialIRQ, SerialUART or SerialPIO and use uart0 or uart1
355-
auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, ser1_txbuf, sizeof(ser1_txbuf), cfg.pin_ser1_rx, ser1_rxbuf, sizeof(ser1_rxbuf));
356-
//auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
357-
//auto *ser = new SerialDMA(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
358-
//auto *ser = new SerialUART(uart1, cfg.pin_ser1_tx, pin_ser1_rx); //SerialUART default Arduino impementation (had some problems with this)
359-
//auto *ser = new SerialPIO(cfg.pin_ser1_tx, pin_ser1_rx, 32); //PIO uarts, any pin allowed (not tested, but expect same as SerialUART)
360-
hal_ser[1] = new MF_SerialPtrWrapper<decltype(ser)>( ser );
361-
*/
362354

363-
/*
355+
/* //SerialIRQ version - does not work for SBUS, works for UBLOX
364356
365357
MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert) {
366358
if(bus_id < 0 || bus_id >= HAL_SER_NUM) return nullptr;
@@ -383,7 +375,7 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
383375
break;
384376
}
385377
386-
//using SerialIRQ - does not work correctly for sbus ...
378+
//using SerialIRQ - works for gps, does not work correctly for sbus ...
387379
switch(bus_id) {
388380
case 0: {
389381
int pin_tx = cfg.pin_ser0_tx;
@@ -394,8 +386,6 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
394386
if(!hal_ser[bus_id]) hal_ser[bus_id] = new MF_SerialPtrWrapper<decltype(ser)>( ser );
395387
}
396388
break;
397-
}
398-
break;
399389
}
400390
case 1: {
401391
int pin_tx = cfg.pin_ser1_tx;
@@ -410,6 +400,20 @@ MF_Serial* hal_get_ser_bus(int bus_id, int baud, MF_SerialMode mode, bool invert
410400
default:
411401
return nullptr;
412402
}
413-
*/
403+
404+
return hal_ser[bus_id];
405+
}
406+
407+
//*/
414408

415409

410+
411+
/*
412+
//uncomment one: SerialIRQ, SerialUART or SerialPIO and use uart0 or uart1
413+
auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, ser1_txbuf, sizeof(ser1_txbuf), cfg.pin_ser1_rx, ser1_rxbuf, sizeof(ser1_rxbuf));
414+
//auto *ser = new SerialIRQ(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
415+
//auto *ser = new SerialDMA(uart1, cfg.pin_ser1_tx, pin_ser1_rx, 256, 256); //TODO
416+
//auto *ser = new SerialUART(uart1, cfg.pin_ser1_tx, pin_ser1_rx); //SerialUART default Arduino impementation (had some problems with this)
417+
//auto *ser = new SerialPIO(cfg.pin_ser1_tx, pin_ser1_rx, 32); //PIO uarts, any pin allowed (not tested, but expect same as SerialUART)
418+
hal_ser[1] = new MF_SerialPtrWrapper<decltype(ser)>( ser );
419+
*/

0 commit comments

Comments
 (0)