STM32L4xx_HAL_Driver  1.14.0

Control functions. More...

Functions

HAL_StatusTypeDef HAL_CAN_Start (CAN_HandleTypeDef *hcan)
 Start the CAN module. More...
 
HAL_StatusTypeDef HAL_CAN_Stop (CAN_HandleTypeDef *hcan)
 Stop the CAN module and enable access to configuration registers. More...
 
HAL_StatusTypeDef HAL_CAN_RequestSleep (CAN_HandleTypeDef *hcan)
 Request the sleep mode (low power) entry. When returning from this function, Sleep mode will be entered as soon as the current CAN activity (transmission or reception of a CAN frame) has been completed. More...
 
HAL_StatusTypeDef HAL_CAN_WakeUp (CAN_HandleTypeDef *hcan)
 Wake up from sleep mode. When returning with HAL_OK status from this function, Sleep mode is exited. More...
 
uint32_t HAL_CAN_IsSleepActive (CAN_HandleTypeDef *hcan)
 Check is sleep mode is active. More...
 
HAL_StatusTypeDef HAL_CAN_AddTxMessage (CAN_HandleTypeDef *hcan, CAN_TxHeaderTypeDef *pHeader, uint8_t aData[], uint32_t *pTxMailbox)
 Add a message to the first free Tx mailbox and activate the corresponding transmission request. More...
 
HAL_StatusTypeDef HAL_CAN_AbortTxRequest (CAN_HandleTypeDef *hcan, uint32_t TxMailboxes)
 Abort transmission requests. More...
 
uint32_t HAL_CAN_GetTxMailboxesFreeLevel (CAN_HandleTypeDef *hcan)
 Return Tx Mailboxes free level: number of free Tx Mailboxes. More...
 
uint32_t HAL_CAN_IsTxMessagePending (CAN_HandleTypeDef *hcan, uint32_t TxMailboxes)
 Check if a transmission request is pending on the selected Tx Mailboxes. More...
 
uint32_t HAL_CAN_GetTxTimestamp (CAN_HandleTypeDef *hcan, uint32_t TxMailbox)
 Return timestamp of Tx message sent, if time triggered communication mode is enabled. More...
 
HAL_StatusTypeDef HAL_CAN_GetRxMessage (CAN_HandleTypeDef *hcan, uint32_t RxFifo, CAN_RxHeaderTypeDef *pHeader, uint8_t aData[])
 Get an CAN frame from the Rx FIFO zone into the message RAM. More...
 
uint32_t HAL_CAN_GetRxFifoFillLevel (CAN_HandleTypeDef *hcan, uint32_t RxFifo)
 Return Rx FIFO fill level. More...
 

Detailed Description

Control functions.

  ==============================================================================
                      ##### Control functions #####
  ==============================================================================
    [..]  This section provides functions allowing to:
      (+) HAL_CAN_Start                    : Start the CAN module
      (+) HAL_CAN_Stop                     : Stop the CAN module
      (+) HAL_CAN_RequestSleep             : Request sleep mode entry.
      (+) HAL_CAN_WakeUp                   : Wake up from sleep mode.
      (+) HAL_CAN_IsSleepActive            : Check is sleep mode is active.
      (+) HAL_CAN_AddTxMessage             : Add a message to the Tx mailboxes
                                             and activate the corresponding
                                             transmission request
      (+) HAL_CAN_AbortTxRequest           : Abort transmission request
      (+) HAL_CAN_GetTxMailboxesFreeLevel  : Return Tx mailboxes free level
      (+) HAL_CAN_IsTxMessagePending       : Check if a transmission request is
                                             pending on the selected Tx mailbox
      (+) HAL_CAN_GetRxMessage             : Get a CAN frame from the Rx FIFO
      (+) HAL_CAN_GetRxFifoFillLevel       : Return Rx FIFO fill level

Function Documentation

◆ HAL_CAN_AbortTxRequest()

HAL_StatusTypeDef HAL_CAN_AbortTxRequest ( CAN_HandleTypeDef hcan,
uint32_t  TxMailboxes 
)

