Skip to content

Commit bdea521

Browse files
committed
Fixing Copilot findings (5)
1 parent 4e4461e commit bdea521

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

ports/espressif/common-hal/qspibus/QSPIBus.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,15 @@ static void qspibus_send_color_bytes(
156156
const uint8_t *cursor = data;
157157
size_t remaining = len;
158158

159+
// Drain stale semaphore tokens that late ISR completions may have
160+
// posted after a previous qspibus_reset_transfer_state(). Without
161+
// this, a stale token could satisfy a future wait, causing the next
162+
// transfer to skip its real DMA-done wait.
163+
if (self->inflight_transfers == 0 && self->transfer_done_sem != NULL) {
164+
while (xSemaphoreTake(self->transfer_done_sem, 0) == pdTRUE) {
165+
}
166+
}
167+
159168
while (remaining > 0) {
160169
// inflight_transfers is only modified in task context (never from ISR),
161170
// so no atomic/critical section is needed. The ISR only signals the

0 commit comments

Comments
 (0)