CAN HAL module driver. This file provides firmware functions to manage the following functionalities of the Controller Area Network (CAN) peripheral: + Initialization and de-initialization functions + Configuration functions + Control functions + Interrupts management + Callbacks functions + Peripheral State and Error functions.
More...
Defines |
#define | CAN_TIMEOUT_VALUE 10U |
Functions |
HAL_StatusTypeDef | HAL_CAN_Init (CAN_HandleTypeDef *hcan) |
| Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
|
HAL_StatusTypeDef | HAL_CAN_DeInit (CAN_HandleTypeDef *hcan) |
| Deinitializes the CAN peripheral registers to their default reset values.
|
__weak void | HAL_CAN_MspInit (CAN_HandleTypeDef *hcan) |
| Initializes the CAN MSP.
|
__weak void | HAL_CAN_MspDeInit (CAN_HandleTypeDef *hcan) |
| DeInitializes the CAN MSP.
|
HAL_StatusTypeDef | HAL_CAN_RegisterCallback (CAN_HandleTypeDef *hcan, HAL_CAN_CallbackIDTypeDef CallbackID, void(*pCallback)(CAN_HandleTypeDef *_hcan)) |
| Register a CAN CallBack.
|
HAL_StatusTypeDef | HAL_CAN_UnRegisterCallback (CAN_HandleTypeDef *hcan, HAL_CAN_CallbackIDTypeDef CallbackID) |
| Unregister a CAN CallBack.
|
HAL_StatusTypeDef | HAL_CAN_ConfigFilter (CAN_HandleTypeDef *hcan, CAN_FilterTypeDef *sFilterConfig) |
| Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct.
|
HAL_StatusTypeDef | HAL_CAN_Start (CAN_HandleTypeDef *hcan) |
| Start the CAN module.
|
HAL_StatusTypeDef | HAL_CAN_Stop (CAN_HandleTypeDef *hcan) |
| Stop the CAN module and enable access to configuration registers.
|
HAL_StatusTypeDef | HAL_CAN_RequestSleep (CAN_HandleTypeDef *hcan) |
| Request the sleep mode (low power) entry.
|
HAL_StatusTypeDef | HAL_CAN_WakeUp (CAN_HandleTypeDef *hcan) |
| Wake up from sleep mode.
|
uint32_t | HAL_CAN_IsSleepActive (CAN_HandleTypeDef *hcan) |
| Check is sleep mode is active.
|
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.
|
HAL_StatusTypeDef | HAL_CAN_AbortTxRequest (CAN_HandleTypeDef *hcan, uint32_t TxMailboxes) |
| Abort transmission requests.
|
uint32_t | HAL_CAN_GetTxMailboxesFreeLevel (CAN_HandleTypeDef *hcan) |
| Return Tx Mailboxes free level: number of free Tx Mailboxes.
|
uint32_t | HAL_CAN_IsTxMessagePending (CAN_HandleTypeDef *hcan, uint32_t TxMailboxes) |
| Check if a transmission request is pending on the selected Tx Mailboxes.
|
uint32_t | HAL_CAN_GetTxTimestamp (CAN_HandleTypeDef *hcan, uint32_t TxMailbox) |
| Return timestamp of Tx message sent, if time triggered communication mode is enabled.
|
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.
|
uint32_t | HAL_CAN_GetRxFifoFillLevel (CAN_HandleTypeDef *hcan, uint32_t RxFifo) |
| Return Rx FIFO fill level.
|
HAL_StatusTypeDef | HAL_CAN_ActivateNotification (CAN_HandleTypeDef *hcan, uint32_t ActiveITs) |
| Enable interrupts.
|
HAL_StatusTypeDef | HAL_CAN_DeactivateNotification (CAN_HandleTypeDef *hcan, uint32_t InactiveITs) |
| Disable interrupts.
|
void | HAL_CAN_IRQHandler (CAN_HandleTypeDef *hcan) |
| Handles CAN interrupt request.
|
__weak void | HAL_CAN_TxMailbox0CompleteCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 0 complete callback.
|
__weak void | HAL_CAN_TxMailbox1CompleteCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 1 complete callback.
|
__weak void | HAL_CAN_TxMailbox2CompleteCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 2 complete callback.
|
__weak void | HAL_CAN_TxMailbox0AbortCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 0 Cancellation callback.
|
__weak void | HAL_CAN_TxMailbox1AbortCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 1 Cancellation callback.
|
__weak void | HAL_CAN_TxMailbox2AbortCallback (CAN_HandleTypeDef *hcan) |
| Transmission Mailbox 2 Cancellation callback.
|
__weak void | HAL_CAN_RxFifo0MsgPendingCallback (CAN_HandleTypeDef *hcan) |
| Rx FIFO 0 message pending callback.
|
__weak void | HAL_CAN_RxFifo0FullCallback (CAN_HandleTypeDef *hcan) |
| Rx FIFO 0 full callback.
|
__weak void | HAL_CAN_RxFifo1MsgPendingCallback (CAN_HandleTypeDef *hcan) |
| Rx FIFO 1 message pending callback.
|
__weak void | HAL_CAN_RxFifo1FullCallback (CAN_HandleTypeDef *hcan) |
| Rx FIFO 1 full callback.
|
__weak void | HAL_CAN_SleepCallback (CAN_HandleTypeDef *hcan) |
| Sleep callback.
|
__weak void | HAL_CAN_WakeUpFromRxMsgCallback (CAN_HandleTypeDef *hcan) |
| WakeUp from Rx message callback.
|
__weak void | HAL_CAN_ErrorCallback (CAN_HandleTypeDef *hcan) |
| Error CAN callback.
|
HAL_CAN_StateTypeDef | HAL_CAN_GetState (CAN_HandleTypeDef *hcan) |
| Return the CAN state.
|
uint32_t | HAL_CAN_GetError (CAN_HandleTypeDef *hcan) |
| Return the CAN error code.
|
HAL_StatusTypeDef | HAL_CAN_ResetError (CAN_HandleTypeDef *hcan) |
| Reset the CAN error code.
|
CAN HAL module driver. This file provides firmware functions to manage the following functionalities of the Controller Area Network (CAN) peripheral: + Initialization and de-initialization functions + Configuration functions + Control functions + Interrupts management + Callbacks functions + Peripheral State and Error functions.
- Author:
- MCD Application Team
==============================================================================
##### How to use this driver #####
==============================================================================
[..]
(#) Initialize the CAN low level resources by implementing the
HAL_CAN_MspInit():
(++) Enable the CAN interface clock using __HAL_RCC_CANx_CLK_ENABLE()
(++) Configure CAN pins
(+++) Enable the clock for the CAN GPIOs
(+++) Configure CAN pins as alternate function open-drain
(++) In case of using interrupts (e.g. HAL_CAN_ActivateNotification())
(+++) Configure the CAN interrupt priority using
HAL_NVIC_SetPriority()
(+++) Enable the CAN IRQ handler using HAL_NVIC_EnableIRQ()
(+++) In CAN IRQ handler, call HAL_CAN_IRQHandler()
(#) Initialize the CAN peripheral using HAL_CAN_Init() function. This
function resorts to HAL_CAN_MspInit() for low-level initialization.
(#) Configure the reception filters using the following configuration
functions:
(++) HAL_CAN_ConfigFilter()
(#) Start the CAN module using HAL_CAN_Start() function. At this level
the node is active on the bus: it receive messages, and can send
messages.
(#) To manage messages transmission, the following Tx control functions
can be used:
(++) HAL_CAN_AddTxMessage() to request transmission of a new
message.
(++) HAL_CAN_AbortTxRequest() to abort transmission of a pending
message.
(++) HAL_CAN_GetTxMailboxesFreeLevel() to get the number of free Tx
mailboxes.
(++) HAL_CAN_IsTxMessagePending() to check if a message is pending
in a Tx mailbox.
(++) HAL_CAN_GetTxTimestamp() to get the timestamp of Tx message
sent, if time triggered communication mode is enabled.
(#) When a message is received into the CAN Rx FIFOs, it can be retrieved
using the HAL_CAN_GetRxMessage() function. The function
HAL_CAN_GetRxFifoFillLevel() allows to know how many Rx message are
stored in the Rx Fifo.
(#) Calling the HAL_CAN_Stop() function stops the CAN module.
(#) The deinitialization is achieved with HAL_CAN_DeInit() function.
*** Polling mode operation ***
==============================
[..]
(#) Reception:
(++) Monitor reception of message using HAL_CAN_GetRxFifoFillLevel()
until at least one message is received.
(++) Then get the message using HAL_CAN_GetRxMessage().
(#) Transmission:
(++) Monitor the Tx mailboxes availability until at least one Tx
mailbox is free, using HAL_CAN_GetTxMailboxesFreeLevel().
(++) Then request transmission of a message using
HAL_CAN_AddTxMessage().
*** Interrupt mode operation ***
================================
[..]
(#) Notifications are activated using HAL_CAN_ActivateNotification()
function. Then, the process can be controlled through the
available user callbacks: HAL_CAN_xxxCallback(), using same APIs
HAL_CAN_GetRxMessage() and HAL_CAN_AddTxMessage().
(#) Notifications can be deactivated using
HAL_CAN_DeactivateNotification() function.
(#) Special care should be taken for CAN_IT_RX_FIFO0_MSG_PENDING and
CAN_IT_RX_FIFO1_MSG_PENDING notifications. These notifications trig
the callbacks HAL_CAN_RxFIFO0MsgPendingCallback() and
HAL_CAN_RxFIFO1MsgPendingCallback(). User has two possible options
here.
(++) Directly get the Rx message in the callback, using
HAL_CAN_GetRxMessage().
(++) Or deactivate the notification in the callback without
getting the Rx message. The Rx message can then be got later
using HAL_CAN_GetRxMessage(). Once the Rx message have been
read, the notification can be activated again.
*** Sleep mode ***
==================
[..]
(#) The CAN peripheral can be put in sleep mode (low power), using
HAL_CAN_RequestSleep(). The sleep mode will be entered as soon as the
current CAN activity (transmission or reception of a CAN frame) will
be completed.
(#) A notification can be activated to be informed when the sleep mode
will be entered.
(#) It can be checked if the sleep mode is entered using
HAL_CAN_IsSleepActive().
Note that the CAN state (accessible from the API HAL_CAN_GetState())
is HAL_CAN_STATE_SLEEP_PENDING as soon as the sleep mode request is
submitted (the sleep mode is not yet entered), and become
HAL_CAN_STATE_SLEEP_ACTIVE when the sleep mode is effective.
(#) The wake-up from sleep mode can be trigged by two ways:
(++) Using HAL_CAN_WakeUp(). When returning from this function,
the sleep mode is exited (if return status is HAL_OK).
(++) When a start of Rx CAN frame is detected by the CAN peripheral,
if automatic wake up mode is enabled.
*** Callback registration ***
=============================================
The compilation define USE_HAL_CAN_REGISTER_CALLBACKS when set to 1
allows the user to configure dynamically the driver callbacks.
Use Function @ref HAL_CAN_RegisterCallback() to register an interrupt callback.
Function @ref HAL_CAN_RegisterCallback() allows to register following callbacks:
(+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback.
(+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback.
(+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback.
(+) TxMailbox0AbortCallback : Tx Mailbox 0 Abort Callback.
(+) TxMailbox1AbortCallback : Tx Mailbox 1 Abort Callback.
(+) TxMailbox2AbortCallback : Tx Mailbox 2 Abort Callback.
(+) RxFifo0MsgPendingCallback : Rx Fifo 0 Message Pending Callback.
(+) RxFifo0FullCallback : Rx Fifo 0 Full Callback.
(+) RxFifo1MsgPendingCallback : Rx Fifo 1 Message Pending Callback.
(+) RxFifo1FullCallback : Rx Fifo 1 Full Callback.
(+) SleepCallback : Sleep Callback.
(+) WakeUpFromRxMsgCallback : Wake Up From Rx Message Callback.
(+) ErrorCallback : Error Callback.
(+) MspInitCallback : CAN MspInit.
(+) MspDeInitCallback : CAN MspDeInit.
This function takes as parameters the HAL peripheral handle, the Callback ID
and a pointer to the user callback function.
Use function @ref HAL_CAN_UnRegisterCallback() to reset a callback to the default
weak function.
@ref HAL_CAN_UnRegisterCallback takes as parameters the HAL peripheral handle,
and the Callback ID.
This function allows to reset following callbacks:
(+) TxMailbox0CompleteCallback : Tx Mailbox 0 Complete Callback.
(+) TxMailbox1CompleteCallback : Tx Mailbox 1 Complete Callback.
(+) TxMailbox2CompleteCallback : Tx Mailbox 2 Complete Callback.
(+) TxMailbox0AbortCallback : Tx Mailbox 0 Abort Callback.
(+) TxMailbox1AbortCallback : Tx Mailbox 1 Abort Callback.
(+) TxMailbox2AbortCallback : Tx Mailbox 2 Abort Callback.
(+) RxFifo0MsgPendingCallback : Rx Fifo 0 Message Pending Callback.
(+) RxFifo0FullCallback : Rx Fifo 0 Full Callback.
(+) RxFifo1MsgPendingCallback : Rx Fifo 1 Message Pending Callback.
(+) RxFifo1FullCallback : Rx Fifo 1 Full Callback.
(+) SleepCallback : Sleep Callback.
(+) WakeUpFromRxMsgCallback : Wake Up From Rx Message Callback.
(+) ErrorCallback : Error Callback.
(+) MspInitCallback : CAN MspInit.
(+) MspDeInitCallback : CAN MspDeInit.
By default, after the @ref HAL_CAN_Init() and when the state is HAL_CAN_STATE_RESET,
all callbacks are set to the corresponding weak functions:
example @ref HAL_CAN_ErrorCallback().
Exception done for MspInit and MspDeInit functions that are
reset to the legacy weak function in the @ref HAL_CAN_Init()/ @ref HAL_CAN_DeInit() only when
these callbacks are null (not registered beforehand).
if not, MspInit or MspDeInit are not null, the @ref HAL_CAN_Init()/ @ref HAL_CAN_DeInit()
keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
Callbacks can be registered/unregistered in HAL_CAN_STATE_READY state only.
Exception done MspInit/MspDeInit that can be registered/unregistered
in HAL_CAN_STATE_READY or HAL_CAN_STATE_RESET state,
thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
In that case first register the MspInit/MspDeInit user callbacks
using @ref HAL_CAN_RegisterCallback() before calling @ref HAL_CAN_DeInit()
or @ref HAL_CAN_Init() function.
When The compilation define USE_HAL_CAN_REGISTER_CALLBACKS is set to 0 or
not defined, the callback registration feature is not available and all callbacks
are set to the corresponding weak functions.
- Attention:
© COPYRIGHT(c) 2017 STMicroelectronics
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of STMicroelectronics nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Definition in file stm32l4xx_hal_can.c.