I was just started with CAN peripheral on my stm32f446re nucleo board.
The problem i am facing is HAL_CAN_Init() added by cubeMx code generation software is failing at the below line of code
it is returning HAL_ERROR in CAN1 LOOP BACK MODE
That means the controller has not set SLAK to zero even if we clear the SLEEP bit
i believe that CAN TX is internally connected to can rx and can rx is not sampled .
on the board i have made no connection to the can tx and can rx. its just a single board.
Please let me know what i am doing wrong .
/* Exit from sleep mode */
/* Get tick */
tickstart = HAL_GetTick();
/* Check Sleep mode leave acknowledge */
while ((hcan->Instance->MSR & CAN_MSR_SLAK) != RESET)
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;
here is picture of all reg contents