Skip to content

STM32H7: FDCAN Fixes #6212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions ports/stm32/fdcan.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,26 +200,38 @@ void can_clearfilter(pyb_can_obj_t *self, uint32_t f, uint8_t bank) {

int can_receive(FDCAN_HandleTypeDef *can, int fifo, FDCAN_RxHeaderTypeDef *hdr, uint8_t *data, uint32_t timeout_ms) {
volatile uint32_t *rxf, *rxa;
uint32_t fl;

if (fifo == FDCAN_RX_FIFO0) {
rxf = &can->Instance->RXF0S;
rxa = &can->Instance->RXF0A;
fl = FDCAN_RXF0S_F0FL;
} else {
rxf = &can->Instance->RXF1S;
rxa = &can->Instance->RXF1A;
fl = FDCAN_RXF1S_F1FL;
}

// Wait for a message to become available, with timeout
uint32_t start = HAL_GetTick();
while ((*rxf & 7) == 0) {
MICROPY_EVENT_POLL_HOOK
if (HAL_GetTick() - start >= timeout_ms) {
return -MP_ETIMEDOUT;
while ((*rxf & fl) == 0) {
if (timeout_ms != HAL_MAX_DELAY) {
if (HAL_GetTick() - start >= timeout_ms) {
return -MP_ETIMEDOUT;
}
}
MICROPY_EVENT_POLL_HOOK
}

// Get pointer to incoming message
uint32_t index = (can->Instance->RXF0S & FDCAN_RXF0S_F0GI) >> 8;
uint32_t *address = (uint32_t *)(can->msgRam.RxFIFO0SA + (index * can->Init.RxFifo0ElmtSize * 4));
uint32_t index, *address;
if (fifo == FDCAN_RX_FIFO0) {
index = (*rxf & FDCAN_RXF0S_F0GI) >> FDCAN_RXF0S_F0GI_Pos;
address = (uint32_t *)(can->msgRam.RxFIFO0SA + (index * can->Init.RxFifo0ElmtSize * 4));
} else {
index = (*rxf & FDCAN_RXF1S_F1GI) >> FDCAN_RXF1S_F1GI_Pos;
address = (uint32_t *)(can->msgRam.RxFIFO1SA + (index * can->Init.RxFifo1ElmtSize * 4));
}

// Parse header of message
hdr->IdType = *address & FDCAN_ELEMENT_MASK_XTD;
Expand Down
14 changes: 14 additions & 0 deletions ports/stm32/pyb_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,20 @@ STATIC mp_obj_t pyb_can_send(size_t n_args, const mp_obj_t *pos_args, mp_map_t *

HAL_StatusTypeDef status;
#if MICROPY_HW_ENABLE_FDCAN
uint32_t timeout_ms = args[ARG_timeout].u_int;
uint32_t start = HAL_GetTick();
while (HAL_FDCAN_GetTxFifoFreeLevel(&self->can) == 0) {
if (timeout_ms == 0) {
mp_raise_OSError(MP_ETIMEDOUT);
}
// Check for the Timeout
if (timeout_ms != HAL_MAX_DELAY) {
if (HAL_GetTick() - start >= timeout_ms) {
mp_raise_OSError(MP_ETIMEDOUT);
}
}
MICROPY_EVENT_POLL_HOOK
}
status = HAL_FDCAN_AddMessageToTxFifoQ(&self->can, &tx_msg, tx_data);
#else
self->can.pTxMsg = &tx_msg;
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy