2 Commits

Author SHA1 Message Date
eeeck 87e8ffc6fa Adapt error handler to log CAN errors and toggle error LED 2026-06-09 10:43:32 +02:00
eeeck 91385d00cf Configure filter banks and start CAN 2026-06-09 10:42:40 +02:00
2 changed files with 41 additions and 1 deletions
+29 -1
View File
@@ -42,7 +42,35 @@ const osThreadAttr_t vLED_CAN2_Heartbeat_attributes = {
/* Private function prototypes -----------------------------------------------*/
void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2){}
/* BEGIN CAN_Logger_Init */
/**
* @brief Initialize CAN
* @param argument: hcan1, hcan2
* @retval None
*/
void CAN_Logger_Init(CAN_HandleTypeDef *hcan1, CAN_HandleTypeDef *hcan2)
{
CAN_FilterTypeDef filter = {0};
filter.FilterMode = CAN_FILTERMODE_IDMASK;
filter.FilterScale = CAN_FILTERSCALE_32BIT;
filter.FilterIdHigh = 0x0000;
filter.FilterMaskIdHigh = 0x0000;
filter.FilterIdLow = 0x0000;
filter.FilterMaskIdLow = 0x0000;
filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
filter.FilterActivation = ENABLE;
filter.SlaveStartFilterBank = 14;
filter.FilterBank = 0;
if (HAL_CAN_ConfigFilter(hcan1, &filter) != HAL_OK) Error_Handler();
filter.FilterBank = 14;
if (HAL_CAN_ConfigFilter(hcan2, &filter) != HAL_OK) Error_Handler();
if (HAL_CAN_Start(hcan1) != HAL_OK) Error_Handler();
if (HAL_CAN_Start(hcan2) != HAL_OK) Error_Handler();
}
/* END CAN_Logger_Init */
static void CAN_Listen(void *argument){}
/* BEGIN vCAN_Get */
+12
View File
@@ -54,6 +54,7 @@ DMA_HandleTypeDef hdma_sdio_tx;
/* USER CODE BEGIN PV */
LED_Config led_can1 = {GPIOB, GPIO_PIN_2};
LED_Config led_can2 = {GPIOB, GPIO_PIN_5};
LED_Config led_error = {GPIOB, GPIO_PIN_3};
/* USER CODE END PV */
/* Private function prototypes -----------------------------------------------*/
@@ -441,8 +442,19 @@ void Error_Handler(void)
/* USER CODE BEGIN Error_Handler_Debug */
/* User can add his own implementation to report the HAL error return state */
__disable_irq();
//TODO: check if it is necessary to stop FreeRTOS
uint32_t error_code;
if (hcan == &hcan1) error_code = HAL_CAN_GetError(&hcan1);
else if (hcan == &hcan2) error_code = HAL_CAN_GetError(&hcan2);
// TODO: write error to SD and/or serial
while (1)
{
HAL_GPIO_TogglePin(led_error.port, led_error.pin);
HAL_Delay(250);
}
/* USER CODE END Error_Handler_Debug */
}