Abort transmission requests.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
TxMailboxesList of the Tx Mailboxes to abort. This parameter can be any combination of
  • CAN_Tx_Mailboxes.
Return values
HALstatus

Definition at line 1330 of file stm32l4xx_hal_can.c.

1331 {
1332  HAL_CAN_StateTypeDef state = hcan->State;
1333 
1334  /* Check function parameters */
1335  assert_param(IS_CAN_TX_MAILBOX_LIST(TxMailboxes));
1336 
1337  if ((state == HAL_CAN_STATE_READY) ||
1338  (state == HAL_CAN_STATE_LISTENING))
1339  {
1340  /* Check Tx Mailbox 0 */
1341  if ((TxMailboxes & CAN_TX_MAILBOX0) != 0U)
1342  {
1343  /* Add cancellation request for Tx Mailbox 0 */
1344  SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ0);
1345  }
1346 
1347  /* Check Tx Mailbox 1 */
1348  if ((TxMailboxes & CAN_TX_MAILBOX1) != 0U)
1349  {
1350  /* Add cancellation request for Tx Mailbox 1 */
1351  SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ1);
1352  }
1353 
1354  /* Check Tx Mailbox 2 */
1355  if ((TxMailboxes & CAN_TX_MAILBOX2) != 0U)
1356  {
1357  /* Add cancellation request for Tx Mailbox 2 */
1358  SET_BIT(hcan->Instance->TSR, CAN_TSR_ABRQ2);
1359  }
1360 
1361  /* Return function status */
1362  return HAL_OK;
1363  }
1364  else
1365  {
1366  /* Update error code */
1367  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1368 
1369  return HAL_ERROR;
1370  }
1371 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_AddTxMessage()

HAL_StatusTypeDef HAL_CAN_AddTxMessage ( CAN_HandleTypeDef hcan,
CAN_TxHeaderTypeDef pHeader,
uint8_t  aData[],
uint32_t *  pTxMailbox 
)

Add a message to the first free Tx mailbox and activate the corresponding transmission request.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
pHeaderpointer to a CAN_TxHeaderTypeDef structure.
aDataarray containing the payload of the Tx frame.
pTxMailboxpointer to a variable where the function will return the TxMailbox used to store the Tx message. This parameter can be a value of
  • CAN_Tx_Mailboxes.
Return values
HALstatus

Definition at line 1222 of file stm32l4xx_hal_can.c.

