STM32L4xx_HAL_Driver  1.14.0
Peripheral State and Error functions

CAN Peripheral State functions. More...

Functions

HAL_CAN_StateTypeDef HAL_CAN_GetState (CAN_HandleTypeDef *hcan)
 Return the CAN state. More...
 
uint32_t HAL_CAN_GetError (CAN_HandleTypeDef *hcan)
 Return the CAN error code. More...
 
HAL_StatusTypeDef HAL_CAN_ResetError (CAN_HandleTypeDef *hcan)
 Reset the CAN error code. More...
 

Detailed Description

CAN Peripheral State functions.

  ==============================================================================
            ##### Peripheral State and Error functions #####
  ==============================================================================
    [..]
    This subsection provides functions allowing to :
      (+) HAL_CAN_GetState()  : Return the CAN state.
      (+) HAL_CAN_GetError()  : Return the CAN error codes if any.
      (+) HAL_CAN_ResetError(): Reset the CAN error codes if any.

Function Documentation

◆ HAL_CAN_GetError()

uint32_t HAL_CAN_GetError ( CAN_HandleTypeDef hcan)

Return the CAN error code.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
CANError Code

Definition at line 2381 of file stm32l4xx_hal_can.c.

2382 {
2383  /* Return CAN error code */
2384  return hcan->ErrorCode;
2385 }

◆ HAL_CAN_GetState()

HAL_CAN_StateTypeDef HAL_CAN_GetState ( CAN_HandleTypeDef hcan)

Return the CAN state.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
HALstate

Definition at line 2346 of file stm32l4xx_hal_can.c.

2347 {
2348  HAL_CAN_StateTypeDef state = hcan->State;
2349 
2350  if ((state == HAL_CAN_STATE_READY) ||
2351  (state == HAL_CAN_STATE_LISTENING))
2352  {
2353  /* Check sleep mode acknowledge flag */
2354  if ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U)
2355  {
2356  /* Sleep mode is active */
2358  }
2359  /* Check sleep mode request flag */
2360  else if ((hcan->Instance->MCR & CAN_MCR_SLEEP) != 0U)
2361  {
2362  /* Sleep mode request is pending */
2364  }
2365  else
2366  {
2367  /* Neither sleep mode request nor sleep mode acknowledge */
2368  }
2369  }
2370 
2371  /* Return CAN state */
2372  return state;
2373 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.

◆ HAL_CAN_ResetError()

HAL_StatusTypeDef HAL_CAN_ResetError ( CAN_HandleTypeDef hcan)

Reset the CAN error code.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
HALstatus

Definition at line 2393 of file stm32l4xx_hal_can.c.

2394 {
2395  HAL_StatusTypeDef status = HAL_OK;
2396  HAL_CAN_StateTypeDef state = hcan->State;
2397 
2398  if ((state == HAL_CAN_STATE_READY) ||
2399  (state == HAL_CAN_STATE_LISTENING))
2400  {
2401  /* Reset CAN error code */
2402  hcan->ErrorCode = 0U;
2403  }
2404  else
2405  {
2406  /* Update error code */
2407  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
2408 
2409  status = HAL_ERROR;
2410  }
2411 
2412  /* Return the status */
2413  return status;
2414 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.