Create release.yml
[betaflight.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_fdcan.c
blob35b51b6a8cdcfffc1bf79f75fa96f7f88a1bfb1e
1 /**
2 ******************************************************************************
3 * @file stm32h7xx_hal_fdcan.c
4 * @author MCD Application Team
5 * @brief FDCAN HAL module driver.
6 * This file provides firmware functions to manage the following
7 * functionalities of the Flexible DataRate Controller Area Network
8 * (FDCAN) peripheral:
9 * + Initialization and de-initialization functions
10 * + IO operation functions
11 * + Peripheral Configuration and Control functions
12 * + Peripheral State and Error functions
14 @verbatim
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
18 [..]
19 (#) Initialize the FDCAN peripheral using HAL_FDCAN_Init function.
21 (#) If needed , configure the reception filters and optional features using
22 the following configuration functions:
23 (++) HAL_FDCAN_ConfigClockCalibration
24 (++) HAL_FDCAN_ConfigFilter
25 (++) HAL_FDCAN_ConfigGlobalFilter
26 (++) HAL_FDCAN_ConfigExtendedIdMask
27 (++) HAL_FDCAN_ConfigRxFifoOverwrite
28 (++) HAL_FDCAN_ConfigFifoWatermark
29 (++) HAL_FDCAN_ConfigRamWatchdog
30 (++) HAL_FDCAN_ConfigTimestampCounter
31 (++) HAL_FDCAN_EnableTimestampCounter
32 (++) HAL_FDCAN_DisableTimestampCounter
33 (++) HAL_FDCAN_ConfigTimeoutCounter
34 (++) HAL_FDCAN_EnableTimeoutCounter
35 (++) HAL_FDCAN_DisableTimeoutCounter
36 (++) HAL_FDCAN_ConfigTxDelayCompensation
37 (++) HAL_FDCAN_EnableTxDelayCompensation
38 (++) HAL_FDCAN_DisableTxDelayCompensation
39 (++) HAL_FDCAN_EnableISOMode
40 (++) HAL_FDCAN_DisableISOMode
41 (++) HAL_FDCAN_EnableEdgeFiltering
42 (++) HAL_FDCAN_DisableEdgeFiltering
43 (++) HAL_FDCAN_TT_ConfigOperation
44 (++) HAL_FDCAN_TT_ConfigReferenceMessage
45 (++) HAL_FDCAN_TT_ConfigTrigger
47 (#) Start the FDCAN module using HAL_FDCAN_Start function. At this level
48 the node is active on the bus: it can send and receive messages.
50 (#) The following Tx control functions can only be called when the FDCAN
51 module is started:
52 (++) HAL_FDCAN_AddMessageToTxFifoQ
53 (++) HAL_FDCAN_EnableTxBufferRequest
54 (++) HAL_FDCAN_AbortTxRequest
56 (#) After having submitted a Tx request in Tx Fifo or Queue, it is possible to
57 get Tx buffer location used to place the Tx request thanks to
58 HAL_FDCAN_GetLatestTxFifoQRequestBuffer API.
59 It is then possible to abort later on the corresponding Tx Request using
60 HAL_FDCAN_AbortTxRequest API.
62 (#) When a message is received into the FDCAN message RAM, it can be
63 retrieved using the HAL_FDCAN_GetRxMessage function.
65 (#) Calling the HAL_FDCAN_Stop function stops the FDCAN module by entering
66 it to initialization mode and re-enabling access to configuration
67 registers through the configuration functions listed here above.
69 (#) All other control functions can be called any time after initialization
70 phase, no matter if the FDCAN module is started or stoped.
72 *** Polling mode operation ***
73 ==============================
75 [..]
76 (#) Reception and transmission states can be monitored via the following
77 functions:
78 (++) HAL_FDCAN_IsRxBufferMessageAvailable
79 (++) HAL_FDCAN_IsTxBufferMessagePending
80 (++) HAL_FDCAN_GetRxFifoFillLevel
81 (++) HAL_FDCAN_GetTxFifoFreeLevel
83 *** Interrupt mode operation ***
84 ================================
85 [..]
86 (#) There are two interrupt lines: line 0 and 1.
87 By default, all interrupts are assigned to line 0. Interrupt lines
88 can be configured using HAL_FDCAN_ConfigInterruptLines function.
90 (#) Notifications are activated using HAL_FDCAN_ActivateNotification
91 function. Then, the process can be controlled through one of the
92 available user callbacks: HAL_FDCAN_xxxCallback.
94 *** Callback registration ***
95 =============================================
97 The compilation define USE_HAL_FDCAN_REGISTER_CALLBACKS when set to 1
98 allows the user to configure dynamically the driver callbacks.
99 Use Function @ref HAL_FDCAN_RegisterCallback() or HAL_FDCAN_RegisterXXXCallback()
100 to register an interrupt callback.
102 Function @ref HAL_FDCAN_RegisterCallback() allows to register following callbacks:
103 (+) TxFifoEmptyCallback : Tx Fifo Empty Callback.
104 (+) RxBufferNewMessageCallback : Rx Buffer New Message Callback.
105 (+) HighPriorityMessageCallback : High Priority Message Callback.
106 (+) TimestampWraparoundCallback : Timestamp Wraparound Callback.
107 (+) TimeoutOccurredCallback : Timeout Occurred Callback.
108 (+) ErrorCallback : Error Callback.
109 (+) MspInitCallback : FDCAN MspInit.
110 (+) MspDeInitCallback : FDCAN MspDeInit.
111 This function takes as parameters the HAL peripheral handle, the Callback ID
112 and a pointer to the user callback function.
114 For specific callbacks ClockCalibrationCallback, TxEventFifoCallback, RxFifo0Callback, RxFifo1Callback,
115 TxBufferCompleteCallback, TxBufferAbortCallback, ErrorStatusCallback, TT_ScheduleSyncCallback, TT_TimeMarkCallback,
116 TT_StopWatchCallback and TT_GlobalTimeCallback, use dedicated register callbacks :
117 respectively @ref HAL_FDCAN_RegisterClockCalibrationCallback(), @ref HAL_FDCAN_RegisterTxEventFifoCallback(),
118 @ref HAL_FDCAN_RegisterRxFifo0Callback(), @ref HAL_FDCAN_RegisterRxFifo1Callback(),
119 @ref HAL_FDCAN_RegisterTxBufferCompleCallback(), @ref HAL_FDCAN_RegisterTxBufferAbortCallback(),
120 @ref HAL_FDCAN_RegisterErrorStatusCallback(), @ref HAL_FDCAN_TT_RegisterScheduleSyncCallback(),
121 @ref HAL_FDCAN_TT_RegisterTimeMarkCallback(), @ref HAL_FDCAN_TT_RegisterStopWatchCallback() and
122 @ref HAL_FDCAN_TT_RegisterGlobalTimeCallback().
124 Use function @ref HAL_FDCAN_UnRegisterCallback() to reset a callback to the default
125 weak function.
126 @ref HAL_FDCAN_UnRegisterCallback takes as parameters the HAL peripheral handle,
127 and the Callback ID.
128 This function allows to reset following callbacks:
129 (+) TxFifoEmptyCallback : Tx Fifo Empty Callback.
130 (+) RxBufferNewMessageCallback : Rx Buffer New Message Callback.
131 (+) HighPriorityMessageCallback : High Priority Message Callback.
132 (+) TimestampWraparoundCallback : Timestamp Wraparound Callback.
133 (+) TimeoutOccurredCallback : Timeout Occurred Callback.
134 (+) ErrorCallback : Error Callback.
135 (+) MspInitCallback : FDCAN MspInit.
136 (+) MspDeInitCallback : FDCAN MspDeInit.
138 For specific callbacks ClockCalibrationCallback, TxEventFifoCallback, RxFifo0Callback,
139 RxFifo1Callback, TxBufferCompleteCallback, TxBufferAbortCallback, TT_ScheduleSyncCallback,
140 TT_TimeMarkCallback, TT_StopWatchCallback and TT_GlobalTimeCallback, use dedicated
141 register callbacks : respectively @ref HAL_FDCAN_UnRegisterClockCalibrationCallback(),
142 @ref HAL_FDCAN_UnRegisterTxEventFifoCallback(), @ref HAL_FDCAN_UnRegisterRxFifo0Callback(),
143 @ref HAL_FDCAN_UnRegisterRxFifo1Callback(), @ref HAL_FDCAN_UnRegisterTxBufferCompleCallback(),
144 @ref HAL_FDCAN_UnRegisterTxBufferAbortCallback(), @ref HAL_FDCAN_UnRegisterErrorStatusCallback(),
145 @ref HAL_FDCAN_TT_UnRegisterScheduleSyncCallback(), @ref HAL_FDCAN_TT_UnRegisterTimeMarkCallback(),
146 @ref HAL_FDCAN_TT_UnRegisterStopWatchCallback() and @ref HAL_FDCAN_TT_UnRegisterGlobalTimeCallback().
148 By default, after the @ref HAL_FDCAN_Init() and when the state is HAL_FDCAN_STATE_RESET,
149 all callbacks are set to the corresponding weak functions:
150 examples @ref HAL_FDCAN_ErrorCallback().
151 Exception done for MspInit and MspDeInit functions that are
152 reset to the legacy weak function in the @ref HAL_FDCAN_Init()/ @ref HAL_FDCAN_DeInit() only when
153 these callbacks are null (not registered beforehand).
154 if not, MspInit or MspDeInit are not null, the @ref HAL_FDCAN_Init()/ @ref HAL_FDCAN_DeInit()
155 keep and use the user MspInit/MspDeInit callbacks (registered beforehand)
157 Callbacks can be registered/unregistered in HAL_FDCAN_STATE_READY state only.
158 Exception done MspInit/MspDeInit that can be registered/unregistered
159 in HAL_FDCAN_STATE_READY or HAL_FDCAN_STATE_RESET state,
160 thus registered (user) MspInit/DeInit callbacks can be used during the Init/DeInit.
161 In that case first register the MspInit/MspDeInit user callbacks
162 using @ref HAL_FDCAN_RegisterCallback() before calling @ref HAL_FDCAN_DeInit()
163 or @ref HAL_FDCAN_Init() function.
165 When The compilation define USE_HAL_FDCAN_REGISTER_CALLBACKS is set to 0 or
166 not defined, the callback registration feature is not available and all callbacks
167 are set to the corresponding weak functions.
169 @endverbatim
171 ******************************************************************************
172 * @attention
174 * <h2><center>&copy; Copyright (c) 2017 STMicroelectronics.
175 * All rights reserved.</center></h2>
177 * This software component is licensed by ST under BSD 3-Clause license,
178 * the "License"; You may not use this file except in compliance with the
179 * License. You may obtain a copy of the License at:
180 * opensource.org/licenses/BSD-3-Clause
182 ******************************************************************************
185 /* Includes ------------------------------------------------------------------*/
186 #include "stm32h7xx_hal.h"
188 #if defined(FDCAN1)
190 /** @addtogroup STM32H7xx_HAL_Driver
191 * @{
194 /** @defgroup FDCAN FDCAN
195 * @brief FDCAN HAL module driver
196 * @{
199 #ifdef HAL_FDCAN_MODULE_ENABLED
201 /* Private typedef -----------------------------------------------------------*/
202 /* Private define ------------------------------------------------------------*/
203 /** @addtogroup FDCAN_Private_Constants
204 * @{
206 #define FDCAN_TIMEOUT_VALUE 10U
207 #define FDCAN_TIMEOUT_COUNT 50U
209 #define FDCAN_TX_EVENT_FIFO_MASK (FDCAN_IR_TEFL | FDCAN_IR_TEFF | FDCAN_IR_TEFW | FDCAN_IR_TEFN)
210 #define FDCAN_RX_FIFO0_MASK (FDCAN_IR_RF0L | FDCAN_IR_RF0F | FDCAN_IR_RF0W | FDCAN_IR_RF0N)
211 #define FDCAN_RX_FIFO1_MASK (FDCAN_IR_RF1L | FDCAN_IR_RF1F | FDCAN_IR_RF1W | FDCAN_IR_RF1N)
212 #define FDCAN_ERROR_MASK (FDCAN_IR_ELO | FDCAN_IR_WDI | FDCAN_IR_PEA | FDCAN_IR_PED | FDCAN_IR_ARA)
213 #define FDCAN_ERROR_STATUS_MASK (FDCAN_IR_EP | FDCAN_IR_EW | FDCAN_IR_BO)
214 #define FDCAN_TT_SCHEDULE_SYNC_MASK (FDCAN_TTIR_SBC | FDCAN_TTIR_SMC | FDCAN_TTIR_CSM | FDCAN_TTIR_SOG)
215 #define FDCAN_TT_TIME_MARK_MASK (FDCAN_TTIR_RTMI | FDCAN_TTIR_TTMI)
216 #define FDCAN_TT_GLOBAL_TIME_MASK (FDCAN_TTIR_GTW | FDCAN_TTIR_GTD)
217 #define FDCAN_TT_DISTURBING_ERROR_MASK (FDCAN_TTIR_GTE | FDCAN_TTIR_TXU | FDCAN_TTIR_TXO | \
218 FDCAN_TTIR_SE1 | FDCAN_TTIR_SE2 | FDCAN_TTIR_ELC)
219 #define FDCAN_TT_FATAL_ERROR_MASK (FDCAN_TTIR_IWT | FDCAN_TTIR_WT | FDCAN_TTIR_AW | FDCAN_TTIR_CER)
221 #define FDCAN_ELEMENT_MASK_STDID ((uint32_t)0x1FFC0000U) /* Standard Identifier */
222 #define FDCAN_ELEMENT_MASK_EXTID ((uint32_t)0x1FFFFFFFU) /* Extended Identifier */
223 #define FDCAN_ELEMENT_MASK_RTR ((uint32_t)0x20000000U) /* Remote Transmission Request */
224 #define FDCAN_ELEMENT_MASK_XTD ((uint32_t)0x40000000U) /* Extended Identifier */
225 #define FDCAN_ELEMENT_MASK_ESI ((uint32_t)0x80000000U) /* Error State Indicator */
226 #define FDCAN_ELEMENT_MASK_TS ((uint32_t)0x0000FFFFU) /* Timestamp */
227 #define FDCAN_ELEMENT_MASK_DLC ((uint32_t)0x000F0000U) /* Data Length Code */
228 #define FDCAN_ELEMENT_MASK_BRS ((uint32_t)0x00100000U) /* Bit Rate Switch */
229 #define FDCAN_ELEMENT_MASK_FDF ((uint32_t)0x00200000U) /* FD Format */
230 #define FDCAN_ELEMENT_MASK_EFC ((uint32_t)0x00800000U) /* Event FIFO Control */
231 #define FDCAN_ELEMENT_MASK_MM ((uint32_t)0xFF000000U) /* Message Marker */
232 #define FDCAN_ELEMENT_MASK_FIDX ((uint32_t)0x7F000000U) /* Filter Index */
233 #define FDCAN_ELEMENT_MASK_ANMF ((uint32_t)0x80000000U) /* Accepted Non-matching Frame */
234 #define FDCAN_ELEMENT_MASK_ET ((uint32_t)0x00C00000U) /* Event type */
236 #define FDCAN_MESSAGE_RAM_SIZE 0x2800U
237 #define FDCAN_MESSAGE_RAM_END_ADDRESS (SRAMCAN_BASE + FDCAN_MESSAGE_RAM_SIZE - 0x4U) /* The Message RAM has a width of 4 Bytes */
240 * @}
243 /* Private macro -------------------------------------------------------------*/
244 /* Private variables ---------------------------------------------------------*/
245 static const uint8_t DLCtoBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
247 /* Private function prototypes -----------------------------------------------*/
248 /** @addtogroup FDCAN_Private_Functions_Prototypes
249 * @{
251 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan);
252 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex);
254 * @}
257 /* Exported functions --------------------------------------------------------*/
258 /** @defgroup FDCAN_Exported_Functions FDCAN Exported Functions
259 * @{
262 /** @defgroup FDCAN_Exported_Functions_Group1 Initialization and de-initialization functions
263 * @brief Initialization and Configuration functions
265 @verbatim
266 ==============================================================================
267 ##### Initialization and de-initialization functions #####
268 ==============================================================================
269 [..] This section provides functions allowing to:
270 (+) Initialize and configure the FDCAN.
271 (+) De-initialize the FDCAN.
272 (+) Enter FDCAN peripheral in power down mode.
273 (+) Exit power down mode.
274 (+) Register callbacks.
275 (+) Unregister callbacks.
277 @endverbatim
278 * @{
282 * @brief Initializes the FDCAN peripheral according to the specified
283 * parameters in the FDCAN_InitTypeDef structure.
284 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
285 * the configuration information for the specified FDCAN.
286 * @retval HAL status
288 HAL_StatusTypeDef HAL_FDCAN_Init(FDCAN_HandleTypeDef *hfdcan)
290 uint32_t tickstart;
291 HAL_StatusTypeDef status;
292 const uint32_t CvtEltSize[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7};
294 /* Check FDCAN handle */
295 if (hfdcan == NULL)
297 return HAL_ERROR;
300 /* Check FDCAN instance */
301 if (hfdcan->Instance == FDCAN1)
303 hfdcan->ttcan = (TTCAN_TypeDef *)((uint32_t)hfdcan->Instance + 0x100U);
306 /* Check function parameters */
307 assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
308 assert_param(IS_FDCAN_FRAME_FORMAT(hfdcan->Init.FrameFormat));
309 assert_param(IS_FDCAN_MODE(hfdcan->Init.Mode));
310 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.AutoRetransmission));
311 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.TransmitPause));
312 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.ProtocolException));
313 assert_param(IS_FDCAN_NOMINAL_PRESCALER(hfdcan->Init.NominalPrescaler));
314 assert_param(IS_FDCAN_NOMINAL_SJW(hfdcan->Init.NominalSyncJumpWidth));
315 assert_param(IS_FDCAN_NOMINAL_TSEG1(hfdcan->Init.NominalTimeSeg1));
316 assert_param(IS_FDCAN_NOMINAL_TSEG2(hfdcan->Init.NominalTimeSeg2));
317 if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
319 assert_param(IS_FDCAN_DATA_PRESCALER(hfdcan->Init.DataPrescaler));
320 assert_param(IS_FDCAN_DATA_SJW(hfdcan->Init.DataSyncJumpWidth));
321 assert_param(IS_FDCAN_DATA_TSEG1(hfdcan->Init.DataTimeSeg1));
322 assert_param(IS_FDCAN_DATA_TSEG2(hfdcan->Init.DataTimeSeg2));
324 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.StdFiltersNbr, 128U));
325 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.ExtFiltersNbr, 64U));
326 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo0ElmtsNbr, 64U));
327 if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
329 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo0ElmtSize));
331 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo1ElmtsNbr, 64U));
332 if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
334 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo1ElmtSize));
336 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxBuffersNbr, 64U));
337 if (hfdcan->Init.RxBuffersNbr > 0U)
339 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxBufferSize));
341 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.TxEventsNbr, 32U));
342 assert_param(IS_FDCAN_MAX_VALUE((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr), 32U));
343 if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
345 assert_param(IS_FDCAN_TX_FIFO_QUEUE_MODE(hfdcan->Init.TxFifoQueueMode));
347 if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
349 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.TxElmtSize));
352 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
353 if (hfdcan->State == HAL_FDCAN_STATE_RESET)
355 /* Allocate lock resource and initialize it */
356 hfdcan->Lock = HAL_UNLOCKED;
358 /* Reset callbacks to legacy functions */
359 hfdcan->ClockCalibrationCallback = HAL_FDCAN_ClockCalibrationCallback; /* Legacy weak ClockCalibrationCallback */
360 hfdcan->TxEventFifoCallback = HAL_FDCAN_TxEventFifoCallback; /* Legacy weak TxEventFifoCallback */
361 hfdcan->RxFifo0Callback = HAL_FDCAN_RxFifo0Callback; /* Legacy weak RxFifo0Callback */
362 hfdcan->RxFifo1Callback = HAL_FDCAN_RxFifo1Callback; /* Legacy weak RxFifo1Callback */
363 hfdcan->TxFifoEmptyCallback = HAL_FDCAN_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
364 hfdcan->TxBufferCompleteCallback = HAL_FDCAN_TxBufferCompleteCallback; /* Legacy weak TxBufferCompleteCallback */
365 hfdcan->TxBufferAbortCallback = HAL_FDCAN_TxBufferAbortCallback; /* Legacy weak TxBufferAbortCallback */
366 hfdcan->RxBufferNewMessageCallback = HAL_FDCAN_RxBufferNewMessageCallback; /* Legacy weak RxBufferNewMessageCallback */
367 hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback; /* Legacy weak HighPriorityMessageCallback */
368 hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback; /* Legacy weak TimestampWraparoundCallback */
369 hfdcan->TimeoutOccurredCallback = HAL_FDCAN_TimeoutOccurredCallback; /* Legacy weak TimeoutOccurredCallback */
370 hfdcan->ErrorCallback = HAL_FDCAN_ErrorCallback; /* Legacy weak ErrorCallback */
371 hfdcan->ErrorStatusCallback = HAL_FDCAN_ErrorStatusCallback; /* Legacy weak ErrorStatusCallback */
372 hfdcan->TT_ScheduleSyncCallback = HAL_FDCAN_TT_ScheduleSyncCallback; /* Legacy weak TT_ScheduleSyncCallback */
373 hfdcan->TT_TimeMarkCallback = HAL_FDCAN_TT_TimeMarkCallback; /* Legacy weak TT_TimeMarkCallback */
374 hfdcan->TT_StopWatchCallback = HAL_FDCAN_TT_StopWatchCallback; /* Legacy weak TT_StopWatchCallback */
375 hfdcan->TT_GlobalTimeCallback = HAL_FDCAN_TT_GlobalTimeCallback; /* Legacy weak TT_GlobalTimeCallback */
377 if (hfdcan->MspInitCallback == NULL)
379 hfdcan->MspInitCallback = HAL_FDCAN_MspInit; /* Legacy weak MspInit */
382 /* Init the low level hardware: CLOCK, NVIC */
383 hfdcan->MspInitCallback(hfdcan);
385 #else
386 if (hfdcan->State == HAL_FDCAN_STATE_RESET)
388 /* Allocate lock resource and initialize it */
389 hfdcan->Lock = HAL_UNLOCKED;
391 /* Init the low level hardware: CLOCK, NVIC */
392 HAL_FDCAN_MspInit(hfdcan);
394 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
396 /* Exit from Sleep mode */
397 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
399 /* Get tick */
400 tickstart = HAL_GetTick();
402 /* Check Sleep mode acknowledge */
403 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
405 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
407 /* Update error code */
408 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
410 /* Change FDCAN state */
411 hfdcan->State = HAL_FDCAN_STATE_ERROR;
413 return HAL_ERROR;
417 /* Request initialisation */
418 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
420 /* Get tick */
421 tickstart = HAL_GetTick();
423 /* Wait until the INIT bit into CCCR register is set */
424 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
426 /* Check for the Timeout */
427 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
429 /* Update error code */
430 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
432 /* Change FDCAN state */
433 hfdcan->State = HAL_FDCAN_STATE_ERROR;
435 return HAL_ERROR;
439 /* Enable configuration change */
440 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
442 /* Set the no automatic retransmission */
443 if (hfdcan->Init.AutoRetransmission == ENABLE)
445 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
447 else
449 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
452 /* Set the transmit pause feature */
453 if (hfdcan->Init.TransmitPause == ENABLE)
455 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
457 else
459 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
462 /* Set the Protocol Exception Handling */
463 if (hfdcan->Init.ProtocolException == ENABLE)
465 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
467 else
469 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
472 /* Set FDCAN Frame Format */
473 MODIFY_REG(hfdcan->Instance->CCCR, FDCAN_FRAME_FD_BRS, hfdcan->Init.FrameFormat);
475 /* Reset FDCAN Operation Mode */
476 CLEAR_BIT(hfdcan->Instance->CCCR, (FDCAN_CCCR_TEST | FDCAN_CCCR_MON | FDCAN_CCCR_ASM));
477 CLEAR_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
479 /* Set FDCAN Operating Mode:
480 | Normal | Restricted | Bus | Internal | External
481 | | Operation | Monitoring | LoopBack | LoopBack
482 CCCR.TEST | 0 | 0 | 0 | 1 | 1
483 CCCR.MON | 0 | 0 | 1 | 1 | 0
484 TEST.LBCK | 0 | 0 | 0 | 1 | 1
485 CCCR.ASM | 0 | 1 | 0 | 0 | 0
487 if (hfdcan->Init.Mode == FDCAN_MODE_RESTRICTED_OPERATION)
489 /* Enable Restricted Operation mode */
490 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
492 else if (hfdcan->Init.Mode != FDCAN_MODE_NORMAL)
494 if (hfdcan->Init.Mode != FDCAN_MODE_BUS_MONITORING)
496 /* Enable write access to TEST register */
497 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TEST);
499 /* Enable LoopBack mode */
500 SET_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
502 if (hfdcan->Init.Mode == FDCAN_MODE_INTERNAL_LOOPBACK)
504 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
507 else
509 /* Enable bus monitoring mode */
510 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
513 else
515 /* Nothing to do: normal mode */
518 /* Set the nominal bit timing register */
519 hfdcan->Instance->NBTP = ((((uint32_t)hfdcan->Init.NominalSyncJumpWidth - 1U) << FDCAN_NBTP_NSJW_Pos) | \
520 (((uint32_t)hfdcan->Init.NominalTimeSeg1 - 1U) << FDCAN_NBTP_NTSEG1_Pos) | \
521 (((uint32_t)hfdcan->Init.NominalTimeSeg2 - 1U) << FDCAN_NBTP_NTSEG2_Pos) | \
522 (((uint32_t)hfdcan->Init.NominalPrescaler - 1U) << FDCAN_NBTP_NBRP_Pos));
524 /* If FD operation with BRS is selected, set the data bit timing register */
525 if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
527 hfdcan->Instance->DBTP = ((((uint32_t)hfdcan->Init.DataSyncJumpWidth - 1U) << FDCAN_DBTP_DSJW_Pos) | \
528 (((uint32_t)hfdcan->Init.DataTimeSeg1 - 1U) << FDCAN_DBTP_DTSEG1_Pos) | \
529 (((uint32_t)hfdcan->Init.DataTimeSeg2 - 1U) << FDCAN_DBTP_DTSEG2_Pos) | \
530 (((uint32_t)hfdcan->Init.DataPrescaler - 1U) << FDCAN_DBTP_DBRP_Pos));
533 if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
535 /* Select between Tx FIFO and Tx Queue operation modes */
536 SET_BIT(hfdcan->Instance->TXBC, hfdcan->Init.TxFifoQueueMode);
539 /* Configure Tx element size */
540 if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
542 MODIFY_REG(hfdcan->Instance->TXESC, FDCAN_TXESC_TBDS, CvtEltSize[hfdcan->Init.TxElmtSize]);
545 /* Configure Rx FIFO 0 element size */
546 if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
548 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F0DS, (CvtEltSize[hfdcan->Init.RxFifo0ElmtSize] << FDCAN_RXESC_F0DS_Pos));
551 /* Configure Rx FIFO 1 element size */
552 if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
554 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F1DS, (CvtEltSize[hfdcan->Init.RxFifo1ElmtSize] << FDCAN_RXESC_F1DS_Pos));
557 /* Configure Rx buffer element size */
558 if (hfdcan->Init.RxBuffersNbr > 0U)
560 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_RBDS, (CvtEltSize[hfdcan->Init.RxBufferSize] << FDCAN_RXESC_RBDS_Pos));
563 /* By default operation mode is set to Event-driven communication.
564 If Time-triggered communication is needed, user should call the
565 HAL_FDCAN_TT_ConfigOperation function just after the HAL_FDCAN_Init */
566 if (hfdcan->Instance == FDCAN1)
568 CLEAR_BIT(hfdcan->ttcan->TTOCF, FDCAN_TTOCF_OM);
571 /* Initialize the Latest Tx FIFO/Queue request buffer index */
572 hfdcan->LatestTxFifoQRequest = 0U;
574 /* Initialize the error code */
575 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
577 /* Initialize the FDCAN state */
578 hfdcan->State = HAL_FDCAN_STATE_READY;
580 /* Calculate each RAM block address */
581 status = FDCAN_CalcultateRamBlockAddresses(hfdcan);
583 /* Return function status */
584 return status;
588 * @brief Deinitializes the FDCAN peripheral registers to their default reset values.
589 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
590 * the configuration information for the specified FDCAN.
591 * @retval HAL status
593 HAL_StatusTypeDef HAL_FDCAN_DeInit(FDCAN_HandleTypeDef *hfdcan)
595 /* Check FDCAN handle */
596 if (hfdcan == NULL)
598 return HAL_ERROR;
601 /* Check function parameters */
602 assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
604 /* Stop the FDCAN module: return value is voluntary ignored */
605 (void)HAL_FDCAN_Stop(hfdcan);
607 /* Disable Interrupt lines */
608 CLEAR_BIT(hfdcan->Instance->ILE, (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1));
610 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
611 if (hfdcan->MspDeInitCallback == NULL)
613 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit; /* Legacy weak MspDeInit */
616 /* DeInit the low level hardware: CLOCK, NVIC */
617 hfdcan->MspDeInitCallback(hfdcan);
618 #else
619 /* DeInit the low level hardware: CLOCK, NVIC */
620 HAL_FDCAN_MspDeInit(hfdcan);
621 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
623 /* Reset the FDCAN ErrorCode */
624 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
626 /* Change FDCAN state */
627 hfdcan->State = HAL_FDCAN_STATE_RESET;
629 /* Return function status */
630 return HAL_OK;
634 * @brief Initializes the FDCAN MSP.
635 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
636 * the configuration information for the specified FDCAN.
637 * @retval None
639 __weak void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *hfdcan)
641 /* Prevent unused argument(s) compilation warning */
642 UNUSED(hfdcan);
643 /* NOTE : This function Should not be modified, when the callback is needed,
644 the HAL_FDCAN_MspInit could be implemented in the user file
649 * @brief DeInitializes the FDCAN MSP.
650 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
651 * the configuration information for the specified FDCAN.
652 * @retval None
654 __weak void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *hfdcan)
656 /* Prevent unused argument(s) compilation warning */
657 UNUSED(hfdcan);
658 /* NOTE : This function Should not be modified, when the callback is needed,
659 the HAL_FDCAN_MspDeInit could be implemented in the user file
664 * @brief Enter FDCAN peripheral in sleep mode.
665 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
666 * the configuration information for the specified FDCAN.
667 * @retval HAL status
669 HAL_StatusTypeDef HAL_FDCAN_EnterPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
671 uint32_t tickstart;
673 /* Request clock stop */
674 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
676 /* Get tick */
677 tickstart = HAL_GetTick();
679 /* Wait until FDCAN is ready for power down */
680 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == 0U)
682 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
684 /* Update error code */
685 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
687 /* Change FDCAN state */
688 hfdcan->State = HAL_FDCAN_STATE_ERROR;
690 return HAL_ERROR;
694 /* Return function status */
695 return HAL_OK;
699 * @brief Exit power down mode.
700 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
701 * the configuration information for the specified FDCAN.
702 * @retval HAL status
704 HAL_StatusTypeDef HAL_FDCAN_ExitPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
706 uint32_t tickstart;
708 /* Reset clock stop request */
709 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
711 /* Get tick */
712 tickstart = HAL_GetTick();
714 /* Wait until FDCAN exits sleep mode */
715 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
717 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
719 /* Update error code */
720 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
722 /* Change FDCAN state */
723 hfdcan->State = HAL_FDCAN_STATE_ERROR;
725 return HAL_ERROR;
729 /* Enter normal operation */
730 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
732 /* Return function status */
733 return HAL_OK;
736 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
738 * @brief Register a FDCAN CallBack.
739 * To be used instead of the weak predefined callback
740 * @param hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
741 * the configuration information for FDCAN module
742 * @param CallbackID ID of the callback to be registered
743 * This parameter can be one of the following values:
744 * @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
745 * @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
746 * @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
747 * @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
748 * @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
749 * @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
750 * @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
751 * @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
752 * @param pCallback pointer to the Callback function
753 * @retval HAL status
755 HAL_StatusTypeDef HAL_FDCAN_RegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID, void (* pCallback)(FDCAN_HandleTypeDef *_hFDCAN))
757 HAL_StatusTypeDef status = HAL_OK;
759 if (pCallback == NULL)
761 /* Update the error code */
762 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
764 return HAL_ERROR;
767 if (hfdcan->State == HAL_FDCAN_STATE_READY)
769 switch (CallbackID)
771 case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
772 hfdcan->TxFifoEmptyCallback = pCallback;
773 break;
775 case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
776 hfdcan->RxBufferNewMessageCallback = pCallback;
777 break;
779 case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
780 hfdcan->HighPriorityMessageCallback = pCallback;
781 break;
783 case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
784 hfdcan->TimestampWraparoundCallback = pCallback;
785 break;
787 case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
788 hfdcan->TimeoutOccurredCallback = pCallback;
789 break;
791 case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
792 hfdcan->ErrorCallback = pCallback;
793 break;
795 case HAL_FDCAN_MSPINIT_CB_ID :
796 hfdcan->MspInitCallback = pCallback;
797 break;
799 case HAL_FDCAN_MSPDEINIT_CB_ID :
800 hfdcan->MspDeInitCallback = pCallback;
801 break;
803 default :
804 /* Update the error code */
805 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
807 /* Return error status */
808 status = HAL_ERROR;
809 break;
812 else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
814 switch (CallbackID)
816 case HAL_FDCAN_MSPINIT_CB_ID :
817 hfdcan->MspInitCallback = pCallback;
818 break;
820 case HAL_FDCAN_MSPDEINIT_CB_ID :
821 hfdcan->MspDeInitCallback = pCallback;
822 break;
824 default :
825 /* Update the error code */
826 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
828 /* Return error status */
829 status = HAL_ERROR;
830 break;
833 else
835 /* Update the error code */
836 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
838 /* Return error status */
839 status = HAL_ERROR;
842 return status;
846 * @brief Unregister a FDCAN CallBack.
847 * FDCAN callback is redirected to the weak predefined callback
848 * @param hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
849 * the configuration information for FDCAN module
850 * @param CallbackID ID of the callback to be unregistered
851 * This parameter can be one of the following values:
852 * @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
853 * @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
854 * @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
855 * @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
856 * @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
857 * @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
858 * @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
859 * @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
860 * @retval HAL status
862 HAL_StatusTypeDef HAL_FDCAN_UnRegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID)
864 HAL_StatusTypeDef status = HAL_OK;
866 if (hfdcan->State == HAL_FDCAN_STATE_READY)
868 switch (CallbackID)
870 case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
871 hfdcan->TxFifoEmptyCallback = HAL_FDCAN_TxFifoEmptyCallback;
872 break;
874 case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
875 hfdcan->RxBufferNewMessageCallback = HAL_FDCAN_RxBufferNewMessageCallback;
876 break;
878 case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
879 hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback;
880 break;
882 case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
883 hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback;
884 break;
886 case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
887 hfdcan->TimeoutOccurredCallback = HAL_FDCAN_TimeoutOccurredCallback;
888 break;
890 case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
891 hfdcan->ErrorCallback = HAL_FDCAN_ErrorCallback;
892 break;
894 case HAL_FDCAN_MSPINIT_CB_ID :
895 hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
896 break;
898 case HAL_FDCAN_MSPDEINIT_CB_ID :
899 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
900 break;
902 default :
903 /* Update the error code */
904 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
906 /* Return error status */
907 status = HAL_ERROR;
908 break;
911 else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
913 switch (CallbackID)
915 case HAL_FDCAN_MSPINIT_CB_ID :
916 hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
917 break;
919 case HAL_FDCAN_MSPDEINIT_CB_ID :
920 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
921 break;
923 default :
924 /* Update the error code */
925 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
927 /* Return error status */
928 status = HAL_ERROR;
929 break;
932 else
934 /* Update the error code */
935 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
937 /* Return error status */
938 status = HAL_ERROR;
941 return status;
945 * @brief Register Clock Calibration FDCAN Callback
946 * To be used instead of the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
947 * @param hfdcan FDCAN handle
948 * @param pCallback pointer to the Clock Calibration Callback function
949 * @retval HAL status
951 HAL_StatusTypeDef HAL_FDCAN_RegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ClockCalibrationCallbackTypeDef pCallback)
953 HAL_StatusTypeDef status = HAL_OK;
955 if (pCallback == NULL)
957 /* Update the error code */
958 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
959 return HAL_ERROR;
962 if (hfdcan->State == HAL_FDCAN_STATE_READY)
964 hfdcan->ClockCalibrationCallback = pCallback;
966 else
968 /* Update the error code */
969 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
971 /* Return error status */
972 status = HAL_ERROR;
975 return status;
979 * @brief UnRegister the Clock Calibration FDCAN Callback
980 * Clock Calibration FDCAN Callback is redirected to the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
981 * @param hfdcan FDCAN handle
982 * @retval HAL status
984 HAL_StatusTypeDef HAL_FDCAN_UnRegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan)
986 HAL_StatusTypeDef status = HAL_OK;
988 if (hfdcan->State == HAL_FDCAN_STATE_READY)
990 hfdcan->ClockCalibrationCallback = HAL_FDCAN_ClockCalibrationCallback; /* Legacy weak ClockCalibrationCallback */
992 else
994 /* Update the error code */
995 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
997 /* Return error status */
998 status = HAL_ERROR;
1001 return status;
1005 * @brief Register Tx Event Fifo FDCAN Callback
1006 * To be used instead of the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
1007 * @param hfdcan FDCAN handle
1008 * @param pCallback pointer to the Tx Event Fifo Callback function
1009 * @retval HAL status
1011 HAL_StatusTypeDef HAL_FDCAN_RegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxEventFifoCallbackTypeDef pCallback)
1013 HAL_StatusTypeDef status = HAL_OK;
1015 if (pCallback == NULL)
1017 /* Update the error code */
1018 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1019 return HAL_ERROR;
1022 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1024 hfdcan->TxEventFifoCallback = pCallback;
1026 else
1028 /* Update the error code */
1029 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1031 /* Return error status */
1032 status = HAL_ERROR;
1035 return status;
1039 * @brief UnRegister the Tx Event Fifo FDCAN Callback
1040 * Tx Event Fifo FDCAN Callback is redirected to the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
1041 * @param hfdcan FDCAN handle
1042 * @retval HAL status
1044 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan)
1046 HAL_StatusTypeDef status = HAL_OK;
1048 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1050 hfdcan->TxEventFifoCallback = HAL_FDCAN_TxEventFifoCallback; /* Legacy weak TxEventFifoCallback */
1052 else
1054 /* Update the error code */
1055 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1057 /* Return error status */
1058 status = HAL_ERROR;
1061 return status;
1065 * @brief Register Rx Fifo 0 FDCAN Callback
1066 * To be used instead of the weak HAL_FDCAN_RxFifo0Callback() predefined callback
1067 * @param hfdcan FDCAN handle
1068 * @param pCallback pointer to the Rx Fifo 0 Callback function
1069 * @retval HAL status
1071 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo0CallbackTypeDef pCallback)
1073 HAL_StatusTypeDef status = HAL_OK;
1075 if (pCallback == NULL)
1077 /* Update the error code */
1078 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1079 return HAL_ERROR;
1082 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1084 hfdcan->RxFifo0Callback = pCallback;
1086 else
1088 /* Update the error code */
1089 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1091 /* Return error status */
1092 status = HAL_ERROR;
1095 return status;
1099 * @brief UnRegister the Rx Fifo 0 FDCAN Callback
1100 * Rx Fifo 0 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo0Callback() predefined callback
1101 * @param hfdcan FDCAN handle
1102 * @retval HAL status
1104 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan)
1106 HAL_StatusTypeDef status = HAL_OK;
1108 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1110 hfdcan->RxFifo0Callback = HAL_FDCAN_RxFifo0Callback; /* Legacy weak RxFifo0Callback */
1112 else
1114 /* Update the error code */
1115 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1117 /* Return error status */
1118 status = HAL_ERROR;
1121 return status;
1125 * @brief Register Rx Fifo 1 FDCAN Callback
1126 * To be used instead of the weak HAL_FDCAN_RxFifo1Callback() predefined callback
1127 * @param hfdcan FDCAN handle
1128 * @param pCallback pointer to the Rx Fifo 1 Callback function
1129 * @retval HAL status
1131 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo1CallbackTypeDef pCallback)
1133 HAL_StatusTypeDef status = HAL_OK;
1135 if (pCallback == NULL)
1137 /* Update the error code */
1138 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1139 return HAL_ERROR;
1142 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1144 hfdcan->RxFifo1Callback = pCallback;
1146 else
1148 /* Update the error code */
1149 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1151 /* Return error status */
1152 status = HAL_ERROR;
1155 return status;
1159 * @brief UnRegister the Rx Fifo 1 FDCAN Callback
1160 * Rx Fifo 1 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo1Callback() predefined callback
1161 * @param hfdcan FDCAN handle
1162 * @retval HAL status
1164 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan)
1166 HAL_StatusTypeDef status = HAL_OK;
1168 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1170 hfdcan->RxFifo1Callback = HAL_FDCAN_RxFifo1Callback; /* Legacy weak RxFifo1Callback */
1172 else
1174 /* Update the error code */
1175 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1177 /* Return error status */
1178 status = HAL_ERROR;
1181 return status;
1185 * @brief Register Tx Buffer Complete FDCAN Callback
1186 * To be used instead of the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
1187 * @param hfdcan FDCAN handle
1188 * @param pCallback pointer to the Tx Buffer Complete Callback function
1189 * @retval HAL status
1191 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferCompleteCallbackTypeDef pCallback)
1193 HAL_StatusTypeDef status = HAL_OK;
1195 if (pCallback == NULL)
1197 /* Update the error code */
1198 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1199 return HAL_ERROR;
1202 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1204 hfdcan->TxBufferCompleteCallback = pCallback;
1206 else
1208 /* Update the error code */
1209 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1211 /* Return error status */
1212 status = HAL_ERROR;
1215 return status;
1219 * @brief UnRegister the Tx Buffer Complete FDCAN Callback
1220 * Tx Buffer Complete FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
1221 * @param hfdcan FDCAN handle
1222 * @retval HAL status
1224 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan)
1226 HAL_StatusTypeDef status = HAL_OK;
1228 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1230 hfdcan->TxBufferCompleteCallback = HAL_FDCAN_TxBufferCompleteCallback; /* Legacy weak TxBufferCompleteCallback */
1232 else
1234 /* Update the error code */
1235 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1237 /* Return error status */
1238 status = HAL_ERROR;
1241 return status;
1245 * @brief Register Tx Buffer Abort FDCAN Callback
1246 * To be used instead of the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
1247 * @param hfdcan FDCAN handle
1248 * @param pCallback pointer to the Tx Buffer Abort Callback function
1249 * @retval HAL status
1251 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferAbortCallbackTypeDef pCallback)
1253 HAL_StatusTypeDef status = HAL_OK;
1255 if (pCallback == NULL)
1257 /* Update the error code */
1258 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1259 return HAL_ERROR;
1262 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1264 hfdcan->TxBufferAbortCallback = pCallback;
1266 else
1268 /* Update the error code */
1269 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1271 /* Return error status */
1272 status = HAL_ERROR;
1275 return status;
1279 * @brief UnRegister the Tx Buffer Abort FDCAN Callback
1280 * Tx Buffer Abort FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
1281 * @param hfdcan FDCAN handle
1282 * @retval HAL status
1284 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan)
1286 HAL_StatusTypeDef status = HAL_OK;
1288 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1290 hfdcan->TxBufferAbortCallback = HAL_FDCAN_TxBufferAbortCallback; /* Legacy weak TxBufferAbortCallback */
1292 else
1294 /* Update the error code */
1295 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1297 /* Return error status */
1298 status = HAL_ERROR;
1301 return status;
1305 * @brief Register Error Status FDCAN Callback
1306 * To be used instead of the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
1307 * @param hfdcan FDCAN handle
1308 * @param pCallback pointer to the Error Status Callback function
1309 * @retval HAL status
1311 HAL_StatusTypeDef HAL_FDCAN_RegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ErrorStatusCallbackTypeDef pCallback)
1313 HAL_StatusTypeDef status = HAL_OK;
1315 if (pCallback == NULL)
1317 /* Update the error code */
1318 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1319 return HAL_ERROR;
1322 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1324 hfdcan->ErrorStatusCallback = pCallback;
1326 else
1328 /* Update the error code */
1329 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1331 /* Return error status */
1332 status = HAL_ERROR;
1335 return status;
1339 * @brief UnRegister the Error Status FDCAN Callback
1340 * Error Status FDCAN Callback is redirected to the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
1341 * @param hfdcan FDCAN handle
1342 * @retval HAL status
1344 HAL_StatusTypeDef HAL_FDCAN_UnRegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan)
1346 HAL_StatusTypeDef status = HAL_OK;
1348 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1350 hfdcan->ErrorStatusCallback = HAL_FDCAN_ErrorStatusCallback; /* Legacy weak ErrorStatusCallback */
1352 else
1354 /* Update the error code */
1355 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1357 /* Return error status */
1358 status = HAL_ERROR;
1361 return status;
1365 * @brief Register TT Schedule Synchronization FDCAN Callback
1366 * To be used instead of the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
1367 * @param hfdcan FDCAN handle
1368 * @param pCallback pointer to the TT Schedule Synchronization Callback function
1369 * @retval HAL status
1371 HAL_StatusTypeDef HAL_FDCAN_RegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_ScheduleSyncCallbackTypeDef pCallback)
1373 HAL_StatusTypeDef status = HAL_OK;
1375 if (pCallback == NULL)
1377 /* Update the error code */
1378 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1379 return HAL_ERROR;
1382 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1384 hfdcan->TT_ScheduleSyncCallback = pCallback;
1386 else
1388 /* Update the error code */
1389 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1391 /* Return error status */
1392 status = HAL_ERROR;
1395 return status;
1399 * @brief UnRegister the TT Schedule Synchronization FDCAN Callback
1400 * TT Schedule Synchronization Callback is redirected to the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
1401 * @param hfdcan FDCAN handle
1402 * @retval HAL status
1404 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan)
1406 HAL_StatusTypeDef status = HAL_OK;
1408 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1410 hfdcan->TT_ScheduleSyncCallback = HAL_FDCAN_TT_ScheduleSyncCallback; /* Legacy weak TT_ScheduleSyncCallback */
1412 else
1414 /* Update the error code */
1415 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1417 /* Return error status */
1418 status = HAL_ERROR;
1421 return status;
1425 * @brief Register TT Time Mark FDCAN Callback
1426 * To be used instead of the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
1427 * @param hfdcan FDCAN handle
1428 * @param pCallback pointer to the TT Time Mark Callback function
1429 * @retval HAL status
1431 HAL_StatusTypeDef HAL_FDCAN_RegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_TimeMarkCallbackTypeDef pCallback)
1433 HAL_StatusTypeDef status = HAL_OK;
1435 if (pCallback == NULL)
1437 /* Update the error code */
1438 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1439 return HAL_ERROR;
1442 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1444 hfdcan->TT_TimeMarkCallback = pCallback;
1446 else
1448 /* Update the error code */
1449 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1451 /* Return error status */
1452 status = HAL_ERROR;
1455 return status;
1459 * @brief UnRegister the TT Time Mark FDCAN Callback
1460 * TT Time Mark Callback is redirected to the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
1461 * @param hfdcan FDCAN handle
1462 * @retval HAL status
1464 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan)
1466 HAL_StatusTypeDef status = HAL_OK;
1468 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1470 hfdcan->TT_TimeMarkCallback = HAL_FDCAN_TT_TimeMarkCallback; /* Legacy weak TT_TimeMarkCallback */
1472 else
1474 /* Update the error code */
1475 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1477 /* Return error status */
1478 status = HAL_ERROR;
1481 return status;
1485 * @brief Register TT Stop Watch FDCAN Callback
1486 * To be used instead of the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
1487 * @param hfdcan FDCAN handle
1488 * @param pCallback pointer to the TT Stop Watch Callback function
1489 * @retval HAL status
1491 HAL_StatusTypeDef HAL_FDCAN_RegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_StopWatchCallbackTypeDef pCallback)
1493 HAL_StatusTypeDef status = HAL_OK;
1495 if (pCallback == NULL)
1497 /* Update the error code */
1498 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1499 return HAL_ERROR;
1502 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1504 hfdcan->TT_StopWatchCallback = pCallback;
1506 else
1508 /* Update the error code */
1509 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1511 /* Return error status */
1512 status = HAL_ERROR;
1515 return status;
1519 * @brief UnRegister the TT Stop Watch FDCAN Callback
1520 * TT Stop Watch Callback is redirected to the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
1521 * @param hfdcan FDCAN handle
1522 * @retval HAL status
1524 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan)
1526 HAL_StatusTypeDef status = HAL_OK;
1528 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1530 hfdcan->TT_StopWatchCallback = HAL_FDCAN_TT_StopWatchCallback; /* Legacy weak TT_StopWatchCallback */
1532 else
1534 /* Update the error code */
1535 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1537 /* Return error status */
1538 status = HAL_ERROR;
1541 return status;
1545 * @brief Register TT Global Time FDCAN Callback
1546 * To be used instead of the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
1547 * @param hfdcan FDCAN handle
1548 * @param pCallback pointer to the TT Global Time Callback function
1549 * @retval HAL status
1551 HAL_StatusTypeDef HAL_FDCAN_RegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_GlobalTimeCallbackTypeDef pCallback)
1553 HAL_StatusTypeDef status = HAL_OK;
1555 if (pCallback == NULL)
1557 /* Update the error code */
1558 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1559 return HAL_ERROR;
1562 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1564 hfdcan->TT_GlobalTimeCallback = pCallback;
1566 else
1568 /* Update the error code */
1569 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1571 /* Return error status */
1572 status = HAL_ERROR;
1575 return status;
1579 * @brief UnRegister the TT Global Time FDCAN Callback
1580 * TT Global Time Callback is redirected to the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
1581 * @param hfdcan FDCAN handle
1582 * @retval HAL status
1584 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan)
1586 HAL_StatusTypeDef status = HAL_OK;
1588 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1590 hfdcan->TT_GlobalTimeCallback = HAL_FDCAN_TT_GlobalTimeCallback; /* Legacy weak TT_GlobalTimeCallback */
1592 else
1594 /* Update the error code */
1595 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1597 /* Return error status */
1598 status = HAL_ERROR;
1601 return status;
1604 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
1607 * @}
1610 /** @defgroup FDCAN_Exported_Functions_Group2 Configuration functions
1611 * @brief FDCAN Configuration functions.
1613 @verbatim
1614 ==============================================================================
1615 ##### Configuration functions #####
1616 ==============================================================================
1617 [..] This section provides functions allowing to:
1618 (+) HAL_FDCAN_ConfigClockCalibration : Configure the FDCAN clock calibration unit
1619 (+) HAL_FDCAN_GetClockCalibrationState : Get the clock calibration state
1620 (+) HAL_FDCAN_ResetClockCalibrationState : Reset the clock calibration state
1621 (+) HAL_FDCAN_GetClockCalibrationCounter : Get the clock calibration counters values
1622 (+) HAL_FDCAN_ConfigFilter : Configure the FDCAN reception filters
1623 (+) HAL_FDCAN_ConfigGlobalFilter : Configure the FDCAN global filter
1624 (+) HAL_FDCAN_ConfigExtendedIdMask : Configure the extended ID mask
1625 (+) HAL_FDCAN_ConfigRxFifoOverwrite : Configure the Rx FIFO operation mode
1626 (+) HAL_FDCAN_ConfigFifoWatermark : Configure the FIFO watermark
1627 (+) HAL_FDCAN_ConfigRamWatchdog : Configure the RAM watchdog
1628 (+) HAL_FDCAN_ConfigTimestampCounter : Configure the timestamp counter
1629 (+) HAL_FDCAN_EnableTimestampCounter : Enable the timestamp counter
1630 (+) HAL_FDCAN_DisableTimestampCounter : Disable the timestamp counter
1631 (+) HAL_FDCAN_GetTimestampCounter : Get the timestamp counter value
1632 (+) HAL_FDCAN_ResetTimestampCounter : Reset the timestamp counter to zero
1633 (+) HAL_FDCAN_ConfigTimeoutCounter : Configure the timeout counter
1634 (+) HAL_FDCAN_EnableTimeoutCounter : Enable the timeout counter
1635 (+) HAL_FDCAN_DisableTimeoutCounter : Disable the timeout counter
1636 (+) HAL_FDCAN_GetTimeoutCounter : Get the timeout counter value
1637 (+) HAL_FDCAN_ResetTimeoutCounter : Reset the timeout counter to its start value
1638 (+) HAL_FDCAN_ConfigTxDelayCompensation : Configure the transmitter delay compensation
1639 (+) HAL_FDCAN_EnableTxDelayCompensation : Enable the transmitter delay compensation
1640 (+) HAL_FDCAN_DisableTxDelayCompensation : Disable the transmitter delay compensation
1641 (+) HAL_FDCAN_EnableISOMode : Enable ISO 11898-1 protocol mode
1642 (+) HAL_FDCAN_DisableISOMode : Disable ISO 11898-1 protocol mode
1643 (+) HAL_FDCAN_EnableEdgeFiltering : Enable edge filtering during bus integration
1644 (+) HAL_FDCAN_DisableEdgeFiltering : Disable edge filtering during bus integration
1646 @endverbatim
1647 * @{
1651 * @brief Configure the FDCAN clock calibration unit according to the specified
1652 * parameters in the FDCAN_ClkCalUnitTypeDef structure.
1653 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1654 * the configuration information for the specified FDCAN.
1655 * @param sCcuConfig pointer to an FDCAN_ClkCalUnitTypeDef structure that
1656 * contains the clock calibration information
1657 * @retval HAL status
1659 HAL_StatusTypeDef HAL_FDCAN_ConfigClockCalibration(FDCAN_HandleTypeDef *hfdcan, FDCAN_ClkCalUnitTypeDef *sCcuConfig)
1661 /* Check function parameters */
1662 assert_param(IS_FDCAN_CLOCK_CALIBRATION(sCcuConfig->ClockCalibration));
1663 if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
1665 assert_param(IS_FDCAN_CKDIV(sCcuConfig->ClockDivider));
1667 else
1669 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->MinOscClkPeriods, 0xFFU));
1670 assert_param(IS_FDCAN_CALIBRATION_FIELD_LENGTH(sCcuConfig->CalFieldLength));
1671 assert_param(IS_FDCAN_MIN_VALUE(sCcuConfig->TimeQuantaPerBitTime, 4U));
1672 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->TimeQuantaPerBitTime, 0x25U));
1673 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->WatchdogStartValue, 0xFFFFU));
1676 /* FDCAN1 should be initialized in order to use clock calibration */
1677 if (hfdcan->Instance != FDCAN1)
1679 /* Update error code */
1680 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
1682 return HAL_ERROR;
1685 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1687 if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
1689 /* Bypass clock calibration */
1690 SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
1692 /* Configure clock divider */
1693 MODIFY_REG(FDCAN_CCU->CCFG, FDCANCCU_CCFG_CDIV, sCcuConfig->ClockDivider);
1695 else /* sCcuConfig->ClockCalibration == ENABLE */
1697 /* Clock calibration unit generates time quanta clock */
1698 CLEAR_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
1700 /* Configure clock calibration unit */
1701 MODIFY_REG(FDCAN_CCU->CCFG,
1702 (FDCANCCU_CCFG_TQBT | FDCANCCU_CCFG_CFL | FDCANCCU_CCFG_OCPM),
1703 ((sCcuConfig->TimeQuantaPerBitTime << FDCANCCU_CCFG_TQBT_Pos) | sCcuConfig->CalFieldLength | (sCcuConfig->MinOscClkPeriods << FDCANCCU_CCFG_OCPM_Pos)));
1705 /* Configure the start value of the calibration watchdog counter */
1706 MODIFY_REG(FDCAN_CCU->CWD, FDCANCCU_CWD_WDC, sCcuConfig->WatchdogStartValue);
1709 /* Return function status */
1710 return HAL_OK;
1712 else
1714 /* Update error code */
1715 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1717 return HAL_ERROR;
1722 * @brief Get the clock calibration state.
1723 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1724 * the configuration information for the specified FDCAN.
1725 * @retval State clock calibration state (can be a value of @arg FDCAN_calibration_state)
1727 uint32_t HAL_FDCAN_GetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
1729 /* Prevent unused argument(s) compilation warning */
1730 UNUSED(hfdcan);
1732 return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_CALS);
1736 * @brief Reset the clock calibration state.
1737 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1738 * the configuration information for the specified FDCAN.
1739 * @retval HAL status
1741 HAL_StatusTypeDef HAL_FDCAN_ResetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
1743 /* FDCAN1 should be initialized in order to use clock calibration */
1744 if (hfdcan->Instance != FDCAN1)
1746 /* Update error code */
1747 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
1749 return HAL_ERROR;
1752 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1754 /* Calibration software reset */
1755 SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_SWR);
1757 /* Return function status */
1758 return HAL_OK;
1760 else
1762 /* Update error code */
1763 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1765 return HAL_ERROR;
1770 * @brief Get the clock calibration counter value.
1771 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1772 * the configuration information for the specified FDCAN.
1773 * @param Counter clock calibration counter.
1774 * This parameter can be a value of @arg FDCAN_calibration_counter.
1775 * @retval Value clock calibration counter value
1777 uint32_t HAL_FDCAN_GetClockCalibrationCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t Counter)
1779 /* Prevent unused argument(s) compilation warning */
1780 UNUSED(hfdcan);
1782 /* Check function parameters */
1783 assert_param(IS_FDCAN_CALIBRATION_COUNTER(Counter));
1785 if (Counter == FDCAN_CALIB_TIME_QUANTA_COUNTER)
1787 return ((FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_TQC) >> FDCANCCU_CSTAT_TQC_Pos);
1789 else if (Counter == FDCAN_CALIB_CLOCK_PERIOD_COUNTER)
1791 return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_OCPC);
1793 else /* Counter == FDCAN_CALIB_WATCHDOG_COUNTER */
1795 return ((FDCAN_CCU->CWD & FDCANCCU_CWD_WDV) >> FDCANCCU_CWD_WDV_Pos);
1800 * @brief Configure the FDCAN reception filter according to the specified
1801 * parameters in the FDCAN_FilterTypeDef structure.
1802 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1803 * the configuration information for the specified FDCAN.
1804 * @param sFilterConfig pointer to an FDCAN_FilterTypeDef structure that
1805 * contains the filter configuration information
1806 * @retval HAL status
1808 HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef *hfdcan, FDCAN_FilterTypeDef *sFilterConfig)
1810 uint32_t FilterElementW1;
1811 uint32_t FilterElementW2;
1812 uint32_t *FilterAddress;
1813 HAL_FDCAN_StateTypeDef state = hfdcan->State;
1815 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
1817 /* Check function parameters */
1818 assert_param(IS_FDCAN_ID_TYPE(sFilterConfig->IdType));
1819 assert_param(IS_FDCAN_FILTER_CFG(sFilterConfig->FilterConfig));
1820 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1822 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->RxBufferIndex, 63U));
1823 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->IsCalibrationMsg, 1U));
1826 if (sFilterConfig->IdType == FDCAN_STANDARD_ID)
1828 /* Check function parameters */
1829 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.StdFiltersNbr - 1U)));
1830 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x7FFU));
1831 if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
1833 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x7FFU));
1834 assert_param(IS_FDCAN_STD_FILTER_TYPE(sFilterConfig->FilterType));
1837 /* Build filter element */
1838 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1840 FilterElementW1 = ((FDCAN_FILTER_TO_RXBUFFER << 27U) |
1841 (sFilterConfig->FilterID1 << 16U) |
1842 (sFilterConfig->IsCalibrationMsg << 8U) |
1843 sFilterConfig->RxBufferIndex);
1845 else
1847 FilterElementW1 = ((sFilterConfig->FilterType << 30U) |
1848 (sFilterConfig->FilterConfig << 27U) |
1849 (sFilterConfig->FilterID1 << 16U) |
1850 sFilterConfig->FilterID2);
1853 /* Calculate filter address */
1854 FilterAddress = (uint32_t *)(hfdcan->msgRam.StandardFilterSA + (sFilterConfig->FilterIndex * 4U));
1856 /* Write filter element to the message RAM */
1857 *FilterAddress = FilterElementW1;
1859 else /* sFilterConfig->IdType == FDCAN_EXTENDED_ID */
1861 /* Check function parameters */
1862 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.ExtFiltersNbr - 1U)));
1863 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x1FFFFFFFU));
1864 if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
1866 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x1FFFFFFFU));
1867 assert_param(IS_FDCAN_EXT_FILTER_TYPE(sFilterConfig->FilterType));
1870 /* Build first word of filter element */
1871 FilterElementW1 = ((sFilterConfig->FilterConfig << 29U) | sFilterConfig->FilterID1);
1873 /* Build second word of filter element */
1874 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1876 FilterElementW2 = sFilterConfig->RxBufferIndex;
1878 else
1880 FilterElementW2 = ((sFilterConfig->FilterType << 30U) | sFilterConfig->FilterID2);
1883 /* Calculate filter address */
1884 FilterAddress = (uint32_t *)(hfdcan->msgRam.ExtendedFilterSA + (sFilterConfig->FilterIndex * 4U * 2U));
1886 /* Write filter element to the message RAM */
1887 *FilterAddress = FilterElementW1;
1888 FilterAddress++;
1889 *FilterAddress = FilterElementW2;
1892 /* Return function status */
1893 return HAL_OK;
1895 else
1897 /* Update error code */
1898 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
1900 return HAL_ERROR;
1905 * @brief Configure the FDCAN global filter.
1906 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1907 * the configuration information for the specified FDCAN.
1908 * @param NonMatchingStd Defines how received messages with 11-bit IDs that
1909 * do not match any element of the filter list are treated.
1910 * This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
1911 * @param NonMatchingExt Defines how received messages with 29-bit IDs that
1912 * do not match any element of the filter list are treated.
1913 * This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
1914 * @param RejectRemoteStd Filter or reject all the remote 11-bit IDs frames.
1915 * This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
1916 * @param RejectRemoteExt Filter or reject all the remote 29-bit IDs frames.
1917 * This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
1918 * @retval HAL status
1920 HAL_StatusTypeDef HAL_FDCAN_ConfigGlobalFilter(FDCAN_HandleTypeDef *hfdcan,
1921 uint32_t NonMatchingStd,
1922 uint32_t NonMatchingExt,
1923 uint32_t RejectRemoteStd,
1924 uint32_t RejectRemoteExt)
1926 /* Check function parameters */
1927 assert_param(IS_FDCAN_NON_MATCHING(NonMatchingStd));
1928 assert_param(IS_FDCAN_NON_MATCHING(NonMatchingExt));
1929 assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteStd));
1930 assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteExt));
1932 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1934 /* Configure global filter */
1935 hfdcan->Instance->GFC = ((NonMatchingStd << FDCAN_GFC_ANFS_Pos) |
1936 (NonMatchingExt << FDCAN_GFC_ANFE_Pos) |
1937 (RejectRemoteStd << FDCAN_GFC_RRFS_Pos) |
1938 (RejectRemoteExt << FDCAN_GFC_RRFE_Pos));
1940 /* Return function status */
1941 return HAL_OK;
1943 else
1945 /* Update error code */
1946 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1948 return HAL_ERROR;
1953 * @brief Configure the extended ID mask.
1954 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1955 * the configuration information for the specified FDCAN.
1956 * @param Mask Extended ID Mask.
1957 * This parameter must be a number between 0 and 0x1FFFFFFF
1958 * @retval HAL status
1960 HAL_StatusTypeDef HAL_FDCAN_ConfigExtendedIdMask(FDCAN_HandleTypeDef *hfdcan, uint32_t Mask)
1962 /* Check function parameters */
1963 assert_param(IS_FDCAN_MAX_VALUE(Mask, 0x1FFFFFFFU));
1965 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1967 /* Configure the extended ID mask */
1968 hfdcan->Instance->XIDAM = Mask;
1970 /* Return function status */
1971 return HAL_OK;
1973 else
1975 /* Update error code */
1976 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1978 return HAL_ERROR;
1983 * @brief Configure the Rx FIFO operation mode.
1984 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1985 * the configuration information for the specified FDCAN.
1986 * @param RxFifo Rx FIFO.
1987 * This parameter can be one of the following values:
1988 * @arg FDCAN_RX_FIFO0: Rx FIFO 0
1989 * @arg FDCAN_RX_FIFO1: Rx FIFO 1
1990 * @param OperationMode operation mode.
1991 * This parameter can be a value of @arg FDCAN_Rx_FIFO_operation_mode.
1992 * @retval HAL status
1994 HAL_StatusTypeDef HAL_FDCAN_ConfigRxFifoOverwrite(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo, uint32_t OperationMode)
1996 /* Check function parameters */
1997 assert_param(IS_FDCAN_RX_FIFO(RxFifo));
1998 assert_param(IS_FDCAN_RX_FIFO_MODE(OperationMode));
2000 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2002 if (RxFifo == FDCAN_RX_FIFO0)
2004 /* Select FIFO 0 Operation Mode */
2005 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0OM, OperationMode);
2007 else /* RxFifo == FDCAN_RX_FIFO1 */
2009 /* Select FIFO 1 Operation Mode */
2010 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1OM, OperationMode);
2013 /* Return function status */
2014 return HAL_OK;
2016 else
2018 /* Update error code */
2019 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2021 return HAL_ERROR;
2026 * @brief Configure the FIFO watermark.
2027 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2028 * the configuration information for the specified FDCAN.
2029 * @param FIFO select the FIFO to be configured.
2030 * This parameter can be a value of @arg FDCAN_FIFO_watermark.
2031 * @param Watermark level for FIFO watermark interrupt.
2032 * This parameter must be a number between:
2033 * - 0 and 32, if FIFO is FDCAN_CFG_TX_EVENT_FIFO
2034 * - 0 and 64, if FIFO is FDCAN_CFG_RX_FIFO0 or FDCAN_CFG_RX_FIFO1
2035 * @retval HAL status
2037 HAL_StatusTypeDef HAL_FDCAN_ConfigFifoWatermark(FDCAN_HandleTypeDef *hfdcan, uint32_t FIFO, uint32_t Watermark)
2039 /* Check function parameters */
2040 assert_param(IS_FDCAN_FIFO_WATERMARK(FIFO));
2041 if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
2043 assert_param(IS_FDCAN_MAX_VALUE(Watermark, 32U));
2045 else /* (FIFO == FDCAN_CFG_RX_FIFO0) || (FIFO == FDCAN_CFG_RX_FIFO1) */
2047 assert_param(IS_FDCAN_MAX_VALUE(Watermark, 64U));
2050 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2052 /* Set the level for FIFO watermark interrupt */
2053 if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
2055 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFWM, (Watermark << FDCAN_TXEFC_EFWM_Pos));
2057 else if (FIFO == FDCAN_CFG_RX_FIFO0)
2059 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0WM, (Watermark << FDCAN_RXF0C_F0WM_Pos));
2061 else /* FIFO == FDCAN_CFG_RX_FIFO1 */
2063 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1WM, (Watermark << FDCAN_RXF1C_F1WM_Pos));
2066 /* Return function status */
2067 return HAL_OK;
2069 else
2071 /* Update error code */
2072 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2074 return HAL_ERROR;
2079 * @brief Configure the RAM watchdog.
2080 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2081 * the configuration information for the specified FDCAN.
2082 * @param CounterStartValue Start value of the Message RAM Watchdog Counter,
2083 * This parameter must be a number between 0x00 and 0xFF,
2084 * with the reset value of 0x00 the counter is disabled.
2085 * @retval HAL status
2087 HAL_StatusTypeDef HAL_FDCAN_ConfigRamWatchdog(FDCAN_HandleTypeDef *hfdcan, uint32_t CounterStartValue)
2089 /* Check function parameters */
2090 assert_param(IS_FDCAN_MAX_VALUE(CounterStartValue, 0xFFU));
2092 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2094 /* Configure the RAM watchdog counter start value */
2095 MODIFY_REG(hfdcan->Instance->RWD, FDCAN_RWD_WDC, CounterStartValue);
2097 /* Return function status */
2098 return HAL_OK;
2100 else
2102 /* Update error code */
2103 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2105 return HAL_ERROR;
2110 * @brief Configure the timestamp counter.
2111 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2112 * the configuration information for the specified FDCAN.
2113 * @param TimestampPrescaler Timestamp Counter Prescaler.
2114 * This parameter can be a value of @arg FDCAN_Timestamp_Prescaler.
2115 * @retval HAL status
2117 HAL_StatusTypeDef HAL_FDCAN_ConfigTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampPrescaler)
2119 /* Check function parameters */
2120 assert_param(IS_FDCAN_TIMESTAMP_PRESCALER(TimestampPrescaler));
2122 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2124 /* Configure prescaler */
2125 MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TCP, TimestampPrescaler);
2127 /* Return function status */
2128 return HAL_OK;
2130 else
2132 /* Update error code */
2133 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2135 return HAL_ERROR;
2140 * @brief Enable the timestamp counter.
2141 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2142 * the configuration information for the specified FDCAN.
2143 * @param TimestampOperation Timestamp counter operation.
2144 * This parameter can be a value of @arg FDCAN_Timestamp.
2145 * @retval HAL status
2147 HAL_StatusTypeDef HAL_FDCAN_EnableTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampOperation)
2149 /* Check function parameters */
2150 assert_param(IS_FDCAN_TIMESTAMP(TimestampOperation));
2152 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2154 /* Enable timestamp counter */
2155 MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS, TimestampOperation);
2157 /* Return function status */
2158 return HAL_OK;
2160 else
2162 /* Update error code */
2163 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2165 return HAL_ERROR;
2170 * @brief Disable the timestamp counter.
2171 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2172 * the configuration information for the specified FDCAN.
2173 * @retval HAL status
2175 HAL_StatusTypeDef HAL_FDCAN_DisableTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2177 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2179 /* Disable timestamp counter */
2180 CLEAR_BIT(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS);
2182 /* Return function status */
2183 return HAL_OK;
2185 else
2187 /* Update error code */
2188 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2190 return HAL_ERROR;
2195 * @brief Get the timestamp counter value.
2196 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2197 * the configuration information for the specified FDCAN.
2198 * @retval Value Timestamp counter value
2200 uint16_t HAL_FDCAN_GetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2202 return (uint16_t)(hfdcan->Instance->TSCV);
2206 * @brief Reset the timestamp counter to zero.
2207 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2208 * the configuration information for the specified FDCAN.
2209 * @retval HAL status
2211 HAL_StatusTypeDef HAL_FDCAN_ResetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2213 if ((hfdcan->Instance->TSCC & FDCAN_TSCC_TSS) != FDCAN_TIMESTAMP_EXTERNAL)
2215 /* Reset timestamp counter.
2216 Actually any write operation to TSCV clears the counter */
2217 CLEAR_REG(hfdcan->Instance->TSCV);
2219 else
2221 /* Update error code.
2222 Unable to reset external counter */
2223 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
2225 return HAL_ERROR;
2228 /* Return function status */
2229 return HAL_OK;
2233 * @brief Configure the timeout counter.
2234 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2235 * the configuration information for the specified FDCAN.
2236 * @param TimeoutOperation Timeout counter operation.
2237 * This parameter can be a value of @arg FDCAN_Timeout_Operation.
2238 * @param TimeoutPeriod Start value of the timeout down-counter.
2239 * This parameter must be a number between 0x0000 and 0xFFFF
2240 * @retval HAL status
2242 HAL_StatusTypeDef HAL_FDCAN_ConfigTimeoutCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimeoutOperation, uint32_t TimeoutPeriod)
2244 /* Check function parameters */
2245 assert_param(IS_FDCAN_TIMEOUT(TimeoutOperation));
2246 assert_param(IS_FDCAN_MAX_VALUE(TimeoutPeriod, 0xFFFFU));
2248 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2250 /* Select timeout operation and configure period */
2251 MODIFY_REG(hfdcan->Instance->TOCC, (FDCAN_TOCC_TOS | FDCAN_TOCC_TOP), (TimeoutOperation | (TimeoutPeriod << FDCAN_TOCC_TOP_Pos)));
2253 /* Return function status */
2254 return HAL_OK;
2256 else
2258 /* Update error code */
2259 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2261 return HAL_ERROR;
2266 * @brief Enable the timeout counter.
2267 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2268 * the configuration information for the specified FDCAN.
2269 * @retval HAL status
2271 HAL_StatusTypeDef HAL_FDCAN_EnableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2273 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2275 /* Enable timeout counter */
2276 SET_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
2278 /* Return function status */
2279 return HAL_OK;
2281 else
2283 /* Update error code */
2284 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2286 return HAL_ERROR;
2291 * @brief Disable the timeout counter.
2292 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2293 * the configuration information for the specified FDCAN.
2294 * @retval HAL status
2296 HAL_StatusTypeDef HAL_FDCAN_DisableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2298 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2300 /* Disable timeout counter */
2301 CLEAR_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
2303 /* Return function status */
2304 return HAL_OK;
2306 else
2308 /* Update error code */
2309 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2311 return HAL_ERROR;
2316 * @brief Get the timeout counter value.
2317 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2318 * the configuration information for the specified FDCAN.
2319 * @retval Value Timeout counter value
2321 uint16_t HAL_FDCAN_GetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2323 return (uint16_t)(hfdcan->Instance->TOCV);
2327 * @brief Reset the timeout counter to its start value.
2328 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2329 * the configuration information for the specified FDCAN.
2330 * @retval HAL status
2332 HAL_StatusTypeDef HAL_FDCAN_ResetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2334 if ((hfdcan->Instance->TOCC & FDCAN_TOCC_TOS) == FDCAN_TIMEOUT_CONTINUOUS)
2336 /* Reset timeout counter to start value */
2337 CLEAR_REG(hfdcan->Instance->TOCV);
2339 /* Return function status */
2340 return HAL_OK;
2342 else
2344 /* Update error code.
2345 Unable to reset counter: controlled only by FIFO empty state */
2346 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
2348 return HAL_ERROR;
2353 * @brief Configure the transmitter delay compensation.
2354 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2355 * the configuration information for the specified FDCAN.
2356 * @param TdcOffset Transmitter Delay Compensation Offset.
2357 * This parameter must be a number between 0x00 and 0x7F.
2358 * @param TdcFilter Transmitter Delay Compensation Filter Window Length.
2359 * This parameter must be a number between 0x00 and 0x7F.
2360 * @retval HAL status
2362 HAL_StatusTypeDef HAL_FDCAN_ConfigTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan, uint32_t TdcOffset, uint32_t TdcFilter)
2364 /* Check function parameters */
2365 assert_param(IS_FDCAN_MAX_VALUE(TdcOffset, 0x7FU));
2366 assert_param(IS_FDCAN_MAX_VALUE(TdcFilter, 0x7FU));
2368 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2370 /* Configure TDC offset and filter window */
2371 hfdcan->Instance->TDCR = ((TdcFilter << FDCAN_TDCR_TDCF_Pos) | (TdcOffset << FDCAN_TDCR_TDCO_Pos));
2373 /* Return function status */
2374 return HAL_OK;
2376 else
2378 /* Update error code */
2379 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2381 return HAL_ERROR;
2386 * @brief Enable the transmitter delay compensation.
2387 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2388 * the configuration information for the specified FDCAN.
2389 * @retval HAL status
2391 HAL_StatusTypeDef HAL_FDCAN_EnableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
2393 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2395 /* Enable transmitter delay compensation */
2396 SET_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
2398 /* Return function status */
2399 return HAL_OK;
2401 else
2403 /* Update error code */
2404 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2406 return HAL_ERROR;
2411 * @brief Disable the transmitter delay compensation.
2412 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2413 * the configuration information for the specified FDCAN.
2414 * @retval HAL status
2416 HAL_StatusTypeDef HAL_FDCAN_DisableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
2418 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2420 /* Disable transmitter delay compensation */
2421 CLEAR_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
2423 /* Return function status */
2424 return HAL_OK;
2426 else
2428 /* Update error code */
2429 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2431 return HAL_ERROR;
2436 * @brief Enable ISO 11898-1 protocol mode.
2437 * CAN FD frame format is according to ISO 11898-1 standard.
2438 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2439 * the configuration information for the specified FDCAN.
2440 * @retval HAL status
2442 HAL_StatusTypeDef HAL_FDCAN_EnableISOMode(FDCAN_HandleTypeDef *hfdcan)
2444 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2446 /* Disable Non ISO protocol mode */
2447 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
2449 /* Return function status */
2450 return HAL_OK;
2452 else
2454 /* Update error code */
2455 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2457 return HAL_ERROR;
2462 * @brief Disable ISO 11898-1 protocol mode.
2463 * CAN FD frame format is according to Bosch CAN FD specification V1.0.
2464 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2465 * the configuration information for the specified FDCAN.
2466 * @retval HAL status
2468 HAL_StatusTypeDef HAL_FDCAN_DisableISOMode(FDCAN_HandleTypeDef *hfdcan)
2470 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2472 /* Enable Non ISO protocol mode */
2473 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
2475 /* Return function status */
2476 return HAL_OK;
2478 else
2480 /* Update error code */
2481 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2483 return HAL_ERROR;
2488 * @brief Enable edge filtering during bus integration.
2489 * Two consecutive dominant tq are required to detect an edge for hard synchronization.
2490 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2491 * the configuration information for the specified FDCAN.
2492 * @retval HAL status
2494 HAL_StatusTypeDef HAL_FDCAN_EnableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
2496 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2498 /* Enable edge filtering */
2499 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
2501 /* Return function status */
2502 return HAL_OK;
2504 else
2506 /* Update error code */
2507 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2509 return HAL_ERROR;
2514 * @brief Disable edge filtering during bus integration.
2515 * One dominant tq is required to detect an edge for hard synchronization.
2516 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2517 * the configuration information for the specified FDCAN.
2518 * @retval HAL status
2520 HAL_StatusTypeDef HAL_FDCAN_DisableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
2522 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2524 /* Disable edge filtering */
2525 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
2527 /* Return function status */
2528 return HAL_OK;
2530 else
2532 /* Update error code */
2533 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2535 return HAL_ERROR;
2540 * @}
2543 /** @defgroup FDCAN_Exported_Functions_Group3 Control functions
2544 * @brief Control functions
2546 @verbatim
2547 ==============================================================================
2548 ##### Control functions #####
2549 ==============================================================================
2550 [..] This section provides functions allowing to:
2551 (+) HAL_FDCAN_Start : Start the FDCAN module
2552 (+) HAL_FDCAN_Stop : Stop the FDCAN module and enable access to configuration registers
2553 (+) HAL_FDCAN_AddMessageToTxFifoQ : Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
2554 (+) HAL_FDCAN_AddMessageToTxBuffer : Add a message to a dedicated Tx buffer
2555 (+) HAL_FDCAN_EnableTxBufferRequest : Enable transmission request
2556 (+) HAL_FDCAN_GetLatestTxFifoQRequestBuffer : Get Tx buffer index of latest Tx FIFO/Queue request
2557 (+) HAL_FDCAN_AbortTxRequest : Abort transmission request
2558 (+) HAL_FDCAN_GetRxMessage : Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM
2559 (+) HAL_FDCAN_GetTxEvent : Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM
2560 (+) HAL_FDCAN_GetHighPriorityMessageStatus : Get high priority message status
2561 (+) HAL_FDCAN_GetProtocolStatus : Get protocol status
2562 (+) HAL_FDCAN_GetErrorCounters : Get error counter values
2563 (+) HAL_FDCAN_IsRxBufferMessageAvailable : Check if a new message is received in the selected Rx buffer
2564 (+) HAL_FDCAN_IsTxBufferMessagePending : Check if a transmission request is pending on the selected Tx buffer
2565 (+) HAL_FDCAN_GetRxFifoFillLevel : Return Rx FIFO fill level
2566 (+) HAL_FDCAN_GetTxFifoFreeLevel : Return Tx FIFO free level
2567 (+) HAL_FDCAN_IsRestrictedOperationMode : Check if the FDCAN peripheral entered Restricted Operation Mode
2568 (+) HAL_FDCAN_ExitRestrictedOperationMode : Exit Restricted Operation Mode
2570 @endverbatim
2571 * @{
2575 * @brief Start the FDCAN module.
2576 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2577 * the configuration information for the specified FDCAN.
2578 * @retval HAL status
2580 HAL_StatusTypeDef HAL_FDCAN_Start(FDCAN_HandleTypeDef *hfdcan)
2582 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2584 /* Change FDCAN peripheral state */
2585 hfdcan->State = HAL_FDCAN_STATE_BUSY;
2587 /* Request leave initialisation */
2588 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
2590 /* Reset the FDCAN ErrorCode */
2591 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
2593 /* Return function status */
2594 return HAL_OK;
2596 else
2598 /* Update error code */
2599 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2601 return HAL_ERROR;
2606 * @brief Stop the FDCAN module and enable access to configuration registers.
2607 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2608 * the configuration information for the specified FDCAN.
2609 * @retval HAL status
2611 HAL_StatusTypeDef HAL_FDCAN_Stop(FDCAN_HandleTypeDef *hfdcan)
2613 uint32_t Counter = 0U;
2615 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2617 /* Request initialisation */
2618 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
2620 /* Wait until the INIT bit into CCCR register is set */
2621 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
2623 /* Check for the Timeout */
2624 if (Counter > FDCAN_TIMEOUT_COUNT)
2626 /* Update error code */
2627 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
2629 /* Change FDCAN state */
2630 hfdcan->State = HAL_FDCAN_STATE_ERROR;
2632 return HAL_ERROR;
2635 /* Increment counter */
2636 Counter++;
2639 /* Reset counter */
2640 Counter = 0U;
2642 /* Exit from Sleep mode */
2643 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
2645 /* Wait until FDCAN exits sleep mode */
2646 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
2648 /* Check for the Timeout */
2649 if (Counter > FDCAN_TIMEOUT_COUNT)
2651 /* Update error code */
2652 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
2654 /* Change FDCAN state */
2655 hfdcan->State = HAL_FDCAN_STATE_ERROR;
2657 return HAL_ERROR;
2660 /* Increment counter */
2661 Counter++;
2664 /* Enable configuration change */
2665 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
2667 /* Reset Latest Tx FIFO/Queue Request Buffer Index */
2668 hfdcan->LatestTxFifoQRequest = 0U;
2670 /* Change FDCAN peripheral state */
2671 hfdcan->State = HAL_FDCAN_STATE_READY;
2673 /* Return function status */
2674 return HAL_OK;
2676 else
2678 /* Update error code */
2679 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2681 return HAL_ERROR;
2686 * @brief Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
2687 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2688 * the configuration information for the specified FDCAN.
2689 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
2690 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
2691 * @retval HAL status
2693 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxFifoQ(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData)
2695 uint32_t PutIndex;
2697 /* Check function parameters */
2698 assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
2699 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
2701 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
2703 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
2705 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
2707 assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
2708 assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
2709 assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
2710 assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
2711 assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
2712 assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
2713 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
2715 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2717 /* Check that the Tx FIFO/Queue has an allocated area into the RAM */
2718 if ((hfdcan->Instance->TXBC & FDCAN_TXBC_TFQS) == 0U)
2720 /* Update error code */
2721 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2723 return HAL_ERROR;
2726 /* Check that the Tx FIFO/Queue is not full */
2727 if ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQF) != 0U)
2729 /* Update error code */
2730 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_FULL;
2732 return HAL_ERROR;
2734 else
2736 /* Retrieve the Tx FIFO PutIndex */
2737 PutIndex = ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQPI) >> FDCAN_TXFQS_TFQPI_Pos);
2739 /* Add the message to the Tx FIFO/Queue */
2740 FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, PutIndex);
2742 /* Activate the corresponding transmission request */
2743 hfdcan->Instance->TXBAR = ((uint32_t)1 << PutIndex);
2745 /* Store the Latest Tx FIFO/Queue Request Buffer Index */
2746 hfdcan->LatestTxFifoQRequest = ((uint32_t)1 << PutIndex);
2749 /* Return function status */
2750 return HAL_OK;
2752 else
2754 /* Update error code */
2755 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2757 return HAL_ERROR;
2762 * @brief Add a message to a dedicated Tx buffer
2763 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2764 * the configuration information for the specified FDCAN.
2765 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
2766 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
2767 * @param BufferIndex index of the buffer to be configured.
2768 * This parameter can be a value of @arg FDCAN_Tx_location.
2769 * @retval HAL status
2771 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxBuffer(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
2773 HAL_FDCAN_StateTypeDef state = hfdcan->State;
2775 /* Check function parameters */
2776 assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
2777 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
2779 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
2781 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
2783 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
2785 assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
2786 assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
2787 assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
2788 assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
2789 assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
2790 assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
2791 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
2792 assert_param(IS_FDCAN_TX_LOCATION(BufferIndex));
2794 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
2796 /* Check that the selected buffer has an allocated area into the RAM */
2797 if (POSITION_VAL(BufferIndex) >= ((hfdcan->Instance->TXBC & FDCAN_TXBC_NDTB) >> FDCAN_TXBC_NDTB_Pos))
2799 /* Update error code */
2800 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2802 return HAL_ERROR;
2805 /* Check that there is no transmittion request pending for the selected buffer */
2806 if ((hfdcan->Instance->TXBRP & BufferIndex) != 0U)
2808 /* Update error code */
2809 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
2811 return HAL_ERROR;
2813 else
2815 /* Add the message to the Tx buffer */
2816 FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, POSITION_VAL(BufferIndex));
2819 /* Return function status */
2820 return HAL_OK;
2822 else
2824 /* Update error code */
2825 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
2827 return HAL_ERROR;
2832 * @brief Enable transmission request.
2833 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2834 * the configuration information for the specified FDCAN.
2835 * @param BufferIndex buffer index.
2836 * This parameter can be any combination of @arg FDCAN_Tx_location.
2837 * @retval HAL status
2839 HAL_StatusTypeDef HAL_FDCAN_EnableTxBufferRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
2841 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2843 /* Add transmission request */
2844 hfdcan->Instance->TXBAR = BufferIndex;
2846 /* Return function status */
2847 return HAL_OK;
2849 else
2851 /* Update error code */
2852 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2854 return HAL_ERROR;
2859 * @brief Get Tx buffer index of latest Tx FIFO/Queue request
2860 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2861 * the configuration information for the specified FDCAN.
2862 * @retval Tx buffer index of last Tx FIFO/Queue request
2863 * - Any value of @arg FDCAN_Tx_location if Tx request has been submitted.
2864 * - 0 if no Tx FIFO/Queue request have been submitted.
2866 uint32_t HAL_FDCAN_GetLatestTxFifoQRequestBuffer(FDCAN_HandleTypeDef *hfdcan)
2868 /* Return Last Tx FIFO/Queue Request Buffer */
2869 return hfdcan->LatestTxFifoQRequest;
2873 * @brief Abort transmission request
2874 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2875 * the configuration information for the specified FDCAN.
2876 * @param BufferIndex buffer index.
2877 * This parameter can be any combination of @arg FDCAN_Tx_location.
2878 * @retval HAL status
2880 HAL_StatusTypeDef HAL_FDCAN_AbortTxRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
2882 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2884 /* Add cancellation request */
2885 hfdcan->Instance->TXBCR = BufferIndex;
2887 /* Return function status */
2888 return HAL_OK;
2890 else
2892 /* Update error code */
2893 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2895 return HAL_ERROR;
2900 * @brief Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM.
2901 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2902 * the configuration information for the specified FDCAN.
2903 * @param RxLocation Location of the received message to be read.
2904 * This parameter can be a value of @arg FDCAN_Rx_location.
2905 * @param pRxHeader pointer to a FDCAN_RxHeaderTypeDef structure.
2906 * @param pRxData pointer to a buffer where the payload of the Rx frame will be stored.
2907 * @retval HAL status
2909 HAL_StatusTypeDef HAL_FDCAN_GetRxMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t RxLocation, FDCAN_RxHeaderTypeDef *pRxHeader, uint8_t *pRxData)
2911 uint32_t *RxAddress;
2912 uint8_t *pData;
2913 uint32_t ByteCounter;
2914 uint32_t GetIndex = 0;
2915 HAL_FDCAN_StateTypeDef state = hfdcan->State;
2917 if (state == HAL_FDCAN_STATE_BUSY)
2919 if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
2921 /* Check that the Rx FIFO 0 has an allocated area into the RAM */
2922 if ((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0S) == 0U)
2924 /* Update error code */
2925 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2927 return HAL_ERROR;
2930 /* Check that the Rx FIFO 0 is not empty */
2931 if ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL) == 0U)
2933 /* Update error code */
2934 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
2936 return HAL_ERROR;
2938 else
2940 /* Check that the Rx FIFO 0 is full & overwrite mode is on*/
2941 if(((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0F) >> FDCAN_RXF0S_F0F_Pos) == 1U)
2943 if(((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0OM) >> FDCAN_RXF0C_F0OM_Pos) == FDCAN_RX_FIFO_OVERWRITE)
2945 /* When overwrite status is on discard first message in FIFO */
2946 GetIndex = 1U;
2950 /* Calculate Rx FIFO 0 element index*/
2951 GetIndex += ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0GI) >> FDCAN_RXF0S_F0GI_Pos);
2953 /* Calculate Rx FIFO 0 element address */
2954 RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO0SA + (GetIndex * hfdcan->Init.RxFifo0ElmtSize * 4U));
2957 else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
2959 /* Check that the Rx FIFO 1 has an allocated area into the RAM */
2960 if ((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1S) == 0U)
2962 /* Update error code */
2963 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2965 return HAL_ERROR;
2968 /* Check that the Rx FIFO 0 is not empty */
2969 if ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL) == 0U)
2971 /* Update error code */
2972 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
2974 return HAL_ERROR;
2976 else
2978 /* Check that the Rx FIFO 1 is full & overwrite mode is on*/
2979 if(((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1F) >> FDCAN_RXF1S_F1F_Pos) == 1U)
2981 if(((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1OM) >> FDCAN_RXF1C_F1OM_Pos) == FDCAN_RX_FIFO_OVERWRITE)
2983 /* When overwrite status is on discard first message in FIFO */
2984 GetIndex = 1U;
2988 /* Calculate Rx FIFO 1 element index*/
2989 GetIndex += ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1GI) >> FDCAN_RXF1S_F1GI_Pos);
2991 /* Calculate Rx FIFO 1 element address */
2992 RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO1SA + (GetIndex * hfdcan->Init.RxFifo1ElmtSize * 4U));
2995 else /* Rx element is assigned to a dedicated Rx buffer */
2997 /* Check that the selected buffer has an allocated area into the RAM */
2998 if (RxLocation >= hfdcan->Init.RxBuffersNbr)
3000 /* Update error code */
3001 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
3003 return HAL_ERROR;
3005 else
3007 /* Calculate Rx buffer address */
3008 RxAddress = (uint32_t *)(hfdcan->msgRam.RxBufferSA + (RxLocation * hfdcan->Init.RxBufferSize * 4U));
3012 /* Retrieve IdType */
3013 pRxHeader->IdType = *RxAddress & FDCAN_ELEMENT_MASK_XTD;
3015 /* Retrieve Identifier */
3016 if (pRxHeader->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
3018 pRxHeader->Identifier = ((*RxAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
3020 else /* Extended ID element */
3022 pRxHeader->Identifier = (*RxAddress & FDCAN_ELEMENT_MASK_EXTID);
3025 /* Retrieve RxFrameType */
3026 pRxHeader->RxFrameType = (*RxAddress & FDCAN_ELEMENT_MASK_RTR);
3028 /* Retrieve ErrorStateIndicator */
3029 pRxHeader->ErrorStateIndicator = (*RxAddress & FDCAN_ELEMENT_MASK_ESI);
3031 /* Increment RxAddress pointer to second word of Rx FIFO element */
3032 RxAddress++;
3034 /* Retrieve RxTimestamp */
3035 pRxHeader->RxTimestamp = (*RxAddress & FDCAN_ELEMENT_MASK_TS);
3037 /* Retrieve DataLength */
3038 pRxHeader->DataLength = (*RxAddress & FDCAN_ELEMENT_MASK_DLC);
3040 /* Retrieve BitRateSwitch */
3041 pRxHeader->BitRateSwitch = (*RxAddress & FDCAN_ELEMENT_MASK_BRS);
3043 /* Retrieve FDFormat */
3044 pRxHeader->FDFormat = (*RxAddress & FDCAN_ELEMENT_MASK_FDF);
3046 /* Retrieve FilterIndex */
3047 pRxHeader->FilterIndex = ((*RxAddress & FDCAN_ELEMENT_MASK_FIDX) >> 24);
3049 /* Retrieve NonMatchingFrame */
3050 pRxHeader->IsFilterMatchingFrame = ((*RxAddress & FDCAN_ELEMENT_MASK_ANMF) >> 31);
3052 /* Increment RxAddress pointer to payload of Rx FIFO element */
3053 RxAddress++;
3055 /* Retrieve Rx payload */
3056 pData = (uint8_t *)RxAddress;
3057 for (ByteCounter = 0; ByteCounter < DLCtoBytes[pRxHeader->DataLength >> 16]; ByteCounter++)
3059 pRxData[ByteCounter] = pData[ByteCounter];
3062 if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
3064 /* Acknowledge the Rx FIFO 0 that the oldest element is read so that it increments the GetIndex */
3065 hfdcan->Instance->RXF0A = GetIndex;
3067 else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
3069 /* Acknowledge the Rx FIFO 1 that the oldest element is read so that it increments the GetIndex */
3070 hfdcan->Instance->RXF1A = GetIndex;
3072 else /* Rx element is assigned to a dedicated Rx buffer */
3074 /* Clear the New Data flag of the current Rx buffer */
3075 if (RxLocation < FDCAN_RX_BUFFER32)
3077 hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxLocation);
3079 else /* FDCAN_RX_BUFFER32 <= RxLocation <= FDCAN_RX_BUFFER63 */
3081 hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxLocation & 0x1FU));
3085 /* Return function status */
3086 return HAL_OK;
3088 else
3090 /* Update error code */
3091 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
3093 return HAL_ERROR;
3098 * @brief Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM.
3099 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3100 * the configuration information for the specified FDCAN.
3101 * @param pTxEvent pointer to a FDCAN_TxEventFifoTypeDef structure.
3102 * @retval HAL status
3104 HAL_StatusTypeDef HAL_FDCAN_GetTxEvent(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxEventFifoTypeDef *pTxEvent)
3106 uint32_t *TxEventAddress;
3107 uint32_t GetIndex;
3108 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3110 /* Check function parameters */
3111 assert_param(IS_FDCAN_MIN_VALUE(hfdcan->Init.TxEventsNbr, 1U));
3113 if (state == HAL_FDCAN_STATE_BUSY)
3115 /* Check that the Tx Event FIFO has an allocated area into the RAM */
3116 if ((hfdcan->Instance->TXEFC & FDCAN_TXEFC_EFS) == 0U)
3118 /* Update error code */
3119 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
3121 return HAL_ERROR;
3124 /* Check that the Tx event FIFO is not empty */
3125 if ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFFL) == 0U)
3127 /* Update error code */
3128 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
3130 return HAL_ERROR;
3133 /* Calculate Tx event FIFO element address */
3134 GetIndex = ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFGI) >> FDCAN_TXEFS_EFGI_Pos);
3135 TxEventAddress = (uint32_t *)(hfdcan->msgRam.TxEventFIFOSA + (GetIndex * 2U * 4U));
3137 /* Retrieve IdType */
3138 pTxEvent->IdType = *TxEventAddress & FDCAN_ELEMENT_MASK_XTD;
3140 /* Retrieve Identifier */
3141 if (pTxEvent->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
3143 pTxEvent->Identifier = ((*TxEventAddress & FDCAN_ELEMENT_MASK_STDID) >> 18U);
3145 else /* Extended ID element */
3147 pTxEvent->Identifier = (*TxEventAddress & FDCAN_ELEMENT_MASK_EXTID);
3150 /* Retrieve TxFrameType */
3151 pTxEvent->TxFrameType = (*TxEventAddress & FDCAN_ELEMENT_MASK_RTR);
3153 /* Retrieve ErrorStateIndicator */
3154 pTxEvent->ErrorStateIndicator = (*TxEventAddress & FDCAN_ELEMENT_MASK_ESI);
3156 /* Increment TxEventAddress pointer to second word of Tx Event FIFO element */
3157 TxEventAddress++;
3159 /* Retrieve TxTimestamp */
3160 pTxEvent->TxTimestamp = (*TxEventAddress & FDCAN_ELEMENT_MASK_TS);
3162 /* Retrieve DataLength */
3163 pTxEvent->DataLength = (*TxEventAddress & FDCAN_ELEMENT_MASK_DLC);
3165 /* Retrieve BitRateSwitch */
3166 pTxEvent->BitRateSwitch = (*TxEventAddress & FDCAN_ELEMENT_MASK_BRS);
3168 /* Retrieve FDFormat */
3169 pTxEvent->FDFormat = (*TxEventAddress & FDCAN_ELEMENT_MASK_FDF);
3171 /* Retrieve EventType */
3172 pTxEvent->EventType = (*TxEventAddress & FDCAN_ELEMENT_MASK_ET);
3174 /* Retrieve MessageMarker */
3175 pTxEvent->MessageMarker = ((*TxEventAddress & FDCAN_ELEMENT_MASK_MM) >> 24);
3177 /* Acknowledge the Tx Event FIFO that the oldest element is read so that it increments the GetIndex */
3178 hfdcan->Instance->TXEFA = GetIndex;
3180 /* Return function status */
3181 return HAL_OK;
3183 else
3185 /* Update error code */
3186 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
3188 return HAL_ERROR;
3193 * @brief Get high priority message status.
3194 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3195 * the configuration information for the specified FDCAN.
3196 * @param HpMsgStatus pointer to an FDCAN_HpMsgStatusTypeDef structure.
3197 * @retval HAL status
3199 HAL_StatusTypeDef HAL_FDCAN_GetHighPriorityMessageStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_HpMsgStatusTypeDef *HpMsgStatus)
3201 HpMsgStatus->FilterList = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FLST) >> FDCAN_HPMS_FLST_Pos);
3202 HpMsgStatus->FilterIndex = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FIDX) >> FDCAN_HPMS_FIDX_Pos);
3203 HpMsgStatus->MessageStorage = (hfdcan->Instance->HPMS & FDCAN_HPMS_MSI);
3204 HpMsgStatus->MessageIndex = (hfdcan->Instance->HPMS & FDCAN_HPMS_BIDX);
3206 /* Return function status */
3207 return HAL_OK;
3211 * @brief Get protocol status.
3212 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3213 * the configuration information for the specified FDCAN.
3214 * @param ProtocolStatus pointer to an FDCAN_ProtocolStatusTypeDef structure.
3215 * @retval HAL status
3217 HAL_StatusTypeDef HAL_FDCAN_GetProtocolStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_ProtocolStatusTypeDef *ProtocolStatus)
3219 uint32_t StatusReg;
3221 /* Read the protocol status register */
3222 StatusReg = READ_REG(hfdcan->Instance->PSR);
3224 /* Fill the protocol status structure */
3225 ProtocolStatus->LastErrorCode = (StatusReg & FDCAN_PSR_LEC);
3226 ProtocolStatus->DataLastErrorCode = ((StatusReg & FDCAN_PSR_DLEC) >> FDCAN_PSR_DLEC_Pos);
3227 ProtocolStatus->Activity = (StatusReg & FDCAN_PSR_ACT);
3228 ProtocolStatus->ErrorPassive = ((StatusReg & FDCAN_PSR_EP) >> FDCAN_PSR_EP_Pos);
3229 ProtocolStatus->Warning = ((StatusReg & FDCAN_PSR_EW) >> FDCAN_PSR_EW_Pos);
3230 ProtocolStatus->BusOff = ((StatusReg & FDCAN_PSR_BO) >> FDCAN_PSR_BO_Pos);
3231 ProtocolStatus->RxESIflag = ((StatusReg & FDCAN_PSR_RESI) >> FDCAN_PSR_RESI_Pos);
3232 ProtocolStatus->RxBRSflag = ((StatusReg & FDCAN_PSR_RBRS) >> FDCAN_PSR_RBRS_Pos);
3233 ProtocolStatus->RxFDFflag = ((StatusReg & FDCAN_PSR_REDL) >> FDCAN_PSR_REDL_Pos);
3234 ProtocolStatus->ProtocolException = ((StatusReg & FDCAN_PSR_PXE) >> FDCAN_PSR_PXE_Pos);
3235 ProtocolStatus->TDCvalue = ((StatusReg & FDCAN_PSR_TDCV) >> FDCAN_PSR_TDCV_Pos);
3237 /* Return function status */
3238 return HAL_OK;
3242 * @brief Get error counter values.
3243 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3244 * the configuration information for the specified FDCAN.
3245 * @param ErrorCounters pointer to an FDCAN_ErrorCountersTypeDef structure.
3246 * @retval HAL status
3248 HAL_StatusTypeDef HAL_FDCAN_GetErrorCounters(FDCAN_HandleTypeDef *hfdcan, FDCAN_ErrorCountersTypeDef *ErrorCounters)
3250 uint32_t CountersReg;
3252 /* Read the error counters register */
3253 CountersReg = READ_REG(hfdcan->Instance->ECR);
3255 /* Fill the error counters structure */
3256 ErrorCounters->TxErrorCnt = ((CountersReg & FDCAN_ECR_TEC) >> FDCAN_ECR_TEC_Pos);
3257 ErrorCounters->RxErrorCnt = ((CountersReg & FDCAN_ECR_REC) >> FDCAN_ECR_REC_Pos);
3258 ErrorCounters->RxErrorPassive = ((CountersReg & FDCAN_ECR_RP) >> FDCAN_ECR_RP_Pos);
3259 ErrorCounters->ErrorLogging = ((CountersReg & FDCAN_ECR_CEL) >> FDCAN_ECR_CEL_Pos);
3261 /* Return function status */
3262 return HAL_OK;
3266 * @brief Check if a new message is received in the selected Rx buffer.
3267 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3268 * the configuration information for the specified FDCAN.
3269 * @param RxBufferIndex Rx buffer index.
3270 * This parameter must be a number between 0 and 63.
3271 * @retval Status
3272 * - 0 : No new message on RxBufferIndex.
3273 * - 1 : New message received on RxBufferIndex.
3275 uint32_t HAL_FDCAN_IsRxBufferMessageAvailable(FDCAN_HandleTypeDef *hfdcan, uint32_t RxBufferIndex)
3277 /* Check function parameters */
3278 assert_param(IS_FDCAN_MAX_VALUE(RxBufferIndex, 63U));
3279 uint32_t NewData1 = hfdcan->Instance->NDAT1;
3280 uint32_t NewData2 = hfdcan->Instance->NDAT2;
3282 /* Check new message reception on the selected buffer */
3283 if (((RxBufferIndex < 32U) && ((NewData1 & (uint32_t)((uint32_t)1 << RxBufferIndex)) == 0U)) ||
3284 ((RxBufferIndex >= 32U) && ((NewData2 & (uint32_t)((uint32_t)1 << (RxBufferIndex & 0x1FU))) == 0U)))
3286 return 0;
3289 /* Clear the New Data flag of the current Rx buffer */
3290 if (RxBufferIndex < 32U)
3292 hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxBufferIndex);
3294 else /* 32 <= RxBufferIndex <= 63 */
3296 hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxBufferIndex & 0x1FU));
3299 return 1;
3303 * @brief Check if a transmission request is pending on the selected Tx buffer.
3304 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3305 * the configuration information for the specified FDCAN.
3306 * @param TxBufferIndex Tx buffer index.
3307 * This parameter can be any combination of @arg FDCAN_Tx_location.
3308 * @retval Status
3309 * - 0 : No pending transmission request on TxBufferIndex.
3310 * - 1 : Pending transmission request on TxBufferIndex.
3312 uint32_t HAL_FDCAN_IsTxBufferMessagePending(FDCAN_HandleTypeDef *hfdcan, uint32_t TxBufferIndex)
3314 /* Check pending transmittion request on the selected buffer */
3315 if ((hfdcan->Instance->TXBRP & TxBufferIndex) == 0U)
3317 return 0;
3319 return 1;
3323 * @brief Return Rx FIFO fill level.
3324 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3325 * the configuration information for the specified FDCAN.
3326 * @param RxFifo Rx FIFO.
3327 * This parameter can be one of the following values:
3328 * @arg FDCAN_RX_FIFO0: Rx FIFO 0
3329 * @arg FDCAN_RX_FIFO1: Rx FIFO 1
3330 * @retval Level Rx FIFO fill level.
3332 uint32_t HAL_FDCAN_GetRxFifoFillLevel(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo)
3334 uint32_t FillLevel;
3336 /* Check function parameters */
3337 assert_param(IS_FDCAN_RX_FIFO(RxFifo));
3339 if (RxFifo == FDCAN_RX_FIFO0)
3341 FillLevel = hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL;
3343 else /* RxFifo == FDCAN_RX_FIFO1 */
3345 FillLevel = hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL;
3348 /* Return Rx FIFO fill level */
3349 return FillLevel;
3353 * @brief Return Tx FIFO free level: number of consecutive free Tx FIFO
3354 * elements starting from Tx FIFO GetIndex.
3355 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3356 * the configuration information for the specified FDCAN.
3357 * @retval Level Tx FIFO free level.
3359 uint32_t HAL_FDCAN_GetTxFifoFreeLevel(FDCAN_HandleTypeDef *hfdcan)
3361 uint32_t FreeLevel;
3363 FreeLevel = hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFFL;
3365 /* Return Tx FIFO free level */
3366 return FreeLevel;
3370 * @brief Check if the FDCAN peripheral entered Restricted Operation Mode.
3371 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3372 * the configuration information for the specified FDCAN.
3373 * @retval Status
3374 * - 0 : Normal FDCAN operation.
3375 * - 1 : Restricted Operation Mode active.
3377 uint32_t HAL_FDCAN_IsRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
3379 uint32_t OperationMode;
3381 /* Get Operation Mode */
3382 OperationMode = ((hfdcan->Instance->CCCR & FDCAN_CCCR_ASM) >> FDCAN_CCCR_ASM_Pos);
3384 return OperationMode;
3388 * @brief Exit Restricted Operation Mode.
3389 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3390 * the configuration information for the specified FDCAN.
3391 * @retval HAL status
3393 HAL_StatusTypeDef HAL_FDCAN_ExitRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
3395 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3397 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3399 /* Exit Restricted Operation mode */
3400 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
3402 /* Return function status */
3403 return HAL_OK;
3405 else
3407 /* Update error code */
3408 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3410 return HAL_ERROR;
3415 * @}
3418 /** @defgroup FDCAN_Exported_Functions_Group4 TT Configuration and control functions
3419 * @brief TT Configuration and control functions
3421 @verbatim
3422 ==============================================================================
3423 ##### TT Configuration and control functions #####
3424 ==============================================================================
3425 [..] This section provides functions allowing to:
3426 (+) HAL_FDCAN_TT_ConfigOperation : Initialize TT operation parameters
3427 (+) HAL_FDCAN_TT_ConfigReferenceMessage : Configure the reference message
3428 (+) HAL_FDCAN_TT_ConfigTrigger : Configure the FDCAN trigger
3429 (+) HAL_FDCAN_TT_SetGlobalTime : Schedule global time adjustment
3430 (+) HAL_FDCAN_TT_SetClockSynchronization : Schedule TUR numerator update
3431 (+) HAL_FDCAN_TT_ConfigStopWatch : Configure stop watch source and polarity
3432 (+) HAL_FDCAN_TT_ConfigRegisterTimeMark : Configure register time mark pulse generation
3433 (+) HAL_FDCAN_TT_EnableRegisterTimeMarkPulse : Enable register time mark pulse generation
3434 (+) HAL_FDCAN_TT_DisableRegisterTimeMarkPulse : Disable register time mark pulse generation
3435 (+) HAL_FDCAN_TT_EnableTriggerTimeMarkPulse : Enable trigger time mark pulse generation
3436 (+) HAL_FDCAN_TT_DisableTriggerTimeMarkPulse : Disable trigger time mark pulse generation
3437 (+) HAL_FDCAN_TT_EnableHardwareGapControl : Enable gap control by input pin fdcan1_evt
3438 (+) HAL_FDCAN_TT_DisableHardwareGapControl : Disable gap control by input pin fdcan1_evt
3439 (+) HAL_FDCAN_TT_EnableTimeMarkGapControl : Enable gap control (finish only) by register time mark interrupt
3440 (+) HAL_FDCAN_TT_DisableTimeMarkGapControl : Disable gap control by register time mark interrupt
3441 (+) HAL_FDCAN_TT_SetNextIsGap : Transmit next reference message with Next_is_Gap = "1"
3442 (+) HAL_FDCAN_TT_SetEndOfGap : Finish a Gap by requesting start of reference message
3443 (+) HAL_FDCAN_TT_ConfigExternalSyncPhase : Configure target phase used for external synchronization
3444 (+) HAL_FDCAN_TT_EnableExternalSynchronization : Synchronize the phase of the FDCAN schedule to an external schedule
3445 (+) HAL_FDCAN_TT_DisableExternalSynchronization : Disable external schedule synchronization
3446 (+) HAL_FDCAN_TT_GetOperationStatus : Get TT operation status
3448 @endverbatim
3449 * @{
3453 * @brief Initialize TT operation parameters.
3454 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3455 * the configuration information for the specified FDCAN.
3456 * @param pTTParams pointer to a FDCAN_TT_ConfigTypeDef structure.
3457 * @retval HAL status
3459 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigOperation(FDCAN_HandleTypeDef *hfdcan, FDCAN_TT_ConfigTypeDef *pTTParams)
3461 uint32_t tickstart;
3462 uint32_t RAMcounter;
3463 uint32_t StartAddress;
3465 /* Check function parameters */
3466 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3467 assert_param(IS_FDCAN_TT_TUR_NUMERATOR(pTTParams->TURNumerator));
3468 assert_param(IS_FDCAN_TT_TUR_DENOMINATOR(pTTParams->TURDenominator));
3469 assert_param(IS_FDCAN_TT_TIME_MASTER(pTTParams->TimeMaster));
3470 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->SyncDevLimit, 7U));
3471 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->InitRefTrigOffset, 127U));
3472 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->TriggerMemoryNbr, 64U));
3473 assert_param(IS_FDCAN_TT_CYCLE_START_SYNC(pTTParams->CycleStartSync));
3474 assert_param(IS_FDCAN_TT_STOP_WATCH_TRIGGER(pTTParams->StopWatchTrigSel));
3475 assert_param(IS_FDCAN_TT_EVENT_TRIGGER(pTTParams->EventTrigSel));
3476 if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
3478 assert_param(IS_FDCAN_TT_BASIC_CYCLES_NUMBER(pTTParams->BasicCyclesNbr));
3480 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3482 assert_param(IS_FDCAN_TT_OPERATION(pTTParams->GapEnable));
3483 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->AppWdgLimit, 255U));
3484 assert_param(IS_FDCAN_TT_EVENT_TRIGGER_POLARITY(pTTParams->EvtTrigPolarity));
3485 assert_param(IS_FDCAN_TT_TX_ENABLE_WINDOW(pTTParams->TxEnableWindow));
3486 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->ExpTxTrigNbr, 4095U));
3488 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
3490 assert_param(IS_FDCAN_TT_TUR_LEVEL_0_2(pTTParams->TURNumerator, pTTParams->TURDenominator));
3491 assert_param(IS_FDCAN_TT_EXTERNAL_CLK_SYNC(pTTParams->ExternalClkSync));
3492 assert_param(IS_FDCAN_TT_GLOBAL_TIME_FILTERING(pTTParams->GlobalTimeFilter));
3493 assert_param(IS_FDCAN_TT_AUTO_CLK_CALIBRATION(pTTParams->ClockCalibration));
3495 else
3497 assert_param(IS_FDCAN_TT_TUR_LEVEL_1(pTTParams->TURNumerator, pTTParams->TURDenominator));
3500 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3502 /* Stop local time in order to enable write access to the other bits of TURCF register */
3503 CLEAR_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
3505 /* Get tick */
3506 tickstart = HAL_GetTick();
3508 /* Wait until the ELT bit into TURCF register is reset */
3509 while ((hfdcan->ttcan->TURCF & FDCAN_TURCF_ELT) != 0U)
3511 /* Check for the Timeout */
3512 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
3514 /* Update error code */
3515 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3517 /* Change FDCAN state */
3518 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3520 return HAL_ERROR;
3524 /* Configure TUR (Time Unit Ratio) */
3525 MODIFY_REG(hfdcan->ttcan->TURCF,
3526 (FDCAN_TURCF_NCL | FDCAN_TURCF_DC),
3527 (((pTTParams->TURNumerator - 0x10000U) << FDCAN_TURCF_NCL_Pos) | (pTTParams->TURDenominator << FDCAN_TURCF_DC_Pos)));
3529 /* Enable local time */
3530 SET_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
3532 /* Configure TT operation */
3533 MODIFY_REG(hfdcan->ttcan->TTOCF,
3534 (FDCAN_TTOCF_OM | FDCAN_TTOCF_TM | FDCAN_TTOCF_LDSDL | FDCAN_TTOCF_IRTO),
3535 (pTTParams->OperationMode | \
3536 pTTParams->TimeMaster | \
3537 (pTTParams->SyncDevLimit << FDCAN_TTOCF_LDSDL_Pos) | \
3538 (pTTParams->InitRefTrigOffset << FDCAN_TTOCF_IRTO_Pos)));
3539 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3541 MODIFY_REG(hfdcan->ttcan->TTOCF,
3542 (FDCAN_TTOCF_GEN | FDCAN_TTOCF_AWL | FDCAN_TTOCF_EVTP),
3543 (pTTParams->GapEnable | \
3544 (pTTParams->AppWdgLimit << FDCAN_TTOCF_AWL_Pos) | \
3545 pTTParams->EvtTrigPolarity));
3547 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
3549 MODIFY_REG(hfdcan->ttcan->TTOCF,
3550 (FDCAN_TTOCF_EECS | FDCAN_TTOCF_EGTF | FDCAN_TTOCF_ECC),
3551 (pTTParams->ExternalClkSync | \
3552 pTTParams->GlobalTimeFilter | \
3553 pTTParams->ClockCalibration));
3556 /* Configure system matrix limits */
3557 MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CSS, pTTParams->CycleStartSync);
3558 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3560 MODIFY_REG(hfdcan->ttcan->TTMLM,
3561 (FDCAN_TTMLM_TXEW | FDCAN_TTMLM_ENTT),
3562 (((pTTParams->TxEnableWindow - 1U) << FDCAN_TTMLM_TXEW_Pos) | (pTTParams->ExpTxTrigNbr << FDCAN_TTMLM_ENTT_Pos)));
3564 if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
3566 MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CCM, pTTParams->BasicCyclesNbr);
3569 /* Configure input triggers: Stop watch and Event */
3570 MODIFY_REG(hfdcan->ttcan->TTTS,
3571 (FDCAN_TTTS_SWTSEL | FDCAN_TTTS_EVTSEL),
3572 (pTTParams->StopWatchTrigSel | pTTParams->EventTrigSel));
3574 /* Configure trigger memory start address */
3575 StartAddress = (hfdcan->msgRam.EndAddress - SRAMCAN_BASE) / 4U;
3576 MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TMSA, (StartAddress << FDCAN_TTTMC_TMSA_Pos));
3578 /* Trigger memory elements number */
3579 MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TME, (pTTParams->TriggerMemoryNbr << FDCAN_TTTMC_TME_Pos));
3581 /* Recalculate End Address */
3582 hfdcan->msgRam.TTMemorySA = hfdcan->msgRam.EndAddress;
3583 hfdcan->msgRam.EndAddress = hfdcan->msgRam.TTMemorySA + (pTTParams->TriggerMemoryNbr * 2U * 4U);
3585 if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
3587 /* Update error code.
3588 Message RAM overflow */
3589 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
3591 return HAL_ERROR;
3593 else
3595 /* Flush the allocated Message RAM area */
3596 for (RAMcounter = hfdcan->msgRam.TTMemorySA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
3598 *(uint32_t *)(RAMcounter) = 0x00000000;
3602 /* Return function status */
3603 return HAL_OK;
3605 else
3607 /* Update error code */
3608 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3610 return HAL_ERROR;
3615 * @brief Configure the reference message.
3616 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3617 * the configuration information for the specified FDCAN.
3618 * @param IdType Identifier Type.
3619 * This parameter can be a value of @arg FDCAN_id_type.
3620 * @param Identifier Reference Identifier.
3621 * This parameter must be a number between:
3622 * - 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
3623 * - 0 and 0x1FFFFFFF, if IdType is FDCAN_EXTENDED_ID
3624 * @param Payload Enable or disable the additional payload.
3625 * This parameter can be a value of @arg FDCAN_TT_Reference_Message_Payload.
3626 * This parameter is ignored in case of time slaves.
3627 * If this parameter is set to FDCAN_TT_REF_MESSAGE_ADD_PAYLOAD, the
3628 * following elements are taken from Tx Buffer 0:
3629 * - MessageMarker
3630 * - TxEventFifoControl
3631 * - DataLength
3632 * - Data Bytes (payload):
3633 * - bytes 2-8, for Level 1
3634 * - bytes 5-8, for Level 0 and Level 2
3635 * @retval HAL status
3637 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigReferenceMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t IdType, uint32_t Identifier, uint32_t Payload)
3639 /* Check function parameters */
3640 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3641 assert_param(IS_FDCAN_ID_TYPE(IdType));
3642 if (IdType == FDCAN_STANDARD_ID)
3644 assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x7FFU));
3646 else /* IdType == FDCAN_EXTENDED_ID */
3648 assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x1FFFFFFFU));
3650 assert_param(IS_FDCAN_TT_REFERENCE_MESSAGE_PAYLOAD(Payload));
3652 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3654 /* Configure reference message identifier type, identifier and payload */
3655 if (IdType == FDCAN_EXTENDED_ID)
3657 MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | Identifier));
3659 else /* IdType == FDCAN_STANDARD_ID */
3661 MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | (Identifier << 18)));
3664 /* Return function status */
3665 return HAL_OK;
3667 else
3669 /* Update error code */
3670 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3672 return HAL_ERROR;
3677 * @brief Configure the FDCAN trigger according to the specified
3678 * parameters in the FDCAN_TriggerTypeDef structure.
3679 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3680 * the configuration information for the specified FDCAN.
3681 * @param sTriggerConfig pointer to an FDCAN_TriggerTypeDef structure that
3682 * contains the trigger configuration information
3683 * @retval HAL status
3685 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigTrigger(FDCAN_HandleTypeDef *hfdcan, FDCAN_TriggerTypeDef *sTriggerConfig)
3687 uint32_t CycleCode;
3688 uint32_t MessageNumber;
3689 uint32_t TriggerElementW1;
3690 uint32_t TriggerElementW2;
3691 uint32_t *TriggerAddress;
3693 /* Check function parameters */
3694 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3695 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TriggerIndex, 63U));
3696 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TimeMark, 0xFFFFU));
3697 assert_param(IS_FDCAN_TT_REPEAT_FACTOR(sTriggerConfig->RepeatFactor));
3698 if (sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
3700 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->StartCycle, (sTriggerConfig->RepeatFactor - 1U)));
3702 assert_param(IS_FDCAN_TT_TM_EVENT_INTERNAL(sTriggerConfig->TmEventInt));
3703 assert_param(IS_FDCAN_TT_TM_EVENT_EXTERNAL(sTriggerConfig->TmEventExt));
3704 assert_param(IS_FDCAN_TT_TRIGGER_TYPE(sTriggerConfig->TriggerType));
3705 assert_param(IS_FDCAN_ID_TYPE(sTriggerConfig->FilterType));
3706 if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
3707 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
3708 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
3709 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
3711 assert_param(IS_FDCAN_TX_LOCATION(sTriggerConfig->TxBufferIndex));
3713 if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
3715 if (sTriggerConfig->FilterType == FDCAN_STANDARD_ID)
3717 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 63U));
3719 else /* sTriggerConfig->FilterType == FDCAN_EXTENDED_ID */
3721 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 127U));
3725 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3727 /* Calculate cycle code */
3728 if (sTriggerConfig->RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
3730 CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
3732 else /* sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
3734 CycleCode = sTriggerConfig->RepeatFactor + sTriggerConfig->StartCycle;
3737 /* Build first word of trigger element */
3738 TriggerElementW1 = ((sTriggerConfig->TimeMark << 16) | \
3739 (CycleCode << 8) | \
3740 sTriggerConfig->TmEventInt | \
3741 sTriggerConfig->TmEventExt | \
3742 sTriggerConfig->TriggerType);
3744 /* Select message number depending on trigger type (transmission or reception) */
3745 if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
3747 MessageNumber = sTriggerConfig->FilterIndex;
3749 else if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
3750 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
3751 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
3752 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
3754 MessageNumber = POSITION_VAL(sTriggerConfig->TxBufferIndex);
3756 else
3758 MessageNumber = 0U;
3761 /* Build second word of trigger element */
3762 TriggerElementW2 = ((sTriggerConfig->FilterType >> 7) | (MessageNumber << 16));
3764 /* Calculate trigger address */
3765 TriggerAddress = (uint32_t *)(hfdcan->msgRam.TTMemorySA + (sTriggerConfig->TriggerIndex * 4U * 2U));
3767 /* Write trigger element to the message RAM */
3768 *TriggerAddress = TriggerElementW1;
3769 TriggerAddress++;
3770 *TriggerAddress = TriggerElementW2;
3772 /* Return function status */
3773 return HAL_OK;
3775 else
3777 /* Update error code */
3778 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3780 return HAL_ERROR;
3785 * @brief Schedule global time adjustment for the next reference message.
3786 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3787 * the configuration information for the specified FDCAN.
3788 * @param TimePreset time preset value.
3789 * This parameter must be a number between:
3790 * - 0x0000 and 0x7FFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark + TimePreset
3791 * or
3792 * - 0x8001 and 0xFFFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark - (0x10000 - TimePreset)
3793 * @retval HAL status
3795 HAL_StatusTypeDef HAL_FDCAN_TT_SetGlobalTime(FDCAN_HandleTypeDef *hfdcan, uint32_t TimePreset)
3797 uint32_t Counter = 0U;
3798 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3800 /* Check function parameters */
3801 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3802 assert_param(IS_FDCAN_TT_TIME_PRESET(TimePreset));
3804 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3806 /* Check that the external clock synchronization is enabled */
3807 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
3809 /* Update error code */
3810 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
3812 return HAL_ERROR;
3815 /* Check that no global time preset is pending */
3816 if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WGTD) == FDCAN_TTOST_WGTD)
3818 /* Update error code */
3819 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
3821 return HAL_ERROR;
3824 /* Configure time preset */
3825 MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_TP, (TimePreset << FDCAN_TTGTP_TP_Pos));
3827 /* Wait until the LCKC bit into TTOCN register is reset */
3828 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3830 /* Check for the Timeout */
3831 if (Counter > FDCAN_TIMEOUT_COUNT)
3833 /* Update error code */
3834 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3836 /* Change FDCAN state */
3837 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3839 return HAL_ERROR;
3842 /* Increment counter */
3843 Counter++;
3846 /* Schedule time preset to take effect by the next reference message */
3847 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_SGT);
3849 /* Return function status */
3850 return HAL_OK;
3852 else
3854 /* Update error code */
3855 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3857 return HAL_ERROR;
3862 * @brief Schedule TUR numerator update for the next reference message.
3863 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3864 * the configuration information for the specified FDCAN.
3865 * @param NewTURNumerator new value of the TUR numerator.
3866 * This parameter must be a number between 0x10000 and 0x1FFFF.
3867 * @retval HAL status
3869 HAL_StatusTypeDef HAL_FDCAN_TT_SetClockSynchronization(FDCAN_HandleTypeDef *hfdcan, uint32_t NewTURNumerator)
3871 uint32_t Counter = 0U;
3872 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3874 /* Check function parameters */
3875 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3876 assert_param(IS_FDCAN_TT_TUR_NUMERATOR(NewTURNumerator));
3878 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3880 /* Check that the external clock synchronization is enabled */
3881 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
3883 /* Update error code */
3884 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
3886 return HAL_ERROR;
3889 /* Check that no external clock synchronization is pending */
3890 if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WECS) == FDCAN_TTOST_WECS)
3892 /* Update error code */
3893 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
3895 return HAL_ERROR;
3898 /* Configure new TUR numerator */
3899 MODIFY_REG(hfdcan->ttcan->TURCF, FDCAN_TURCF_NCL, (NewTURNumerator - 0x10000U));
3901 /* Wait until the LCKC bit into TTOCN register is reset */
3902 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3904 /* Check for the Timeout */
3905 if (Counter > FDCAN_TIMEOUT_COUNT)
3907 /* Update error code */
3908 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3910 /* Change FDCAN state */
3911 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3913 return HAL_ERROR;
3916 /* Increment counter */
3917 Counter++;
3920 /* Schedule TUR numerator update by the next reference message */
3921 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ECS);
3923 /* Return function status */
3924 return HAL_OK;
3926 else
3928 /* Update error code */
3929 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3931 return HAL_ERROR;
3936 * @brief Configure stop watch source and polarity.
3937 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3938 * the configuration information for the specified FDCAN.
3939 * @param Source stop watch source.
3940 * This parameter can be a value of @arg FDCAN_TT_stop_watch_source.
3941 * @param Polarity stop watch polarity.
3942 * This parameter can be a value of @arg FDCAN_TT_stop_watch_polarity.
3943 * @retval HAL status
3945 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigStopWatch(FDCAN_HandleTypeDef *hfdcan, uint32_t Source, uint32_t Polarity)
3947 uint32_t Counter = 0U;
3948 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3950 /* Check function parameters */
3951 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3952 assert_param(IS_FDCAN_TT_STOP_WATCH_SOURCE(Source));
3953 assert_param(IS_FDCAN_TT_STOP_WATCH_POLARITY(Polarity));
3955 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3957 /* Wait until the LCKC bit into TTOCN register is reset */
3958 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3960 /* Check for the Timeout */
3961 if (Counter > FDCAN_TIMEOUT_COUNT)
3963 /* Update error code */
3964 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3966 /* Change FDCAN state */
3967 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3969 return HAL_ERROR;
3972 /* Increment counter */
3973 Counter++;
3976 /* Select stop watch source and polarity */
3977 MODIFY_REG(hfdcan->ttcan->TTOCN, (FDCAN_TTOCN_SWS | FDCAN_TTOCN_SWP), (Source | Polarity));
3979 /* Return function status */
3980 return HAL_OK;
3982 else
3984 /* Update error code */
3985 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3987 return HAL_ERROR;
3992 * @brief Configure register time mark pulse generation.
3993 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3994 * the configuration information for the specified FDCAN.
3995 * @param TimeMarkSource time mark source.
3996 * This parameter can be a value of @arg FDCAN_TT_time_mark_source.
3997 * @param TimeMarkValue time mark value (reference).
3998 * This parameter must be a number between 0 and 0xFFFF.
3999 * @param RepeatFactor repeat factor of the cycle for which the time mark is valid.
4000 * This parameter can be a value of @arg FDCAN_TT_Repeat_Factor.
4001 * @param StartCycle index of the first cycle in which the time mark becomes valid.
4002 * This parameter is ignored if RepeatFactor is set to FDCAN_TT_REPEAT_EVERY_CYCLE.
4003 * This parameter must be a number between 0 and RepeatFactor.
4004 * @retval HAL status
4006 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigRegisterTimeMark(FDCAN_HandleTypeDef *hfdcan,
4007 uint32_t TimeMarkSource, uint32_t TimeMarkValue,
4008 uint32_t RepeatFactor, uint32_t StartCycle)
4010 uint32_t Counter = 0U;
4011 uint32_t CycleCode;
4012 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4014 /* Check function parameters */
4015 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4016 assert_param(IS_FDCAN_TT_REGISTER_TIME_MARK_SOURCE(TimeMarkSource));
4017 assert_param(IS_FDCAN_MAX_VALUE(TimeMarkValue, 0xFFFFU));
4018 assert_param(IS_FDCAN_TT_REPEAT_FACTOR(RepeatFactor));
4019 if (RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
4021 assert_param(IS_FDCAN_MAX_VALUE(StartCycle, (RepeatFactor - 1U)));
4024 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4026 /* Wait until the LCKC bit into TTOCN register is reset */
4027 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4029 /* Check for the Timeout */
4030 if (Counter > FDCAN_TIMEOUT_COUNT)
4032 /* Update error code */
4033 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4035 /* Change FDCAN state */
4036 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4038 return HAL_ERROR;
4041 /* Increment counter */
4042 Counter++;
4045 /* Disable the time mark compare function */
4046 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC);
4048 if (TimeMarkSource != FDCAN_TT_REG_TIMEMARK_DIABLED)
4050 /* Calculate cycle code */
4051 if (RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
4053 CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
4055 else /* RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
4057 CycleCode = RepeatFactor + StartCycle;
4060 Counter = 0U;
4062 /* Wait until the LCKM bit into TTTMK register is reset */
4063 while ((hfdcan->ttcan->TTTMK & FDCAN_TTTMK_LCKM) != 0U)
4065 /* Check for the Timeout */
4066 if (Counter > FDCAN_TIMEOUT_COUNT)
4068 /* Update error code */
4069 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4071 /* Change FDCAN state */
4072 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4074 return HAL_ERROR;
4077 /* Increment counter */
4078 Counter++;
4081 /* Configure time mark value and cycle code */
4082 hfdcan->ttcan->TTTMK = ((TimeMarkValue << FDCAN_TTTMK_TM_Pos) | (CycleCode << FDCAN_TTTMK_TICC_Pos));
4084 Counter = 0U;
4086 /* Wait until the LCKC bit into TTOCN register is reset */
4087 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4089 /* Check for the Timeout */
4090 if (Counter > FDCAN_TIMEOUT_COUNT)
4092 /* Update error code */
4093 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4095 /* Change FDCAN state */
4096 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4098 return HAL_ERROR;
4101 /* Increment counter */
4102 Counter++;
4105 /* Update the register time mark compare source */
4106 MODIFY_REG(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC, TimeMarkSource);
4109 /* Return function status */
4110 return HAL_OK;
4112 else
4114 /* Update error code */
4115 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4117 return HAL_ERROR;
4122 * @brief Enable register time mark pulse generation.
4123 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4124 * the configuration information for the specified FDCAN.
4125 * @retval HAL status
4127 HAL_StatusTypeDef HAL_FDCAN_TT_EnableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4129 uint32_t Counter = 0U;
4130 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4132 /* Check function parameters */
4133 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4135 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4137 /* Wait until the LCKC bit into TTOCN register is reset */
4138 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4140 /* Check for the Timeout */
4141 if (Counter > FDCAN_TIMEOUT_COUNT)
4143 /* Update error code */
4144 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4146 /* Change FDCAN state */
4147 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4149 return HAL_ERROR;
4152 /* Increment counter */
4153 Counter++;
4156 /* Enable Register Time Mark Interrupt output on fdcan1_rtp */
4157 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
4159 /* Return function status */
4160 return HAL_OK;
4162 else
4164 /* Update error code */
4165 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4167 return HAL_ERROR;
4172 * @brief Disable register time mark pulse generation.
4173 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4174 * the configuration information for the specified FDCAN.
4175 * @retval HAL status
4177 HAL_StatusTypeDef HAL_FDCAN_TT_DisableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4179 uint32_t Counter = 0U;
4180 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4182 /* Check function parameters */
4183 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4185 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4187 /* Wait until the LCKC bit into TTOCN register is reset */
4188 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4190 /* Check for the Timeout */
4191 if (Counter > FDCAN_TIMEOUT_COUNT)
4193 /* Update error code */
4194 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4196 /* Change FDCAN state */
4197 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4199 return HAL_ERROR;
4202 /* Increment counter */
4203 Counter++;
4206 /* Disable Register Time Mark Interrupt output on fdcan1_rtp */
4207 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
4209 /* Return function status */
4210 return HAL_OK;
4212 else
4214 /* Update error code */
4215 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4217 return HAL_ERROR;
4222 * @brief Enable trigger time mark pulse generation.
4223 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4224 * the configuration information for the specified FDCAN.
4225 * @retval HAL status
4227 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4229 uint32_t Counter = 0U;
4230 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4232 /* Check function parameters */
4233 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4235 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4237 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4239 /* Wait until the LCKC bit into TTOCN register is reset */
4240 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4242 /* Check for the Timeout */
4243 if (Counter > FDCAN_TIMEOUT_COUNT)
4245 /* Update error code */
4246 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4248 /* Change FDCAN state */
4249 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4251 return HAL_ERROR;
4254 /* Increment counter */
4255 Counter++;
4258 /* Enable Trigger Time Mark Interrupt output on fdcan1_tmp */
4259 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
4261 /* Return function status */
4262 return HAL_OK;
4264 else
4266 /* Update error code.
4267 Feature not supported for TT Level 0 */
4268 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4270 return HAL_ERROR;
4273 else
4275 /* Update error code */
4276 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4278 return HAL_ERROR;
4283 * @brief Disable trigger time mark pulse generation.
4284 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4285 * the configuration information for the specified FDCAN.
4286 * @retval HAL status
4288 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4290 uint32_t Counter = 0U;
4291 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4293 /* Check function parameters */
4294 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4296 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4298 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4300 /* Wait until the LCKC bit into TTOCN register is reset */
4301 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4303 /* Check for the Timeout */
4304 if (Counter > FDCAN_TIMEOUT_COUNT)
4306 /* Update error code */
4307 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4309 /* Change FDCAN state */
4310 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4312 return HAL_ERROR;
4315 /* Increment counter */
4316 Counter++;
4319 /* Disable Trigger Time Mark Interrupt output on fdcan1_rtp */
4320 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
4322 /* Return function status */
4323 return HAL_OK;
4325 else
4327 /* Update error code.
4328 Feature not supported for TT Level 0 */
4329 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4331 return HAL_ERROR;
4334 else
4336 /* Update error code */
4337 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4339 return HAL_ERROR;
4344 * @brief Enable gap control by input pin fdcan1_evt.
4345 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4346 * the configuration information for the specified FDCAN.
4347 * @retval HAL status
4349 HAL_StatusTypeDef HAL_FDCAN_TT_EnableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
4351 uint32_t Counter = 0U;
4352 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4354 /* Check function parameters */
4355 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4357 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4359 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4361 /* Wait until the LCKC bit into TTOCN register is reset */
4362 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4364 /* Check for the Timeout */
4365 if (Counter > FDCAN_TIMEOUT_COUNT)
4367 /* Update error code */
4368 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4370 /* Change FDCAN state */
4371 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4373 return HAL_ERROR;
4376 /* Increment counter */
4377 Counter++;
4380 /* Enable gap control by pin fdcan1_evt */
4381 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
4383 /* Return function status */
4384 return HAL_OK;
4386 else
4388 /* Update error code.
4389 Feature not supported for TT Level 0 */
4390 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4392 return HAL_ERROR;
4395 else
4397 /* Update error code */
4398 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4400 return HAL_ERROR;
4405 * @brief Disable gap control by input pin fdcan1_evt.
4406 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4407 * the configuration information for the specified FDCAN.
4408 * @retval HAL status
4410 HAL_StatusTypeDef HAL_FDCAN_TT_DisableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
4412 uint32_t Counter = 0U;
4413 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4415 /* Check function parameters */
4416 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4418 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4420 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4422 /* Wait until the LCKC bit into TTOCN register is reset */
4423 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4425 /* Check for the Timeout */
4426 if (Counter > FDCAN_TIMEOUT_COUNT)
4428 /* Update error code */
4429 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4431 /* Change FDCAN state */
4432 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4434 return HAL_ERROR;
4437 /* Increment counter */
4438 Counter++;
4441 /* Disable gap control by pin fdcan1_evt */
4442 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
4444 /* Return function status */
4445 return HAL_OK;
4447 else
4449 /* Update error code.
4450 Feature not supported for TT Level 0 */
4451 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4453 return HAL_ERROR;
4456 else
4458 /* Update error code */
4459 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4461 return HAL_ERROR;
4466 * @brief Enable gap control (finish only) by register time mark interrupt.
4467 * The next register time mark interrupt (TTIR.RTMI = "1") will finish
4468 * the Gap and start the reference message.
4469 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4470 * the configuration information for the specified FDCAN.
4471 * @retval HAL status
4473 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
4475 uint32_t Counter = 0U;
4476 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4478 /* Check function parameters */
4479 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4481 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4483 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4485 /* Wait until the LCKC bit into TTOCN register is reset */
4486 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4488 /* Check for the Timeout */
4489 if (Counter > FDCAN_TIMEOUT_COUNT)
4491 /* Update error code */
4492 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4494 /* Change FDCAN state */
4495 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4497 return HAL_ERROR;
4500 /* Increment counter */
4501 Counter++;
4504 /* Enable gap control by register time mark interrupt */
4505 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
4507 /* Return function status */
4508 return HAL_OK;
4510 else
4512 /* Update error code.
4513 Feature not supported for TT Level 0 */
4514 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4516 return HAL_ERROR;
4519 else
4521 /* Update error code */
4522 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4524 return HAL_ERROR;
4529 * @brief Disable gap control by register time mark interrupt.
4530 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4531 * the configuration information for the specified FDCAN.
4532 * @retval HAL status
4534 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
4536 uint32_t Counter = 0U;
4537 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4539 /* Check function parameters */
4540 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4542 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4544 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4546 /* Wait until the LCKC bit into TTOCN register is reset */
4547 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4549 /* Check for the Timeout */
4550 if (Counter > FDCAN_TIMEOUT_COUNT)
4552 /* Update error code */
4553 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4555 /* Change FDCAN state */
4556 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4558 return HAL_ERROR;
4561 /* Increment counter */
4562 Counter++;
4565 /* Disable gap control by register time mark interrupt */
4566 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
4568 /* Return function status */
4569 return HAL_OK;
4571 else
4573 /* Update error code.
4574 Feature not supported for TT Level 0 */
4575 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4577 return HAL_ERROR;
4580 else
4582 /* Update error code */
4583 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4585 return HAL_ERROR;
4590 * @brief Transmit next reference message with Next_is_Gap = "1".
4591 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4592 * the configuration information for the specified FDCAN.
4593 * @retval HAL status
4595 HAL_StatusTypeDef HAL_FDCAN_TT_SetNextIsGap(FDCAN_HandleTypeDef *hfdcan)
4597 uint32_t Counter = 0U;
4598 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4600 /* Check function parameters */
4601 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4603 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4605 /* Check that the node is configured for external event-synchronized TT operation */
4606 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
4608 /* Update error code */
4609 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4611 return HAL_ERROR;
4614 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4616 /* Wait until the LCKC bit into TTOCN register is reset */
4617 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4619 /* Check for the Timeout */
4620 if (Counter > FDCAN_TIMEOUT_COUNT)
4622 /* Update error code */
4623 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4625 /* Change FDCAN state */
4626 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4628 return HAL_ERROR;
4631 /* Increment counter */
4632 Counter++;
4635 /* Set Next is Gap */
4636 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_NIG);
4638 /* Return function status */
4639 return HAL_OK;
4641 else
4643 /* Update error code.
4644 Feature not supported for TT Level 0 */
4645 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4647 return HAL_ERROR;
4650 else
4652 /* Update error code */
4653 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4655 return HAL_ERROR;
4660 * @brief Finish a Gap by requesting start of reference message.
4661 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4662 * the configuration information for the specified FDCAN.
4663 * @retval HAL status
4665 HAL_StatusTypeDef HAL_FDCAN_TT_SetEndOfGap(FDCAN_HandleTypeDef *hfdcan)
4667 uint32_t Counter = 0U;
4668 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4670 /* Check function parameters */
4671 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4673 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4675 /* Check that the node is configured for external event-synchronized TT operation */
4676 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
4678 /* Update error code */
4679 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4681 return HAL_ERROR;
4684 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4686 /* Wait until the LCKC bit into TTOCN register is reset */
4687 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4689 /* Check for the Timeout */
4690 if (Counter > FDCAN_TIMEOUT_COUNT)
4692 /* Update error code */
4693 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4695 /* Change FDCAN state */
4696 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4698 return HAL_ERROR;
4701 /* Increment counter */
4702 Counter++;
4705 /* Set Finish Gap */
4706 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_FGP);
4708 /* Return function status */
4709 return HAL_OK;
4711 else
4713 /* Update error code.
4714 Feature not supported for TT Level 0 */
4715 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4717 return HAL_ERROR;
4720 else
4722 /* Update error code */
4723 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4725 return HAL_ERROR;
4730 * @brief Configure target phase used for external synchronization by event
4731 * trigger input pin fdcan1_evt.
4732 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4733 * the configuration information for the specified FDCAN.
4734 * @param TargetPhase defines target value of cycle time when a rising edge
4735 * of fdcan1_evt is expected.
4736 * This parameter must be a number between 0 and 0xFFFF.
4737 * @retval HAL status
4739 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigExternalSyncPhase(FDCAN_HandleTypeDef *hfdcan, uint32_t TargetPhase)
4741 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4743 /* Check function parameters */
4744 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4745 assert_param(IS_FDCAN_MAX_VALUE(TargetPhase, 0xFFFFU));
4747 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4749 /* Check that no external schedule synchronization is pending */
4750 if ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_ESCN) == FDCAN_TTOCN_ESCN)
4752 /* Update error code */
4753 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
4755 return HAL_ERROR;
4758 /* Configure cycle time target phase */
4759 MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_CTP, (TargetPhase << FDCAN_TTGTP_CTP_Pos));
4761 /* Return function status */
4762 return HAL_OK;
4764 else
4766 /* Update error code */
4767 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4769 return HAL_ERROR;
4774 * @brief Synchronize the phase of the FDCAN schedule to an external schedule
4775 * using event trigger input pin fdcan1_evt.
4776 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4777 * the configuration information for the specified FDCAN.
4778 * @retval HAL status
4780 HAL_StatusTypeDef HAL_FDCAN_TT_EnableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
4782 uint32_t Counter = 0U;
4783 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4785 /* Check function parameters */
4786 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4788 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4790 /* Wait until the LCKC bit into TTOCN register is reset */
4791 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4793 /* Check for the Timeout */
4794 if (Counter > FDCAN_TIMEOUT_COUNT)
4796 /* Update error code */
4797 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4799 /* Change FDCAN state */
4800 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4802 return HAL_ERROR;
4805 /* Increment counter */
4806 Counter++;
4809 /* Enable external synchronization */
4810 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
4812 /* Return function status */
4813 return HAL_OK;
4815 else
4817 /* Update error code */
4818 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4820 return HAL_ERROR;
4825 * @brief Disable external schedule synchronization.
4826 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4827 * the configuration information for the specified FDCAN.
4828 * @retval HAL status
4830 HAL_StatusTypeDef HAL_FDCAN_TT_DisableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
4832 uint32_t Counter = 0U;
4833 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4835 /* Check function parameters */
4836 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4838 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4840 /* Wait until the LCKC bit into TTOCN register is reset */
4841 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4843 /* Check for the Timeout */
4844 if (Counter > FDCAN_TIMEOUT_COUNT)
4846 /* Update error code */
4847 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4849 /* Change FDCAN state */
4850 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4852 return HAL_ERROR;
4855 /* Increment counter */
4856 Counter++;
4859 /* Disable external synchronization */
4860 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
4862 /* Return function status */
4863 return HAL_OK;
4865 else
4867 /* Update error code */
4868 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4870 return HAL_ERROR;
4875 * @brief Get TT operation status.
4876 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4877 * the configuration information for the specified FDCAN.
4878 * @param TTOpStatus pointer to an FDCAN_TTOperationStatusTypeDef structure.
4879 * @retval HAL status
4881 HAL_StatusTypeDef HAL_FDCAN_TT_GetOperationStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_TTOperationStatusTypeDef *TTOpStatus)
4883 uint32_t TTStatusReg;
4885 /* Check function parameters */
4886 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4888 /* Read the TT operation status register */
4889 TTStatusReg = READ_REG(hfdcan->ttcan->TTOST);
4891 /* Fill the TT operation status structure */
4892 TTOpStatus->ErrorLevel = (TTStatusReg & FDCAN_TTOST_EL);
4893 TTOpStatus->MasterState = (TTStatusReg & FDCAN_TTOST_MS);
4894 TTOpStatus->SyncState = (TTStatusReg & FDCAN_TTOST_SYS);
4895 TTOpStatus->GTimeQuality = ((TTStatusReg & FDCAN_TTOST_QGTP) >> FDCAN_TTOST_QGTP_Pos);
4896 TTOpStatus->ClockQuality = ((TTStatusReg & FDCAN_TTOST_QCS) >> FDCAN_TTOST_QCS_Pos);
4897 TTOpStatus->RefTrigOffset = ((TTStatusReg & FDCAN_TTOST_RTO) >> FDCAN_TTOST_RTO_Pos);
4898 TTOpStatus->GTimeDiscPending = ((TTStatusReg & FDCAN_TTOST_WGTD) >> FDCAN_TTOST_WGTD_Pos);
4899 TTOpStatus->GapFinished = ((TTStatusReg & FDCAN_TTOST_GFI) >> FDCAN_TTOST_GFI_Pos);
4900 TTOpStatus->MasterPriority = ((TTStatusReg & FDCAN_TTOST_TMP) >> FDCAN_TTOST_TMP_Pos);
4901 TTOpStatus->GapStarted = ((TTStatusReg & FDCAN_TTOST_GSI) >> FDCAN_TTOST_GSI_Pos);
4902 TTOpStatus->WaitForEvt = ((TTStatusReg & FDCAN_TTOST_WFE) >> FDCAN_TTOST_WFE_Pos);
4903 TTOpStatus->AppWdgEvt = ((TTStatusReg & FDCAN_TTOST_AWE) >> FDCAN_TTOST_AWE_Pos);
4904 TTOpStatus->ECSPending = ((TTStatusReg & FDCAN_TTOST_WECS) >> FDCAN_TTOST_WECS_Pos);
4905 TTOpStatus->PhaseLock = ((TTStatusReg & FDCAN_TTOST_SPL) >> FDCAN_TTOST_SPL_Pos);
4907 /* Return function status */
4908 return HAL_OK;
4912 * @}
4915 /** @defgroup FDCAN_Exported_Functions_Group5 Interrupts management
4916 * @brief Interrupts management
4918 @verbatim
4919 ==============================================================================
4920 ##### Interrupts management #####
4921 ==============================================================================
4922 [..] This section provides functions allowing to:
4923 (+) HAL_FDCAN_ConfigInterruptLines : Assign interrupts to either Interrupt line 0 or 1
4924 (+) HAL_FDCAN_TT_ConfigInterruptLines : Assign TT interrupts to either Interrupt line 0 or 1
4925 (+) HAL_FDCAN_ActivateNotification : Enable interrupts
4926 (+) HAL_FDCAN_DeactivateNotification : Disable interrupts
4927 (+) HAL_FDCAN_TT_ActivateNotification : Enable TT interrupts
4928 (+) HAL_FDCAN_TT_DeactivateNotification : Disable TT interrupts
4929 (+) HAL_FDCAN_IRQHandler : Handles FDCAN interrupt request
4931 @endverbatim
4932 * @{
4936 * @brief Assign interrupts to either Interrupt line 0 or 1.
4937 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4938 * the configuration information for the specified FDCAN.
4939 * @param ITList indicates which interrupts will be assigned to the selected interrupt line.
4940 * This parameter can be any combination of @arg FDCAN_Interrupts.
4941 * @param InterruptLine Interrupt line.
4942 * This parameter can be a value of @arg FDCAN_Interrupt_Line.
4943 * @retval HAL status
4945 HAL_StatusTypeDef HAL_FDCAN_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t ITList, uint32_t InterruptLine)
4947 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4949 /* Check function parameters */
4950 assert_param(IS_FDCAN_IT(ITList));
4951 assert_param(IS_FDCAN_IT_LINE(InterruptLine));
4953 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4955 /* Assign list of interrupts to the selected line */
4956 if (InterruptLine == FDCAN_INTERRUPT_LINE0)
4958 CLEAR_BIT(hfdcan->Instance->ILS, ITList);
4960 else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
4962 SET_BIT(hfdcan->Instance->ILS, ITList);
4965 /* Return function status */
4966 return HAL_OK;
4968 else
4970 /* Update error code */
4971 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4973 return HAL_ERROR;
4978 * @brief Assign TT interrupts to either Interrupt line 0 or 1.
4979 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4980 * the configuration information for the specified FDCAN.
4981 * @param TTITList indicates which interrupts will be assigned to the selected interrupt line.
4982 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
4983 * @param InterruptLine Interrupt line.
4984 * This parameter can be a value of @arg FDCAN_Interrupt_Line.
4985 * @retval HAL status
4987 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t TTITList, uint32_t InterruptLine)
4989 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4991 /* Check function parameters */
4992 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4993 assert_param(IS_FDCAN_TT_IT(TTITList));
4994 assert_param(IS_FDCAN_IT_LINE(InterruptLine));
4996 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4998 /* Assign list of interrupts to the selected line */
4999 if (InterruptLine == FDCAN_INTERRUPT_LINE0)
5001 CLEAR_BIT(hfdcan->ttcan->TTILS, TTITList);
5003 else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
5005 SET_BIT(hfdcan->ttcan->TTILS, TTITList);
5008 /* Return function status */
5009 return HAL_OK;
5011 else
5013 /* Update error code */
5014 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5016 return HAL_ERROR;
5021 * @brief Enable interrupts.
5022 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5023 * the configuration information for the specified FDCAN.
5024 * @param ActiveITs indicates which interrupts will be enabled.
5025 * This parameter can be any combination of @arg FDCAN_Interrupts.
5026 * @param BufferIndexes Tx Buffer Indexes.
5027 * This parameter can be any combination of @arg FDCAN_Tx_location.
5028 * This parameter is ignored if ActiveITs does not include one of the following:
5029 * - FDCAN_IT_TX_COMPLETE
5030 * - FDCAN_IT_TX_ABORT_COMPLETE
5031 * @retval HAL status
5033 HAL_StatusTypeDef HAL_FDCAN_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveITs, uint32_t BufferIndexes)
5035 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5037 /* Check function parameters */
5038 assert_param(IS_FDCAN_IT(ActiveITs));
5040 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5042 /* Enable Interrupt lines */
5043 if ((ActiveITs & hfdcan->Instance->ILS) == 0U)
5045 /* Enable Interrupt line 0 */
5046 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5048 else if ((ActiveITs & hfdcan->Instance->ILS) == ActiveITs)
5050 /* Enable Interrupt line 1 */
5051 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5053 else
5055 /* Enable Interrupt lines 0 and 1 */
5056 hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
5059 if ((ActiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
5061 /* Enable Tx Buffer Transmission Interrupt to set TC flag in IR register,
5062 but interrupt will only occure if TC is enabled in IE register */
5063 SET_BIT(hfdcan->Instance->TXBTIE, BufferIndexes);
5066 if ((ActiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5068 /* Enable Tx Buffer Cancellation Finished Interrupt to set TCF flag in IR register,
5069 but interrupt will only occure if TCF is enabled in IE register */
5070 SET_BIT(hfdcan->Instance->TXBCIE, BufferIndexes);
5073 /* Enable the selected interrupts */
5074 __HAL_FDCAN_ENABLE_IT(hfdcan, ActiveITs);
5076 /* Return function status */
5077 return HAL_OK;
5079 else
5081 /* Update error code */
5082 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5084 return HAL_ERROR;
5089 * @brief Disable interrupts.
5090 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5091 * the configuration information for the specified FDCAN.
5092 * @param InactiveITs indicates which interrupts will be disabled.
5093 * This parameter can be any combination of @arg FDCAN_Interrupts.
5094 * @retval HAL status
5096 HAL_StatusTypeDef HAL_FDCAN_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveITs)
5098 uint32_t ITLineSelection;
5099 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5101 /* Check function parameters */
5102 assert_param(IS_FDCAN_IT(InactiveITs));
5104 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5106 /* Disable the selected interrupts */
5107 __HAL_FDCAN_DISABLE_IT(hfdcan, InactiveITs);
5109 if ((InactiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
5111 /* Disable Tx Buffer Transmission Interrupts */
5112 CLEAR_REG(hfdcan->Instance->TXBTIE);
5115 if ((InactiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5117 /* Disable Tx Buffer Cancellation Finished Interrupt */
5118 CLEAR_REG(hfdcan->Instance->TXBCIE);
5121 ITLineSelection = hfdcan->Instance->ILS;
5123 if ((hfdcan->Instance->IE | ITLineSelection) == ITLineSelection)
5125 /* Disable Interrupt line 0 */
5126 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5129 if ((hfdcan->Instance->IE & ITLineSelection) == 0U)
5131 /* Disable Interrupt line 1 */
5132 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5135 /* Return function status */
5136 return HAL_OK;
5138 else
5140 /* Update error code */
5141 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5143 return HAL_ERROR;
5148 * @brief Enable TT interrupts.
5149 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5150 * the configuration information for the specified FDCAN.
5151 * @param ActiveTTITs indicates which TT interrupts will be enabled.
5152 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
5153 * @retval HAL status
5155 HAL_StatusTypeDef HAL_FDCAN_TT_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveTTITs)
5157 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5159 /* Check function parameters */
5160 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
5161 assert_param(IS_FDCAN_TT_IT(ActiveTTITs));
5163 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5165 /* Enable Interrupt lines */
5166 if ((ActiveTTITs & hfdcan->ttcan->TTILS) == 0U)
5168 /* Enable Interrupt line 0 */
5169 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5171 else if ((ActiveTTITs & hfdcan->ttcan->TTILS) == ActiveTTITs)
5173 /* Enable Interrupt line 1 */
5174 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5176 else
5178 /* Enable Interrupt lines 0 and 1 */
5179 hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
5182 /* Enable the selected TT interrupts */
5183 __HAL_FDCAN_TT_ENABLE_IT(hfdcan, ActiveTTITs);
5185 /* Return function status */
5186 return HAL_OK;
5188 else
5190 /* Update error code */
5191 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5193 return HAL_ERROR;
5198 * @brief Disable TT interrupts.
5199 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5200 * the configuration information for the specified FDCAN.
5201 * @param InactiveTTITs indicates which TT interrupts will be disabled.
5202 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
5203 * @retval HAL status
5205 HAL_StatusTypeDef HAL_FDCAN_TT_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveTTITs)
5207 uint32_t ITLineSelection;
5208 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5210 /* Check function parameters */
5211 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
5212 assert_param(IS_FDCAN_TT_IT(InactiveTTITs));
5214 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5216 /* Disable the selected TT interrupts */
5217 __HAL_FDCAN_TT_DISABLE_IT(hfdcan, InactiveTTITs);
5219 ITLineSelection = hfdcan->ttcan->TTILS;
5221 if ((hfdcan->ttcan->TTIE | ITLineSelection) == ITLineSelection)
5223 /* Disable Interrupt line 0 */
5224 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5227 if ((hfdcan->ttcan->TTIE & ITLineSelection) == 0U)
5229 /* Disable Interrupt line 1 */
5230 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5233 /* Return function status */
5234 return HAL_OK;
5236 else
5238 /* Update error code */
5239 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5241 return HAL_ERROR;
5246 * @brief Handles FDCAN interrupt request.
5247 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5248 * the configuration information for the specified FDCAN.
5249 * @retval HAL status
5251 void HAL_FDCAN_IRQHandler(FDCAN_HandleTypeDef *hfdcan)
5253 uint32_t ClkCalibrationITs;
5254 uint32_t TxEventFifoITs;
5255 uint32_t RxFifo0ITs;
5256 uint32_t RxFifo1ITs;
5257 uint32_t Errors;
5258 uint32_t ErrorStatusITs;
5259 uint32_t TransmittedBuffers;
5260 uint32_t AbortedBuffers;
5261 uint32_t TTSchedSyncITs;
5262 uint32_t TTTimeMarkITs;
5263 uint32_t TTGlobTimeITs;
5264 uint32_t TTDistErrors;
5265 uint32_t TTFatalErrors;
5266 uint32_t SWTime;
5267 uint32_t SWCycleCount;
5269 ClkCalibrationITs = (FDCAN_CCU->IR << 30);
5270 ClkCalibrationITs &= (FDCAN_CCU->IE << 30);
5271 TxEventFifoITs = hfdcan->Instance->IR & FDCAN_TX_EVENT_FIFO_MASK;
5272 TxEventFifoITs &= hfdcan->Instance->IE;
5273 RxFifo0ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO0_MASK;
5274 RxFifo0ITs &= hfdcan->Instance->IE;
5275 RxFifo1ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO1_MASK;
5276 RxFifo1ITs &= hfdcan->Instance->IE;
5277 Errors = hfdcan->Instance->IR & FDCAN_ERROR_MASK;
5278 Errors &= hfdcan->Instance->IE;
5279 ErrorStatusITs = hfdcan->Instance->IR & FDCAN_ERROR_STATUS_MASK;
5280 ErrorStatusITs &= hfdcan->Instance->IE;
5282 /* High Priority Message interrupt management *******************************/
5283 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_HIGH_PRIORITY_MSG) != 0U)
5285 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG) != 0U)
5287 /* Clear the High Priority Message flag */
5288 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG);
5290 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5291 /* Call registered callback*/
5292 hfdcan->HighPriorityMessageCallback(hfdcan);
5293 #else
5294 /* High Priority Message Callback */
5295 HAL_FDCAN_HighPriorityMessageCallback(hfdcan);
5296 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5300 /* Transmission Abort interrupt management **********************************/
5301 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5303 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE) != 0U)
5305 /* List of aborted monitored buffers */
5306 AbortedBuffers = hfdcan->Instance->TXBCF;
5307 AbortedBuffers &= hfdcan->Instance->TXBCIE;
5309 /* Clear the Transmission Cancellation flag */
5310 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE);
5312 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5313 /* Call registered callback*/
5314 hfdcan->TxBufferAbortCallback(hfdcan, AbortedBuffers);
5315 #else
5316 /* Transmission Cancellation Callback */
5317 HAL_FDCAN_TxBufferAbortCallback(hfdcan, AbortedBuffers);
5318 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5322 /* Clock calibration unit interrupts management *****************************/
5323 if (ClkCalibrationITs != 0U)
5325 /* Clear the Clock Calibration flags */
5326 __HAL_FDCAN_CLEAR_FLAG(hfdcan, ClkCalibrationITs);
5328 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5329 /* Call registered callback*/
5330 hfdcan->ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
5331 #else
5332 /* Clock Calibration Callback */
5333 HAL_FDCAN_ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
5334 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5337 /* Tx event FIFO interrupts management **************************************/
5338 if (TxEventFifoITs != 0U)
5340 /* Clear the Tx Event FIFO flags */
5341 __HAL_FDCAN_CLEAR_FLAG(hfdcan, TxEventFifoITs);
5343 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5344 /* Call registered callback*/
5345 hfdcan->TxEventFifoCallback(hfdcan, TxEventFifoITs);
5346 #else
5347 /* Tx Event FIFO Callback */
5348 HAL_FDCAN_TxEventFifoCallback(hfdcan, TxEventFifoITs);
5349 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5352 /* Rx FIFO 0 interrupts management ******************************************/
5353 if (RxFifo0ITs != 0U)
5355 /* Clear the Rx FIFO 0 flags */
5356 __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo0ITs);
5358 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5359 /* Call registered callback*/
5360 hfdcan->RxFifo0Callback(hfdcan, RxFifo0ITs);
5361 #else
5362 /* Rx FIFO 0 Callback */
5363 HAL_FDCAN_RxFifo0Callback(hfdcan, RxFifo0ITs);
5364 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5367 /* Rx FIFO 1 interrupts management ******************************************/
5368 if (RxFifo1ITs != 0U)
5370 /* Clear the Rx FIFO 1 flags */
5371 __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo1ITs);
5373 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5374 /* Call registered callback*/
5375 hfdcan->RxFifo1Callback(hfdcan, RxFifo1ITs);
5376 #else
5377 /* Rx FIFO 1 Callback */
5378 HAL_FDCAN_RxFifo1Callback(hfdcan, RxFifo1ITs);
5379 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5382 /* Tx FIFO empty interrupt management ***************************************/
5383 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_FIFO_EMPTY) != 0U)
5385 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY) != 0U)
5387 /* Clear the Tx FIFO empty flag */
5388 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY);
5390 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5391 /* Call registered callback*/
5392 hfdcan->TxFifoEmptyCallback(hfdcan);
5393 #else
5394 /* Tx FIFO empty Callback */
5395 HAL_FDCAN_TxFifoEmptyCallback(hfdcan);
5396 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5400 /* Transmission Complete interrupt management *******************************/
5401 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_COMPLETE) != 0U)
5403 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE) != 0U)
5405 /* List of transmitted monitored buffers */
5406 TransmittedBuffers = hfdcan->Instance->TXBTO;
5407 TransmittedBuffers &= hfdcan->Instance->TXBTIE;
5409 /* Clear the Transmission Complete flag */
5410 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE);
5412 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5413 /* Call registered callback*/
5414 hfdcan->TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
5415 #else
5416 /* Transmission Complete Callback */
5417 HAL_FDCAN_TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
5418 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5422 /* Rx Buffer New Message interrupt management *******************************/
5423 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_BUFFER_NEW_MESSAGE) != 0U)
5425 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE) != 0U)
5427 /* Clear the Rx Buffer New Message flag */
5428 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE);
5430 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5431 /* Call registered callback*/
5432 hfdcan->RxBufferNewMessageCallback(hfdcan);
5433 #else
5434 /* Rx Buffer New Message Callback */
5435 HAL_FDCAN_RxBufferNewMessageCallback(hfdcan);
5436 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5440 /* Timestamp Wraparound interrupt management ********************************/
5441 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMESTAMP_WRAPAROUND) != 0U)
5443 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND) != 0U)
5445 /* Clear the Timestamp Wraparound flag */
5446 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND);
5448 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5449 /* Call registered callback*/
5450 hfdcan->TimestampWraparoundCallback(hfdcan);
5451 #else
5452 /* Timestamp Wraparound Callback */
5453 HAL_FDCAN_TimestampWraparoundCallback(hfdcan);
5454 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5458 /* Timeout Occurred interrupt management ************************************/
5459 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMEOUT_OCCURRED) != 0U)
5461 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED) != 0U)
5463 /* Clear the Timeout Occurred flag */
5464 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED);
5466 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5467 /* Call registered callback*/
5468 hfdcan->TimeoutOccurredCallback(hfdcan);
5469 #else
5470 /* Timeout Occurred Callback */
5471 HAL_FDCAN_TimeoutOccurredCallback(hfdcan);
5472 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5476 /* Message RAM access failure interrupt management **************************/
5477 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RAM_ACCESS_FAILURE) != 0U)
5479 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE) != 0U)
5481 /* Clear the Message RAM access failure flag */
5482 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE);
5484 /* Update error code */
5485 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_RAM_ACCESS;
5489 /* Error Status interrupts management ***************************************/
5490 if (ErrorStatusITs != 0U)
5492 /* Clear the Error flags */
5493 __HAL_FDCAN_CLEAR_FLAG(hfdcan, ErrorStatusITs);
5495 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5496 /* Call registered callback*/
5497 hfdcan->ErrorStatusCallback(hfdcan, ErrorStatusITs);
5498 #else
5499 /* Error Status Callback */
5500 HAL_FDCAN_ErrorStatusCallback(hfdcan, ErrorStatusITs);
5501 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5504 /* Error interrupts management **********************************************/
5505 if (Errors != 0U)
5507 /* Clear the Error flags */
5508 __HAL_FDCAN_CLEAR_FLAG(hfdcan, Errors);
5510 /* Update error code */
5511 hfdcan->ErrorCode |= Errors;
5514 if (hfdcan->Instance == FDCAN1)
5516 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != 0U)
5518 TTSchedSyncITs = hfdcan->ttcan->TTIR & FDCAN_TT_SCHEDULE_SYNC_MASK;
5519 TTSchedSyncITs &= hfdcan->ttcan->TTIE;
5520 TTTimeMarkITs = hfdcan->ttcan->TTIR & FDCAN_TT_TIME_MARK_MASK;
5521 TTTimeMarkITs &= hfdcan->ttcan->TTIE;
5522 TTGlobTimeITs = hfdcan->ttcan->TTIR & FDCAN_TT_GLOBAL_TIME_MASK;
5523 TTGlobTimeITs &= hfdcan->ttcan->TTIE;
5524 TTDistErrors = hfdcan->ttcan->TTIR & FDCAN_TT_DISTURBING_ERROR_MASK;
5525 TTDistErrors &= hfdcan->ttcan->TTIE;
5526 TTFatalErrors = hfdcan->ttcan->TTIR & FDCAN_TT_FATAL_ERROR_MASK;
5527 TTFatalErrors &= hfdcan->ttcan->TTIE;
5529 /* TT Schedule Synchronization interrupts management **********************/
5530 if (TTSchedSyncITs != 0U)
5532 /* Clear the TT Schedule Synchronization flags */
5533 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTSchedSyncITs);
5535 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5536 /* Call registered callback*/
5537 hfdcan->TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
5538 #else
5539 /* TT Schedule Synchronization Callback */
5540 HAL_FDCAN_TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
5541 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5544 /* TT Time Mark interrupts management *************************************/
5545 if (TTTimeMarkITs != 0U)
5547 /* Clear the TT Time Mark flags */
5548 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTTimeMarkITs);
5550 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5551 /* Call registered callback*/
5552 hfdcan->TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
5553 #else
5554 /* TT Time Mark Callback */
5555 HAL_FDCAN_TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
5556 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5559 /* TT Stop Watch interrupt management *************************************/
5560 if (__HAL_FDCAN_TT_GET_IT_SOURCE(hfdcan, FDCAN_TT_IT_STOP_WATCH) != 0U)
5562 if (__HAL_FDCAN_TT_GET_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH) != 0U)
5564 /* Retrieve Stop watch Time and Cycle count */
5565 SWTime = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_SWV) >> FDCAN_TTCPT_SWV_Pos);
5566 SWCycleCount = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_CCV) >> FDCAN_TTCPT_CCV_Pos);
5568 /* Clear the TT Stop Watch flag */
5569 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH);
5571 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5572 /* Call registered callback*/
5573 hfdcan->TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
5574 #else
5575 /* TT Stop Watch Callback */
5576 HAL_FDCAN_TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
5577 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5581 /* TT Global Time interrupts management ***********************************/
5582 if (TTGlobTimeITs != 0U)
5584 /* Clear the TT Global Time flags */
5585 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTGlobTimeITs);
5587 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5588 /* Call registered callback*/
5589 hfdcan->TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
5590 #else
5591 /* TT Global Time Callback */
5592 HAL_FDCAN_TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
5593 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5596 /* TT Disturbing Error interrupts management ******************************/
5597 if (TTDistErrors != 0U)
5599 /* Clear the TT Disturbing Error flags */
5600 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTDistErrors);
5602 /* Update error code */
5603 hfdcan->ErrorCode |= TTDistErrors;
5606 /* TT Fatal Error interrupts management ***********************************/
5607 if (TTFatalErrors != 0U)
5609 /* Clear the TT Fatal Error flags */
5610 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTFatalErrors);
5612 /* Update error code */
5613 hfdcan->ErrorCode |= TTFatalErrors;
5618 if (hfdcan->ErrorCode != HAL_FDCAN_ERROR_NONE)
5620 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5621 /* Call registered callback*/
5622 hfdcan->ErrorCallback(hfdcan);
5623 #else
5624 /* Error Callback */
5625 HAL_FDCAN_ErrorCallback(hfdcan);
5626 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5631 * @}
5634 /** @defgroup FDCAN_Exported_Functions_Group6 Callback functions
5635 * @brief FDCAN Callback functions
5637 @verbatim
5638 ==============================================================================
5639 ##### Callback functions #####
5640 ==============================================================================
5641 [..]
5642 This subsection provides the following callback functions:
5643 (+) HAL_FDCAN_ClockCalibrationCallback
5644 (+) HAL_FDCAN_TxEventFifoCallback
5645 (+) HAL_FDCAN_RxFifo0Callback
5646 (+) HAL_FDCAN_RxFifo1Callback
5647 (+) HAL_FDCAN_TxFifoEmptyCallback
5648 (+) HAL_FDCAN_TxBufferCompleteCallback
5649 (+) HAL_FDCAN_TxBufferAbortCallback
5650 (+) HAL_FDCAN_RxBufferNewMessageCallback
5651 (+) HAL_FDCAN_HighPriorityMessageCallback
5652 (+) HAL_FDCAN_TimestampWraparoundCallback
5653 (+) HAL_FDCAN_TimeoutOccurredCallback
5654 (+) HAL_FDCAN_ErrorCallback
5655 (+) HAL_FDCAN_ErrorStatusCallback
5656 (+) HAL_FDCAN_TT_ScheduleSyncCallback
5657 (+) HAL_FDCAN_TT_TimeMarkCallback
5658 (+) HAL_FDCAN_TT_StopWatchCallback
5659 (+) HAL_FDCAN_TT_GlobalTimeCallback
5661 @endverbatim
5662 * @{
5666 * @brief Clock Calibration callback.
5667 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5668 * the configuration information for the specified FDCAN.
5669 * @param ClkCalibrationITs indicates which Clock Calibration interrupts are signaled.
5670 * This parameter can be any combination of @arg FDCAN_Clock_Calibration_Interrupts.
5671 * @retval None
5673 __weak void HAL_FDCAN_ClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ClkCalibrationITs)
5675 /* Prevent unused argument(s) compilation warning */
5676 UNUSED(hfdcan);
5677 UNUSED(ClkCalibrationITs);
5679 /* NOTE : This function Should not be modified, when the callback is needed,
5680 the HAL_FDCAN_ClockCalibrationCallback could be implemented in the user file
5685 * @brief Tx Event callback.
5686 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5687 * the configuration information for the specified FDCAN.
5688 * @param TxEventFifoITs indicates which Tx Event FIFO interrupts are signaled.
5689 * This parameter can be any combination of @arg FDCAN_Tx_Event_Fifo_Interrupts.
5690 * @retval None
5692 __weak void HAL_FDCAN_TxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TxEventFifoITs)
5694 /* Prevent unused argument(s) compilation warning */
5695 UNUSED(hfdcan);
5696 UNUSED(TxEventFifoITs);
5698 /* NOTE : This function Should not be modified, when the callback is needed,
5699 the HAL_FDCAN_TxEventFifoCallback could be implemented in the user file
5704 * @brief Rx FIFO 0 callback.
5705 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5706 * the configuration information for the specified FDCAN.
5707 * @param RxFifo0ITs indicates which Rx FIFO 0 interrupts are signaled.
5708 * This parameter can be any combination of @arg FDCAN_Rx_Fifo0_Interrupts.
5709 * @retval None
5711 __weak void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
5713 /* Prevent unused argument(s) compilation warning */
5714 UNUSED(hfdcan);
5715 UNUSED(RxFifo0ITs);
5717 /* NOTE : This function Should not be modified, when the callback is needed,
5718 the HAL_FDCAN_RxFifo0Callback could be implemented in the user file
5723 * @brief Rx FIFO 1 callback.
5724 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5725 * the configuration information for the specified FDCAN.
5726 * @param RxFifo1ITs indicates which Rx FIFO 1 interrupts are signaled.
5727 * This parameter can be any combination of @arg FDCAN_Rx_Fifo1_Interrupts.
5728 * @retval None
5730 __weak void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs)
5732 /* Prevent unused argument(s) compilation warning */
5733 UNUSED(hfdcan);
5734 UNUSED(RxFifo1ITs);
5736 /* NOTE : This function Should not be modified, when the callback is needed,
5737 the HAL_FDCAN_RxFifo1Callback could be implemented in the user file
5742 * @brief Tx FIFO Empty callback.
5743 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5744 * the configuration information for the specified FDCAN.
5745 * @retval None
5747 __weak void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef *hfdcan)
5749 /* Prevent unused argument(s) compilation warning */
5750 UNUSED(hfdcan);
5752 /* NOTE : This function Should not be modified, when the callback is needed,
5753 the HAL_FDCAN_TxFifoEmptyCallback could be implemented in the user file
5758 * @brief Transmission Complete callback.
5759 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5760 * the configuration information for the specified FDCAN.
5761 * @param BufferIndexes Indexes of the transmitted buffers.
5762 * This parameter can be any combination of @arg FDCAN_Tx_location.
5763 * @retval None
5765 __weak void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
5767 /* Prevent unused argument(s) compilation warning */
5768 UNUSED(hfdcan);
5769 UNUSED(BufferIndexes);
5771 /* NOTE : This function Should not be modified, when the callback is needed,
5772 the HAL_FDCAN_TxBufferCompleteCallback could be implemented in the user file
5777 * @brief Transmission Cancellation callback.
5778 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5779 * the configuration information for the specified FDCAN.
5780 * @param BufferIndexes Indexes of the aborted buffers.
5781 * This parameter can be any combination of @arg FDCAN_Tx_location.
5782 * @retval None
5784 __weak void HAL_FDCAN_TxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
5786 /* Prevent unused argument(s) compilation warning */
5787 UNUSED(hfdcan);
5788 UNUSED(BufferIndexes);
5790 /* NOTE : This function Should not be modified, when the callback is needed,
5791 the HAL_FDCAN_TxBufferAbortCallback could be implemented in the user file
5796 * @brief Rx Buffer New Message callback.
5797 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5798 * the configuration information for the specified FDCAN.
5799 * @retval None
5801 __weak void HAL_FDCAN_RxBufferNewMessageCallback(FDCAN_HandleTypeDef *hfdcan)
5803 /* Prevent unused argument(s) compilation warning */
5804 UNUSED(hfdcan);
5806 /* NOTE : This function Should not be modified, when the callback is needed,
5807 the HAL_FDCAN_RxBufferNewMessageCallback could be implemented in the user file
5812 * @brief Timestamp Wraparound callback.
5813 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5814 * the configuration information for the specified FDCAN.
5815 * @retval None
5817 __weak void HAL_FDCAN_TimestampWraparoundCallback(FDCAN_HandleTypeDef *hfdcan)
5819 /* Prevent unused argument(s) compilation warning */
5820 UNUSED(hfdcan);
5822 /* NOTE : This function Should not be modified, when the callback is needed,
5823 the HAL_FDCAN_TimestampWraparoundCallback could be implemented in the user file
5828 * @brief Timeout Occurred callback.
5829 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5830 * the configuration information for the specified FDCAN.
5831 * @retval None
5833 __weak void HAL_FDCAN_TimeoutOccurredCallback(FDCAN_HandleTypeDef *hfdcan)
5835 /* Prevent unused argument(s) compilation warning */
5836 UNUSED(hfdcan);
5838 /* NOTE : This function Should not be modified, when the callback is needed,
5839 the HAL_FDCAN_TimeoutOccurredCallback could be implemented in the user file
5844 * @brief High Priority Message callback.
5845 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5846 * the configuration information for the specified FDCAN.
5847 * @retval None
5849 __weak void HAL_FDCAN_HighPriorityMessageCallback(FDCAN_HandleTypeDef *hfdcan)
5851 /* Prevent unused argument(s) compilation warning */
5852 UNUSED(hfdcan);
5854 /* NOTE : This function Should not be modified, when the callback is needed,
5855 the HAL_FDCAN_HighPriorityMessageCallback could be implemented in the user file
5860 * @brief Error callback.
5861 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5862 * the configuration information for the specified FDCAN.
5863 * @retval None
5865 __weak void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef *hfdcan)
5867 /* Prevent unused argument(s) compilation warning */
5868 UNUSED(hfdcan);
5870 /* NOTE : This function Should not be modified, when the callback is needed,
5871 the HAL_FDCAN_ErrorCallback could be implemented in the user file
5876 * @brief Error status callback.
5877 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5878 * the configuration information for the specified FDCAN.
5879 * @param ErrorStatusITs indicates which Error Status interrupts are signaled.
5880 * This parameter can be any combination of @arg FDCAN_Error_Status_Interrupts.
5881 * @retval None
5883 __weak void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
5885 /* Prevent unused argument(s) compilation warning */
5886 UNUSED(hfdcan);
5887 UNUSED(ErrorStatusITs);
5889 /* NOTE : This function Should not be modified, when the callback is needed,
5890 the HAL_FDCAN_ErrorStatusCallback could be implemented in the user file
5895 * @brief TT Schedule Synchronization callback.
5896 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5897 * the configuration information for the specified FDCAN.
5898 * @param TTSchedSyncITs indicates which TT Schedule Synchronization interrupts are signaled.
5899 * This parameter can be any combination of @arg FDCAN_TTScheduleSynchronization_Interrupts.
5900 * @retval None
5902 __weak void HAL_FDCAN_TT_ScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTSchedSyncITs)
5904 /* Prevent unused argument(s) compilation warning */
5905 UNUSED(hfdcan);
5906 UNUSED(TTSchedSyncITs);
5908 /* NOTE : This function Should not be modified, when the callback is needed,
5909 the HAL_FDCAN_TT_ScheduleSyncCallback could be implemented in the user file
5914 * @brief TT Time Mark callback.
5915 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5916 * the configuration information for the specified FDCAN.
5917 * @param TTTimeMarkITs indicates which TT Schedule Synchronization interrupts are signaled.
5918 * This parameter can be any combination of @arg FDCAN_TTTimeMark_Interrupts.
5919 * @retval None
5921 __weak void HAL_FDCAN_TT_TimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTTimeMarkITs)
5923 /* Prevent unused argument(s) compilation warning */
5924 UNUSED(hfdcan);
5925 UNUSED(TTTimeMarkITs);
5927 /* NOTE : This function Should not be modified, when the callback is needed,
5928 the HAL_FDCAN_TT_TimeMarkCallback could be implemented in the user file
5933 * @brief TT Stop Watch callback.
5934 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5935 * the configuration information for the specified FDCAN.
5936 * @param SWTime Time Value captured at the Stop Watch Trigger pin (fdcan1_swt) falling/rising
5937 * edge (as configured via HAL_FDCAN_TTConfigStopWatch).
5938 * This parameter is a number between 0 and 0xFFFF.
5939 * @param SWCycleCount Cycle count value captured together with SWTime.
5940 * This parameter is a number between 0 and 0x3F.
5941 * @retval None
5943 __weak void HAL_FDCAN_TT_StopWatchCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t SWTime, uint32_t SWCycleCount)
5945 /* Prevent unused argument(s) compilation warning */
5946 UNUSED(hfdcan);
5947 UNUSED(SWTime);
5948 UNUSED(SWCycleCount);
5950 /* NOTE : This function Should not be modified, when the callback is needed,
5951 the HAL_FDCAN_TT_StopWatchCallback could be implemented in the user file
5956 * @brief TT Global Time callback.
5957 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5958 * the configuration information for the specified FDCAN.
5959 * @param TTGlobTimeITs indicates which TT Global Time interrupts are signaled.
5960 * This parameter can be any combination of @arg FDCAN_TTGlobalTime_Interrupts.
5961 * @retval None
5963 __weak void HAL_FDCAN_TT_GlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTGlobTimeITs)
5965 /* Prevent unused argument(s) compilation warning */
5966 UNUSED(hfdcan);
5967 UNUSED(TTGlobTimeITs);
5969 /* NOTE : This function Should not be modified, when the callback is needed,
5970 the HAL_FDCAN_TT_GlobalTimeCallback could be implemented in the user file
5975 * @}
5978 /** @defgroup FDCAN_Exported_Functions_Group7 Peripheral State functions
5979 * @brief FDCAN Peripheral State functions
5981 @verbatim
5982 ==============================================================================
5983 ##### Peripheral State functions #####
5984 ==============================================================================
5985 [..]
5986 This subsection provides functions allowing to :
5987 (+) HAL_FDCAN_GetState() : Return the FDCAN state.
5988 (+) HAL_FDCAN_GetError() : Return the FDCAN error code if any.
5990 @endverbatim
5991 * @{
5994 * @brief Return the FDCAN state
5995 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5996 * the configuration information for the specified FDCAN.
5997 * @retval HAL state
5999 HAL_FDCAN_StateTypeDef HAL_FDCAN_GetState(FDCAN_HandleTypeDef *hfdcan)
6001 /* Return FDCAN state */
6002 return hfdcan->State;
6006 * @brief Return the FDCAN error code
6007 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
6008 * the configuration information for the specified FDCAN.
6009 * @retval FDCAN Error Code
6011 uint32_t HAL_FDCAN_GetError(FDCAN_HandleTypeDef *hfdcan)
6013 /* Return FDCAN error code */
6014 return hfdcan->ErrorCode;
6018 * @}
6022 * @}
6025 /** @addtogroup FDCAN_Private_Functions
6026 * @{
6030 * @brief Calculate each RAM block start address and size
6031 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
6032 * the configuration information for the specified FDCAN.
6033 * @retval HAL status
6035 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan)
6037 uint32_t RAMcounter;
6038 uint32_t StartAddress;
6040 StartAddress = hfdcan->Init.MessageRAMOffset;
6042 /* Standard filter list start address */
6043 MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_FLSSA, (StartAddress << FDCAN_SIDFC_FLSSA_Pos));
6045 /* Standard filter elements number */
6046 MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_LSS, (hfdcan->Init.StdFiltersNbr << FDCAN_SIDFC_LSS_Pos));
6048 /* Extended filter list start address */
6049 StartAddress += hfdcan->Init.StdFiltersNbr;
6050 MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_FLESA, (StartAddress << FDCAN_XIDFC_FLESA_Pos));
6052 /* Extended filter elements number */
6053 MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_LSE, (hfdcan->Init.ExtFiltersNbr << FDCAN_XIDFC_LSE_Pos));
6055 /* Rx FIFO 0 start address */
6056 StartAddress += (hfdcan->Init.ExtFiltersNbr * 2U);
6057 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0SA, (StartAddress << FDCAN_RXF0C_F0SA_Pos));
6059 /* Rx FIFO 0 elements number */
6060 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0S, (hfdcan->Init.RxFifo0ElmtsNbr << FDCAN_RXF0C_F0S_Pos));
6062 /* Rx FIFO 1 start address */
6063 StartAddress += (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize);
6064 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1SA, (StartAddress << FDCAN_RXF1C_F1SA_Pos));
6066 /* Rx FIFO 1 elements number */
6067 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1S, (hfdcan->Init.RxFifo1ElmtsNbr << FDCAN_RXF1C_F1S_Pos));
6069 /* Rx buffer list start address */
6070 StartAddress += (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize);
6071 MODIFY_REG(hfdcan->Instance->RXBC, FDCAN_RXBC_RBSA, (StartAddress << FDCAN_RXBC_RBSA_Pos));
6073 /* Tx event FIFO start address */
6074 StartAddress += (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize);
6075 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFSA, (StartAddress << FDCAN_TXEFC_EFSA_Pos));
6077 /* Tx event FIFO elements number */
6078 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFS, (hfdcan->Init.TxEventsNbr << FDCAN_TXEFC_EFS_Pos));
6080 /* Tx buffer list start address */
6081 StartAddress += (hfdcan->Init.TxEventsNbr * 2U);
6082 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TBSA, (StartAddress << FDCAN_TXBC_TBSA_Pos));
6084 /* Dedicated Tx buffers number */
6085 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_NDTB, (hfdcan->Init.TxBuffersNbr << FDCAN_TXBC_NDTB_Pos));
6087 /* Tx FIFO/queue elements number */
6088 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TFQS, (hfdcan->Init.TxFifoQueueElmtsNbr << FDCAN_TXBC_TFQS_Pos));
6090 hfdcan->msgRam.StandardFilterSA = SRAMCAN_BASE + (hfdcan->Init.MessageRAMOffset * 4U);
6091 hfdcan->msgRam.ExtendedFilterSA = hfdcan->msgRam.StandardFilterSA + (hfdcan->Init.StdFiltersNbr * 4U);
6092 hfdcan->msgRam.RxFIFO0SA = hfdcan->msgRam.ExtendedFilterSA + (hfdcan->Init.ExtFiltersNbr * 2U * 4U);
6093 hfdcan->msgRam.RxFIFO1SA = hfdcan->msgRam.RxFIFO0SA + (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize * 4U);
6094 hfdcan->msgRam.RxBufferSA = hfdcan->msgRam.RxFIFO1SA + (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize * 4U);
6095 hfdcan->msgRam.TxEventFIFOSA = hfdcan->msgRam.RxBufferSA + (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize * 4U);
6096 hfdcan->msgRam.TxBufferSA = hfdcan->msgRam.TxEventFIFOSA + (hfdcan->Init.TxEventsNbr * 2U * 4U);
6097 hfdcan->msgRam.TxFIFOQSA = hfdcan->msgRam.TxBufferSA + (hfdcan->Init.TxBuffersNbr * hfdcan->Init.TxElmtSize * 4U);
6099 hfdcan->msgRam.EndAddress = hfdcan->msgRam.TxFIFOQSA + (hfdcan->Init.TxFifoQueueElmtsNbr * hfdcan->Init.TxElmtSize * 4U);
6101 if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
6103 /* Update error code.
6104 Message RAM overflow */
6105 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
6107 /* Change FDCAN state */
6108 hfdcan->State = HAL_FDCAN_STATE_ERROR;
6110 return HAL_ERROR;
6112 else
6114 /* Flush the allocated Message RAM area */
6115 for (RAMcounter = hfdcan->msgRam.StandardFilterSA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
6117 *(uint32_t *)(RAMcounter) = 0x00000000;
6121 /* Return function status */
6122 return HAL_OK;
6126 * @brief Copy Tx message to the message RAM.
6127 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
6128 * the configuration information for the specified FDCAN.
6129 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
6130 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
6131 * @param BufferIndex index of the buffer to be configured.
6132 * @retval HAL status
6134 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
6136 uint32_t TxElementW1;
6137 uint32_t TxElementW2;
6138 uint32_t *TxAddress;
6139 uint32_t ByteCounter;
6141 /* Build first word of Tx header element */
6142 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
6144 TxElementW1 = (pTxHeader->ErrorStateIndicator |
6145 FDCAN_STANDARD_ID |
6146 pTxHeader->TxFrameType |
6147 (pTxHeader->Identifier << 18));
6149 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
6151 TxElementW1 = (pTxHeader->ErrorStateIndicator |
6152 FDCAN_EXTENDED_ID |
6153 pTxHeader->TxFrameType |
6154 pTxHeader->Identifier);
6157 /* Build second word of Tx header element */
6158 TxElementW2 = ((pTxHeader->MessageMarker << 24) |
6159 pTxHeader->TxEventFifoControl |
6160 pTxHeader->FDFormat |
6161 pTxHeader->BitRateSwitch |
6162 pTxHeader->DataLength);
6164 /* Calculate Tx element address */
6165 TxAddress = (uint32_t *)(hfdcan->msgRam.TxBufferSA + (BufferIndex * hfdcan->Init.TxElmtSize * 4U));
6167 /* Write Tx element header to the message RAM */
6168 *TxAddress = TxElementW1;
6169 TxAddress++;
6170 *TxAddress = TxElementW2;
6171 TxAddress++;
6173 /* Write Tx payload to the message RAM */
6174 for (ByteCounter = 0; ByteCounter < DLCtoBytes[pTxHeader->DataLength >> 16]; ByteCounter += 4U)
6176 *TxAddress = (((uint32_t)pTxData[ByteCounter + 3U] << 24) |
6177 ((uint32_t)pTxData[ByteCounter + 2U] << 16) |
6178 ((uint32_t)pTxData[ByteCounter + 1U] << 8) |
6179 (uint32_t)pTxData[ByteCounter]);
6180 TxAddress++;
6185 * @}
6187 #endif /* HAL_FDCAN_MODULE_ENABLED */
6189 * @}
6193 * @}
6196 #endif /* FDCAN1 */
6198 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/