add Uart _begun, fix potetial hard fault with Debug level ON but Serial.begin() is not called
This commit is contained in:
1 parent
555e4a368a
commit
fe148b78d7
3 files changed
+11
-1
No files matched your search
@@ -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()
|
||||
|
||||
+3
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user