@@ -70,7 +70,7 @@ SemaphoreHandle_t uart_buffer_Mutex = NULL;
70
70
// task created when onReceive() is used
71
71
void UART0_RX_CB () {
72
72
// take the mutex, waits forever until loop() finishes its processing
73
- if (xSemaphoreTake (uart_buffer_Mutex, portMAX_DELAY)) {
73
+ if (uart_buffer_Mutex != NULL && xSemaphoreTake (uart_buffer_Mutex, portMAX_DELAY)) {
74
74
uint32_t now = millis (); // tracks timeout
75
75
while ((millis () - now) < communicationTimeout_ms) {
76
76
if (UART0.available ()) {
@@ -88,7 +88,10 @@ void UART0_RX_CB() {
88
88
void setup () {
89
89
// creates a mutex object to control access to uart_buffer
90
90
uart_buffer_Mutex = xSemaphoreCreateMutex ();
91
-
91
+ if (uart_buffer_Mutex == NULL ) {
92
+ log_e (" Error creating Mutex. Sketch will fail." );
93
+ delay (1000 );
94
+ }
92
95
UART0.begin (115200 );
93
96
UART0.onReceive (UART0_RX_CB); // sets the callback function
94
97
UART0.println (" Send data to UART0 in order to activate the RX callback" );
@@ -98,7 +101,7 @@ uint32_t counter = 0;
98
101
void loop () {
99
102
if (uart_buffer.length () > 0 ) {
100
103
// signals that the onReceive function shall not change uart_buffer while processing
101
- if (xSemaphoreTake (uart_buffer_Mutex, portMAX_DELAY)) {
104
+ if (uart_buffer_Mutex != NULL && xSemaphoreTake (uart_buffer_Mutex, portMAX_DELAY)) {
102
105
// process the received data from UART0 - example, just print it beside a counter
103
106
UART0.print (" [" );
104
107
UART0.print (counter++);
0 commit comments