1223 {
1224  uint32_t transmitmailbox;
1225  HAL_CAN_StateTypeDef state = hcan->State;
1226  uint32_t tsr = READ_REG(hcan->Instance->TSR);
1227 
1228  /* Check the parameters */
1229  assert_param(IS_CAN_IDTYPE(pHeader->IDE));
1230  assert_param(IS_CAN_RTR(pHeader->RTR));
1231  assert_param(IS_CAN_DLC(pHeader->DLC));
1232  if (pHeader->IDE == CAN_ID_STD)
1233  {
1234  assert_param(IS_CAN_STDID(pHeader->StdId));
1235  }
1236  else
1237  {
1238  assert_param(IS_CAN_EXTID(pHeader->ExtId));
1239  }
1240  assert_param(IS_FUNCTIONAL_STATE(pHeader->TransmitGlobalTime));
1241 
1242  if ((state == HAL_CAN_STATE_READY) ||
1243  (state == HAL_CAN_STATE_LISTENING))
1244  {
1245  /* Check that all the Tx mailboxes are not full */
1246  if (((tsr & CAN_TSR_TME0) != 0U) ||
1247  ((tsr & CAN_TSR_TME1) != 0U) ||
1248  ((tsr & CAN_TSR_TME2) != 0U))
1249  {
1250  /* Select an empty transmit mailbox */
1251  transmitmailbox = (tsr & CAN_TSR_CODE) >> CAN_TSR_CODE_Pos;
1252 
1253  /* Check transmit mailbox value */
1254  if (transmitmailbox > 2U)
1255  {
1256  /* Update error code */
1257  hcan->ErrorCode |= HAL_CAN_ERROR_INTERNAL;
1258 
1259  return HAL_ERROR;
1260  }
1261 
1262  /* Store the Tx mailbox */
1263  *pTxMailbox = (uint32_t)1 << transmitmailbox;
1264 
1265  /* Set up the Id */
1266  if (pHeader->IDE == CAN_ID_STD)
1267  {
1268  hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->StdId << CAN_TI0R_STID_Pos) |
1269  pHeader->RTR);
1270  }
1271  else
1272  {
1273  hcan->Instance->sTxMailBox[transmitmailbox].TIR = ((pHeader->ExtId << CAN_TI0R_EXID_Pos) |
1274  pHeader->IDE |
1275  pHeader->RTR);
1276  }
1277 
1278  /* Set up the DLC */
1279  hcan->Instance->sTxMailBox[transmitmailbox].TDTR = (pHeader->DLC);
1280 
1281  /* Set up the Transmit Global Time mode */
1282  if (pHeader->TransmitGlobalTime == ENABLE)
1283  {
1284  SET_BIT(hcan->Instance->sTxMailBox[transmitmailbox].TDTR, CAN_TDT0R_TGT);
1285  }
1286 
1287  /* Set up the data field */
1288  WRITE_REG(hcan->Instance->sTxMailBox[transmitmailbox].TDHR,
1289  ((uint32_t)aData[7] << CAN_TDH0R_DATA7_Pos) |
1290  ((uint32_t)aData[6] << CAN_TDH0R_DATA6_Pos) |
1291  ((uint32_t)aData[5] << CAN_TDH0R_DATA5_Pos) |
1292  ((uint32_t)aData[4] << CAN_TDH0R_DATA4_Pos));
1293  WRITE_REG(hcan->Instance->sTxMailBox[transmitmailbox].TDLR,
1294  ((uint32_t)aData[3] << CAN_TDL0R_DATA3_Pos) |
1295  ((uint32_t)aData[2] << CAN_TDL0R_DATA2_Pos) |
1296  ((uint32_t)aData[1] << CAN_TDL0R_DATA1_Pos) |
1297  ((uint32_t)aData[0] << CAN_TDL0R_DATA0_Pos));
1298 
1299  /* Request transmission */
1300  SET_BIT(hcan->Instance->sTxMailBox[transmitmailbox].TIR, CAN_TI0R_TXRQ);
1301 
1302  /* Return function status */
1303  return HAL_OK;
1304  }
1305  else
1306  {
1307  /* Update error code */
1308  hcan->ErrorCode |= HAL_CAN_ERROR_PARAM;
1309 
1310  return HAL_ERROR;
1311  }
1312  }
1313  else
1314  {
1315  /* Update error code */
1316  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1317 
1318  return HAL_ERROR;
1319  }
1320 }
FunctionalState TransmitGlobalTime
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_GetRxFifoFillLevel()

uint32_t HAL_CAN_GetRxFifoFillLevel ( CAN_HandleTypeDef hcan,
uint32_t  RxFifo 
)

Return Rx FIFO fill level.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
RxFifoRx FIFO. This parameter can be a value of
  • CAN_receive_FIFO_number.
Return values
Numberof messages available in Rx FIFO.

Definition at line 1578 of file stm32l4xx_hal_can.c.

