cancel
Showing results for 
Search instead for 
Did you mean: 

STM32FCubeMX CAN-Bus Initialisation fails

dunkindonut
Associate II
Posted on July 04, 2014 at 16:03

Hi;

I am using STM32FCubeMX with its default configuration for the STRM32F4DISCOVERY board. I have enabled CAN1 master Mode (Loopback) and generated the Code for ''MDK-ARM 4.73.

When i run the code the CAN initialisation fails in:

HAL_CAN_Init(CAN_HandleTypeDef* hcan); Line 298

.....

....

..

    /* Request leave initialisation */

    hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ;

  /* Get tick */

  tickstart = HAL_GetTick();

   /* Wait the acknowledge */

   while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)

   {

    if((HAL_GetTick() - tickstart ) > CAN_TIMEOUT_VALUE)

     {

       hcan->State= HAL_CAN_STATE_TIMEOUT;

       /* Process unlocked */

       __HAL_UNLOCK(hcan);

       return HAL_TIMEOUT;   // ; Line 298

     }

   }

............

...........

the funtion returns always HAL_TIMEOUT.

What must i do to get the CAN-BUS Initialisation running?

Thanks

4 REPLIES 4
dunkindonut
Associate II
Posted on July 08, 2014 at 13:03

I have found the problem. The Initialisation failes without CAN-Driver hardware . It fails also in Loopback mode.

zhaojingyangchun
Associate II
Posted on December 21, 2014 at 04:53

Thank you,I am the same situation as you,I have two discovery boards,But they are different, One of them failed because HAL_CAN_STATE_TIMEOUT,but another work well.So I check the Circuit diagram and I found that I should change the GPIO to PB8&PB9(The Circuit diagram Use those GPIOs),then the board works well.But CAN1 was in CAN_MODE_LOOPBACK mode,I guess this mode have relationship with hardware.

 

 

dfacchin
Associate II
Posted on May 28, 2015 at 16:14

To fool the controller if  you have no transceiver attached (just for a CAN_MODE_SILENT_LOOPBACK mode) you can just put the RX pin in pullup, this is the recessive state and the controller finds the line in a not busy state.

I used it to test some code with a discovery board and it works

Posted on May 04, 2017 at 08:25

Hi All,

      i am using STM32F303RE my code also stuck at this function :-  

     while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)

{

if((HAL_GetTick()-tickstart) > CAN_TIMEOUT_VALUE)

{

hcan->State= HAL_CAN_STATE_TIMEOUT;

/* Process unlocked */

__HAL_UNLOCK(hcan);

return HAL_TIMEOUT;

}

}

i am using default code with certain pin changes (PIN are correct i crosscheck  )  and my rx pin configuration are mention below :-

/* CAN1 RX GPIO pin configuration */

GPIO_InitStruct.Pin = CANx_RX_PIN;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

GPIO_InitStruct.Pull = GPIO_PULLUP;

GPIO_InitStruct.Alternate = CANx_RX_AF;

Please help, i will have to deliver this with in 2 day.

Thank's 

Ankit Rathore