Skip to content

Commit b7c6948

Browse files
committed
Fixes SetRxBufferSize(0) with end()
1 parent 1a5b3e2 commit b7c6948

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

Diff for: cores/esp32/USBCDC.cpp

+9-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,15 @@ void USBCDC::onEvent(arduino_usb_cdc_event_t event, esp_event_handler_t callback
114114
}
115115

116116
size_t USBCDC::setRxBufferSize(size_t rx_queue_len){
117-
if(rx_queue){
118-
vQueueDelete(rx_queue);
119-
rx_queue = NULL;
120-
if(!rx_queue_len){
121-
return 0;
122-
}
117+
size_t currentQueueSize = rx_queue ?
118+
uxQueueSpacesAvailable(rx_queue) + uxQueueMessagesWaiting(rx_queue) : 0;
119+
120+
if (rx_queue && (!rx_queue_len || rx_queue_len != currentQueueSize)) {
121+
vQueueDelete(rx_queue);
122+
rx_queue = NULL;
123+
}
124+
if(!rx_queue_len || rx_queue_len == currentQueueSize){
125+
return 0;
123126
}
124127
rx_queue = xQueueCreate(rx_queue_len, sizeof(uint8_t));
125128
if(!rx_queue){

0 commit comments

Comments
 (0)