diff --git a/platforms/stm32f405/src/can.c b/platforms/stm32f405/src/can.c index 13d3a2c..c8a9471 100644 --- a/platforms/stm32f405/src/can.c +++ b/platforms/stm32f405/src/can.c @@ -7,12 +7,13 @@ * implement in `stm32xxxx_it.c`, which STM32CubeMX generates */ -HAL_StatusTypeDef can_init(can_t *can) { +HAL_StatusTypeDef can_init(can_t *can) +{ /* set up interrupt & activate CAN */ HAL_CAN_IRQHandler(can->hcan); int8_t err = HAL_CAN_ActivateNotification(can->hcan, - CAN_IT_RX_FIFO0_MSG_PENDING); + CAN_IT_RX_FIFO0_MSG_PENDING); if (err != HAL_OK) return err; err = HAL_CAN_Start(can->hcan); @@ -22,7 +23,8 @@ HAL_StatusTypeDef can_init(can_t *can) { return err; } -HAL_StatusTypeDef can_add_filter(can_t *can, uint32_t id_list[4]) { +HAL_StatusTypeDef can_add_filter(can_t *can, uint32_t id_list[4]) +{ static int filterBank = 0; if (filterBank > 7) @@ -30,24 +32,25 @@ HAL_StatusTypeDef can_add_filter(can_t *can, uint32_t id_list[4]) { CAN_FilterTypeDef filter; - filter.FilterActivation = ENABLE; + filter.FilterActivation = ENABLE; filter.FilterFIFOAssignment = CAN_FILTER_FIFO0; - filter.FilterScale = CAN_FILTERSCALE_16BIT; - filter.FilterMode = CAN_FILTERMODE_IDLIST; - - filter.FilterIdLow = id_list[0] << 5u; - filter.FilterMaskIdLow = id_list[1] << 5u; - filter.FilterIdHigh = id_list[2] << 5u; - filter.FilterMaskIdHigh = id_list[3] << 5u; + filter.FilterScale = CAN_FILTERSCALE_16BIT; + filter.FilterMode = CAN_FILTERMODE_IDLIST; - filter.FilterBank = filterBank; + filter.FilterIdLow = id_list[0] << 5u; + filter.FilterMaskIdLow = id_list[1] << 5u; + filter.FilterIdHigh = id_list[2] << 5u; + filter.FilterMaskIdHigh = id_list[3] << 5u; + + filter.FilterBank = filterBank; filterBank++; return HAL_CAN_ConfigFilter(can->hcan, &filter); -} +} -HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg) { +HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg) +{ CAN_TxHeaderTypeDef tx_header; tx_header.StdId = msg->id; tx_header.ExtId = 0; @@ -66,7 +69,8 @@ HAL_StatusTypeDef can_send_msg(can_t *can, can_msg_t *msg) { return HAL_OK; } -HAL_StatusTypeDef can_send_extended_msg(can_t *can, can_msg_t *msg) { +HAL_StatusTypeDef can_send_extended_msg(can_t *can, can_msg_t *msg) +{ CAN_TxHeaderTypeDef tx_header; tx_header.StdId = 0; tx_header.ExtId = msg->id;