Skip to content

Commit ed7417a

Browse files
authored
Merge pull request #9882 from iNavFlight/dzikuvx-h7-gcc13-potential-fix
Potential fix for GCC 13 VCP broken on H7
2 parents 3fcddf2 + 19597ea commit ed7417a

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

src/main/drivers/nvic.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@
2626
#else
2727
#define NVIC_PRIORITY_GROUPING NVIC_PriorityGroup_4
2828
#endif
29-
#endif
29+
#endif

src/main/vcp_hal/usbd_cdc_interface.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
#include "usbd_cdc_interface.h"
5555
#include "stdbool.h"
5656
#include "drivers/time.h"
57+
#include "drivers/nvic.h"
58+
#include "build/atomic.h"
5759

5860
/* Private typedef -----------------------------------------------------------*/
5961
/* Private define ------------------------------------------------------------*/
@@ -366,14 +368,13 @@ uint32_t CDC_Receive_BytesAvailable(void)
366368

367369
uint32_t CDC_Send_FreeBytes(void)
368370
{
369-
/*
370-
return the bytes free in the circular buffer
371-
372-
functionally equivalent to:
373-
(APP_Rx_ptr_out > APP_Rx_ptr_in ? APP_Rx_ptr_out - APP_Rx_ptr_in : APP_RX_DATA_SIZE - APP_Rx_ptr_in + APP_Rx_ptr_in)
374-
but without the impact of the condition check.
375-
*/
376-
return ((UserTxBufPtrOut - UserTxBufPtrIn) + (-((int)(UserTxBufPtrOut <= UserTxBufPtrIn)) & APP_TX_DATA_SIZE)) - 1;
371+
uint32_t freeBytes;
372+
373+
ATOMIC_BLOCK(NVIC_PRIO_VCP) {
374+
freeBytes = ((UserTxBufPtrOut - UserTxBufPtrIn) + (-((int)(UserTxBufPtrOut <= UserTxBufPtrIn)) & APP_TX_DATA_SIZE)) - 1;
375+
}
376+
377+
return freeBytes;
377378
}
378379

379380
/**

0 commit comments

Comments
 (0)