cancel
Showing results for 
Search instead for 
Did you mean: 

How to overcome FIFO overrun error in CAN communication?

Ss.61
Associate III

Hellow sir/madam,

  • I am using stm32f042g6(controller)
  • In my CAN communication transmission is working fine but in receiver section i enabled Interrrupt to receive msg's,
  • In that i am facing FIFO overrun error <Error Code:0x00000200> after few times of reception process,

{ HAL_CAN_ERROR_FOV0     (0x00000200U) /*!< FIFO0 overrun error */ }

  • Help me how to overcome the error / how to reset the FIFO buffer after one reception process completed.

4 REPLIES 4
Javier1
Principal

show us some code.

It would be nice to see the interrupt function youre triggering with the canbus reception and if youre really reading the fifo.

we dont need to firmware by ourselves, lets talk

Thank you for your response,

  • Here is the code i am using this is nothing but simple can rx example

CAN RX EXAMPLE

/* Includes ------------------------------------------------------------------*/

#include "main.h"

#include "stm32f0xx_hal.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private variables ---------------------------------------------------------*/

CAN_HandleTypeDef hcan;

static CanTxMsgTypeDef    TxMessage;

static CanRxMsgTypeDef    RxMessage;

/* USER CODE BEGIN PV */

/* Private variables ---------------------------------------------------------*/

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/

void SystemClock_Config(void);

static void MX_GPIO_Init(void);

static void MX_CAN_Init(void);

/* USER CODE BEGIN PFP */

/* Private function prototypes -----------------------------------------------*/

/* USER CODE END PFP */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */

int main(void)

{

 /* USER CODE BEGIN 1 */

 /* USER CODE END 1 */

 /* MCU Configuration----------------------------------------------------------*/

 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 /* USER CODE BEGIN SysInit */

 /* USER CODE END SysInit */

 /* Initialize all configured peripherals */

 MX_GPIO_Init();

 MX_CAN_Init();

 /* USER CODE BEGIN 2 */

 hcan.Instance->MCR = 0x60; //IMPORTANT FOR DEBUG!!!!!!!

 /* Receive interrupt enable */

 if (HAL_CAN_Receive_IT(&hcan, CAN_FIFO0) != HAL_OK)

 {

   

  Error_Handler();

 }

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

 /* USER CODE END WHILE */

 /* USER CODE BEGIN 3 */

 }

 /* USER CODE END 3 */

}

/**

 * @brief System Clock Configuration

 * @retval None

 */

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct;

 RCC_ClkInitTypeDef RCC_ClkInitStruct;

  /**Initializes the CPU, AHB and APB busses clocks 

  */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;

 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

  /**Initializes the CPU, AHB and APB busses clocks 

  */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

  /**Configure the Systick interrupt time 

  */

 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

  /**Configure the Systick 

  */

 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

 /* SysTick_IRQn interrupt configuration */

 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

/* CAN init function */

static void MX_CAN_Init(void)

{

 CAN_FilterConfTypeDef sFilterConfig;

 static CanTxMsgTypeDef    TxMessage;

 static CanRxMsgTypeDef    RxMessage;

 hcan.Instance = CAN;

 hcan.Init.Prescaler = 6;

 hcan.Init.Mode = CAN_MODE_NORMAL;

 hcan.Init.SJW = CAN_SJW_1TQ;

 hcan.Init.BS1 = CAN_BS1_13TQ;

 hcan.Init.BS2 = CAN_BS2_2TQ;

 hcan.Init.TTCM = DISABLE;

 hcan.Init.ABOM = DISABLE;

 hcan.Init.AWUM = DISABLE;

 hcan.Init.NART = DISABLE;

 hcan.Init.RFLM = DISABLE;

 hcan.Init.TXFP = DISABLE;

 if (HAL_CAN_Init(&hcan) != HAL_OK)

 {

  _Error_Handler(__FILE__, __LINE__);

 }

hcan.pTxMsg = &TxMessage;

hcan.pRxMsg = &RxMessage;

/*##-2- Configure the CAN Filter ###########################################*/

 sFilterConfig.FilterNumber = 0;

 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

 sFilterConfig.FilterIdHigh = 0x0000;

 sFilterConfig.FilterIdLow = 0x0000;

 sFilterConfig.FilterMaskIdHigh = 0x0000;

 sFilterConfig.FilterMaskIdLow = 0x0000;

 sFilterConfig.FilterFIFOAssignment = 0;

 sFilterConfig.FilterActivation = ENABLE;

 sFilterConfig.BankNumber = 14;

if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)

 {

 /* Filter configuration Error */

 Error_Handler();

 }

 hcan.pTxMsg->StdId = 0x100;

 hcan.pTxMsg->ExtId = 0x01;

 hcan.pTxMsg->RTR = CAN_RTR_DATA;

 hcan.pTxMsg->IDE = CAN_ID_STD;

 hcan.pTxMsg->DLC = 0;

// hcan.pTxMsg->Data[0] = 0;  

}

