AnsweredAssumed Answered

STM32F429 - CAN stop IT stops firing randomly

Question asked by honeycutt.matt on Feb 8, 2016
Latest reply on Apr 7, 2016 by Msba.Mehran
Hi,

I'm using a STM32F429 disco board. I used the CubeMX to gen my HAL. Everything works pretty great, except for after a while my CAN IT stops firing. 

Here is my code below. In the HAL_CAN_RxCpltCallback, the HandleCanEvent does some slight data manipulation then transmits this info back on the bus. It appears that when the CAN bus is very active is when the IT stops firing and I have to reset the Micro.

Why would my Interrupt stop firing? Any thoughts?

void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* CanHandle)
{  
    HAL_GPIO_TogglePin(GPIOG, LD4_Pin); // Da activity LED
     
    //Now process crap
    canConversionFactory->HandleCanEvent(CanHandle);
     
    /* Receive */
    if (HAL_CAN_Receive_IT(CanHandle, CAN_FIFO0) != HAL_OK)
    {
        /* Reception Error */
        //TODO implement handeling
    }
 
}
 
void CAN1_RX0_IRQHandler(void)
{
  /* USER CODE BEGIN CAN1_RX0_IRQn 0 */
 
  /* USER CODE END CAN1_RX0_IRQn 0 */
  HAL_CAN_IRQHandler(&hcan1);
  /* USER CODE BEGIN CAN1_RX0_IRQn 1 */
 
  /* USER CODE END CAN1_RX0_IRQn 1 */
}
 
void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{
 
  GPIO_InitTypeDef GPIO_InitStruct;
  if(hcan->Instance==CAN1)
  {
  /* USER CODE BEGIN CAN1_MspInit 0 */
 
  /* USER CODE END CAN1_MspInit 0 */
    /* Peripheral clock enable */
    CAN1_CLK_ENABLED++;
    if(CAN1_CLK_ENABLED==1){
      __CAN1_CLK_ENABLE();
    }
   
    /**CAN1 GPIO Configuration   
    PB8     ------> CAN1_RX
    PB9     ------> CAN1_TX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /* Peripheral interrupt init*/
    HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
  /* USER CODE BEGIN CAN1_MspInit 1 */
 
  /* USER CODE END CAN1_MspInit 1 */
  }
  else if(hcan->Instance==CAN2)
  {
  /* USER CODE BEGIN CAN2_MspInit 0 */
 
  /* USER CODE END CAN2_MspInit 0 */
    /* Peripheral clock enable */
    __CAN2_CLK_ENABLE();
    CAN1_CLK_ENABLED++;
    if(CAN1_CLK_ENABLED==1){
      __CAN1_CLK_ENABLE();
    }
   
    /**CAN2 GPIO Configuration   
    PB5     ------> CAN2_RX
    PB6     ------> CAN2_TX
    */
    GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF9_CAN2;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
  /* Peripheral interrupt init*/
    HAL_NVIC_SetPriority(CAN2_RX0_IRQn, 0, 0);
    HAL_NVIC_EnableIRQ(CAN2_RX0_IRQn);
  /* USER CODE BEGIN CAN2_MspInit 1 */
 
  /* USER CODE END CAN2_MspInit 1 */
  }
 
}
 
HAL_StatusTypeDef CanDriver::InitializeCan1(BaudRate baudRate)
{
    if (!hcan1)
        return HAL_ERROR;
 
    if (!baudRate)
        return HAL_ERROR;
 
    hcan1->Instance = CAN1;
 
    static CanTxMsgTypeDef TxMessage;
    static CanRxMsgTypeDef RxMessage;
 
    if (baudRate == this->BITRATE_500k)
    {
        hcan1->Init.Prescaler = 4;
        hcan1->Init.SJW = CAN_SJW_1TQ ;
        hcan1->Init.BS1 = CAN_BS1_14TQ ;
        hcan1->Init.BS2 = CAN_BS2_6TQ ;
    }
    else if (baudRate == this->BITRATE_250k)
    {
        //TODO     
    }
    else //Assume 500k
    {
        hcan1->Init.Prescaler = 4;
        hcan1->Init.SJW = CAN_SJW_1TQ ; // This is for 500k can
        hcan1->Init.BS1 = CAN_BS1_14TQ ;
        hcan1->Init.BS2 = CAN_BS2_6TQ ;
    }
 
    hcan1->Init.TTCM = DISABLE;
    hcan1->Init.ABOM = DISABLE;
    hcan1->Init.AWUM = DISABLE;
    hcan1->Init.NART = DISABLE;
    hcan1->Init.RFLM = DISABLE;
    hcan1->Init.TXFP = DISABLE;
 
    //Setup the empty Rx/Tx
    hcan1->pRxMsg = &RxMessage;
    hcan1->pTxMsg = &TxMessage;
     
 
    HAL_StatusTypeDef can1SetupStatus = HAL_CAN_Init(hcan1);
     
    HAL_StatusTypeDef can1FilterStatus = this->InitializeOpenFilters(CANBUS1);
     
    if (HAL_CAN_Receive_IT(hcan1, CAN_FIFO0) != HAL_OK) // Start listning
    {
        return HAL_ERROR;
    }
     
    return can1SetupStatus;
}
 
HAL_StatusTypeDef CanDriver::InitializeOpenFilters(int bus)
{
    if (bus < 1 || bus > 2)
        return HAL_ERROR;
     
    CAN_FilterConfTypeDef sFilterConfig;
 
    /*##-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 (bus == CANBUS1)
        return HAL_CAN_ConfigFilter(hcan1, &sFilterConfig);
         
 
    if (bus == CANBUS2)
        return HAL_CAN_ConfigFilter(hcan2, &sFilterConfig);
         
    return HAL_ERROR;//we should never get here
}

Outcomes