Make HardwareSerial::begin() and end() interrupt safe and disable TX/RX if we can't allocate a buffer for them.
Make HardwareSerial::begin() and end() interrupt safe and disable TX/RX if we can't allocate a buffer for them.

Prior to this change, the interrupt could fire during initialisation,
necessitating a deep check that the HardwareSerial structure had valid
_tx_buffer or _rx_buffer each time an interrupt occurred.

By keeping uart_t's and HardwareSerial's (txEnabled, _tx_buffer) and
(rxEnabled, _rx_buffer) in sync, we can remove this extra check, as
well as fixing a null pointer dereference if e.g. _tx_buffer allocation
failed and write() was subsequently called.

NextDevBoard/Arduino,lrmoreno007/Arduino,sticilface/Arduino,hallard/Arduino,lrmoreno007/Arduino,me-no-dev/Arduino,Lan-Hekary/Arduino,jes/Arduino,Juppit/Arduino,gguuss/Arduino,jes/Arduino,jes/Arduino,gguuss/Arduino,jes/Arduino,Links2004/Arduino,martinayotte/ESP8266-Arduino,Links2004/Arduino,NullMedia/Arduino,hallard/Arduino,KaloNK/Arduino,Lan-Hekary/Arduino,quertenmont/Arduino,Juppit/Arduino,NextDevBoard/Arduino,gguuss/Arduino,Juppit/Arduino,sticilface/Arduino,wemos/Arduino,toastedcode/esp8266-Arduino,NextDevBoard/Arduino,sticilface/Arduino,esp8266/Arduino,Adam5Wu/Arduino,martinayotte/ESP8266-Arduino,KaloNK/Arduino,martinayotte/ESP8266-Arduino,jes/Arduino,Adam5Wu/Arduino,NextDevBoard/Arduino,me-no-dev/Arduino,quertenmont/Arduino,esp8266/Arduino,gguuss/Arduino,esp8266/Arduino,KaloNK/Arduino,me-no-dev/Arduino,Lan-Hekary/Arduino,esp8266/Arduino,martinayotte/ESP8266-Arduino,Adam5Wu/Arduino,me-no-dev/Arduino,lrmoreno007/Arduino,toastedcode/esp8266-Arduino,lrmoreno007/Arduino,hallard/Arduino,toastedcode/esp8266-Arduino,wemos/Arduino,NullMedia/Arduino,quertenmont/Arduino,me-no-dev/Arduino,Juppit/Arduino,Links2004/Arduino,lrmoreno007/Arduino,hallard/Arduino,martinayotte/ESP8266-Arduino,quertenmont/Arduino,wemos/Arduino,esp8266/Arduino,KaloNK/Arduino,wemos/Arduino,sticilface/Arduino,hallard/Arduino,Adam5Wu/Arduino,NullMedia/Arduino,Adam5Wu/Arduino,sticilface/Arduino,Links2004/Arduino,NullMedia/Arduino,toastedcode/esp8266-Arduino,NextDevBoard/Arduino,NullMedia/Arduino,wemos/Arduino,Lan-Hekary/Arduino,Links2004/Arduino,Juppit/Arduino,gguuss/Arduino,quertenmont/Arduino,toastedcode/esp8266-Arduino,Lan-Hekary/Arduino,KaloNK/Arduino