Browse Source

Update HardwareSerial.cpp

If called second time - fix the counts to reflect just the size of the new buffer plus the static buffer.

Also as a precaution, resets the TX or RX head tail pointers back to 0 to make sure it is not indexing into memory that may not exist.
main
Kurt Eckhardt 4 years ago
parent
commit
7190fda027
1 changed files with 10 additions and 4 deletions
  1. +10
    -4
      teensy4/HardwareSerial.cpp

+ 10
- 4
teensy4/HardwareSerial.cpp View File

{ {
rx_buffer_storage_ = (BUFTYPE*)buffer; rx_buffer_storage_ = (BUFTYPE*)buffer;
if (buffer) { if (buffer) {
rx_buffer_total_size_ = rx_buffer_total_size_ + length;
rx_buffer_total_size_ = rx_buffer_size_ + length;
} else { } else {
rx_buffer_total_size_ = rx_buffer_total_size_;
rx_buffer_total_size_ = rx_buffer_size_;
} }


// Make sure we don't end up indexing into no mans land.
rx_buffer_head_ = 0;
rx_buffer_tail_ = 0;
rts_low_watermark_ = rx_buffer_total_size_ - hardware->rts_low_watermark; rts_low_watermark_ = rx_buffer_total_size_ - hardware->rts_low_watermark;
rts_high_watermark_ = rx_buffer_total_size_ - hardware->rts_high_watermark; rts_high_watermark_ = rx_buffer_total_size_ - hardware->rts_high_watermark;
} }
{ {
tx_buffer_storage_ = (BUFTYPE*)buffer; tx_buffer_storage_ = (BUFTYPE*)buffer;
if (buffer) { if (buffer) {
tx_buffer_total_size_ = tx_buffer_total_size_ + length;
tx_buffer_total_size_ = tx_buffer_size_ + length;
} else { } else {
tx_buffer_total_size_ = tx_buffer_total_size_;
tx_buffer_total_size_ = tx_buffer_size_;
} }
// Make sure we don't end up indexing into no mans land.
tx_buffer_head_ = 0;
tx_buffer_tail_ = 0;
} }


int HardwareSerial::peek(void) int HardwareSerial::peek(void)

Loading…
Cancel
Save