cancel
Showing results for 
Search instead for 
Did you mean: 

CAN bus HAL driver running on nucleo 144 F767ZI stopped at the HAL_CAN_Init function

guy falach
Associate
Posted on May 01, 2018 at 04:39

Hello 

I am trying to use the stm32f7xx_hal_can driver on Nucleo 144 F767ZI , and the code is stuck at the init state. 

While using the debugger and reading the Reference manual i found the fallowing:

- the initial state of the CAN contoller is SLEEP state

- To exit the sleep state it is needed to clear the 

SLEEP bit in the MCR register

- Then the CAN controller acknowledge to the software that he move from SLEEP state by clear SLAK bit in    MSR  

register

I did not connect the can transceiver yet.

here is the the code 'stm32f7xx_hal_can.c' I mark the line were the program stuck

HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef *hcan)

{

uint32_t tickstart = 0U;

/* Check CAN handle */

if (hcan == NULL)

{

return HAL_ERROR;

}

/* Check the parameters */

assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TimeTriggeredMode));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoBusOff));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoWakeUp));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AutoRetransmission));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ReceiveFifoLocked));

assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TransmitFifoPriority));

assert_param(IS_CAN_MODE(hcan->Init.Mode));

assert_param(IS_CAN_SJW(hcan->Init.SyncJumpWidth));

assert_param(IS_CAN_BS1(hcan->Init.TimeSeg1));

assert_param(IS_CAN_BS2(hcan->Init.TimeSeg2));

assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler));

if (hcan->State == HAL_CAN_STATE_RESET)

{

/* Init the low level hardware: CLOCK, NVIC */

HAL_CAN_MspInit(hcan);

}

/* Exit from sleep mode */

CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);                         

<--- clear the SLEEP bit

/* Get tick */

tickstart = HAL_GetTick();

/* Check Sleep mode leave acknowledge */

while ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET)    <---------- stuck here while waiting for  ack

{

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

{

/* Update error code */

hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;

/* Change CAN state */

hcan->State = HAL_CAN_STATE_ERROR;

return HAL_ERROR;

}

}

....

Does anyone have an idea why ?

2 REPLIES 2
T J
Lead
Posted on May 01, 2018 at 11:51

only one reason for this is the pull up.

you need a transceiver chip without a pullup or

without a transceiver chip, you need a pullup on the CanRx pin.

Posted on May 01, 2018 at 18:25

Thanks , I connected the transceiver , and now is want get stuck on that line  =].