3 Commits

2 changed files with 11 additions and 8 deletions

View File

@ -32,14 +32,14 @@ HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask) {
static uint32_t next_filter_no = 0; static uint32_t next_filter_no = 0;
static CAN_FilterTypeDef filter; static CAN_FilterTypeDef filter;
if (next_filter_no % 2 == 0) { if (next_filter_no % 2 == 0) {
filter.FilterIdHigh = id; filter.FilterIdHigh = id << 5;
filter.FilterMaskIdHigh = mask; filter.FilterMaskIdHigh = mask << 5;
filter.FilterIdLow = 0; filter.FilterIdLow = id << 5;
filter.FilterMaskIdLow = 0xFFFF; filter.FilterMaskIdLow = mask << 5;
} else { } else {
// Leave high filter untouched from the last configuration // Leave high filter untouched from the last configuration
filter.FilterIdLow = id; filter.FilterIdLow = id << 5;
filter.FilterMaskIdLow = mask; filter.FilterMaskIdLow = mask << 5;
} }
filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
filter.FilterBank = next_filter_no / 2; filter.FilterBank = next_filter_no / 2;
@ -141,7 +141,10 @@ HAL_StatusTypeDef ftcan_transmit(uint16_t id, const uint8_t *data,
header.FDFormat = FDCAN_CLASSIC_CAN; header.FDFormat = FDCAN_CLASSIC_CAN;
header.TxEventFifoControl = FDCAN_NO_TX_EVENTS; header.TxEventFifoControl = FDCAN_NO_TX_EVENTS;
return HAL_FDCAN_AddMessageToTxFifoQ(hcan, &header, data); // HAL_FDCAN_AddMessageToTxFifoQ doesn't modify the data, but it's not marked
// as const for some reason.
uint8_t *data_nonconst = (uint8_t *)data;
return HAL_FDCAN_AddMessageToTxFifoQ(hcan, &header, data_nonconst);
} }
HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask) { HAL_StatusTypeDef ftcan_add_filter(uint16_t id, uint16_t mask) {

View File

@ -1,7 +1,7 @@
#ifndef CAN_HALAL_H #ifndef CAN_HALAL_H
#define CAN_HALAL_H #define CAN_HALAL_H
#if defined(STM32F3) #if defined(STM32F302x8) || defined(STM32F302xB) || defined(STM32F302xC) || defined(STM32F3)
#include "stm32f3xx_hal.h" #include "stm32f3xx_hal.h"
#define FTCAN_IS_BXCAN #define FTCAN_IS_BXCAN
#define FTCAN_NUM_FILTERS 13 #define FTCAN_NUM_FILTERS 13