/** Pinout Configuration

*/

static void MX_GPIO_Init(void)

{

 /* GPIO Ports Clock Enable */

 __HAL_RCC_GPIOA_CLK_ENABLE();

}

/* USER CODE BEGIN 4 */

//Receive all msg's through interrupt...

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan)

{

 if (HAL_CAN_Receive_IT(hcan, CAN_FIFO0) != HAL_OK)      //it troughs error or hang this function itself once after 2 or 3 reception completed..

 {

  status=0;

  Error_Handler();

 } 

}

/* USER CODE END 4 */

/**

 * @brief This function is executed in case of error occurrence.

 * @param file: The file name as string.

 * @param line: The line in file as a number.

 * @retval None

 */

void _Error_Handler(char *file, int line)

{

 /* USER CODE BEGIN Error_Handler_Debug */

 /* User can add his own implementation to report the HAL error return state */

  

 /* USER CODE END Error_Handler_Debug */

}

#ifdef USE_FULL_ASSERT

/**

 * @brief Reports the name of the source file and the source line number

 *     where the assert_param error has occurred.

 * @param file: pointer to the source file name

 * @param line: assert_param error line source number

 * @retval None

 */

void assert_failed(uint8_t* file, uint32_t line)

 /* USER CODE BEGIN 6 */

 /* User can add his own implementation to report the file name and line number,

   tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

 /* USER CODE END 6 */

}

#endif /* USE_FULL_ASSERT */

/**

 * @}

 */

/**

 * @}

 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

Next time try to use the code format </> button, its easier to read :

CAN RX EXAMPLE

 
/* Includes ------------------------------------------------------------------*/
 
#include "main.h"
 
#include "stm32f0xx_hal.h"
 
 
 
/* USER CODE BEGIN Includes */
 
 
 
/* USER CODE END Includes */
 
 
 
/* Private variables ---------------------------------------------------------*/
 
CAN_HandleTypeDef hcan;
 
static CanTxMsgTypeDef    TxMessage;
 
static CanRxMsgTypeDef    RxMessage;
 
/* USER CODE BEGIN PV */
 
/* Private variables ---------------------------------------------------------*/
 
 
 
/* USER CODE END PV */
 
 
 
/* Private function prototypes -----------------------------------------------*/
 
void SystemClock_Config(void);
 
static void MX_GPIO_Init(void);
 
static void MX_CAN_Init(void);
 
 
 
/* USER CODE BEGIN PFP */
 
/* Private function prototypes -----------------------------------------------*/
 
 
 
/* USER CODE END PFP */
 
 
 
/* USER CODE BEGIN 0 */
 
 
 
/* USER CODE END 0 */
 
 
 
int main(void)
 
{
 
 /* USER CODE BEGIN 1 */
 
 
 
 /* USER CODE END 1 */
 
 
 
 /* MCU Configuration----------------------------------------------------------*/
 
 
 
 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
 
 HAL_Init();
 
 
 
 /* USER CODE BEGIN Init */
 
 
 
 /* USER CODE END Init */
 
 
 
 /* Configure the system clock */
 
 SystemClock_Config();
 
 
 
 /* USER CODE BEGIN SysInit */
 
 
 
 /* USER CODE END SysInit */
 
 
 
 /* Initialize all configured peripherals */
 
 MX_GPIO_Init();
 
 MX_CAN_Init();
 
 /* USER CODE BEGIN 2 */
 
 
 
 hcan.Instance->MCR = 0x60; //IMPORTANT FOR DEBUG!!!!!!!
 
 
 
 /* Receive interrupt enable */
 
 if (HAL_CAN_Receive_IT(&hcan, CAN_FIFO0) != HAL_OK)
 
 {
 
   
 
  Error_Handler();
 
 }
 
 
 
 /* USER CODE END 2 */
 
 
 
 /* Infinite loop */
 
 /* USER CODE BEGIN WHILE */
 
 while (1)
 
 {
 
 
 
 /* USER CODE END WHILE */
 
 
 
 /* USER CODE BEGIN 3 */
 
 
 
 }
 
 /* USER CODE END 3 */
 
 
 
}
 
 
 
/**
 
 * @brief System Clock Configuration
 
 * @retval None
 
 */
 
void SystemClock_Config(void)
 
{
 
 
 
 RCC_OscInitTypeDef RCC_OscInitStruct;
 
 RCC_ClkInitTypeDef RCC_ClkInitStruct;
 
 
 
  /**Initializes the CPU, AHB and APB busses clocks 
 
  */
 
 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI48;
 
 RCC_OscInitStruct.HSI48State = RCC_HSI48_ON;
 
 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
 
 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
 
 {
 
  _Error_Handler(__FILE__, __LINE__);
 
 }
 
 
 
  /**Initializes the CPU, AHB and APB busses clocks 
 
  */
 
 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
 
               |RCC_CLOCKTYPE_PCLK1;
 
 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI48;
 
 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
 
 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
 
 
 
 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
 
 {
 
  _Error_Handler(__FILE__, __LINE__);
 
 }
 
 
 
  /**Configure the Systick interrupt time 
 
  */
 
 HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
 
 
 
  /**Configure the Systick 
 
  */
 
 HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
 
 
 
 /* SysTick_IRQn interrupt configuration */
 
 HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
 
}
 
 
 
