Skip to content

Commit fe148b7

Browse files
committed
add Uart _begun, fix potetial hard fault with Debug level ON but Serial.begin() is not called
1 parent 555e4a3 commit fe148b7

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

cores/nRF5/Uart.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ Uart::Uart(NRF_UART_Type *_nrfUart, IRQn_Type _IRQn, uint8_t _pinRX, uint8_t _pi
2828
uc_pinRX = g_ADigitalPinMap[_pinRX];
2929
uc_pinTX = g_ADigitalPinMap[_pinTX];
3030
uc_hwFlow = 0;
31+
32+
_begun = false;
3133
}
3234

3335
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
3941
uc_pinCTS = g_ADigitalPinMap[_pinCTS];
4042
uc_pinRTS = g_ADigitalPinMap[_pinRTS];
4143
uc_hwFlow = 1;
44+
45+
_begun = false;
4246
}
4347

4448
void Uart::begin(unsigned long baudrate)
@@ -147,6 +151,8 @@ void Uart::begin(unsigned long baudrate, uint16_t /*config*/)
147151
NVIC_ClearPendingIRQ(IRQn);
148152
NVIC_SetPriority(IRQn, 3);
149153
NVIC_EnableIRQ(IRQn);
154+
155+
_begun = true;
150156
}
151157

152158
void Uart::end()

cores/nRF5/Uart.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Uart : public HardwareSerial
4343

4444
void IrqHandler();
4545

46-
operator bool() { return true; }
46+
operator bool() { return _begun; }
4747

4848
private:
4949
NRF_UART_Type *nrfUart;
@@ -56,6 +56,8 @@ class Uart : public HardwareSerial
5656
uint8_t uc_pinCTS;
5757
uint8_t uc_pinRTS;
5858
uint8_t uc_hwFlow;
59+
60+
bool _begun;
5961
};
6062

6163
#ifdef __cplusplus

cores/nRF5/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ static void loop_task(void* arg)
3434
setup();
3535

3636
#if CFG_DEBUG
37+
// If Serial is not begin(), call it to avoid hard fault
38+
if (!Serial) Serial.begin(115200);
3739
dbgPrintVersion();
3840
#endif
3941

0 commit comments

Comments
 (0)