Not work original Lib on F446RE & L432KC . Change usage prime() & setNext() for both TX and RX function due to unexpected behavior (maybe os TimerEvent function problem)
Dependents: BufferedSoftSerial
Revision 13:6399b30798a5, committed 2020-05-12
- Comitter:
- kenjiArai
- Date:
- Tue May 12 05:27:07 2020 +0000
- Parent:
- 12:cd58d03b8559
- Commit message:
- expand for several CPU's.
Changed in this revision
diff -r cd58d03b8559 -r 6399b30798a5 SoftSerial.cpp --- a/SoftSerial.cpp Sun May 10 08:05:32 2020 +0000 +++ b/SoftSerial.cpp Tue May 12 05:27:07 2020 +0000 @@ -1,4 +1,4 @@ -// Modified by K.Arai / JH1PJL May 10th, 2020 +// Modified by K.Arai / JH1PJL May 12th, 2020 #include "SoftSerial.h"
diff -r cd58d03b8559 -r 6399b30798a5 SoftSerial.h --- a/SoftSerial.h Sun May 10 08:05:32 2020 +0000 +++ b/SoftSerial.h Tue May 12 05:27:07 2020 +0000 @@ -2,7 +2,7 @@ Original Library by Erik- & SonyPony https://os.mbed.com/users/Sissors/code/SoftSerial/ - Modified by K.Arai / JH1PJL May 10th, 2020 + Modified by K.Arai / JH1PJL May 12th, 2020 modified functions tx_handler() @@ -96,7 +96,6 @@ */ void attach(void (*fptr)(void), IrqType type=RxIrq) { - //fpointer[type].attach(fptr); fpointer[type] = Callback<void()>(fptr); } @@ -111,7 +110,6 @@ template<typename T> void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - //fpointer[type].attach(tptr, mptr); fpointer[type] = Callback<void()>(tptr, mptr); } @@ -128,7 +126,6 @@ int _bits, _stop_bits, _total_bits; Parity _parity; - //FunctionPointer fpointer[2]; Callback<void()> fpointer[2]; //rx @@ -150,7 +147,6 @@ int _char; volatile int tx_bit; - virtual int _getc(); virtual int _putc(int c); };
diff -r cd58d03b8559 -r 6399b30798a5 SoftSerial_Ticker.h --- a/SoftSerial_Ticker.h Sun May 10 08:05:32 2020 +0000 +++ b/SoftSerial_Ticker.h Tue May 12 05:27:07 2020 +0000 @@ -1,7 +1,7 @@ //A modified version of the regular ticker/timeout libraries // to allow us to do timeout without losing accuracy -// Modified by K.Arai / JH1PJL May 9th, 2020 +// Modified by K.Arai / JH1PJL May 12th, 2020 #ifndef FLEXTICKER_H #define FLEXTICKER_H @@ -14,7 +14,6 @@ template<typename T> void attach(T* tptr, void (T::*mptr)(void)) { - //_function.attach(tptr, mptr); _function = Callback<void()>(tptr, mptr); } @@ -28,12 +27,11 @@ void setNext(int delay) { insert(event.timestamp + delay); - //insert_absolute(event.timestamp + delay); } - void prime(int adjust_time) + void prime(int comp_time = 0) { - event.timestamp = us_ticker_read() - adjust_time; + event.timestamp = us_ticker_read() + comp_time; } protected:
diff -r cd58d03b8559 -r 6399b30798a5 SoftSerial_rx.cpp --- a/SoftSerial_rx.cpp Sun May 10 08:05:32 2020 +0000 +++ b/SoftSerial_rx.cpp Tue May 12 05:27:07 2020 +0000 @@ -1,7 +1,29 @@ -// Modified by K.Arai / JH1PJL May 10th, 2020 +// Modified by K.Arai / JH1PJL May 12th, 2020 #include "SoftSerial.h" +//------------------------------------------------------------------------------ +#if defined(TARGET_NUCLEO_L152RE) +# define MAGIC_NUM (-560) +#elif defined(TARGET_NUCLEO_F401RE) +# define MAGIC_NUM (-205) +#elif defined(TARGET_NUCLEO_F411RE) +# define MAGIC_NUM (-180) +#elif defined(TARGET_NUCLEO_F446RE) +# define MAGIC_NUM (-115) +#elif defined(TARGET_NUCLEO_L432KC) +# define MAGIC_NUM (-50) +#elif defined(TARGET_NUCLEO_L476RG) +# define MAGIC_NUM (-50) +#elif defined(TARGET_K64F) +# define MAGIC_NUM (0) +#else +# warning "you need to tune MAGIC_NUM! in SoftSerial_rx.cpp" +# define MAGIC_NUM (0) +#endif +//------------------------------------------------------------------------------ + + // please make a constructor in main.cpp if you use below pc & led #if DEBUG_TIMING == 2 extern Serial pc; @@ -15,9 +37,6 @@ # define DBG_PRINTF(...) {;} #endif -// Random estimation of the overhead of mbed libs, -// makes slow devices like LPC812 @ 12MHz perform better -uint32_t overhead_us = 200 * 1000000 / SystemCoreClock; int SoftSerial::_getc( void ) { @@ -37,14 +56,14 @@ void SoftSerial::rx_gpio_irq_handler(void) { TP_ON; - rxticker.prime(0); + rxticker.prime(MAGIC_NUM); rx->fall(NULL); rx_bit = 0; rx_error = false; // dummy setting for 1st timer interrupt rx_1st = true; - rxticker.setNext(0); rx_st_time = us_ticker_read(); + rxticker.setNext(10); TP_OFF; }; @@ -54,13 +73,12 @@ // dummy IRQ for 1st shot if (rx_1st) { rx_1st = false; - //rxticker.setNext(bit_period + (bit_period >> 1) - overhead_us); int next_preiod = us_ticker_read() - rx_st_time; next_preiod = bit_period + (bit_period >> 1) - next_preiod; if (next_preiod > 0) { rxticker.setNext(next_preiod); } else { - rxticker.setNext(0); + rxticker.setNext(5); } TP_OFF; return; @@ -71,7 +89,6 @@ rxticker.setNext(bit_period); rx_bit++; - if (rx_bit <= _bits) { read_buffer |= val << (rx_bit - 1); TP_OFF; @@ -127,7 +144,6 @@ } read_buffer = 0; rxticker.detach(); - //rx->fall(this, &SoftSerial::rx_gpio_irq_handler); rx->fall(callback(this, &SoftSerial::rx_gpio_irq_handler)); TP_OFF; }
diff -r cd58d03b8559 -r 6399b30798a5 SoftSerial_tx.cpp --- a/SoftSerial_tx.cpp Sun May 10 08:05:32 2020 +0000 +++ b/SoftSerial_tx.cpp Tue May 12 05:27:07 2020 +0000 @@ -1,4 +1,4 @@ -// Modified by K.Arai / JH1PJL May 10th, 2020 +// Modified by K.Arai / JH1PJL May 12th, 2020 #include "SoftSerial.h" @@ -23,7 +23,7 @@ prepare_tx(c); tx_bit = 0; tx->write(1); - txticker.prime(0); + txticker.prime(); tx_handler(); return 0; } @@ -63,25 +63,23 @@ } if (tx_bit == 0){ tx->write(1); - } else if (tx_bit == 0){ - tx->write(0); + txticker.setNext(10); } else { int bitchk = _char >> tx_bit; - if (bitchk & 1UL) { + if (bitchk & 1) { tx->write(1); } else { tx->write(0); } + txticker.setNext(bit_period); } tx_bit++; - txticker.setNext(bit_period); TP_OFF; } void SoftSerial::prepare_tx(int c) { _char = c << 2; // set start bit as bit1 and dummy as bit0 - DBG_PRINTF("_char(in) = 0x%08x\r\n", _char); bool parity; switch (_parity) { @@ -116,6 +114,4 @@ _char |= 0xffffffff << num; _char |= 1UL; _char &= ~(1 << _total_bits); - DBG_PRINTF("_char(out) = 0x%08x, num = %d, ", _char, num); - DBG_PRINTF("_total_bits = %d\r\n", _total_bits); }