8000 stm32/pyb_can: Handle timeout arg for FDCAN in pyb_can_send. · micropython/micropython@c299cc9 · GitHub
[go: up one dir, main page]

Skip to content

Commit c299cc9

Browse files
iabdalkaderdpgeorge
authored andcommitted
stm32/pyb_can: Handle timeout arg for FDCAN in pyb_can_send.
Following the documented pyb can_send behavior in pyb.CAN docs.
1 parent d07073f commit c299cc9

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ports/stm32/pyb_can.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,20 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *
432432

433433
HAL_StatusTypeDef status;
434434
#if MICROPY_HW_ENABLE_FDCAN
435+
uint32_t timeout_ms = args[ARG_timeout].u_int;
436+
uint32_t start = HAL_GetTick();
437+
while (HAL_FDCAN_GetTxFifoFreeLevel(&self->can) == 0) {
438+
if (timeout_ms == 0) {
439+
mp_raise_OSError(MP_ETIMEDOUT);
440+
}
441+
// Check for the Timeout
442+
if (timeout_ms != HAL_MAX_DELAY) {
443+
if (HAL_GetTick() - start >= timeout_ms) {
444+
mp_raise_OSError(MP_ETIMEDOUT);
445+
}
446+
}
447+
MICROPY_EVENT_POLL_HOOK
448+
}
435449
status = HAL_FDCAN_AddMessageToTxFifoQ(&self->can, &tx_msg, tx_data);
436450
#else
437451
self->can.pTxMsg = &tx_msg;

0 commit comments

Comments
 (0)
0