stm32: Add support for disabling the canbus filter

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-06-11 18:19:53 -04:00
parent 84b2bfe313
commit f5d5f53914
3 changed files with 18 additions and 7 deletions

View File

@ -83,6 +83,9 @@ config CANSERIAL
config CANBUS_FREQUENCY
int "CAN bus speed" if LOW_LEVEL_OPTIONS && CANSERIAL
default 500000
config CANBUS_FILTER
bool
default y if CANSERIAL
# Support setting gpio state at startup
config INITIAL_PINS

View File

@ -136,13 +136,19 @@ canbus_set_filter(uint32_t id)
/* Initialisation mode for the filter */
SOC_CAN->FA1R = 0;
uint32_t mask = CAN_TI0R_STID | CAN_TI0R_IDE | CAN_TI0R_RTR;
SOC_CAN->sFilterRegister[0].FR1 = CANBUS_ID_ADMIN << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[0].FR2 = mask;
SOC_CAN->sFilterRegister[1].FR1 = (id + 1) << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[1].FR2 = mask;
SOC_CAN->sFilterRegister[2].FR1 = id << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[2].FR2 = mask;
if (CONFIG_CANBUS_FILTER) {
uint32_t mask = CAN_TI0R_STID | CAN_TI0R_IDE | CAN_TI0R_RTR;
SOC_CAN->sFilterRegister[0].FR1 = CANBUS_ID_ADMIN << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[0].FR2 = mask;
SOC_CAN->sFilterRegister[1].FR1 = (id + 1) << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[1].FR2 = mask;
SOC_CAN->sFilterRegister[2].FR1 = id << CAN_RI0R_STID_Pos;
SOC_CAN->sFilterRegister[2].FR2 = mask;
} else {
SOC_CAN->sFilterRegister[0].FR1 = 0;
SOC_CAN->sFilterRegister[0].FR2 = 0;
id = 0;
}
/* 32-bit scale for the filter */
SOC_CAN->FS1R = (1<<0) | (1<<1) | (1<<2);

View File

@ -113,6 +113,8 @@ can_filter(uint32_t index, uint32_t id)
void
canbus_set_filter(uint32_t id)
{
if (!CONFIG_CANBUS_FILTER)
return;
/* Request initialisation */
SOC_CAN->CCCR |= FDCAN_CCCR_INIT;
/* Wait the acknowledge */