/* CAN init function */
 
static void MX_CAN_Init(void)
 
{
 
 CAN_FilterConfTypeDef sFilterConfig;
 
 static CanTxMsgTypeDef    TxMessage;
 
 static CanRxMsgTypeDef    RxMessage;
 
 hcan.Instance = CAN;
 
 hcan.Init.Prescaler = 6;
 
 hcan.Init.Mode = CAN_MODE_NORMAL;
 
 hcan.Init.SJW = CAN_SJW_1TQ;
 
 hcan.Init.BS1 = CAN_BS1_13TQ;
 
 hcan.Init.BS2 = CAN_BS2_2TQ;
 
 hcan.Init.TTCM = DISABLE;
 
 hcan.Init.ABOM = DISABLE;
 
 hcan.Init.AWUM = DISABLE;
 
 hcan.Init.NART = DISABLE;
 
 hcan.Init.RFLM = DISABLE;
 
 hcan.Init.TXFP = DISABLE;
 
 if (HAL_CAN_Init(&hcan) != HAL_OK)
 
 {
 
  _Error_Handler(__FILE__, __LINE__);
 
 }
 
hcan.pTxMsg = &TxMessage;
 
hcan.pRxMsg = &RxMessage;
 
/*##-2- Configure the CAN Filter ###########################################*/
 
 sFilterConfig.FilterNumber = 0;
 
 sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;
 
 sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;
 
 sFilterConfig.FilterIdHigh = 0x0000;
 
 sFilterConfig.FilterIdLow = 0x0000;
 
 sFilterConfig.FilterMaskIdHigh = 0x0000;
 
 sFilterConfig.FilterMaskIdLow = 0x0000;
 
 sFilterConfig.FilterFIFOAssignment = 0;
 
 sFilterConfig.FilterActivation = ENABLE;
 
 sFilterConfig.BankNumber = 14;
 
if (HAL_CAN_ConfigFilter(&hcan, &sFilterConfig) != HAL_OK)
 
 {
 
 /* Filter configuration Error */
 
 Error_Handler();
 
 }
 
 
 
 hcan.pTxMsg->StdId = 0x100;
 
 hcan.pTxMsg->ExtId = 0x01;
 
 hcan.pTxMsg->RTR = CAN_RTR_DATA;
 
 hcan.pTxMsg->IDE = CAN_ID_STD;
 
 hcan.pTxMsg->DLC = 0;
 
// hcan.pTxMsg->Data[0] = 0;  
 
 
 
}
 
 
 
/** Pinout Configuration
 
*/
 
static void MX_GPIO_Init(void)
 
{
 
 
 
 /* GPIO Ports Clock Enable */
 
 __HAL_RCC_GPIOA_CLK_ENABLE();
 
 
 
}
 
 
 
/* USER CODE BEGIN 4 */
 
//Receive all msg's through interrupt...
 
void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan)
 
{
 
 
 
 if (HAL_CAN_Receive_IT(hcan, CAN_FIFO0) != HAL_OK)      //it troughs error or hang this function itself once after 2 or 3 reception completed..
 
 {
 
  status=0;
 
  Error_Handler();
 
 } 
 
}
 
/* USER CODE END 4 */
 
 
 
/**
 
 * @brief This function is executed in case of error occurrence.
 
 * @param file: The file name as string.
 
 * @param line: The line in file as a number.
 
 * @retval None
 
 */
 
void _Error_Handler(char *file, int line)
 
{
 
 /* USER CODE BEGIN Error_Handler_Debug */
 
 /* User can add his own implementation to report the HAL error return state */
 
  
 
 /* USER CODE END Error_Handler_Debug */
 
}
 
 
 
#ifdef USE_FULL_ASSERT
 
/**
 
 * @brief Reports the name of the source file and the source line number
 
 *     where the assert_param error has occurred.
 
 * @param file: pointer to the source file name
 
 * @param line: assert_param error line source number
 
 * @retval None
 
 */
 
void assert_failed(uint8_t* file, uint32_t line)
 
{ 
 
 /* USER CODE BEGIN 6 */
 
 /* User can add his own implementation to report the file name and line number,
 
   tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
 
 /* USER CODE END 6 */
 
}
 
#endif /* USE_FULL_ASSERT */
 
 
 
/**
 
 * @}
 
 */
 
 
 
/**
 
 * @}
 
 */
 
 
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

we dont need to firmware by ourselves, lets talk

Youre trying to implement the received callback function HAL_CAN_Receive_IT in a very weird way, thats why your code is not working.

I could explain it to you but this guy knows much better

https://www.youtube.com/watch?v=ar3I38lCLT4

Try to follow and replicate the process shown in the video

we dont need to firmware by ourselves, lets talk