1579 {
1580  uint32_t filllevel = 0U;
1581  HAL_CAN_StateTypeDef state = hcan->State;
1582 
1583  /* Check function parameters */
1584  assert_param(IS_CAN_RX_FIFO(RxFifo));
1585 
1586  if ((state == HAL_CAN_STATE_READY) ||
1587  (state == HAL_CAN_STATE_LISTENING))
1588  {
1589  if (RxFifo == CAN_RX_FIFO0)
1590  {
1591  filllevel = hcan->Instance->RF0R & CAN_RF0R_FMP0;
1592  }
1593  else /* RxFifo == CAN_RX_FIFO1 */
1594  {
1595  filllevel = hcan->Instance->RF1R & CAN_RF1R_FMP1;
1596  }
1597  }
1598 
1599  /* Return Rx FIFO fill level */
1600  return filllevel;
1601 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_GetRxMessage()

HAL_StatusTypeDef HAL_CAN_GetRxMessage ( CAN_HandleTypeDef hcan,
uint32_t  RxFifo,
CAN_RxHeaderTypeDef pHeader,
uint8_t  aData[] 
)

Get an CAN frame from the Rx FIFO zone into the message RAM.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
RxFifoFifo number of the received message to be read. This parameter can be a value of
  • CAN_receive_FIFO_number.
pHeaderpointer to a CAN_RxHeaderTypeDef structure where the header of the Rx frame will be stored.
aDataarray where the payload of the Rx frame will be stored.
Return values
HALstatus

Definition at line 1488 of file stm32l4xx_hal_can.c.

1489 {
1490  HAL_CAN_StateTypeDef state = hcan->State;
1491 
1492  assert_param(IS_CAN_RX_FIFO(RxFifo));
1493 
1494  if ((state == HAL_CAN_STATE_READY) ||
1495  (state == HAL_CAN_STATE_LISTENING))
1496  {
1497  /* Check the Rx FIFO */
1498  if (RxFifo == CAN_RX_FIFO0) /* Rx element is assigned to Rx FIFO 0 */
1499  {
1500  /* Check that the Rx FIFO 0 is not empty */
1501  if ((hcan->Instance->RF0R & CAN_RF0R_FMP0) == 0U)
1502  {
1503  /* Update error code */
1504  hcan->ErrorCode |= HAL_CAN_ERROR_PARAM;
1505 
1506  return HAL_ERROR;
1507  }
1508  }
1509  else /* Rx element is assigned to Rx FIFO 1 */
1510  {
1511  /* Check that the Rx FIFO 1 is not empty */
1512  if ((hcan->Instance->RF1R & CAN_RF1R_FMP1) == 0U)
1513  {
1514  /* Update error code */
1515  hcan->ErrorCode |= HAL_CAN_ERROR_PARAM;
1516 
1517  return HAL_ERROR;
1518  }
1519  }
1520 
1521  /* Get the header */
1522  pHeader->IDE = CAN_RI0R_IDE & hcan->Instance->sFIFOMailBox[RxFifo].RIR;
1523  if (pHeader->IDE == CAN_ID_STD)
1524  {
1525  pHeader->StdId = (CAN_RI0R_STID & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_TI0R_STID_Pos;
1526  }
1527  else
1528  {
1529  pHeader->ExtId = ((CAN_RI0R_EXID | CAN_RI0R_STID) & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_RI0R_EXID_Pos;
1530  }
1531  pHeader->RTR = (CAN_RI0R_RTR & hcan->Instance->sFIFOMailBox[RxFifo].RIR) >> CAN_RI0R_RTR_Pos;
1532  pHeader->DLC = (CAN_RDT0R_DLC & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_DLC_Pos;
1533  pHeader->FilterMatchIndex = (CAN_RDT0R_FMI & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_FMI_Pos;
1534  pHeader->Timestamp = (CAN_RDT0R_TIME & hcan->Instance->sFIFOMailBox[RxFifo].RDTR) >> CAN_RDT0R_TIME_Pos;
1535 
1536  /* Get the data */
1537  aData[0] = (uint8_t)((CAN_RDL0R_DATA0 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA0_Pos);
1538  aData[1] = (uint8_t)((CAN_RDL0R_DATA1 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA1_Pos);
1539  aData[2] = (uint8_t)((CAN_RDL0R_DATA2 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA2_Pos);
1540  aData[3] = (uint8_t)((CAN_RDL0R_DATA3 & hcan->Instance->sFIFOMailBox[RxFifo].RDLR) >> CAN_RDL0R_DATA3_Pos);
1541  aData[4] = (uint8_t)((CAN_RDH0R_DATA4 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA4_Pos);
1542  aData[5] = (uint8_t)((CAN_RDH0R_DATA5 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA5_Pos);
1543  aData[6] = (uint8_t)((CAN_RDH0R_DATA6 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA6_Pos);
1544  aData[7] = (uint8_t)((CAN_RDH0R_DATA7 & hcan->Instance->sFIFOMailBox[RxFifo].RDHR) >> CAN_RDH0R_DATA7_Pos);
1545 
1546  /* Release the FIFO */
1547  if (RxFifo == CAN_RX_FIFO0) /* Rx element is assigned to Rx FIFO 0 */
1548  {
1549  /* Release RX FIFO 0 */
1550  SET_BIT(hcan->Instance->RF0R, CAN_RF0R_RFOM0);
1551  }
1552  else /* Rx element is assigned to Rx FIFO 1 */
1553  {
1554  /* Release RX FIFO 1 */
1555  SET_BIT(hcan->Instance->RF1R, CAN_RF1R_RFOM1);
1556  }
1557 
1558  /* Return function status */
1559  return HAL_OK;
1560  }
1561  else
1562  {
1563  /* Update error code */
1564  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1565 
1566  return HAL_ERROR;
1567  }
1568 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_GetTxMailboxesFreeLevel()

uint32_t HAL_CAN_GetTxMailboxesFreeLevel ( CAN_HandleTypeDef hcan)

Return Tx Mailboxes free level: number of free Tx Mailboxes.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
Numberof free Tx Mailboxes.

Definition at line 1379 of file stm32l4xx_hal_can.c.

1380 {
1381  uint32_t freelevel = 0U;
1382  HAL_CAN_StateTypeDef state = hcan->State;
1383 
1384  if ((state == HAL_CAN_STATE_READY) ||
1385  (state == HAL_CAN_STATE_LISTENING))
1386  {
1387  /* Check Tx Mailbox 0 status */
1388  if ((hcan->Instance->TSR & CAN_TSR_TME0) != 0U)
1389  {
1390  freelevel++;
1391  }
1392 
1393  /* Check Tx Mailbox 1 status */
1394  if ((hcan->Instance->TSR & CAN_TSR_TME1) != 0U)
1395  {
1396  freelevel++;
1397  }
1398 
1399  /* Check Tx Mailbox 2 status */
1400  if ((hcan->Instance->TSR & CAN_TSR_TME2) != 0U)
1401  {
1402  freelevel++;
1403  }
1404  }
1405 
1406  /* Return Tx Mailboxes free level */
1407  return freelevel;
1408 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.

◆ HAL_CAN_GetTxTimestamp()

uint32_t HAL_CAN_GetTxTimestamp ( CAN_HandleTypeDef hcan,
uint32_t  TxMailbox 
)

Return timestamp of Tx message sent, if time triggered communication mode is enabled.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
TxMailboxTx Mailbox where the timestamp of message sent will be read. This parameter can be one value of
  • CAN_Tx_Mailboxes.
Return values
Timestampof message sent from Tx Mailbox.

Definition at line 1454 of file stm32l4xx_hal_can.c.

1455 {
1456  uint32_t timestamp = 0U;
1457  uint32_t transmitmailbox;
1458  HAL_CAN_StateTypeDef state = hcan->State;
1459 
1460  /* Check function parameters */
1461  assert_param(IS_CAN_TX_MAILBOX(TxMailbox));
1462 
1463  if ((state == HAL_CAN_STATE_READY) ||
1464  (state == HAL_CAN_STATE_LISTENING))
1465  {
1466  /* Select the Tx mailbox */
1467  transmitmailbox = POSITION_VAL(TxMailbox);
1468 
1469  /* Get timestamp */
1470  timestamp = (hcan->Instance->sTxMailBox[transmitmailbox].TDTR & CAN_TDT0R_TIME) >> CAN_TDT0R_TIME_Pos;
1471  }
1472 
1473  /* Return the timestamp */
1474  return timestamp;
1475 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_IsSleepActive()

uint32_t HAL_CAN_IsSleepActive ( CAN_HandleTypeDef hcan)

Check is sleep mode is active.

Parameters
hcanpointer to a CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
Return values
Status
  • 0 : Sleep mode is not active.
  • 1 : Sleep mode is active.

Definition at line 1191 of file stm32l4xx_hal_can.c.

1192 {
1193  uint32_t status = 0U;
1194  HAL_CAN_StateTypeDef state = hcan->State;
1195 
1196  if ((state == HAL_CAN_STATE_READY) ||
1197  (state == HAL_CAN_STATE_LISTENING))
1198  {
1199  /* Check Sleep mode */
1200  if ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U)
1201  {
1202  status = 1U;
1203  }
1204  }
1205 
1206  /* Return function status */
1207  return status;
1208 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.

◆ HAL_CAN_IsTxMessagePending()

uint32_t HAL_CAN_IsTxMessagePending ( CAN_HandleTypeDef hcan,
uint32_t  TxMailboxes 
)

Check if a transmission request is pending on the selected Tx Mailboxes.

Parameters
hcanpointer to an CAN_HandleTypeDef structure that contains the configuration information for the specified CAN.
TxMailboxesList of Tx Mailboxes to check. This parameter can be any combination of
  • CAN_Tx_Mailboxes.
Return values
Status
  • 0 : No pending transmission request on any selected Tx Mailboxes.
  • 1 : Pending transmission request on at least one of the selected Tx Mailbox.

Definition at line 1422 of file stm32l4xx_hal_can.c.

1423 {
1424  uint32_t status = 0U;
1425  HAL_CAN_StateTypeDef state = hcan->State;
1426 
1427  /* Check function parameters */
1428  assert_param(IS_CAN_TX_MAILBOX_LIST(TxMailboxes));
1429 
1430  if ((state == HAL_CAN_STATE_READY) ||
1431  (state == HAL_CAN_STATE_LISTENING))
1432  {
1433  /* Check pending transmission request on the selected Tx Mailboxes */
1434  if ((hcan->Instance->TSR & (TxMailboxes << CAN_TSR_TME0_Pos)) != (TxMailboxes << CAN_TSR_TME0_Pos))
1435  {
1436  status = 1U;
1437  }
1438  }
1439 
1440  /* Return status */
1441  return status;
1442 }
__IO HAL_CAN_StateTypeDef State
HAL_CAN_StateTypeDef
HAL State structures definition.
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))

◆ HAL_CAN_RequestSleep()

HAL_StatusTypeDef HAL_CAN_RequestSleep ( CAN_HandleTypeDef hcan)

Request the sleep mode (low power) entry. When returning from this function, Sleep mode will be entered as soon as the current CAN activity (transmission or reception of a CAN frame) has been completed.

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

Definition at line 1111 of file stm32l4xx_hal_can.c.

1112 {
1113  HAL_CAN_StateTypeDef state = hcan->State;
1114 
1115  if ((state == HAL_CAN_STATE_READY) ||
1116  (state == HAL_CAN_STATE_LISTENING))
1117  {
1118  /* Request Sleep mode */
1119  SET_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);
1120 
1121  /* Return function status */
1122  return HAL_OK;
1123  }
1124  else
1125  {
1126  /* Update error code */
1127  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1128 
1129  /* Return function status */
1130  return HAL_ERROR;
1131  }
1132 }
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.

◆ HAL_CAN_Start()

HAL_StatusTypeDef HAL_CAN_Start ( CAN_HandleTypeDef hcan)

Start the CAN module.

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

Definition at line 1004 of file stm32l4xx_hal_can.c.

1005 {
1006  uint32_t tickstart;
1007 
1008  if (hcan->State == HAL_CAN_STATE_READY)
1009  {
1010  /* Change CAN peripheral state */
1012 
1013  /* Request leave initialisation */
1014  CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_INRQ);
1015 
1016  /* Get tick */
1017  tickstart = HAL_GetTick();
1018 
1019  /* Wait the acknowledge */
1020  while ((hcan->Instance->MSR & CAN_MSR_INAK) != 0U)
1021  {
1022  /* Check for the Timeout */
1023  if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)
1024  {
1025  /* Update error code */
1026  hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;
1027 
1028  /* Change CAN state */
1029  hcan->State = HAL_CAN_STATE_ERROR;
1030 
1031  return HAL_ERROR;
1032  }
1033  }
1034 
1035  /* Reset the CAN ErrorCode */
1036  hcan->ErrorCode = HAL_CAN_ERROR_NONE;
1037 
1038  /* Return function status */
1039  return HAL_OK;
1040  }
1041  else
1042  {
1043  /* Update error code */
1044  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_READY;
1045 
1046  return HAL_ERROR;
1047  }
1048 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__IO HAL_CAN_StateTypeDef State
return HAL_OK

◆ HAL_CAN_Stop()

HAL_StatusTypeDef HAL_CAN_Stop ( CAN_HandleTypeDef hcan)

Stop the CAN module and enable access to configuration registers.

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

Definition at line 1056 of file stm32l4xx_hal_can.c.

1057 {
1058  uint32_t tickstart;
1059 
1060  if (hcan->State == HAL_CAN_STATE_LISTENING)
1061  {
1062  /* Request initialisation */
1063  SET_BIT(hcan->Instance->MCR, CAN_MCR_INRQ);
1064 
1065  /* Get tick */
1066  tickstart = HAL_GetTick();
1067 
1068  /* Wait the acknowledge */
1069  while ((hcan->Instance->MSR & CAN_MSR_INAK) == 0U)
1070  {
1071  /* Check for the Timeout */
1072  if ((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE)
1073  {
1074  /* Update error code */
1075  hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;
1076 
1077  /* Change CAN state */
1078  hcan->State = HAL_CAN_STATE_ERROR;
1079 
1080  return HAL_ERROR;
1081  }
1082  }
1083 
1084  /* Exit from sleep mode */
1085  CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);
1086 
1087  /* Change CAN peripheral state */
1088  hcan->State = HAL_CAN_STATE_READY;
1089 
1090  /* Return function status */
1091  return HAL_OK;
1092  }
1093  else
1094  {
1095  /* Update error code */
1096  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_STARTED;
1097 
1098  return HAL_ERROR;
1099  }
1100 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__IO HAL_CAN_StateTypeDef State
return HAL_OK

◆ HAL_CAN_WakeUp()

HAL_StatusTypeDef HAL_CAN_WakeUp ( CAN_HandleTypeDef hcan)

Wake up from sleep mode. When returning with HAL_OK status from this function, Sleep mode is exited.

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

Definition at line 1142 of file stm32l4xx_hal_can.c.

1143 {
1144  __IO uint32_t count = 0;
1145  uint32_t timeout = 1000000U;
1146  HAL_CAN_StateTypeDef state = hcan->State;
1147 
1148  if ((state == HAL_CAN_STATE_READY) ||
1149  (state == HAL_CAN_STATE_LISTENING))
1150  {
1151  /* Wake up request */
1152  CLEAR_BIT(hcan->Instance->MCR, CAN_MCR_SLEEP);
1153 
1154  /* Wait sleep mode is exited */
1155  do
1156  {
1157  /* Increment counter */
1158  count++;
1159 
1160  /* Check if timeout is reached */
1161  if (count > timeout)
1162  {
1163  /* Update error code */
1164  hcan->ErrorCode |= HAL_CAN_ERROR_TIMEOUT;
1165 
1166  return HAL_ERROR;
1167  }
1168  }
1169  while ((hcan->Instance->MSR & CAN_MSR_SLAK) != 0U);
1170 
1171  /* Return function status */
1172  return HAL_OK;
1173  }
1174  else
1175  {
1176  /* Update error code */
1177  hcan->ErrorCode |= HAL_CAN_ERROR_NOT_INITIALIZED;
1178 
1179  return HAL_ERROR;
1180  }
1181 }
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__IO HAL_CAN_StateTypeDef State
return HAL_OK
HAL_CAN_StateTypeDef
HAL State structures definition.