AnsweredAssumed Answered

STM32F303CCT6 - STM32CubeF3.1.2.0

Question asked by GeorgeP on Sep 4, 2015
Latest reply on May 4, 2017 by Rathore.Ankit
Hello,

I'm having problems initializing the CAN peripheral, using generated code by Cube.

APB1 Peripheral clock is 32MHz (XTAL16*PLL4*0.5PRESC).
The device cannot get INAK cleared after clearing INRQ.
Pins seem to be correctly set up on the alternate function (Mode = AF_PP and Alternate = AF9_CAN).
Any help would be great!

Here are some code snippets.

void MX_CAN_Init(void)
{


  hcan.Instance = CAN;
  hcan.Init.Prescaler = 8;
  hcan.Init.Mode = CAN_MODE_NORMAL;
  hcan.Init.SJW = CAN_SJW_1TQ;
  hcan.Init.BS1 = CAN_BS1_8TQ;
  hcan.Init.BS2 = CAN_BS2_7TQ;
  hcan.Init.TTCM = DISABLE;
  hcan.Init.ABOM = DISABLE;
  hcan.Init.AWUM = DISABLE;
  hcan.Init.NART = DISABLE;
  hcan.Init.RFLM = DISABLE;
  hcan.Init.TXFP = DISABLE;
  HAL_CAN_Init(&hcan);


}

void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
{


  GPIO_InitTypeDef GPIO_InitStruct;
  if(hcan->Instance==CAN)
  {
  /* USER CODE BEGIN CAN_MspInit 0 */


  /* USER CODE END CAN_MspInit 0 */
    /* Peripheral clock enable */
    __CAN_CLK_ENABLE();
  
    /**CAN GPIO Configuration    
    PB8     ------> CAN_RX
    PB9     ------> CAN_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_CAN;
    HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);


  /* USER CODE BEGIN CAN_MspInit 1 */


  /* USER CODE END CAN_MspInit 1 */
  }
}

/* Request leave initialisation */
    hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ;


    /* Get timeout */
    tickstart = HAL_GetTick();   
   
    /* Wait the acknowledge */
    while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
    {
      if((HAL_GetTick()-tickstart) > INAK_TIMEOUT)
      {
         hcan->State= HAL_CAN_STATE_TIMEOUT;
         return HAL_TIMEOUT;
      }
    } 

Outcomes