通常Arduino中调整串口缓存大小的方法是修改HardwareSerial.h中的常量。
其实根本无需修改系统core中的定义值,只需要在代码最上方添加以下常量定义,抢在HardwareSerial.h之前定义缓存大小就可以了。
#define SERIAL_RX_BUFFER_SIZE 512
#define SERIAL_TX_BUFFER_SIZE 128
但是如果使用STM32的板子就没那么简单了。
无论你如何修改HardwareSerial.h的常量定义,或者是在代码上方添加定义都是无效的。
因为在STM32的HardwareSerial.h中即便有该常量的定义,其实也是没有用到的,请看以下代码。
#if 0
volatile uint8_t * const _ubrrh;
volatile uint8_t * const _ubrrl;
volatile uint8_t * const _ucsra;
volatile uint8_t * const _ucsrb;
volatile uint8_t * const _ucsrc;
volatile uint8_t * const _udr;
// Has any byte been written to the UART since begin()
bool _written;
volatile rx_buffer_index_t _rx_buffer_head;
volatile rx_buffer_index_t _rx_buffer_tail;
volatile tx_buffer_index_t _tx_buffer_head;
volatile tx_buffer_index_t _tx_buffer_tail;
// Don't put any members after these