From 2ab77d75d62298e39b9ee5d29ad065d69d2d4406 Mon Sep 17 00:00:00 2001 From: Kilian Bracher Date: Wed, 18 Jun 2025 16:18:45 +0200 Subject: [PATCH] fix buffer index calculation they take a bit field as an argument, and then immediately use a clz instruction to convert it back to an index for some reason --- can-halal.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/can-halal.c b/can-halal.c index 10dabaa..72c5434 100644 --- a/can-halal.c +++ b/can-halal.c @@ -230,12 +230,14 @@ HAL_StatusTypeDef ftcan_get_tx_queue_length(uint32_t *length) { } #if FTCAN_NUM_TX_BUFFERS +static_assert(FDCAN_TX_BUFFER11 == 1 << 11 && FDCAN_TX_BUFFER21 == 1 << 21, "Your HAL version has a different definition for the transmit buffer indices. Please update your HAL version or change the code below."); + HAL_StatusTypeDef ftcan_transmit_buffer(uint16_t id, const uint8_t *data, size_t datalen, uint32_t buffer_index) { static FDCAN_TxHeaderTypeDef header; if (buffer_index >= FTCAN_NUM_TX_BUFFERS) { return HAL_ERROR; } - return HAL_FDCAN_AddMessageToTxBuffer(hcan, fdcan_initialize_tx_header(&header, id, datalen), data, buffer_index); + return HAL_FDCAN_AddMessageToTxBuffer(hcan, fdcan_initialize_tx_header(&header, id, datalen), data, 1 << buffer_index); } #endif // FTCAN_NUM_TX_BUFFERS #endif