Skip to content

Commit eed3387

Browse files
committed
stm32: canio: Fix message cancellation
.. it's necessary to wait for a cancellation request to actually free the respective Tx mailbox
1 parent abe0405 commit eed3387

File tree

1 file changed

+10
-2
lines changed
  • ports/stm/common-hal/canio

1 file changed

+10
-2
lines changed

ports/stm/common-hal/canio/CAN.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,21 @@ void common_hal_canio_can_send(canio_can_obj_t *self, mp_obj_t message_in)
241241
//
242242
// We don't strictly guarantee that we abort the oldest Tx request,
243243
// rather we just abort a different index each time. This permits us
244-
// to avoid tracking this information altogether.
244+
// to just track a single cancel index
245245
HAL_CAN_AbortTxRequest(&self->handle, 1 << (self->cancel_mailbox));
246246
self->cancel_mailbox = (self->cancel_mailbox + 1) % 3;
247+
// The abort request may not have completed immediately, so wait for
248+
// the Tx mailbox to become free
249+
do {
250+
free_level = HAL_CAN_GetTxMailboxesFreeLevel(&self->handle);
251+
} while (!free_level);
247252
}
248253
HAL_StatusTypeDef status = HAL_CAN_AddTxMessage(&self->handle, &header, message->data, &mailbox);
249254
if (status != HAL_OK) {
250-
mp_raise_OSError(MP_ENOMEM);
255+
// this is a "shouldn't happen" condition. we don't throw because the
256+
// contract of send() is that it queues the packet to be sent if
257+
// possible and does not signal success or failure to actually send.
258+
return;
251259
}
252260

253261
// wait 8ms (hard coded for now) for TX to occur

0 commit comments

Comments
 (0)