diff --git a/cores/nRF5/Uart.cpp b/cores/nRF5/Uart.cpp index bf8fe195..3f1c0121 100644 --- a/cores/nRF5/Uart.cpp +++ b/cores/nRF5/Uart.cpp @@ -28,6 +28,8 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi uc_pinRX = g_ADigitalPinMap[_pinRX]; uc_pinTX = g_ADigitalPinMap[_pinTX]; uc_hwFlow = 0; + + _begun = false; } Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pinTX, uint8_t _pinCTS, uint8_t _pinRTS) @@ -39,6 +41,8 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi uc_pinCTS = g_ADigitalPinMap[_pinCTS]; uc_pinRTS = g_ADigitalPinMap[_pinRTS]; uc_hwFlow = 1; + + _begun = false; } void Uart::begin(unsigned long baudrate) @@ -147,6 +151,8 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/) NVIC_ClearPendingIRQ(IRQn); NVIC_SetPriority(IRQn, 3); NVIC_EnableIRQ(IRQn); + + _begun = true; } void Uart::end() diff --git a/cores/nRF5/Uart.h b/cores/nRF5/Uart.h index 76472983..d3c56976 100644 --- a/cores/nRF5/Uart.h +++ b/cores/nRF5/Uart.h @@ -43,7 +43,7 @@ class Uart : public HardwareSerial void IrqHandler(); - operator bool() { return true; } + operator bool() { return _begun; } private: NRF_UART_Type *nrfUart; @@ -56,6 +56,8 @@ class Uart : public HardwareSerial uint8_t uc_pinCTS; uint8_t uc_pinRTS; uint8_t uc_hwFlow; + + bool _begun; }; #ifdef __cplusplus diff --git a/cores/nRF5/main.cpp b/cores/nRF5/main.cpp index e2457800..2368b2c1 100644 --- a/cores/nRF5/main.cpp +++ b/cores/nRF5/main.cpp @@ -34,6 +34,8 @@ static void loop_task(void* arg) setup(); #if CFG_DEBUG + // If Serial is not begin(), call it to avoid hard fault + if (!Serial) Serial.begin(115200); dbgPrintVersion(); #endif