Merge pull request #10592 from iNavFlight/MrD_Update-parameter-description
[inav.git] / lib / main / STM32H7 / Drivers / STM32H7xx_HAL_Driver / Src / stm32h7xx_hal_fdcan.c
blobfb4b0faa05c2e12e6c7806107547b1fa2dea2c49
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 /** @addtogroup STM32H7xx_HAL_Driver
189 * @{
192 /** @defgroup FDCAN FDCAN
193 * @brief FDCAN HAL module driver
194 * @{
197 #ifdef HAL_FDCAN_MODULE_ENABLED
199 /* Private typedef -----------------------------------------------------------*/
200 /* Private define ------------------------------------------------------------*/
201 /** @addtogroup FDCAN_Private_Constants
202 * @{
204 #define FDCAN_TIMEOUT_VALUE 10U
206 #define FDCAN_TX_EVENT_FIFO_MASK (FDCAN_IR_TEFL | FDCAN_IR_TEFF | FDCAN_IR_TEFW | FDCAN_IR_TEFN)
207 #define FDCAN_RX_FIFO0_MASK (FDCAN_IR_RF0L | FDCAN_IR_RF0F | FDCAN_IR_RF0W | FDCAN_IR_RF0N)
208 #define FDCAN_RX_FIFO1_MASK (FDCAN_IR_RF1L | FDCAN_IR_RF1F | FDCAN_IR_RF1W | FDCAN_IR_RF1N)
209 #define FDCAN_ERROR_MASK (FDCAN_IR_ELO | FDCAN_IR_WDI | FDCAN_IR_PEA | FDCAN_IR_PED | FDCAN_IR_ARA)
210 #define FDCAN_ERROR_STATUS_MASK (FDCAN_IR_EP | FDCAN_IR_EW | FDCAN_IR_BO)
211 #define FDCAN_TT_SCHEDULE_SYNC_MASK (FDCAN_TTIR_SBC | FDCAN_TTIR_SMC | FDCAN_TTIR_CSM | FDCAN_TTIR_SOG)
212 #define FDCAN_TT_TIME_MARK_MASK (FDCAN_TTIR_RTMI | FDCAN_TTIR_TTMI)
213 #define FDCAN_TT_GLOBAL_TIME_MASK (FDCAN_TTIR_GTW | FDCAN_TTIR_GTD)
214 #define FDCAN_TT_DISTURBING_ERROR_MASK (FDCAN_TTIR_GTE | FDCAN_TTIR_TXU | FDCAN_TTIR_TXO | \
215 FDCAN_TTIR_SE1 | FDCAN_TTIR_SE2 | FDCAN_TTIR_ELC)
216 #define FDCAN_TT_FATAL_ERROR_MASK (FDCAN_TTIR_IWT | FDCAN_TTIR_WT | FDCAN_TTIR_AW | FDCAN_TTIR_CER)
218 #define FDCAN_ELEMENT_MASK_STDID ((uint32_t)0x1FFC0000U) /* Standard Identifier */
219 #define FDCAN_ELEMENT_MASK_EXTID ((uint32_t)0x1FFFFFFFU) /* Extended Identifier */
220 #define FDCAN_ELEMENT_MASK_RTR ((uint32_t)0x20000000U) /* Remote Transmission Request */
221 #define FDCAN_ELEMENT_MASK_XTD ((uint32_t)0x40000000U) /* Extended Identifier */
222 #define FDCAN_ELEMENT_MASK_ESI ((uint32_t)0x80000000U) /* Error State Indicator */
223 #define FDCAN_ELEMENT_MASK_TS ((uint32_t)0x0000FFFFU) /* Timestamp */
224 #define FDCAN_ELEMENT_MASK_DLC ((uint32_t)0x000F0000U) /* Data Length Code */
225 #define FDCAN_ELEMENT_MASK_BRS ((uint32_t)0x00100000U) /* Bit Rate Switch */
226 #define FDCAN_ELEMENT_MASK_FDF ((uint32_t)0x00200000U) /* FD Format */
227 #define FDCAN_ELEMENT_MASK_EFC ((uint32_t)0x00800000U) /* Event FIFO Control */
228 #define FDCAN_ELEMENT_MASK_MM ((uint32_t)0xFF000000U) /* Message Marker */
229 #define FDCAN_ELEMENT_MASK_FIDX ((uint32_t)0x7F000000U) /* Filter Index */
230 #define FDCAN_ELEMENT_MASK_ANMF ((uint32_t)0x80000000U) /* Accepted Non-matching Frame */
231 #define FDCAN_ELEMENT_MASK_ET ((uint32_t)0x00C00000U) /* Event type */
233 #define FDCAN_MESSAGE_RAM_SIZE 0x2800U
234 #define FDCAN_MESSAGE_RAM_END_ADDRESS (SRAMCAN_BASE + FDCAN_MESSAGE_RAM_SIZE - 0x4U) /* The Message RAM has a width of 4 Bytes */
237 * @}
240 /* Private macro -------------------------------------------------------------*/
241 /* Private variables ---------------------------------------------------------*/
242 static const uint8_t DLCtoBytes[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 12, 16, 20, 24, 32, 48, 64};
244 /* Private function prototypes -----------------------------------------------*/
245 /** @addtogroup FDCAN_Private_Functions_Prototypes
246 * @{
248 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan);
249 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex);
251 * @}
254 /* Exported functions --------------------------------------------------------*/
255 /** @defgroup FDCAN_Exported_Functions FDCAN Exported Functions
256 * @{
259 /** @defgroup FDCAN_Exported_Functions_Group1 Initialization and de-initialization functions
260 * @brief Initialization and Configuration functions
262 @verbatim
263 ==============================================================================
264 ##### Initialization and de-initialization functions #####
265 ==============================================================================
266 [..] This section provides functions allowing to:
267 (+) Initialize and configure the FDCAN.
268 (+) De-initialize the FDCAN.
269 (+) Enter FDCAN peripheral in power down mode.
270 (+) Exit power down mode.
271 (+) Register callbacks.
272 (+) Unregister callbacks.
274 @endverbatim
275 * @{
279 * @brief Initializes the FDCAN peripheral according to the specified
280 * parameters in the FDCAN_InitTypeDef structure.
281 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
282 * the configuration information for the specified FDCAN.
283 * @retval HAL status
285 HAL_StatusTypeDef HAL_FDCAN_Init(FDCAN_HandleTypeDef *hfdcan)
287 uint32_t tickstart;
288 HAL_StatusTypeDef status;
289 const uint32_t CvtEltSize[] = {0, 0, 0, 0, 0, 1, 2, 3, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0, 7};
291 /* Check FDCAN handle */
292 if (hfdcan == NULL)
294 return HAL_ERROR;
297 /* Check FDCAN instance */
298 if (hfdcan->Instance == FDCAN1)
300 hfdcan->ttcan = (TTCAN_TypeDef *)((uint32_t)hfdcan->Instance + 0x100U);
303 /* Check function parameters */
304 assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
305 assert_param(IS_FDCAN_FRAME_FORMAT(hfdcan->Init.FrameFormat));
306 assert_param(IS_FDCAN_MODE(hfdcan->Init.Mode));
307 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.AutoRetransmission));
308 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.TransmitPause));
309 assert_param(IS_FUNCTIONAL_STATE(hfdcan->Init.ProtocolException));
310 assert_param(IS_FDCAN_NOMINAL_PRESCALER(hfdcan->Init.NominalPrescaler));
311 assert_param(IS_FDCAN_NOMINAL_SJW(hfdcan->Init.NominalSyncJumpWidth));
312 assert_param(IS_FDCAN_NOMINAL_TSEG1(hfdcan->Init.NominalTimeSeg1));
313 assert_param(IS_FDCAN_NOMINAL_TSEG2(hfdcan->Init.NominalTimeSeg2));
314 if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
316 assert_param(IS_FDCAN_DATA_PRESCALER(hfdcan->Init.DataPrescaler));
317 assert_param(IS_FDCAN_DATA_SJW(hfdcan->Init.DataSyncJumpWidth));
318 assert_param(IS_FDCAN_DATA_TSEG1(hfdcan->Init.DataTimeSeg1));
319 assert_param(IS_FDCAN_DATA_TSEG2(hfdcan->Init.DataTimeSeg2));
321 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.StdFiltersNbr, 128U));
322 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.ExtFiltersNbr, 64U));
323 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo0ElmtsNbr, 64U));
324 if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
326 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo0ElmtSize));
328 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxFifo1ElmtsNbr, 64U));
329 if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
331 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxFifo1ElmtSize));
333 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.RxBuffersNbr, 64U));
334 if (hfdcan->Init.RxBuffersNbr > 0U)
336 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.RxBufferSize));
338 assert_param(IS_FDCAN_MAX_VALUE(hfdcan->Init.TxEventsNbr, 32U));
339 assert_param(IS_FDCAN_MAX_VALUE((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr), 32U));
340 if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
342 assert_param(IS_FDCAN_TX_FIFO_QUEUE_MODE(hfdcan->Init.TxFifoQueueMode));
344 if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
346 assert_param(IS_FDCAN_DATA_SIZE(hfdcan->Init.TxElmtSize));
349 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
350 if (hfdcan->State == HAL_FDCAN_STATE_RESET)
352 /* Allocate lock resource and initialize it */
353 hfdcan->Lock = HAL_UNLOCKED;
355 /* Reset callbacks to legacy functions */
356 hfdcan->ClockCalibrationCallback = HAL_FDCAN_ClockCalibrationCallback; /* Legacy weak ClockCalibrationCallback */
357 hfdcan->TxEventFifoCallback = HAL_FDCAN_TxEventFifoCallback; /* Legacy weak TxEventFifoCallback */
358 hfdcan->RxFifo0Callback = HAL_FDCAN_RxFifo0Callback; /* Legacy weak RxFifo0Callback */
359 hfdcan->RxFifo1Callback = HAL_FDCAN_RxFifo1Callback; /* Legacy weak RxFifo1Callback */
360 hfdcan->TxFifoEmptyCallback = HAL_FDCAN_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
361 hfdcan->TxBufferCompleteCallback = HAL_FDCAN_TxBufferCompleteCallback; /* Legacy weak TxBufferCompleteCallback */
362 hfdcan->TxBufferAbortCallback = HAL_FDCAN_TxBufferAbortCallback; /* Legacy weak TxBufferAbortCallback */
363 hfdcan->RxBufferNewMessageCallback = HAL_FDCAN_RxBufferNewMessageCallback; /* Legacy weak RxBufferNewMessageCallback */
364 hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback; /* Legacy weak HighPriorityMessageCallback */
365 hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback; /* Legacy weak TimestampWraparoundCallback */
366 hfdcan->TimeoutOccurredCallback = HAL_FDCAN_TimeoutOccurredCallback; /* Legacy weak TimeoutOccurredCallback */
367 hfdcan->ErrorCallback = HAL_FDCAN_ErrorCallback; /* Legacy weak ErrorCallback */
368 hfdcan->ErrorStatusCallback = HAL_FDCAN_ErrorStatusCallback; /* Legacy weak ErrorStatusCallback */
369 hfdcan->TT_ScheduleSyncCallback = HAL_FDCAN_TT_ScheduleSyncCallback; /* Legacy weak TT_ScheduleSyncCallback */
370 hfdcan->TT_TimeMarkCallback = HAL_FDCAN_TT_TimeMarkCallback; /* Legacy weak TT_TimeMarkCallback */
371 hfdcan->TT_StopWatchCallback = HAL_FDCAN_TT_StopWatchCallback; /* Legacy weak TT_StopWatchCallback */
372 hfdcan->TT_GlobalTimeCallback = HAL_FDCAN_TT_GlobalTimeCallback; /* Legacy weak TT_GlobalTimeCallback */
374 if (hfdcan->MspInitCallback == NULL)
376 hfdcan->MspInitCallback = HAL_FDCAN_MspInit; /* Legacy weak MspInit */
379 /* Init the low level hardware: CLOCK, NVIC */
380 hfdcan->MspInitCallback(hfdcan);
382 #else
383 if (hfdcan->State == HAL_FDCAN_STATE_RESET)
385 /* Allocate lock resource and initialize it */
386 hfdcan->Lock = HAL_UNLOCKED;
388 /* Init the low level hardware: CLOCK, NVIC */
389 HAL_FDCAN_MspInit(hfdcan);
391 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
393 /* Exit from Sleep mode */
394 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
396 /* Get tick */
397 tickstart = HAL_GetTick();
399 /* Check Sleep mode acknowledge */
400 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
402 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
404 /* Update error code */
405 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
407 /* Change FDCAN state */
408 hfdcan->State = HAL_FDCAN_STATE_ERROR;
410 return HAL_ERROR;
414 /* Request initialisation */
415 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
417 /* Get tick */
418 tickstart = HAL_GetTick();
420 /* Wait until the INIT bit into CCCR register is set */
421 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
423 /* Check for the Timeout */
424 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
426 /* Update error code */
427 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
429 /* Change FDCAN state */
430 hfdcan->State = HAL_FDCAN_STATE_ERROR;
432 return HAL_ERROR;
436 /* Enable configuration change */
437 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
439 /* Set the no automatic retransmission */
440 if (hfdcan->Init.AutoRetransmission == ENABLE)
442 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
444 else
446 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_DAR);
449 /* Set the transmit pause feature */
450 if (hfdcan->Init.TransmitPause == ENABLE)
452 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
454 else
456 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TXP);
459 /* Set the Protocol Exception Handling */
460 if (hfdcan->Init.ProtocolException == ENABLE)
462 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
464 else
466 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_PXHD);
469 /* Set FDCAN Frame Format */
470 MODIFY_REG(hfdcan->Instance->CCCR, FDCAN_FRAME_FD_BRS, hfdcan->Init.FrameFormat);
472 /* Reset FDCAN Operation Mode */
473 CLEAR_BIT(hfdcan->Instance->CCCR, (FDCAN_CCCR_TEST | FDCAN_CCCR_MON | FDCAN_CCCR_ASM));
474 CLEAR_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
476 /* Set FDCAN Operating Mode:
477 | Normal | Restricted | Bus | Internal | External
478 | | Operation | Monitoring | LoopBack | LoopBack
479 CCCR.TEST | 0 | 0 | 0 | 1 | 1
480 CCCR.MON | 0 | 0 | 1 | 1 | 0
481 TEST.LBCK | 0 | 0 | 0 | 1 | 1
482 CCCR.ASM | 0 | 1 | 0 | 0 | 0
484 if (hfdcan->Init.Mode == FDCAN_MODE_RESTRICTED_OPERATION)
486 /* Enable Restricted Operation mode */
487 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
489 else if (hfdcan->Init.Mode != FDCAN_MODE_NORMAL)
491 if (hfdcan->Init.Mode != FDCAN_MODE_BUS_MONITORING)
493 /* Enable write access to TEST register */
494 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_TEST);
496 /* Enable LoopBack mode */
497 SET_BIT(hfdcan->Instance->TEST, FDCAN_TEST_LBCK);
499 if (hfdcan->Init.Mode == FDCAN_MODE_INTERNAL_LOOPBACK)
501 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
504 else
506 /* Enable bus monitoring mode */
507 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_MON);
510 else
512 /* Nothing to do: normal mode */
515 /* Set the nominal bit timing register */
516 hfdcan->Instance->NBTP = ((((uint32_t)hfdcan->Init.NominalSyncJumpWidth - 1U) << FDCAN_NBTP_NSJW_Pos) | \
517 (((uint32_t)hfdcan->Init.NominalTimeSeg1 - 1U) << FDCAN_NBTP_NTSEG1_Pos) | \
518 (((uint32_t)hfdcan->Init.NominalTimeSeg2 - 1U) << FDCAN_NBTP_NTSEG2_Pos) | \
519 (((uint32_t)hfdcan->Init.NominalPrescaler - 1U) << FDCAN_NBTP_NBRP_Pos));
521 /* If FD operation with BRS is selected, set the data bit timing register */
522 if (hfdcan->Init.FrameFormat == FDCAN_FRAME_FD_BRS)
524 hfdcan->Instance->DBTP = ((((uint32_t)hfdcan->Init.DataSyncJumpWidth - 1U) << FDCAN_DBTP_DSJW_Pos) | \
525 (((uint32_t)hfdcan->Init.DataTimeSeg1 - 1U) << FDCAN_DBTP_DTSEG1_Pos) | \
526 (((uint32_t)hfdcan->Init.DataTimeSeg2 - 1U) << FDCAN_DBTP_DTSEG2_Pos) | \
527 (((uint32_t)hfdcan->Init.DataPrescaler - 1U) << FDCAN_DBTP_DBRP_Pos));
530 if (hfdcan->Init.TxFifoQueueElmtsNbr > 0U)
532 /* Select between Tx FIFO and Tx Queue operation modes */
533 SET_BIT(hfdcan->Instance->TXBC, hfdcan->Init.TxFifoQueueMode);
536 /* Configure Tx element size */
537 if ((hfdcan->Init.TxBuffersNbr + hfdcan->Init.TxFifoQueueElmtsNbr) > 0U)
539 MODIFY_REG(hfdcan->Instance->TXESC, FDCAN_TXESC_TBDS, CvtEltSize[hfdcan->Init.TxElmtSize]);
542 /* Configure Rx FIFO 0 element size */
543 if (hfdcan->Init.RxFifo0ElmtsNbr > 0U)
545 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F0DS, (CvtEltSize[hfdcan->Init.RxFifo0ElmtSize] << FDCAN_RXESC_F0DS_Pos));
548 /* Configure Rx FIFO 1 element size */
549 if (hfdcan->Init.RxFifo1ElmtsNbr > 0U)
551 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_F1DS, (CvtEltSize[hfdcan->Init.RxFifo1ElmtSize] << FDCAN_RXESC_F1DS_Pos));
554 /* Configure Rx buffer element size */
555 if (hfdcan->Init.RxBuffersNbr > 0U)
557 MODIFY_REG(hfdcan->Instance->RXESC, FDCAN_RXESC_RBDS, (CvtEltSize[hfdcan->Init.RxBufferSize] << FDCAN_RXESC_RBDS_Pos));
560 /* By default operation mode is set to Event-driven communication.
561 If Time-triggered communication is needed, user should call the
562 HAL_FDCAN_TT_ConfigOperation function just after the HAL_FDCAN_Init */
563 if (hfdcan->Instance == FDCAN1)
565 CLEAR_BIT(hfdcan->ttcan->TTOCF, FDCAN_TTOCF_OM);
568 /* Initialize the Latest Tx FIFO/Queue request buffer index */
569 hfdcan->LatestTxFifoQRequest = 0U;
571 /* Initialize the error code */
572 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
574 /* Initialize the FDCAN state */
575 hfdcan->State = HAL_FDCAN_STATE_READY;
577 /* Calculate each RAM block address */
578 status = FDCAN_CalcultateRamBlockAddresses(hfdcan);
580 /* Return function status */
581 return status;
585 * @brief Deinitializes the FDCAN peripheral registers to their default reset values.
586 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
587 * the configuration information for the specified FDCAN.
588 * @retval HAL status
590 HAL_StatusTypeDef HAL_FDCAN_DeInit(FDCAN_HandleTypeDef *hfdcan)
592 /* Check FDCAN handle */
593 if (hfdcan == NULL)
595 return HAL_ERROR;
598 /* Check function parameters */
599 assert_param(IS_FDCAN_ALL_INSTANCE(hfdcan->Instance));
601 /* Stop the FDCAN module: return value is voluntary ignored */
602 (void)HAL_FDCAN_Stop(hfdcan);
604 /* Disable Interrupt lines */
605 CLEAR_BIT(hfdcan->Instance->ILE, (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1));
607 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
608 if (hfdcan->MspDeInitCallback == NULL)
610 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit; /* Legacy weak MspDeInit */
613 /* DeInit the low level hardware: CLOCK, NVIC */
614 hfdcan->MspDeInitCallback(hfdcan);
615 #else
616 /* DeInit the low level hardware: CLOCK, NVIC */
617 HAL_FDCAN_MspDeInit(hfdcan);
618 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
620 /* Reset the FDCAN ErrorCode */
621 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
623 /* Change FDCAN state */
624 hfdcan->State = HAL_FDCAN_STATE_RESET;
626 /* Return function status */
627 return HAL_OK;
631 * @brief Initializes the FDCAN MSP.
632 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
633 * the configuration information for the specified FDCAN.
634 * @retval None
636 __weak void HAL_FDCAN_MspInit(FDCAN_HandleTypeDef *hfdcan)
638 /* Prevent unused argument(s) compilation warning */
639 UNUSED(hfdcan);
640 /* NOTE : This function Should not be modified, when the callback is needed,
641 the HAL_FDCAN_MspInit could be implemented in the user file
646 * @brief DeInitializes the FDCAN MSP.
647 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
648 * the configuration information for the specified FDCAN.
649 * @retval None
651 __weak void HAL_FDCAN_MspDeInit(FDCAN_HandleTypeDef *hfdcan)
653 /* Prevent unused argument(s) compilation warning */
654 UNUSED(hfdcan);
655 /* NOTE : This function Should not be modified, when the callback is needed,
656 the HAL_FDCAN_MspDeInit could be implemented in the user file
661 * @brief Enter FDCAN peripheral in sleep mode.
662 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
663 * the configuration information for the specified FDCAN.
664 * @retval HAL status
666 HAL_StatusTypeDef HAL_FDCAN_EnterPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
668 uint32_t tickstart;
670 /* Request clock stop */
671 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
673 /* Get tick */
674 tickstart = HAL_GetTick();
676 /* Wait until FDCAN is ready for power down */
677 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == 0U)
679 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
681 /* Update error code */
682 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
684 /* Change FDCAN state */
685 hfdcan->State = HAL_FDCAN_STATE_ERROR;
687 return HAL_ERROR;
691 /* Return function status */
692 return HAL_OK;
696 * @brief Exit power down mode.
697 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
698 * the configuration information for the specified FDCAN.
699 * @retval HAL status
701 HAL_StatusTypeDef HAL_FDCAN_ExitPowerDownMode(FDCAN_HandleTypeDef *hfdcan)
703 uint32_t tickstart;
705 /* Reset clock stop request */
706 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
708 /* Get tick */
709 tickstart = HAL_GetTick();
711 /* Wait until FDCAN exits sleep mode */
712 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
714 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
716 /* Update error code */
717 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
719 /* Change FDCAN state */
720 hfdcan->State = HAL_FDCAN_STATE_ERROR;
722 return HAL_ERROR;
726 /* Enter normal operation */
727 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
729 /* Return function status */
730 return HAL_OK;
733 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
735 * @brief Register a FDCAN CallBack.
736 * To be used instead of the weak predefined callback
737 * @param hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
738 * the configuration information for FDCAN module
739 * @param CallbackID ID of the callback to be registered
740 * This parameter can be one of the following values:
741 * @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
742 * @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
743 * @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
744 * @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
745 * @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
746 * @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
747 * @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
748 * @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
749 * @param pCallback pointer to the Callback function
750 * @retval HAL status
752 HAL_StatusTypeDef HAL_FDCAN_RegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID, void (* pCallback)(FDCAN_HandleTypeDef *_hFDCAN))
754 HAL_StatusTypeDef status = HAL_OK;
756 if (pCallback == NULL)
758 /* Update the error code */
759 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
761 return HAL_ERROR;
764 if (hfdcan->State == HAL_FDCAN_STATE_READY)
766 switch (CallbackID)
768 case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
769 hfdcan->TxFifoEmptyCallback = pCallback;
770 break;
772 case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
773 hfdcan->RxBufferNewMessageCallback = pCallback;
774 break;
776 case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
777 hfdcan->HighPriorityMessageCallback = pCallback;
778 break;
780 case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
781 hfdcan->TimestampWraparoundCallback = pCallback;
782 break;
784 case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
785 hfdcan->TimeoutOccurredCallback = pCallback;
786 break;
788 case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
789 hfdcan->ErrorCallback = pCallback;
790 break;
792 case HAL_FDCAN_MSPINIT_CB_ID :
793 hfdcan->MspInitCallback = pCallback;
794 break;
796 case HAL_FDCAN_MSPDEINIT_CB_ID :
797 hfdcan->MspDeInitCallback = pCallback;
798 break;
800 default :
801 /* Update the error code */
802 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
804 /* Return error status */
805 status = HAL_ERROR;
806 break;
809 else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
811 switch (CallbackID)
813 case HAL_FDCAN_MSPINIT_CB_ID :
814 hfdcan->MspInitCallback = pCallback;
815 break;
817 case HAL_FDCAN_MSPDEINIT_CB_ID :
818 hfdcan->MspDeInitCallback = pCallback;
819 break;
821 default :
822 /* Update the error code */
823 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
825 /* Return error status */
826 status = HAL_ERROR;
827 break;
830 else
832 /* Update the error code */
833 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
835 /* Return error status */
836 status = HAL_ERROR;
839 return status;
843 * @brief Unregister a FDCAN CallBack.
844 * FDCAN callback is redirected to the weak predefined callback
845 * @param hfdcan pointer to a FDCAN_HandleTypeDef structure that contains
846 * the configuration information for FDCAN module
847 * @param CallbackID ID of the callback to be unregistered
848 * This parameter can be one of the following values:
849 * @arg @ref HAL_FDCAN_TX_FIFO_EMPTY_CB_ID Tx Fifo Empty callback ID
850 * @arg @ref HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID Rx buffer new message callback ID
851 * @arg @ref HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID High priority message callback ID
852 * @arg @ref HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID Timestamp wraparound callback ID
853 * @arg @ref HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID Timeout occurred callback ID
854 * @arg @ref HAL_FDCAN_ERROR_CALLBACK_CB_ID Error callback ID
855 * @arg @ref HAL_FDCAN_MSPINIT_CB_ID MspInit callback ID
856 * @arg @ref HAL_FDCAN_MSPDEINIT_CB_ID MspDeInit callback ID
857 * @retval HAL status
859 HAL_StatusTypeDef HAL_FDCAN_UnRegisterCallback(FDCAN_HandleTypeDef *hfdcan, HAL_FDCAN_CallbackIDTypeDef CallbackID)
861 HAL_StatusTypeDef status = HAL_OK;
863 if (hfdcan->State == HAL_FDCAN_STATE_READY)
865 switch (CallbackID)
867 case HAL_FDCAN_TX_FIFO_EMPTY_CB_ID :
868 hfdcan->TxFifoEmptyCallback = HAL_FDCAN_TxFifoEmptyCallback;
869 break;
871 case HAL_FDCAN_RX_BUFFER_NEW_MSG_CB_ID :
872 hfdcan->RxBufferNewMessageCallback = HAL_FDCAN_RxBufferNewMessageCallback;
873 break;
875 case HAL_FDCAN_HIGH_PRIO_MESSAGE_CB_ID :
876 hfdcan->HighPriorityMessageCallback = HAL_FDCAN_HighPriorityMessageCallback;
877 break;
879 case HAL_FDCAN_TIMESTAMP_WRAPAROUND_CB_ID :
880 hfdcan->TimestampWraparoundCallback = HAL_FDCAN_TimestampWraparoundCallback;
881 break;
883 case HAL_FDCAN_TIMEOUT_OCCURRED_CB_ID :
884 hfdcan->TimeoutOccurredCallback = HAL_FDCAN_TimeoutOccurredCallback;
885 break;
887 case HAL_FDCAN_ERROR_CALLBACK_CB_ID :
888 hfdcan->ErrorCallback = HAL_FDCAN_ErrorCallback;
889 break;
891 case HAL_FDCAN_MSPINIT_CB_ID :
892 hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
893 break;
895 case HAL_FDCAN_MSPDEINIT_CB_ID :
896 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
897 break;
899 default :
900 /* Update the error code */
901 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
903 /* Return error status */
904 status = HAL_ERROR;
905 break;
908 else if (hfdcan->State == HAL_FDCAN_STATE_RESET)
910 switch (CallbackID)
912 case HAL_FDCAN_MSPINIT_CB_ID :
913 hfdcan->MspInitCallback = HAL_FDCAN_MspInit;
914 break;
916 case HAL_FDCAN_MSPDEINIT_CB_ID :
917 hfdcan->MspDeInitCallback = HAL_FDCAN_MspDeInit;
918 break;
920 default :
921 /* Update the error code */
922 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
924 /* Return error status */
925 status = HAL_ERROR;
926 break;
929 else
931 /* Update the error code */
932 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
934 /* Return error status */
935 status = HAL_ERROR;
938 return status;
942 * @brief Register Clock Calibration FDCAN Callback
943 * To be used instead of the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
944 * @param hfdcan FDCAN handle
945 * @param pCallback pointer to the Clock Calibration Callback function
946 * @retval HAL status
948 HAL_StatusTypeDef HAL_FDCAN_RegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ClockCalibrationCallbackTypeDef pCallback)
950 HAL_StatusTypeDef status = HAL_OK;
952 if (pCallback == NULL)
954 /* Update the error code */
955 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
956 return HAL_ERROR;
959 if (hfdcan->State == HAL_FDCAN_STATE_READY)
961 hfdcan->ClockCalibrationCallback = pCallback;
963 else
965 /* Update the error code */
966 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
968 /* Return error status */
969 status = HAL_ERROR;
972 return status;
976 * @brief UnRegister the Clock Calibration FDCAN Callback
977 * Clock Calibration FDCAN Callback is redirected to the weak HAL_FDCAN_ClockCalibrationCallback() predefined callback
978 * @param hfdcan FDCAN handle
979 * @retval HAL status
981 HAL_StatusTypeDef HAL_FDCAN_UnRegisterClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan)
983 HAL_StatusTypeDef status = HAL_OK;
985 if (hfdcan->State == HAL_FDCAN_STATE_READY)
987 hfdcan->ClockCalibrationCallback = HAL_FDCAN_ClockCalibrationCallback; /* Legacy weak ClockCalibrationCallback */
989 else
991 /* Update the error code */
992 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
994 /* Return error status */
995 status = HAL_ERROR;
998 return status;
1002 * @brief Register Tx Event Fifo FDCAN Callback
1003 * To be used instead of the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
1004 * @param hfdcan FDCAN handle
1005 * @param pCallback pointer to the Tx Event Fifo Callback function
1006 * @retval HAL status
1008 HAL_StatusTypeDef HAL_FDCAN_RegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxEventFifoCallbackTypeDef pCallback)
1010 HAL_StatusTypeDef status = HAL_OK;
1012 if (pCallback == NULL)
1014 /* Update the error code */
1015 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1016 return HAL_ERROR;
1019 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1021 hfdcan->TxEventFifoCallback = pCallback;
1023 else
1025 /* Update the error code */
1026 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1028 /* Return error status */
1029 status = HAL_ERROR;
1032 return status;
1036 * @brief UnRegister the Tx Event Fifo FDCAN Callback
1037 * Tx Event Fifo FDCAN Callback is redirected to the weak HAL_FDCAN_TxEventFifoCallback() predefined callback
1038 * @param hfdcan FDCAN handle
1039 * @retval HAL status
1041 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan)
1043 HAL_StatusTypeDef status = HAL_OK;
1045 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1047 hfdcan->TxEventFifoCallback = HAL_FDCAN_TxEventFifoCallback; /* Legacy weak TxEventFifoCallback */
1049 else
1051 /* Update the error code */
1052 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1054 /* Return error status */
1055 status = HAL_ERROR;
1058 return status;
1062 * @brief Register Rx Fifo 0 FDCAN Callback
1063 * To be used instead of the weak HAL_FDCAN_RxFifo0Callback() predefined callback
1064 * @param hfdcan FDCAN handle
1065 * @param pCallback pointer to the Rx Fifo 0 Callback function
1066 * @retval HAL status
1068 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo0CallbackTypeDef pCallback)
1070 HAL_StatusTypeDef status = HAL_OK;
1072 if (pCallback == NULL)
1074 /* Update the error code */
1075 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1076 return HAL_ERROR;
1079 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1081 hfdcan->RxFifo0Callback = pCallback;
1083 else
1085 /* Update the error code */
1086 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1088 /* Return error status */
1089 status = HAL_ERROR;
1092 return status;
1096 * @brief UnRegister the Rx Fifo 0 FDCAN Callback
1097 * Rx Fifo 0 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo0Callback() predefined callback
1098 * @param hfdcan FDCAN handle
1099 * @retval HAL status
1101 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo0Callback(FDCAN_HandleTypeDef *hfdcan)
1103 HAL_StatusTypeDef status = HAL_OK;
1105 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1107 hfdcan->RxFifo0Callback = HAL_FDCAN_RxFifo0Callback; /* Legacy weak RxFifo0Callback */
1109 else
1111 /* Update the error code */
1112 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1114 /* Return error status */
1115 status = HAL_ERROR;
1118 return status;
1122 * @brief Register Rx Fifo 1 FDCAN Callback
1123 * To be used instead of the weak HAL_FDCAN_RxFifo1Callback() predefined callback
1124 * @param hfdcan FDCAN handle
1125 * @param pCallback pointer to the Rx Fifo 1 Callback function
1126 * @retval HAL status
1128 HAL_StatusTypeDef HAL_FDCAN_RegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_RxFifo1CallbackTypeDef pCallback)
1130 HAL_StatusTypeDef status = HAL_OK;
1132 if (pCallback == NULL)
1134 /* Update the error code */
1135 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1136 return HAL_ERROR;
1139 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1141 hfdcan->RxFifo1Callback = pCallback;
1143 else
1145 /* Update the error code */
1146 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1148 /* Return error status */
1149 status = HAL_ERROR;
1152 return status;
1156 * @brief UnRegister the Rx Fifo 1 FDCAN Callback
1157 * Rx Fifo 1 FDCAN Callback is redirected to the weak HAL_FDCAN_RxFifo1Callback() predefined callback
1158 * @param hfdcan FDCAN handle
1159 * @retval HAL status
1161 HAL_StatusTypeDef HAL_FDCAN_UnRegisterRxFifo1Callback(FDCAN_HandleTypeDef *hfdcan)
1163 HAL_StatusTypeDef status = HAL_OK;
1165 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1167 hfdcan->RxFifo1Callback = HAL_FDCAN_RxFifo1Callback; /* Legacy weak RxFifo1Callback */
1169 else
1171 /* Update the error code */
1172 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1174 /* Return error status */
1175 status = HAL_ERROR;
1178 return status;
1182 * @brief Register Tx Buffer Complete FDCAN Callback
1183 * To be used instead of the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
1184 * @param hfdcan FDCAN handle
1185 * @param pCallback pointer to the Tx Buffer Complete Callback function
1186 * @retval HAL status
1188 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferCompleteCallbackTypeDef pCallback)
1190 HAL_StatusTypeDef status = HAL_OK;
1192 if (pCallback == NULL)
1194 /* Update the error code */
1195 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1196 return HAL_ERROR;
1199 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1201 hfdcan->TxBufferCompleteCallback = pCallback;
1203 else
1205 /* Update the error code */
1206 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1208 /* Return error status */
1209 status = HAL_ERROR;
1212 return status;
1216 * @brief UnRegister the Tx Buffer Complete FDCAN Callback
1217 * Tx Buffer Complete FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferCompleteCallback() predefined callback
1218 * @param hfdcan FDCAN handle
1219 * @retval HAL status
1221 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan)
1223 HAL_StatusTypeDef status = HAL_OK;
1225 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1227 hfdcan->TxBufferCompleteCallback = HAL_FDCAN_TxBufferCompleteCallback; /* Legacy weak TxBufferCompleteCallback */
1229 else
1231 /* Update the error code */
1232 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1234 /* Return error status */
1235 status = HAL_ERROR;
1238 return status;
1242 * @brief Register Tx Buffer Abort FDCAN Callback
1243 * To be used instead of the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
1244 * @param hfdcan FDCAN handle
1245 * @param pCallback pointer to the Tx Buffer Abort Callback function
1246 * @retval HAL status
1248 HAL_StatusTypeDef HAL_FDCAN_RegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TxBufferAbortCallbackTypeDef pCallback)
1250 HAL_StatusTypeDef status = HAL_OK;
1252 if (pCallback == NULL)
1254 /* Update the error code */
1255 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1256 return HAL_ERROR;
1259 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1261 hfdcan->TxBufferAbortCallback = pCallback;
1263 else
1265 /* Update the error code */
1266 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1268 /* Return error status */
1269 status = HAL_ERROR;
1272 return status;
1276 * @brief UnRegister the Tx Buffer Abort FDCAN Callback
1277 * Tx Buffer Abort FDCAN Callback is redirected to the weak HAL_FDCAN_TxBufferAbortCallback() predefined callback
1278 * @param hfdcan FDCAN handle
1279 * @retval HAL status
1281 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan)
1283 HAL_StatusTypeDef status = HAL_OK;
1285 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1287 hfdcan->TxBufferAbortCallback = HAL_FDCAN_TxBufferAbortCallback; /* Legacy weak TxBufferAbortCallback */
1289 else
1291 /* Update the error code */
1292 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1294 /* Return error status */
1295 status = HAL_ERROR;
1298 return status;
1302 * @brief Register Error Status FDCAN Callback
1303 * To be used instead of the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
1304 * @param hfdcan FDCAN handle
1305 * @param pCallback pointer to the Error Status Callback function
1306 * @retval HAL status
1308 HAL_StatusTypeDef HAL_FDCAN_RegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_ErrorStatusCallbackTypeDef pCallback)
1310 HAL_StatusTypeDef status = HAL_OK;
1312 if (pCallback == NULL)
1314 /* Update the error code */
1315 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1316 return HAL_ERROR;
1319 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1321 hfdcan->ErrorStatusCallback = pCallback;
1323 else
1325 /* Update the error code */
1326 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1328 /* Return error status */
1329 status = HAL_ERROR;
1332 return status;
1336 * @brief UnRegister the Error Status FDCAN Callback
1337 * Error Status FDCAN Callback is redirected to the weak HAL_FDCAN_ErrorStatusCallback() predefined callback
1338 * @param hfdcan FDCAN handle
1339 * @retval HAL status
1341 HAL_StatusTypeDef HAL_FDCAN_UnRegisterErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan)
1343 HAL_StatusTypeDef status = HAL_OK;
1345 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1347 hfdcan->ErrorStatusCallback = HAL_FDCAN_ErrorStatusCallback; /* Legacy weak ErrorStatusCallback */
1349 else
1351 /* Update the error code */
1352 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1354 /* Return error status */
1355 status = HAL_ERROR;
1358 return status;
1362 * @brief Register TT Schedule Synchronization FDCAN Callback
1363 * To be used instead of the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
1364 * @param hfdcan FDCAN handle
1365 * @param pCallback pointer to the TT Schedule Synchronization Callback function
1366 * @retval HAL status
1368 HAL_StatusTypeDef HAL_FDCAN_RegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_ScheduleSyncCallbackTypeDef pCallback)
1370 HAL_StatusTypeDef status = HAL_OK;
1372 if (pCallback == NULL)
1374 /* Update the error code */
1375 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1376 return HAL_ERROR;
1379 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1381 hfdcan->TT_ScheduleSyncCallback = pCallback;
1383 else
1385 /* Update the error code */
1386 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1388 /* Return error status */
1389 status = HAL_ERROR;
1392 return status;
1396 * @brief UnRegister the TT Schedule Synchronization FDCAN Callback
1397 * TT Schedule Synchronization Callback is redirected to the weak HAL_FDCAN_TT_ScheduleSyncCallback() predefined callback
1398 * @param hfdcan FDCAN handle
1399 * @retval HAL status
1401 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan)
1403 HAL_StatusTypeDef status = HAL_OK;
1405 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1407 hfdcan->TT_ScheduleSyncCallback = HAL_FDCAN_TT_ScheduleSyncCallback; /* Legacy weak TT_ScheduleSyncCallback */
1409 else
1411 /* Update the error code */
1412 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1414 /* Return error status */
1415 status = HAL_ERROR;
1418 return status;
1422 * @brief Register TT Time Mark FDCAN Callback
1423 * To be used instead of the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
1424 * @param hfdcan FDCAN handle
1425 * @param pCallback pointer to the TT Time Mark Callback function
1426 * @retval HAL status
1428 HAL_StatusTypeDef HAL_FDCAN_RegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_TimeMarkCallbackTypeDef pCallback)
1430 HAL_StatusTypeDef status = HAL_OK;
1432 if (pCallback == NULL)
1434 /* Update the error code */
1435 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1436 return HAL_ERROR;
1439 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1441 hfdcan->TT_TimeMarkCallback = pCallback;
1443 else
1445 /* Update the error code */
1446 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1448 /* Return error status */
1449 status = HAL_ERROR;
1452 return status;
1456 * @brief UnRegister the TT Time Mark FDCAN Callback
1457 * TT Time Mark Callback is redirected to the weak HAL_FDCAN_TT_TimeMarkCallback() predefined callback
1458 * @param hfdcan FDCAN handle
1459 * @retval HAL status
1461 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTTimeMarkCallback(FDCAN_HandleTypeDef *hfdcan)
1463 HAL_StatusTypeDef status = HAL_OK;
1465 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1467 hfdcan->TT_TimeMarkCallback = HAL_FDCAN_TT_TimeMarkCallback; /* Legacy weak TT_TimeMarkCallback */
1469 else
1471 /* Update the error code */
1472 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1474 /* Return error status */
1475 status = HAL_ERROR;
1478 return status;
1482 * @brief Register TT Stop Watch FDCAN Callback
1483 * To be used instead of the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
1484 * @param hfdcan FDCAN handle
1485 * @param pCallback pointer to the TT Stop Watch Callback function
1486 * @retval HAL status
1488 HAL_StatusTypeDef HAL_FDCAN_RegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_StopWatchCallbackTypeDef pCallback)
1490 HAL_StatusTypeDef status = HAL_OK;
1492 if (pCallback == NULL)
1494 /* Update the error code */
1495 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1496 return HAL_ERROR;
1499 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1501 hfdcan->TT_StopWatchCallback = pCallback;
1503 else
1505 /* Update the error code */
1506 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1508 /* Return error status */
1509 status = HAL_ERROR;
1512 return status;
1516 * @brief UnRegister the TT Stop Watch FDCAN Callback
1517 * TT Stop Watch Callback is redirected to the weak HAL_FDCAN_TT_StopWatchCallback() predefined callback
1518 * @param hfdcan FDCAN handle
1519 * @retval HAL status
1521 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTStopWatchCallback(FDCAN_HandleTypeDef *hfdcan)
1523 HAL_StatusTypeDef status = HAL_OK;
1525 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1527 hfdcan->TT_StopWatchCallback = HAL_FDCAN_TT_StopWatchCallback; /* Legacy weak TT_StopWatchCallback */
1529 else
1531 /* Update the error code */
1532 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1534 /* Return error status */
1535 status = HAL_ERROR;
1538 return status;
1542 * @brief Register TT Global Time FDCAN Callback
1543 * To be used instead of the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
1544 * @param hfdcan FDCAN handle
1545 * @param pCallback pointer to the TT Global Time Callback function
1546 * @retval HAL status
1548 HAL_StatusTypeDef HAL_FDCAN_RegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, pFDCAN_TT_GlobalTimeCallbackTypeDef pCallback)
1550 HAL_StatusTypeDef status = HAL_OK;
1552 if (pCallback == NULL)
1554 /* Update the error code */
1555 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1556 return HAL_ERROR;
1559 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1561 hfdcan->TT_GlobalTimeCallback = pCallback;
1563 else
1565 /* Update the error code */
1566 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1568 /* Return error status */
1569 status = HAL_ERROR;
1572 return status;
1576 * @brief UnRegister the TT Global Time FDCAN Callback
1577 * TT Global Time Callback is redirected to the weak HAL_FDCAN_TT_GlobalTimeCallback() predefined callback
1578 * @param hfdcan FDCAN handle
1579 * @retval HAL status
1581 HAL_StatusTypeDef HAL_FDCAN_UnRegisterTTGlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan)
1583 HAL_StatusTypeDef status = HAL_OK;
1585 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1587 hfdcan->TT_GlobalTimeCallback = HAL_FDCAN_TT_GlobalTimeCallback; /* Legacy weak TT_GlobalTimeCallback */
1589 else
1591 /* Update the error code */
1592 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_INVALID_CALLBACK;
1594 /* Return error status */
1595 status = HAL_ERROR;
1598 return status;
1601 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
1604 * @}
1607 /** @defgroup FDCAN_Exported_Functions_Group2 Configuration functions
1608 * @brief FDCAN Configuration functions.
1610 @verbatim
1611 ==============================================================================
1612 ##### Configuration functions #####
1613 ==============================================================================
1614 [..] This section provides functions allowing to:
1615 (+) HAL_FDCAN_ConfigClockCalibration : Configure the FDCAN clock calibration unit
1616 (+) HAL_FDCAN_GetClockCalibrationState : Get the clock calibration state
1617 (+) HAL_FDCAN_ResetClockCalibrationState : Reset the clock calibration state
1618 (+) HAL_FDCAN_GetClockCalibrationCounter : Get the clock calibration counters values
1619 (+) HAL_FDCAN_ConfigFilter : Configure the FDCAN reception filters
1620 (+) HAL_FDCAN_ConfigGlobalFilter : Configure the FDCAN global filter
1621 (+) HAL_FDCAN_ConfigExtendedIdMask : Configure the extended ID mask
1622 (+) HAL_FDCAN_ConfigRxFifoOverwrite : Configure the Rx FIFO operation mode
1623 (+) HAL_FDCAN_ConfigFifoWatermark : Configure the FIFO watermark
1624 (+) HAL_FDCAN_ConfigRamWatchdog : Configure the RAM watchdog
1625 (+) HAL_FDCAN_ConfigTimestampCounter : Configure the timestamp counter
1626 (+) HAL_FDCAN_EnableTimestampCounter : Enable the timestamp counter
1627 (+) HAL_FDCAN_DisableTimestampCounter : Disable the timestamp counter
1628 (+) HAL_FDCAN_GetTimestampCounter : Get the timestamp counter value
1629 (+) HAL_FDCAN_ResetTimestampCounter : Reset the timestamp counter to zero
1630 (+) HAL_FDCAN_ConfigTimeoutCounter : Configure the timeout counter
1631 (+) HAL_FDCAN_EnableTimeoutCounter : Enable the timeout counter
1632 (+) HAL_FDCAN_DisableTimeoutCounter : Disable the timeout counter
1633 (+) HAL_FDCAN_GetTimeoutCounter : Get the timeout counter value
1634 (+) HAL_FDCAN_ResetTimeoutCounter : Reset the timeout counter to its start value
1635 (+) HAL_FDCAN_ConfigTxDelayCompensation : Configure the transmitter delay compensation
1636 (+) HAL_FDCAN_EnableTxDelayCompensation : Enable the transmitter delay compensation
1637 (+) HAL_FDCAN_DisableTxDelayCompensation : Disable the transmitter delay compensation
1638 (+) HAL_FDCAN_EnableISOMode : Enable ISO 11898-1 protocol mode
1639 (+) HAL_FDCAN_DisableISOMode : Disable ISO 11898-1 protocol mode
1640 (+) HAL_FDCAN_EnableEdgeFiltering : Enable edge filtering during bus integration
1641 (+) HAL_FDCAN_DisableEdgeFiltering : Disable edge filtering during bus integration
1643 @endverbatim
1644 * @{
1648 * @brief Configure the FDCAN clock calibration unit according to the specified
1649 * parameters in the FDCAN_ClkCalUnitTypeDef structure.
1650 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1651 * the configuration information for the specified FDCAN.
1652 * @param sCcuConfig pointer to an FDCAN_ClkCalUnitTypeDef structure that
1653 * contains the clock calibration information
1654 * @retval HAL status
1656 HAL_StatusTypeDef HAL_FDCAN_ConfigClockCalibration(FDCAN_HandleTypeDef *hfdcan, FDCAN_ClkCalUnitTypeDef *sCcuConfig)
1658 /* Check function parameters */
1659 assert_param(IS_FDCAN_CLOCK_CALIBRATION(sCcuConfig->ClockCalibration));
1660 if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
1662 assert_param(IS_FDCAN_CKDIV(sCcuConfig->ClockDivider));
1664 else
1666 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->MinOscClkPeriods, 0xFFU));
1667 assert_param(IS_FDCAN_CALIBRATION_FIELD_LENGTH(sCcuConfig->CalFieldLength));
1668 assert_param(IS_FDCAN_MIN_VALUE(sCcuConfig->TimeQuantaPerBitTime, 4U));
1669 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->TimeQuantaPerBitTime, 0x25U));
1670 assert_param(IS_FDCAN_MAX_VALUE(sCcuConfig->WatchdogStartValue, 0xFFFFU));
1673 /* FDCAN1 should be initialized in order to use clock calibration */
1674 if (hfdcan->Instance != FDCAN1)
1676 /* Update error code */
1677 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
1679 return HAL_ERROR;
1682 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1684 if (sCcuConfig->ClockCalibration == FDCAN_CLOCK_CALIBRATION_DISABLE)
1686 /* Bypass clock calibration */
1687 SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
1689 /* Configure clock divider */
1690 MODIFY_REG(FDCAN_CCU->CCFG, FDCANCCU_CCFG_CDIV, sCcuConfig->ClockDivider);
1692 else /* sCcuConfig->ClockCalibration == ENABLE */
1694 /* Clock calibration unit generates time quanta clock */
1695 CLEAR_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_BCC);
1697 /* Configure clock calibration unit */
1698 MODIFY_REG(FDCAN_CCU->CCFG,
1699 (FDCANCCU_CCFG_TQBT | FDCANCCU_CCFG_CFL | FDCANCCU_CCFG_OCPM),
1700 ((sCcuConfig->TimeQuantaPerBitTime << FDCANCCU_CCFG_TQBT_Pos) | sCcuConfig->CalFieldLength | (sCcuConfig->MinOscClkPeriods << FDCANCCU_CCFG_OCPM_Pos)));
1702 /* Configure the start value of the calibration watchdog counter */
1703 MODIFY_REG(FDCAN_CCU->CWD, FDCANCCU_CWD_WDC, sCcuConfig->WatchdogStartValue);
1706 /* Return function status */
1707 return HAL_OK;
1709 else
1711 /* Update error code */
1712 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1714 return HAL_ERROR;
1719 * @brief Get the clock calibration state.
1720 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1721 * the configuration information for the specified FDCAN.
1722 * @retval State clock calibration state (can be a value of @arg FDCAN_calibration_state)
1724 uint32_t HAL_FDCAN_GetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
1726 /* Prevent unused argument(s) compilation warning */
1727 UNUSED(hfdcan);
1729 return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_CALS);
1733 * @brief Reset the clock calibration state.
1734 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1735 * the configuration information for the specified FDCAN.
1736 * @retval HAL status
1738 HAL_StatusTypeDef HAL_FDCAN_ResetClockCalibrationState(FDCAN_HandleTypeDef *hfdcan)
1740 /* FDCAN1 should be initialized in order to use clock calibration */
1741 if (hfdcan->Instance != FDCAN1)
1743 /* Update error code */
1744 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
1746 return HAL_ERROR;
1749 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1751 /* Calibration software reset */
1752 SET_BIT(FDCAN_CCU->CCFG, FDCANCCU_CCFG_SWR);
1754 /* Return function status */
1755 return HAL_OK;
1757 else
1759 /* Update error code */
1760 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1762 return HAL_ERROR;
1767 * @brief Get the clock calibration counter value.
1768 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1769 * the configuration information for the specified FDCAN.
1770 * @param Counter clock calibration counter.
1771 * This parameter can be a value of @arg FDCAN_calibration_counter.
1772 * @retval Value clock calibration counter value
1774 uint32_t HAL_FDCAN_GetClockCalibrationCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t Counter)
1776 /* Prevent unused argument(s) compilation warning */
1777 UNUSED(hfdcan);
1779 /* Check function parameters */
1780 assert_param(IS_FDCAN_CALIBRATION_COUNTER(Counter));
1782 if (Counter == FDCAN_CALIB_TIME_QUANTA_COUNTER)
1784 return ((FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_TQC) >> FDCANCCU_CSTAT_TQC_Pos);
1786 else if (Counter == FDCAN_CALIB_CLOCK_PERIOD_COUNTER)
1788 return (FDCAN_CCU->CSTAT & FDCANCCU_CSTAT_OCPC);
1790 else /* Counter == FDCAN_CALIB_WATCHDOG_COUNTER */
1792 return ((FDCAN_CCU->CWD & FDCANCCU_CWD_WDV) >> FDCANCCU_CWD_WDV_Pos);
1797 * @brief Configure the FDCAN reception filter according to the specified
1798 * parameters in the FDCAN_FilterTypeDef structure.
1799 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1800 * the configuration information for the specified FDCAN.
1801 * @param sFilterConfig pointer to an FDCAN_FilterTypeDef structure that
1802 * contains the filter configuration information
1803 * @retval HAL status
1805 HAL_StatusTypeDef HAL_FDCAN_ConfigFilter(FDCAN_HandleTypeDef *hfdcan, FDCAN_FilterTypeDef *sFilterConfig)
1807 uint32_t FilterElementW1;
1808 uint32_t FilterElementW2;
1809 uint32_t *FilterAddress;
1810 HAL_FDCAN_StateTypeDef state = hfdcan->State;
1812 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
1814 /* Check function parameters */
1815 assert_param(IS_FDCAN_ID_TYPE(sFilterConfig->IdType));
1816 assert_param(IS_FDCAN_FILTER_CFG(sFilterConfig->FilterConfig));
1817 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1819 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->RxBufferIndex, 63U));
1820 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->IsCalibrationMsg, 1U));
1823 if (sFilterConfig->IdType == FDCAN_STANDARD_ID)
1825 /* Check function parameters */
1826 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.StdFiltersNbr - 1U)));
1827 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x7FFU));
1828 if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
1830 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x7FFU));
1831 assert_param(IS_FDCAN_STD_FILTER_TYPE(sFilterConfig->FilterType));
1834 /* Build filter element */
1835 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1837 FilterElementW1 = ((FDCAN_FILTER_TO_RXBUFFER << 27U) |
1838 (sFilterConfig->FilterID1 << 16U) |
1839 (sFilterConfig->IsCalibrationMsg << 8U) |
1840 sFilterConfig->RxBufferIndex);
1842 else
1844 FilterElementW1 = ((sFilterConfig->FilterType << 30U) |
1845 (sFilterConfig->FilterConfig << 27U) |
1846 (sFilterConfig->FilterID1 << 16U) |
1847 sFilterConfig->FilterID2);
1850 /* Calculate filter address */
1851 FilterAddress = (uint32_t *)(hfdcan->msgRam.StandardFilterSA + (sFilterConfig->FilterIndex * 4U));
1853 /* Write filter element to the message RAM */
1854 *FilterAddress = FilterElementW1;
1856 else /* sFilterConfig->IdType == FDCAN_EXTENDED_ID */
1858 /* Check function parameters */
1859 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterIndex, (hfdcan->Init.ExtFiltersNbr - 1U)));
1860 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID1, 0x1FFFFFFFU));
1861 if (sFilterConfig->FilterConfig != FDCAN_FILTER_TO_RXBUFFER)
1863 assert_param(IS_FDCAN_MAX_VALUE(sFilterConfig->FilterID2, 0x1FFFFFFFU));
1864 assert_param(IS_FDCAN_EXT_FILTER_TYPE(sFilterConfig->FilterType));
1867 /* Build first word of filter element */
1868 FilterElementW1 = ((sFilterConfig->FilterConfig << 29U) | sFilterConfig->FilterID1);
1870 /* Build second word of filter element */
1871 if (sFilterConfig->FilterConfig == FDCAN_FILTER_TO_RXBUFFER)
1873 FilterElementW2 = sFilterConfig->RxBufferIndex;
1875 else
1877 FilterElementW2 = ((sFilterConfig->FilterType << 30U) | sFilterConfig->FilterID2);
1880 /* Calculate filter address */
1881 FilterAddress = (uint32_t *)(hfdcan->msgRam.ExtendedFilterSA + (sFilterConfig->FilterIndex * 4U * 2U));
1883 /* Write filter element to the message RAM */
1884 *FilterAddress = FilterElementW1;
1885 FilterAddress++;
1886 *FilterAddress = FilterElementW2;
1889 /* Return function status */
1890 return HAL_OK;
1892 else
1894 /* Update error code */
1895 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
1897 return HAL_ERROR;
1902 * @brief Configure the FDCAN global filter.
1903 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1904 * the configuration information for the specified FDCAN.
1905 * @param NonMatchingStd Defines how received messages with 11-bit IDs that
1906 * do not match any element of the filter list are treated.
1907 * This parameter can be a value of @arg FDCAN_Non_Matching_Frames.
1908 * @param NonMatchingExt Defines how received messages with 29-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 RejectRemoteStd Filter or reject all the remote 11-bit IDs frames.
1912 * This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
1913 * @param RejectRemoteExt Filter or reject all the remote 29-bit IDs frames.
1914 * This parameter can be a value of @arg FDCAN_Reject_Remote_Frames.
1915 * @retval HAL status
1917 HAL_StatusTypeDef HAL_FDCAN_ConfigGlobalFilter(FDCAN_HandleTypeDef *hfdcan,
1918 uint32_t NonMatchingStd,
1919 uint32_t NonMatchingExt,
1920 uint32_t RejectRemoteStd,
1921 uint32_t RejectRemoteExt)
1923 /* Check function parameters */
1924 assert_param(IS_FDCAN_NON_MATCHING(NonMatchingStd));
1925 assert_param(IS_FDCAN_NON_MATCHING(NonMatchingExt));
1926 assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteStd));
1927 assert_param(IS_FDCAN_REJECT_REMOTE(RejectRemoteExt));
1929 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1931 /* Configure global filter */
1932 hfdcan->Instance->GFC = ((NonMatchingStd << FDCAN_GFC_ANFS_Pos) |
1933 (NonMatchingExt << FDCAN_GFC_ANFE_Pos) |
1934 (RejectRemoteStd << FDCAN_GFC_RRFS_Pos) |
1935 (RejectRemoteExt << FDCAN_GFC_RRFE_Pos));
1937 /* Return function status */
1938 return HAL_OK;
1940 else
1942 /* Update error code */
1943 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1945 return HAL_ERROR;
1950 * @brief Configure the extended ID mask.
1951 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1952 * the configuration information for the specified FDCAN.
1953 * @param Mask Extended ID Mask.
1954 * This parameter must be a number between 0 and 0x1FFFFFFF
1955 * @retval HAL status
1957 HAL_StatusTypeDef HAL_FDCAN_ConfigExtendedIdMask(FDCAN_HandleTypeDef *hfdcan, uint32_t Mask)
1959 /* Check function parameters */
1960 assert_param(IS_FDCAN_MAX_VALUE(Mask, 0x1FFFFFFFU));
1962 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1964 /* Configure the extended ID mask */
1965 hfdcan->Instance->XIDAM = Mask;
1967 /* Return function status */
1968 return HAL_OK;
1970 else
1972 /* Update error code */
1973 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
1975 return HAL_ERROR;
1980 * @brief Configure the Rx FIFO operation mode.
1981 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
1982 * the configuration information for the specified FDCAN.
1983 * @param RxFifo Rx FIFO.
1984 * This parameter can be one of the following values:
1985 * @arg FDCAN_RX_FIFO0: Rx FIFO 0
1986 * @arg FDCAN_RX_FIFO1: Rx FIFO 1
1987 * @param OperationMode operation mode.
1988 * This parameter can be a value of @arg FDCAN_Rx_FIFO_operation_mode.
1989 * @retval HAL status
1991 HAL_StatusTypeDef HAL_FDCAN_ConfigRxFifoOverwrite(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo, uint32_t OperationMode)
1993 /* Check function parameters */
1994 assert_param(IS_FDCAN_RX_FIFO(RxFifo));
1995 assert_param(IS_FDCAN_RX_FIFO_MODE(OperationMode));
1997 if (hfdcan->State == HAL_FDCAN_STATE_READY)
1999 if (RxFifo == FDCAN_RX_FIFO0)
2001 /* Select FIFO 0 Operation Mode */
2002 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0OM, OperationMode);
2004 else /* RxFifo == FDCAN_RX_FIFO1 */
2006 /* Select FIFO 1 Operation Mode */
2007 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1OM, OperationMode);
2010 /* Return function status */
2011 return HAL_OK;
2013 else
2015 /* Update error code */
2016 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2018 return HAL_ERROR;
2023 * @brief Configure the FIFO watermark.
2024 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2025 * the configuration information for the specified FDCAN.
2026 * @param FIFO select the FIFO to be configured.
2027 * This parameter can be a value of @arg FDCAN_FIFO_watermark.
2028 * @param Watermark level for FIFO watermark interrupt.
2029 * This parameter must be a number between:
2030 * - 0 and 32, if FIFO is FDCAN_CFG_TX_EVENT_FIFO
2031 * - 0 and 64, if FIFO is FDCAN_CFG_RX_FIFO0 or FDCAN_CFG_RX_FIFO1
2032 * @retval HAL status
2034 HAL_StatusTypeDef HAL_FDCAN_ConfigFifoWatermark(FDCAN_HandleTypeDef *hfdcan, uint32_t FIFO, uint32_t Watermark)
2036 /* Check function parameters */
2037 assert_param(IS_FDCAN_FIFO_WATERMARK(FIFO));
2038 if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
2040 assert_param(IS_FDCAN_MAX_VALUE(Watermark, 32U));
2042 else /* (FIFO == FDCAN_CFG_RX_FIFO0) || (FIFO == FDCAN_CFG_RX_FIFO1) */
2044 assert_param(IS_FDCAN_MAX_VALUE(Watermark, 64U));
2047 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2049 /* Set the level for FIFO watermark interrupt */
2050 if (FIFO == FDCAN_CFG_TX_EVENT_FIFO)
2052 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFWM, (Watermark << FDCAN_TXEFC_EFWM_Pos));
2054 else if (FIFO == FDCAN_CFG_RX_FIFO0)
2056 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0WM, (Watermark << FDCAN_RXF0C_F0WM_Pos));
2058 else /* FIFO == FDCAN_CFG_RX_FIFO1 */
2060 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1WM, (Watermark << FDCAN_RXF1C_F1WM_Pos));
2063 /* Return function status */
2064 return HAL_OK;
2066 else
2068 /* Update error code */
2069 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2071 return HAL_ERROR;
2076 * @brief Configure the RAM watchdog.
2077 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2078 * the configuration information for the specified FDCAN.
2079 * @param CounterStartValue Start value of the Message RAM Watchdog Counter,
2080 * This parameter must be a number between 0x00 and 0xFF,
2081 * with the reset value of 0x00 the counter is disabled.
2082 * @retval HAL status
2084 HAL_StatusTypeDef HAL_FDCAN_ConfigRamWatchdog(FDCAN_HandleTypeDef *hfdcan, uint32_t CounterStartValue)
2086 /* Check function parameters */
2087 assert_param(IS_FDCAN_MAX_VALUE(CounterStartValue, 0xFFU));
2089 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2091 /* Configure the RAM watchdog counter start value */
2092 MODIFY_REG(hfdcan->Instance->RWD, FDCAN_RWD_WDC, CounterStartValue);
2094 /* Return function status */
2095 return HAL_OK;
2097 else
2099 /* Update error code */
2100 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2102 return HAL_ERROR;
2107 * @brief Configure the timestamp counter.
2108 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2109 * the configuration information for the specified FDCAN.
2110 * @param TimestampPrescaler Timestamp Counter Prescaler.
2111 * This parameter can be a value of @arg FDCAN_Timestamp_Prescaler.
2112 * @retval HAL status
2114 HAL_StatusTypeDef HAL_FDCAN_ConfigTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampPrescaler)
2116 /* Check function parameters */
2117 assert_param(IS_FDCAN_TIMESTAMP_PRESCALER(TimestampPrescaler));
2119 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2121 /* Configure prescaler */
2122 MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TCP, TimestampPrescaler);
2124 /* Return function status */
2125 return HAL_OK;
2127 else
2129 /* Update error code */
2130 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2132 return HAL_ERROR;
2137 * @brief Enable the timestamp counter.
2138 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2139 * the configuration information for the specified FDCAN.
2140 * @param TimestampOperation Timestamp counter operation.
2141 * This parameter can be a value of @arg FDCAN_Timestamp.
2142 * @retval HAL status
2144 HAL_StatusTypeDef HAL_FDCAN_EnableTimestampCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimestampOperation)
2146 /* Check function parameters */
2147 assert_param(IS_FDCAN_TIMESTAMP(TimestampOperation));
2149 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2151 /* Enable timestamp counter */
2152 MODIFY_REG(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS, TimestampOperation);
2154 /* Return function status */
2155 return HAL_OK;
2157 else
2159 /* Update error code */
2160 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2162 return HAL_ERROR;
2167 * @brief Disable the timestamp counter.
2168 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2169 * the configuration information for the specified FDCAN.
2170 * @retval HAL status
2172 HAL_StatusTypeDef HAL_FDCAN_DisableTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2174 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2176 /* Disable timestamp counter */
2177 CLEAR_BIT(hfdcan->Instance->TSCC, FDCAN_TSCC_TSS);
2179 /* Return function status */
2180 return HAL_OK;
2182 else
2184 /* Update error code */
2185 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2187 return HAL_ERROR;
2192 * @brief Get the timestamp counter value.
2193 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2194 * the configuration information for the specified FDCAN.
2195 * @retval Value Timestamp counter value
2197 uint16_t HAL_FDCAN_GetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2199 return (uint16_t)(hfdcan->Instance->TSCV);
2203 * @brief Reset the timestamp counter to zero.
2204 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2205 * the configuration information for the specified FDCAN.
2206 * @retval HAL status
2208 HAL_StatusTypeDef HAL_FDCAN_ResetTimestampCounter(FDCAN_HandleTypeDef *hfdcan)
2210 if ((hfdcan->Instance->TSCC & FDCAN_TSCC_TSS) != FDCAN_TIMESTAMP_EXTERNAL)
2212 /* Reset timestamp counter.
2213 Actually any write operation to TSCV clears the counter */
2214 CLEAR_REG(hfdcan->Instance->TSCV);
2216 else
2218 /* Update error code.
2219 Unable to reset external counter */
2220 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
2222 return HAL_ERROR;
2225 /* Return function status */
2226 return HAL_OK;
2230 * @brief Configure the timeout counter.
2231 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2232 * the configuration information for the specified FDCAN.
2233 * @param TimeoutOperation Timeout counter operation.
2234 * This parameter can be a value of @arg FDCAN_Timeout_Operation.
2235 * @param TimeoutPeriod Start value of the timeout down-counter.
2236 * This parameter must be a number between 0x0000 and 0xFFFF
2237 * @retval HAL status
2239 HAL_StatusTypeDef HAL_FDCAN_ConfigTimeoutCounter(FDCAN_HandleTypeDef *hfdcan, uint32_t TimeoutOperation, uint32_t TimeoutPeriod)
2241 /* Check function parameters */
2242 assert_param(IS_FDCAN_TIMEOUT(TimeoutOperation));
2243 assert_param(IS_FDCAN_MAX_VALUE(TimeoutPeriod, 0xFFFFU));
2245 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2247 /* Select timeout operation and configure period */
2248 MODIFY_REG(hfdcan->Instance->TOCC, (FDCAN_TOCC_TOS | FDCAN_TOCC_TOP), (TimeoutOperation | (TimeoutPeriod << FDCAN_TOCC_TOP_Pos)));
2250 /* Return function status */
2251 return HAL_OK;
2253 else
2255 /* Update error code */
2256 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2258 return HAL_ERROR;
2263 * @brief Enable the timeout counter.
2264 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2265 * the configuration information for the specified FDCAN.
2266 * @retval HAL status
2268 HAL_StatusTypeDef HAL_FDCAN_EnableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2270 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2272 /* Enable timeout counter */
2273 SET_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
2275 /* Return function status */
2276 return HAL_OK;
2278 else
2280 /* Update error code */
2281 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2283 return HAL_ERROR;
2288 * @brief Disable the timeout counter.
2289 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2290 * the configuration information for the specified FDCAN.
2291 * @retval HAL status
2293 HAL_StatusTypeDef HAL_FDCAN_DisableTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2295 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2297 /* Disable timeout counter */
2298 CLEAR_BIT(hfdcan->Instance->TOCC, FDCAN_TOCC_ETOC);
2300 /* Return function status */
2301 return HAL_OK;
2303 else
2305 /* Update error code */
2306 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2308 return HAL_ERROR;
2313 * @brief Get the timeout counter value.
2314 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2315 * the configuration information for the specified FDCAN.
2316 * @retval Value Timeout counter value
2318 uint16_t HAL_FDCAN_GetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2320 return (uint16_t)(hfdcan->Instance->TOCV);
2324 * @brief Reset the timeout counter to its start value.
2325 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2326 * the configuration information for the specified FDCAN.
2327 * @retval HAL status
2329 HAL_StatusTypeDef HAL_FDCAN_ResetTimeoutCounter(FDCAN_HandleTypeDef *hfdcan)
2331 if ((hfdcan->Instance->TOCC & FDCAN_TOCC_TOS) == FDCAN_TIMEOUT_CONTINUOUS)
2333 /* Reset timeout counter to start value */
2334 CLEAR_REG(hfdcan->Instance->TOCV);
2336 /* Return function status */
2337 return HAL_OK;
2339 else
2341 /* Update error code.
2342 Unable to reset counter: controlled only by FIFO empty state */
2343 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
2345 return HAL_ERROR;
2350 * @brief Configure the transmitter delay compensation.
2351 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2352 * the configuration information for the specified FDCAN.
2353 * @param TdcOffset Transmitter Delay Compensation Offset.
2354 * This parameter must be a number between 0x00 and 0x7F.
2355 * @param TdcFilter Transmitter Delay Compensation Filter Window Length.
2356 * This parameter must be a number between 0x00 and 0x7F.
2357 * @retval HAL status
2359 HAL_StatusTypeDef HAL_FDCAN_ConfigTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan, uint32_t TdcOffset, uint32_t TdcFilter)
2361 /* Check function parameters */
2362 assert_param(IS_FDCAN_MAX_VALUE(TdcOffset, 0x7FU));
2363 assert_param(IS_FDCAN_MAX_VALUE(TdcFilter, 0x7FU));
2365 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2367 /* Configure TDC offset and filter window */
2368 hfdcan->Instance->TDCR = ((TdcFilter << FDCAN_TDCR_TDCF_Pos) | (TdcOffset << FDCAN_TDCR_TDCO_Pos));
2370 /* Return function status */
2371 return HAL_OK;
2373 else
2375 /* Update error code */
2376 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2378 return HAL_ERROR;
2383 * @brief Enable the transmitter delay compensation.
2384 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2385 * the configuration information for the specified FDCAN.
2386 * @retval HAL status
2388 HAL_StatusTypeDef HAL_FDCAN_EnableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
2390 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2392 /* Enable transmitter delay compensation */
2393 SET_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
2395 /* Return function status */
2396 return HAL_OK;
2398 else
2400 /* Update error code */
2401 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2403 return HAL_ERROR;
2408 * @brief Disable the transmitter delay compensation.
2409 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2410 * the configuration information for the specified FDCAN.
2411 * @retval HAL status
2413 HAL_StatusTypeDef HAL_FDCAN_DisableTxDelayCompensation(FDCAN_HandleTypeDef *hfdcan)
2415 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2417 /* Disable transmitter delay compensation */
2418 CLEAR_BIT(hfdcan->Instance->DBTP, FDCAN_DBTP_TDC);
2420 /* Return function status */
2421 return HAL_OK;
2423 else
2425 /* Update error code */
2426 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2428 return HAL_ERROR;
2433 * @brief Enable ISO 11898-1 protocol mode.
2434 * CAN FD frame format is according to ISO 11898-1 standard.
2435 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2436 * the configuration information for the specified FDCAN.
2437 * @retval HAL status
2439 HAL_StatusTypeDef HAL_FDCAN_EnableISOMode(FDCAN_HandleTypeDef *hfdcan)
2441 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2443 /* Disable Non ISO protocol mode */
2444 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
2446 /* Return function status */
2447 return HAL_OK;
2449 else
2451 /* Update error code */
2452 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2454 return HAL_ERROR;
2459 * @brief Disable ISO 11898-1 protocol mode.
2460 * CAN FD frame format is according to Bosch CAN FD specification V1.0.
2461 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2462 * the configuration information for the specified FDCAN.
2463 * @retval HAL status
2465 HAL_StatusTypeDef HAL_FDCAN_DisableISOMode(FDCAN_HandleTypeDef *hfdcan)
2467 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2469 /* Enable Non ISO protocol mode */
2470 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_NISO);
2472 /* Return function status */
2473 return HAL_OK;
2475 else
2477 /* Update error code */
2478 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2480 return HAL_ERROR;
2485 * @brief Enable edge filtering during bus integration.
2486 * Two consecutive dominant tq are required to detect an edge for hard synchronization.
2487 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2488 * the configuration information for the specified FDCAN.
2489 * @retval HAL status
2491 HAL_StatusTypeDef HAL_FDCAN_EnableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
2493 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2495 /* Enable edge filtering */
2496 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
2498 /* Return function status */
2499 return HAL_OK;
2501 else
2503 /* Update error code */
2504 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2506 return HAL_ERROR;
2511 * @brief Disable edge filtering during bus integration.
2512 * One dominant tq is required to detect an edge for hard synchronization.
2513 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2514 * the configuration information for the specified FDCAN.
2515 * @retval HAL status
2517 HAL_StatusTypeDef HAL_FDCAN_DisableEdgeFiltering(FDCAN_HandleTypeDef *hfdcan)
2519 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2521 /* Disable edge filtering */
2522 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_EFBI);
2524 /* Return function status */
2525 return HAL_OK;
2527 else
2529 /* Update error code */
2530 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2532 return HAL_ERROR;
2537 * @}
2540 /** @defgroup FDCAN_Exported_Functions_Group3 Control functions
2541 * @brief Control functions
2543 @verbatim
2544 ==============================================================================
2545 ##### Control functions #####
2546 ==============================================================================
2547 [..] This section provides functions allowing to:
2548 (+) HAL_FDCAN_Start : Start the FDCAN module
2549 (+) HAL_FDCAN_Stop : Stop the FDCAN module and enable access to configuration registers
2550 (+) HAL_FDCAN_AddMessageToTxFifoQ : Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
2551 (+) HAL_FDCAN_AddMessageToTxBuffer : Add a message to a dedicated Tx buffer
2552 (+) HAL_FDCAN_EnableTxBufferRequest : Enable transmission request
2553 (+) HAL_FDCAN_GetLatestTxFifoQRequestBuffer : Get Tx buffer index of latest Tx FIFO/Queue request
2554 (+) HAL_FDCAN_AbortTxRequest : Abort transmission request
2555 (+) HAL_FDCAN_GetRxMessage : Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM
2556 (+) HAL_FDCAN_GetTxEvent : Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM
2557 (+) HAL_FDCAN_GetHighPriorityMessageStatus : Get high priority message status
2558 (+) HAL_FDCAN_GetProtocolStatus : Get protocol status
2559 (+) HAL_FDCAN_GetErrorCounters : Get error counter values
2560 (+) HAL_FDCAN_IsRxBufferMessageAvailable : Check if a new message is received in the selected Rx buffer
2561 (+) HAL_FDCAN_IsTxBufferMessagePending : Check if a transmission request is pending on the selected Tx buffer
2562 (+) HAL_FDCAN_GetRxFifoFillLevel : Return Rx FIFO fill level
2563 (+) HAL_FDCAN_GetTxFifoFreeLevel : Return Tx FIFO free level
2564 (+) HAL_FDCAN_IsRestrictedOperationMode : Check if the FDCAN peripheral entered Restricted Operation Mode
2565 (+) HAL_FDCAN_ExitRestrictedOperationMode : Exit Restricted Operation Mode
2567 @endverbatim
2568 * @{
2572 * @brief Start the FDCAN module.
2573 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2574 * the configuration information for the specified FDCAN.
2575 * @retval HAL status
2577 HAL_StatusTypeDef HAL_FDCAN_Start(FDCAN_HandleTypeDef *hfdcan)
2579 if (hfdcan->State == HAL_FDCAN_STATE_READY)
2581 /* Change FDCAN peripheral state */
2582 hfdcan->State = HAL_FDCAN_STATE_BUSY;
2584 /* Request leave initialisation */
2585 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
2587 /* Reset the FDCAN ErrorCode */
2588 hfdcan->ErrorCode = HAL_FDCAN_ERROR_NONE;
2590 /* Return function status */
2591 return HAL_OK;
2593 else
2595 /* Update error code */
2596 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
2598 return HAL_ERROR;
2603 * @brief Stop the FDCAN module and enable access to configuration registers.
2604 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2605 * the configuration information for the specified FDCAN.
2606 * @retval HAL status
2608 HAL_StatusTypeDef HAL_FDCAN_Stop(FDCAN_HandleTypeDef *hfdcan)
2610 uint32_t Counter = 0U;
2612 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2614 /* Request initialisation */
2615 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_INIT);
2617 /* Wait until the INIT bit into CCCR register is set */
2618 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_INIT) == 0U)
2620 /* Check for the Timeout */
2621 if (Counter > FDCAN_TIMEOUT_VALUE)
2623 /* Update error code */
2624 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
2626 /* Change FDCAN state */
2627 hfdcan->State = HAL_FDCAN_STATE_ERROR;
2629 return HAL_ERROR;
2632 /* Increment counter */
2633 Counter++;
2636 /* Reset counter */
2637 Counter = 0U;
2639 /* Exit from Sleep mode */
2640 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CSR);
2642 /* Wait until FDCAN exits sleep mode */
2643 while ((hfdcan->Instance->CCCR & FDCAN_CCCR_CSA) == FDCAN_CCCR_CSA)
2645 /* Check for the Timeout */
2646 if (Counter > FDCAN_TIMEOUT_VALUE)
2648 /* Update error code */
2649 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
2651 /* Change FDCAN state */
2652 hfdcan->State = HAL_FDCAN_STATE_ERROR;
2654 return HAL_ERROR;
2657 /* Increment counter */
2658 Counter++;
2661 /* Enable configuration change */
2662 SET_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_CCE);
2664 /* Reset Latest Tx FIFO/Queue Request Buffer Index */
2665 hfdcan->LatestTxFifoQRequest = 0U;
2667 /* Change FDCAN peripheral state */
2668 hfdcan->State = HAL_FDCAN_STATE_READY;
2670 /* Return function status */
2671 return HAL_OK;
2673 else
2675 /* Update error code */
2676 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2678 return HAL_ERROR;
2683 * @brief Add a message to the Tx FIFO/Queue and activate the corresponding transmission request
2684 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2685 * the configuration information for the specified FDCAN.
2686 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
2687 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
2688 * @retval HAL status
2690 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxFifoQ(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData)
2692 uint32_t PutIndex;
2694 /* Check function parameters */
2695 assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
2696 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
2698 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
2700 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
2702 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
2704 assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
2705 assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
2706 assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
2707 assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
2708 assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
2709 assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
2710 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
2712 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2714 /* Check that the Tx FIFO/Queue has an allocated area into the RAM */
2715 if ((hfdcan->Instance->TXBC & FDCAN_TXBC_TFQS) == 0U)
2717 /* Update error code */
2718 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2720 return HAL_ERROR;
2723 /* Check that the Tx FIFO/Queue is not full */
2724 if ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQF) != 0U)
2726 /* Update error code */
2727 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_FULL;
2729 return HAL_ERROR;
2731 else
2733 /* Retrieve the Tx FIFO PutIndex */
2734 PutIndex = ((hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFQPI) >> FDCAN_TXFQS_TFQPI_Pos);
2736 /* Add the message to the Tx FIFO/Queue */
2737 FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, PutIndex);
2739 /* Activate the corresponding transmission request */
2740 hfdcan->Instance->TXBAR = ((uint32_t)1 << PutIndex);
2742 /* Store the Latest Tx FIFO/Queue Request Buffer Index */
2743 hfdcan->LatestTxFifoQRequest = ((uint32_t)1 << PutIndex);
2746 /* Return function status */
2747 return HAL_OK;
2749 else
2751 /* Update error code */
2752 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2754 return HAL_ERROR;
2759 * @brief Add a message to a dedicated Tx buffer
2760 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2761 * the configuration information for the specified FDCAN.
2762 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
2763 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
2764 * @param BufferIndex index of the buffer to be configured.
2765 * This parameter can be a value of @arg FDCAN_Tx_location.
2766 * @retval HAL status
2768 HAL_StatusTypeDef HAL_FDCAN_AddMessageToTxBuffer(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
2770 HAL_FDCAN_StateTypeDef state = hfdcan->State;
2772 /* Check function parameters */
2773 assert_param(IS_FDCAN_ID_TYPE(pTxHeader->IdType));
2774 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
2776 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x7FFU));
2778 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
2780 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->Identifier, 0x1FFFFFFFU));
2782 assert_param(IS_FDCAN_FRAME_TYPE(pTxHeader->TxFrameType));
2783 assert_param(IS_FDCAN_DLC(pTxHeader->DataLength));
2784 assert_param(IS_FDCAN_ESI(pTxHeader->ErrorStateIndicator));
2785 assert_param(IS_FDCAN_BRS(pTxHeader->BitRateSwitch));
2786 assert_param(IS_FDCAN_FDF(pTxHeader->FDFormat));
2787 assert_param(IS_FDCAN_EFC(pTxHeader->TxEventFifoControl));
2788 assert_param(IS_FDCAN_MAX_VALUE(pTxHeader->MessageMarker, 0xFFU));
2789 assert_param(IS_FDCAN_TX_LOCATION(BufferIndex));
2791 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
2793 /* Check that the selected buffer has an allocated area into the RAM */
2794 if (POSITION_VAL(BufferIndex) >= ((hfdcan->Instance->TXBC & FDCAN_TXBC_NDTB) >> FDCAN_TXBC_NDTB_Pos))
2796 /* Update error code */
2797 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2799 return HAL_ERROR;
2802 /* Check that there is no transmittion request pending for the selected buffer */
2803 if ((hfdcan->Instance->TXBRP & BufferIndex) != 0U)
2805 /* Update error code */
2806 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
2808 return HAL_ERROR;
2810 else
2812 /* Add the message to the Tx buffer */
2813 FDCAN_CopyMessageToRAM(hfdcan, pTxHeader, pTxData, POSITION_VAL(BufferIndex));
2816 /* Return function status */
2817 return HAL_OK;
2819 else
2821 /* Update error code */
2822 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
2824 return HAL_ERROR;
2829 * @brief Enable transmission request.
2830 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2831 * the configuration information for the specified FDCAN.
2832 * @param BufferIndex buffer index.
2833 * This parameter can be any combination of @arg FDCAN_Tx_location.
2834 * @retval HAL status
2836 HAL_StatusTypeDef HAL_FDCAN_EnableTxBufferRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
2838 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2840 /* Add transmission request */
2841 hfdcan->Instance->TXBAR = BufferIndex;
2843 /* Return function status */
2844 return HAL_OK;
2846 else
2848 /* Update error code */
2849 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2851 return HAL_ERROR;
2856 * @brief Get Tx buffer index of latest Tx FIFO/Queue request
2857 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2858 * the configuration information for the specified FDCAN.
2859 * @retval Tx buffer index of last Tx FIFO/Queue request
2860 * - Any value of @arg FDCAN_Tx_location if Tx request has been submitted.
2861 * - 0 if no Tx FIFO/Queue request have been submitted.
2863 uint32_t HAL_FDCAN_GetLatestTxFifoQRequestBuffer(FDCAN_HandleTypeDef *hfdcan)
2865 /* Return Last Tx FIFO/Queue Request Buffer */
2866 return hfdcan->LatestTxFifoQRequest;
2870 * @brief Abort transmission request
2871 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2872 * the configuration information for the specified FDCAN.
2873 * @param BufferIndex buffer index.
2874 * This parameter can be any combination of @arg FDCAN_Tx_location.
2875 * @retval HAL status
2877 HAL_StatusTypeDef HAL_FDCAN_AbortTxRequest(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndex)
2879 if (hfdcan->State == HAL_FDCAN_STATE_BUSY)
2881 /* Add cancellation request */
2882 hfdcan->Instance->TXBCR = BufferIndex;
2884 /* Return function status */
2885 return HAL_OK;
2887 else
2889 /* Update error code */
2890 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
2892 return HAL_ERROR;
2897 * @brief Get an FDCAN frame from the Rx Buffer/FIFO zone into the message RAM.
2898 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
2899 * the configuration information for the specified FDCAN.
2900 * @param RxLocation Location of the received message to be read.
2901 * This parameter can be a value of @arg FDCAN_Rx_location.
2902 * @param pRxHeader pointer to a FDCAN_RxHeaderTypeDef structure.
2903 * @param pRxData pointer to a buffer where the payload of the Rx frame will be stored.
2904 * @retval HAL status
2906 HAL_StatusTypeDef HAL_FDCAN_GetRxMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t RxLocation, FDCAN_RxHeaderTypeDef *pRxHeader, uint8_t *pRxData)
2908 uint32_t *RxAddress;
2909 uint8_t *pData;
2910 uint32_t ByteCounter;
2911 uint32_t GetIndex = 0;
2912 HAL_FDCAN_StateTypeDef state = hfdcan->State;
2914 if (state == HAL_FDCAN_STATE_BUSY)
2916 if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
2918 /* Check that the Rx FIFO 0 has an allocated area into the RAM */
2919 if ((hfdcan->Instance->RXF0C & FDCAN_RXF0C_F0S) == 0U)
2921 /* Update error code */
2922 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2924 return HAL_ERROR;
2927 /* Check that the Rx FIFO 0 is not empty */
2928 if ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL) == 0U)
2930 /* Update error code */
2931 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
2933 return HAL_ERROR;
2935 else
2937 /* Calculate Rx FIFO 0 element address */
2938 GetIndex = ((hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0GI) >> FDCAN_RXF0S_F0GI_Pos);
2939 RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO0SA + (GetIndex * hfdcan->Init.RxFifo0ElmtSize * 4U));
2942 else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
2944 /* Check that the Rx FIFO 1 has an allocated area into the RAM */
2945 if ((hfdcan->Instance->RXF1C & FDCAN_RXF1C_F1S) == 0U)
2947 /* Update error code */
2948 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2950 return HAL_ERROR;
2953 /* Check that the Rx FIFO 0 is not empty */
2954 if ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL) == 0U)
2956 /* Update error code */
2957 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
2959 return HAL_ERROR;
2961 else
2963 /* Calculate Rx FIFO 1 element address */
2964 GetIndex = ((hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1GI) >> FDCAN_RXF1S_F1GI_Pos);
2965 RxAddress = (uint32_t *)(hfdcan->msgRam.RxFIFO1SA + (GetIndex * hfdcan->Init.RxFifo1ElmtSize * 4U));
2968 else /* Rx element is assigned to a dedicated Rx buffer */
2970 /* Check that the selected buffer has an allocated area into the RAM */
2971 if (RxLocation >= hfdcan->Init.RxBuffersNbr)
2973 /* Update error code */
2974 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
2976 return HAL_ERROR;
2978 else
2980 /* Calculate Rx buffer address */
2981 RxAddress = (uint32_t *)(hfdcan->msgRam.RxBufferSA + (RxLocation * hfdcan->Init.RxBufferSize * 4U));
2985 /* Retrieve IdType */
2986 pRxHeader->IdType = *RxAddress & FDCAN_ELEMENT_MASK_XTD;
2988 /* Retrieve Identifier */
2989 if (pRxHeader->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
2991 pRxHeader->Identifier = ((*RxAddress & FDCAN_ELEMENT_MASK_STDID) >> 18);
2993 else /* Extended ID element */
2995 pRxHeader->Identifier = (*RxAddress & FDCAN_ELEMENT_MASK_EXTID);
2998 /* Retrieve RxFrameType */
2999 pRxHeader->RxFrameType = (*RxAddress & FDCAN_ELEMENT_MASK_RTR);
3001 /* Retrieve ErrorStateIndicator */
3002 pRxHeader->ErrorStateIndicator = (*RxAddress & FDCAN_ELEMENT_MASK_ESI);
3004 /* Increment RxAddress pointer to second word of Rx FIFO element */
3005 RxAddress++;
3007 /* Retrieve RxTimestamp */
3008 pRxHeader->RxTimestamp = (*RxAddress & FDCAN_ELEMENT_MASK_TS);
3010 /* Retrieve DataLength */
3011 pRxHeader->DataLength = (*RxAddress & FDCAN_ELEMENT_MASK_DLC);
3013 /* Retrieve BitRateSwitch */
3014 pRxHeader->BitRateSwitch = (*RxAddress & FDCAN_ELEMENT_MASK_BRS);
3016 /* Retrieve FDFormat */
3017 pRxHeader->FDFormat = (*RxAddress & FDCAN_ELEMENT_MASK_FDF);
3019 /* Retrieve FilterIndex */
3020 pRxHeader->FilterIndex = ((*RxAddress & FDCAN_ELEMENT_MASK_FIDX) >> 24);
3022 /* Retrieve NonMatchingFrame */
3023 pRxHeader->IsFilterMatchingFrame = ((*RxAddress & FDCAN_ELEMENT_MASK_ANMF) >> 31);
3025 /* Increment RxAddress pointer to payload of Rx FIFO element */
3026 RxAddress++;
3028 /* Retrieve Rx payload */
3029 pData = (uint8_t *)RxAddress;
3030 for (ByteCounter = 0; ByteCounter < DLCtoBytes[pRxHeader->DataLength >> 16]; ByteCounter++)
3032 pRxData[ByteCounter] = pData[ByteCounter];
3035 if (RxLocation == FDCAN_RX_FIFO0) /* Rx element is assigned to the Rx FIFO 0 */
3037 /* Acknowledge the Rx FIFO 0 that the oldest element is read so that it increments the GetIndex */
3038 hfdcan->Instance->RXF0A = GetIndex;
3040 else if (RxLocation == FDCAN_RX_FIFO1) /* Rx element is assigned to the Rx FIFO 1 */
3042 /* Acknowledge the Rx FIFO 1 that the oldest element is read so that it increments the GetIndex */
3043 hfdcan->Instance->RXF1A = GetIndex;
3045 else /* Rx element is assigned to a dedicated Rx buffer */
3047 /* Clear the New Data flag of the current Rx buffer */
3048 if (RxLocation < FDCAN_RX_BUFFER32)
3050 hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxLocation);
3052 else /* FDCAN_RX_BUFFER32 <= RxLocation <= FDCAN_RX_BUFFER63 */
3054 hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxLocation & 0x1FU));
3058 /* Return function status */
3059 return HAL_OK;
3061 else
3063 /* Update error code */
3064 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
3066 return HAL_ERROR;
3071 * @brief Get an FDCAN Tx event from the Tx Event FIFO zone into the message RAM.
3072 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3073 * the configuration information for the specified FDCAN.
3074 * @param pTxEvent pointer to a FDCAN_TxEventFifoTypeDef structure.
3075 * @retval HAL status
3077 HAL_StatusTypeDef HAL_FDCAN_GetTxEvent(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxEventFifoTypeDef *pTxEvent)
3079 uint32_t *TxEventAddress;
3080 uint32_t GetIndex;
3081 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3083 /* Check function parameters */
3084 assert_param(IS_FDCAN_MIN_VALUE(hfdcan->Init.TxEventsNbr, 1U));
3086 if (state == HAL_FDCAN_STATE_BUSY)
3088 /* Check that the Tx Event FIFO has an allocated area into the RAM */
3089 if ((hfdcan->Instance->TXEFC & FDCAN_TXEFC_EFS) == 0U)
3091 /* Update error code */
3092 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
3094 return HAL_ERROR;
3097 /* Check that the Tx event FIFO is not empty */
3098 if ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFFL) == 0U)
3100 /* Update error code */
3101 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_FIFO_EMPTY;
3103 return HAL_ERROR;
3106 /* Calculate Tx event FIFO element address */
3107 GetIndex = ((hfdcan->Instance->TXEFS & FDCAN_TXEFS_EFGI) >> FDCAN_TXEFS_EFGI_Pos);
3108 TxEventAddress = (uint32_t *)(hfdcan->msgRam.TxEventFIFOSA + (GetIndex * 2U * 4U));
3110 /* Retrieve IdType */
3111 pTxEvent->IdType = *TxEventAddress & FDCAN_ELEMENT_MASK_XTD;
3113 /* Retrieve Identifier */
3114 if (pTxEvent->IdType == FDCAN_STANDARD_ID) /* Standard ID element */
3116 pTxEvent->Identifier = ((*TxEventAddress & FDCAN_ELEMENT_MASK_STDID) >> 18U);
3118 else /* Extended ID element */
3120 pTxEvent->Identifier = (*TxEventAddress & FDCAN_ELEMENT_MASK_EXTID);
3123 /* Retrieve RxFrameType */
3124 pTxEvent->TxFrameType = (*TxEventAddress & FDCAN_ELEMENT_MASK_RTR);
3126 /* Retrieve ErrorStateIndicator */
3127 pTxEvent->ErrorStateIndicator = (*TxEventAddress & FDCAN_ELEMENT_MASK_ESI);
3129 /* Increment TxEventAddress pointer to second word of Tx Event FIFO element */
3130 TxEventAddress++;
3132 /* Retrieve RxTimestamp */
3133 pTxEvent->TxTimestamp = (*TxEventAddress & FDCAN_ELEMENT_MASK_TS);
3135 /* Retrieve DataLength */
3136 pTxEvent->DataLength = (*TxEventAddress & FDCAN_ELEMENT_MASK_DLC);
3138 /* Retrieve BitRateSwitch */
3139 pTxEvent->BitRateSwitch = (*TxEventAddress & FDCAN_ELEMENT_MASK_BRS);
3141 /* Retrieve FDFormat */
3142 pTxEvent->FDFormat = (*TxEventAddress & FDCAN_ELEMENT_MASK_FDF);
3144 /* Retrieve EventType */
3145 pTxEvent->EventType = (*TxEventAddress & FDCAN_ELEMENT_MASK_ET);
3147 /* Retrieve MessageMarker */
3148 pTxEvent->MessageMarker = ((*TxEventAddress & FDCAN_ELEMENT_MASK_MM) >> 24);
3150 /* Acknowledge the Tx Event FIFO that the oldest element is read so that it increments the GetIndex */
3151 hfdcan->Instance->TXEFA = GetIndex;
3153 /* Return function status */
3154 return HAL_OK;
3156 else
3158 /* Update error code */
3159 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_STARTED;
3161 return HAL_ERROR;
3166 * @brief Get high priority message status.
3167 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3168 * the configuration information for the specified FDCAN.
3169 * @param HpMsgStatus pointer to an FDCAN_HpMsgStatusTypeDef structure.
3170 * @retval HAL status
3172 HAL_StatusTypeDef HAL_FDCAN_GetHighPriorityMessageStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_HpMsgStatusTypeDef *HpMsgStatus)
3174 HpMsgStatus->FilterList = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FLST) >> FDCAN_HPMS_FLST_Pos);
3175 HpMsgStatus->FilterIndex = ((hfdcan->Instance->HPMS & FDCAN_HPMS_FIDX) >> FDCAN_HPMS_FIDX_Pos);
3176 HpMsgStatus->MessageStorage = (hfdcan->Instance->HPMS & FDCAN_HPMS_MSI);
3177 HpMsgStatus->MessageIndex = (hfdcan->Instance->HPMS & FDCAN_HPMS_BIDX);
3179 /* Return function status */
3180 return HAL_OK;
3184 * @brief Get protocol status.
3185 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3186 * the configuration information for the specified FDCAN.
3187 * @param ProtocolStatus pointer to an FDCAN_ProtocolStatusTypeDef structure.
3188 * @retval HAL status
3190 HAL_StatusTypeDef HAL_FDCAN_GetProtocolStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_ProtocolStatusTypeDef *ProtocolStatus)
3192 uint32_t StatusReg;
3194 /* Read the protocol status register */
3195 StatusReg = READ_REG(hfdcan->Instance->PSR);
3197 /* Fill the protocol status structure */
3198 ProtocolStatus->LastErrorCode = (StatusReg & FDCAN_PSR_LEC);
3199 ProtocolStatus->DataLastErrorCode = ((StatusReg & FDCAN_PSR_DLEC) >> FDCAN_PSR_DLEC_Pos);
3200 ProtocolStatus->Activity = (StatusReg & FDCAN_PSR_ACT);
3201 ProtocolStatus->ErrorPassive = ((StatusReg & FDCAN_PSR_EP) >> FDCAN_PSR_EP_Pos);
3202 ProtocolStatus->Warning = ((StatusReg & FDCAN_PSR_EW) >> FDCAN_PSR_EW_Pos);
3203 ProtocolStatus->BusOff = ((StatusReg & FDCAN_PSR_BO) >> FDCAN_PSR_BO_Pos);
3204 ProtocolStatus->RxESIflag = ((StatusReg & FDCAN_PSR_RESI) >> FDCAN_PSR_RESI_Pos);
3205 ProtocolStatus->RxBRSflag = ((StatusReg & FDCAN_PSR_RBRS) >> FDCAN_PSR_RBRS_Pos);
3206 ProtocolStatus->RxFDFflag = ((StatusReg & FDCAN_PSR_REDL) >> FDCAN_PSR_REDL_Pos);
3207 ProtocolStatus->ProtocolException = ((StatusReg & FDCAN_PSR_PXE) >> FDCAN_PSR_PXE_Pos);
3208 ProtocolStatus->TDCvalue = ((StatusReg & FDCAN_PSR_TDCV) >> FDCAN_PSR_TDCV_Pos);
3210 /* Return function status */
3211 return HAL_OK;
3215 * @brief Get error counter values.
3216 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3217 * the configuration information for the specified FDCAN.
3218 * @param ErrorCounters pointer to an FDCAN_ErrorCountersTypeDef structure.
3219 * @retval HAL status
3221 HAL_StatusTypeDef HAL_FDCAN_GetErrorCounters(FDCAN_HandleTypeDef *hfdcan, FDCAN_ErrorCountersTypeDef *ErrorCounters)
3223 uint32_t CountersReg;
3225 /* Read the error counters register */
3226 CountersReg = READ_REG(hfdcan->Instance->ECR);
3228 /* Fill the error counters structure */
3229 ErrorCounters->TxErrorCnt = ((CountersReg & FDCAN_ECR_TEC) >> FDCAN_ECR_TEC_Pos);
3230 ErrorCounters->RxErrorCnt = ((CountersReg & FDCAN_ECR_REC) >> FDCAN_ECR_REC_Pos);
3231 ErrorCounters->RxErrorPassive = ((CountersReg & FDCAN_ECR_RP) >> FDCAN_ECR_RP_Pos);
3232 ErrorCounters->ErrorLogging = ((CountersReg & FDCAN_ECR_CEL) >> FDCAN_ECR_CEL_Pos);
3234 /* Return function status */
3235 return HAL_OK;
3239 * @brief Check if a new message is received in the selected Rx buffer.
3240 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3241 * the configuration information for the specified FDCAN.
3242 * @param RxBufferIndex Rx buffer index.
3243 * This parameter must be a number between 0 and 63.
3244 * @retval Status
3245 * - 0 : No new message on RxBufferIndex.
3246 * - 1 : New message received on RxBufferIndex.
3248 uint32_t HAL_FDCAN_IsRxBufferMessageAvailable(FDCAN_HandleTypeDef *hfdcan, uint32_t RxBufferIndex)
3250 /* Check function parameters */
3251 assert_param(IS_FDCAN_MAX_VALUE(RxBufferIndex, 63U));
3252 uint32_t NewData1 = hfdcan->Instance->NDAT1;
3253 uint32_t NewData2 = hfdcan->Instance->NDAT2;
3255 /* Check new message reception on the selected buffer */
3256 if (((RxBufferIndex < 32U) && ((NewData1 & (uint32_t)((uint32_t)1 << RxBufferIndex)) == 0U)) ||
3257 ((RxBufferIndex >= 32U) && ((NewData2 & (uint32_t)((uint32_t)1 << (RxBufferIndex & 0x1FU))) == 0U)))
3259 return 0;
3262 /* Clear the New Data flag of the current Rx buffer */
3263 if (RxBufferIndex < 32U)
3265 hfdcan->Instance->NDAT1 = ((uint32_t)1 << RxBufferIndex);
3267 else /* 32 <= RxBufferIndex <= 63 */
3269 hfdcan->Instance->NDAT2 = ((uint32_t)1 << (RxBufferIndex & 0x1FU));
3272 return 1;
3276 * @brief Check if a transmission request is pending on the selected Tx buffer.
3277 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3278 * the configuration information for the specified FDCAN.
3279 * @param TxBufferIndex Tx buffer index.
3280 * This parameter can be any combination of @arg FDCAN_Tx_location.
3281 * @retval Status
3282 * - 0 : No pending transmission request on TxBufferIndex.
3283 * - 1 : Pending transmission request on TxBufferIndex.
3285 uint32_t HAL_FDCAN_IsTxBufferMessagePending(FDCAN_HandleTypeDef *hfdcan, uint32_t TxBufferIndex)
3287 /* Check pending transmittion request on the selected buffer */
3288 if ((hfdcan->Instance->TXBRP & TxBufferIndex) == 0U)
3290 return 0;
3292 return 1;
3296 * @brief Return Rx FIFO fill level.
3297 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3298 * the configuration information for the specified FDCAN.
3299 * @param RxFifo Rx FIFO.
3300 * This parameter can be one of the following values:
3301 * @arg FDCAN_RX_FIFO0: Rx FIFO 0
3302 * @arg FDCAN_RX_FIFO1: Rx FIFO 1
3303 * @retval Level Rx FIFO fill level.
3305 uint32_t HAL_FDCAN_GetRxFifoFillLevel(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo)
3307 uint32_t FillLevel;
3309 /* Check function parameters */
3310 assert_param(IS_FDCAN_RX_FIFO(RxFifo));
3312 if (RxFifo == FDCAN_RX_FIFO0)
3314 FillLevel = hfdcan->Instance->RXF0S & FDCAN_RXF0S_F0FL;
3316 else /* RxFifo == FDCAN_RX_FIFO1 */
3318 FillLevel = hfdcan->Instance->RXF1S & FDCAN_RXF1S_F1FL;
3321 /* Return Rx FIFO fill level */
3322 return FillLevel;
3326 * @brief Return Tx FIFO free level: number of consecutive free Tx FIFO
3327 * elements starting from Tx FIFO GetIndex.
3328 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3329 * the configuration information for the specified FDCAN.
3330 * @retval Level Tx FIFO free level.
3332 uint32_t HAL_FDCAN_GetTxFifoFreeLevel(FDCAN_HandleTypeDef *hfdcan)
3334 uint32_t FreeLevel;
3336 FreeLevel = hfdcan->Instance->TXFQS & FDCAN_TXFQS_TFFL;
3338 /* Return Tx FIFO free level */
3339 return FreeLevel;
3343 * @brief Check if the FDCAN peripheral entered Restricted Operation Mode.
3344 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3345 * the configuration information for the specified FDCAN.
3346 * @retval Status
3347 * - 0 : Normal FDCAN operation.
3348 * - 1 : Restricted Operation Mode active.
3350 uint32_t HAL_FDCAN_IsRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
3352 uint32_t OperationMode;
3354 /* Get Operation Mode */
3355 OperationMode = ((hfdcan->Instance->CCCR & FDCAN_CCCR_ASM) >> FDCAN_CCCR_ASM_Pos);
3357 return OperationMode;
3361 * @brief Exit Restricted Operation Mode.
3362 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3363 * the configuration information for the specified FDCAN.
3364 * @retval HAL status
3366 HAL_StatusTypeDef HAL_FDCAN_ExitRestrictedOperationMode(FDCAN_HandleTypeDef *hfdcan)
3368 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3370 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3372 /* Exit Restricted Operation mode */
3373 CLEAR_BIT(hfdcan->Instance->CCCR, FDCAN_CCCR_ASM);
3375 /* Return function status */
3376 return HAL_OK;
3378 else
3380 /* Update error code */
3381 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3383 return HAL_ERROR;
3388 * @}
3391 /** @defgroup FDCAN_Exported_Functions_Group4 TT Configuration and control functions
3392 * @brief TT Configuration and control functions
3394 @verbatim
3395 ==============================================================================
3396 ##### TT Configuration and control functions #####
3397 ==============================================================================
3398 [..] This section provides functions allowing to:
3399 (+) HAL_FDCAN_TT_ConfigOperation : Initialize TT operation parameters
3400 (+) HAL_FDCAN_TT_ConfigReferenceMessage : Configure the reference message
3401 (+) HAL_FDCAN_TT_ConfigTrigger : Configure the FDCAN trigger
3402 (+) HAL_FDCAN_TT_SetGlobalTime : Schedule global time adjustment
3403 (+) HAL_FDCAN_TT_SetClockSynchronization : Schedule TUR numerator update
3404 (+) HAL_FDCAN_TT_ConfigStopWatch : Configure stop watch source and polarity
3405 (+) HAL_FDCAN_TT_ConfigRegisterTimeMark : Configure register time mark pulse generation
3406 (+) HAL_FDCAN_TT_EnableRegisterTimeMarkPulse : Enable register time mark pulse generation
3407 (+) HAL_FDCAN_TT_DisableRegisterTimeMarkPulse : Disable register time mark pulse generation
3408 (+) HAL_FDCAN_TT_EnableTriggerTimeMarkPulse : Enable trigger time mark pulse generation
3409 (+) HAL_FDCAN_TT_DisableTriggerTimeMarkPulse : Disable trigger time mark pulse generation
3410 (+) HAL_FDCAN_TT_EnableHardwareGapControl : Enable gap control by input pin fdcan1_evt
3411 (+) HAL_FDCAN_TT_DisableHardwareGapControl : Disable gap control by input pin fdcan1_evt
3412 (+) HAL_FDCAN_TT_EnableTimeMarkGapControl : Enable gap control (finish only) by register time mark interrupt
3413 (+) HAL_FDCAN_TT_DisableTimeMarkGapControl : Disable gap control by register time mark interrupt
3414 (+) HAL_FDCAN_TT_SetNextIsGap : Transmit next reference message with Next_is_Gap = "1"
3415 (+) HAL_FDCAN_TT_SetEndOfGap : Finish a Gap by requesting start of reference message
3416 (+) HAL_FDCAN_TT_ConfigExternalSyncPhase : Configure target phase used for external synchronization
3417 (+) HAL_FDCAN_TT_EnableExternalSynchronization : Synchronize the phase of the FDCAN schedule to an external schedule
3418 (+) HAL_FDCAN_TT_DisableExternalSynchronization : Disable external schedule synchronization
3419 (+) HAL_FDCAN_TT_GetOperationStatus : Get TT operation status
3421 @endverbatim
3422 * @{
3426 * @brief Initialize TT operation parameters.
3427 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3428 * the configuration information for the specified FDCAN.
3429 * @param pTTParams pointer to a FDCAN_TT_ConfigTypeDef structure.
3430 * @retval HAL status
3432 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigOperation(FDCAN_HandleTypeDef *hfdcan, FDCAN_TT_ConfigTypeDef *pTTParams)
3434 uint32_t tickstart;
3435 uint32_t RAMcounter;
3436 uint32_t StartAddress;
3438 /* Check function parameters */
3439 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3440 assert_param(IS_FDCAN_TT_TUR_NUMERATOR(pTTParams->TURNumerator));
3441 assert_param(IS_FDCAN_TT_TUR_DENOMINATOR(pTTParams->TURDenominator));
3442 assert_param(IS_FDCAN_TT_TIME_MASTER(pTTParams->TimeMaster));
3443 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->SyncDevLimit, 7U));
3444 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->InitRefTrigOffset, 127U));
3445 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->TriggerMemoryNbr, 64U));
3446 assert_param(IS_FDCAN_TT_CYCLE_START_SYNC(pTTParams->CycleStartSync));
3447 assert_param(IS_FDCAN_TT_STOP_WATCH_TRIGGER(pTTParams->StopWatchTrigSel));
3448 assert_param(IS_FDCAN_TT_EVENT_TRIGGER(pTTParams->EventTrigSel));
3449 if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
3451 assert_param(IS_FDCAN_TT_BASIC_CYCLES_NUMBER(pTTParams->BasicCyclesNbr));
3453 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3455 assert_param(IS_FDCAN_TT_OPERATION(pTTParams->GapEnable));
3456 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->AppWdgLimit, 255U));
3457 assert_param(IS_FDCAN_TT_EVENT_TRIGGER_POLARITY(pTTParams->EvtTrigPolarity));
3458 assert_param(IS_FDCAN_TT_TX_ENABLE_WINDOW(pTTParams->TxEnableWindow));
3459 assert_param(IS_FDCAN_MAX_VALUE(pTTParams->ExpTxTrigNbr, 4095U));
3461 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
3463 assert_param(IS_FDCAN_TT_TUR_LEVEL_0_2(pTTParams->TURNumerator, pTTParams->TURDenominator));
3464 assert_param(IS_FDCAN_TT_EXTERNAL_CLK_SYNC(pTTParams->ExternalClkSync));
3465 assert_param(IS_FDCAN_TT_GLOBAL_TIME_FILTERING(pTTParams->GlobalTimeFilter));
3466 assert_param(IS_FDCAN_TT_AUTO_CLK_CALIBRATION(pTTParams->ClockCalibration));
3468 else
3470 assert_param(IS_FDCAN_TT_TUR_LEVEL_1(pTTParams->TURNumerator, pTTParams->TURDenominator));
3473 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3475 /* Stop local time in order to enable write access to the other bits of TURCF register */
3476 CLEAR_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
3478 /* Get tick */
3479 tickstart = HAL_GetTick();
3481 /* Wait until the ELT bit into TURCF register is reset */
3482 while ((hfdcan->ttcan->TURCF & FDCAN_TURCF_ELT) != 0U)
3484 /* Check for the Timeout */
3485 if ((HAL_GetTick() - tickstart) > FDCAN_TIMEOUT_VALUE)
3487 /* Update error code */
3488 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3490 /* Change FDCAN state */
3491 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3493 return HAL_ERROR;
3497 /* Configure TUR (Time Unit Ratio) */
3498 MODIFY_REG(hfdcan->ttcan->TURCF,
3499 (FDCAN_TURCF_NCL | FDCAN_TURCF_DC),
3500 (((pTTParams->TURNumerator - 0x10000U) << FDCAN_TURCF_NCL_Pos) | (pTTParams->TURDenominator << FDCAN_TURCF_DC_Pos)));
3502 /* Enable local time */
3503 SET_BIT(hfdcan->ttcan->TURCF, FDCAN_TURCF_ELT);
3505 /* Configure TT operation */
3506 MODIFY_REG(hfdcan->ttcan->TTOCF,
3507 (FDCAN_TTOCF_OM | FDCAN_TTOCF_TM | FDCAN_TTOCF_LDSDL | FDCAN_TTOCF_IRTO),
3508 (pTTParams->OperationMode | \
3509 pTTParams->TimeMaster | \
3510 (pTTParams->SyncDevLimit << FDCAN_TTOCF_LDSDL_Pos) | \
3511 (pTTParams->InitRefTrigOffset << FDCAN_TTOCF_IRTO_Pos)));
3512 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3514 MODIFY_REG(hfdcan->ttcan->TTOCF,
3515 (FDCAN_TTOCF_GEN | FDCAN_TTOCF_AWL | FDCAN_TTOCF_EVTP),
3516 (pTTParams->GapEnable | \
3517 (pTTParams->AppWdgLimit << FDCAN_TTOCF_AWL_Pos) | \
3518 pTTParams->EvtTrigPolarity));
3520 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL1)
3522 MODIFY_REG(hfdcan->ttcan->TTOCF,
3523 (FDCAN_TTOCF_EECS | FDCAN_TTOCF_EGTF | FDCAN_TTOCF_ECC),
3524 (pTTParams->ExternalClkSync | \
3525 pTTParams->GlobalTimeFilter | \
3526 pTTParams->ClockCalibration));
3529 /* Configure system matrix limits */
3530 MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CSS, pTTParams->CycleStartSync);
3531 if (pTTParams->OperationMode != FDCAN_TT_COMMUNICATION_LEVEL0)
3533 MODIFY_REG(hfdcan->ttcan->TTMLM,
3534 (FDCAN_TTMLM_TXEW | FDCAN_TTMLM_ENTT),
3535 (((pTTParams->TxEnableWindow - 1U) << FDCAN_TTMLM_TXEW_Pos) | (pTTParams->ExpTxTrigNbr << FDCAN_TTMLM_ENTT_Pos)));
3537 if (pTTParams->TimeMaster == FDCAN_TT_POTENTIAL_MASTER)
3539 MODIFY_REG(hfdcan->ttcan->TTMLM, FDCAN_TTMLM_CCM, pTTParams->BasicCyclesNbr);
3542 /* Configure input triggers: Stop watch and Event */
3543 MODIFY_REG(hfdcan->ttcan->TTTS,
3544 (FDCAN_TTTS_SWTSEL | FDCAN_TTTS_EVTSEL),
3545 (pTTParams->StopWatchTrigSel | pTTParams->EventTrigSel));
3547 /* Configure trigger memory start address */
3548 StartAddress = (hfdcan->msgRam.EndAddress - SRAMCAN_BASE) / 4U;
3549 MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TMSA, (StartAddress << FDCAN_TTTMC_TMSA_Pos));
3551 /* Trigger memory elements number */
3552 MODIFY_REG(hfdcan->ttcan->TTTMC, FDCAN_TTTMC_TME, (pTTParams->TriggerMemoryNbr << FDCAN_TTTMC_TME_Pos));
3554 /* Recalculate End Address */
3555 hfdcan->msgRam.TTMemorySA = hfdcan->msgRam.EndAddress;
3556 hfdcan->msgRam.EndAddress = hfdcan->msgRam.TTMemorySA + (pTTParams->TriggerMemoryNbr * 2U * 4U);
3558 if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
3560 /* Update error code.
3561 Message RAM overflow */
3562 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
3564 return HAL_ERROR;
3566 else
3568 /* Flush the allocated Message RAM area */
3569 for (RAMcounter = hfdcan->msgRam.TTMemorySA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
3571 *(uint32_t *)(RAMcounter) = 0x00000000;
3575 /* Return function status */
3576 return HAL_OK;
3578 else
3580 /* Update error code */
3581 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3583 return HAL_ERROR;
3588 * @brief Configure the reference message.
3589 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3590 * the configuration information for the specified FDCAN.
3591 * @param IdType Identifier Type.
3592 * This parameter can be a value of @arg FDCAN_id_type.
3593 * @param Identifier Reference Identifier.
3594 * This parameter must be a number between:
3595 * - 0 and 0x7FF, if IdType is FDCAN_STANDARD_ID
3596 * - 0 and 0x1FFFFFFF, if IdType is FDCAN_EXTENDED_ID
3597 * @param Payload Enable or disable the additional payload.
3598 * This parameter can be a value of @arg FDCAN_TT_Reference_Message_Payload.
3599 * This parameter is ignored in case of time slaves.
3600 * If this parameter is set to FDCAN_TT_REF_MESSAGE_ADD_PAYLOAD, the
3601 * following elements are taken from Tx Buffer 0:
3602 * - MessageMarker
3603 * - TxEventFifoControl
3604 * - DataLength
3605 * - Data Bytes (payload):
3606 * - bytes 2-8, for Level 1
3607 * - bytes 5-8, for Level 0 and Level 2
3608 * @retval HAL status
3610 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigReferenceMessage(FDCAN_HandleTypeDef *hfdcan, uint32_t IdType, uint32_t Identifier, uint32_t Payload)
3612 /* Check function parameters */
3613 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3614 assert_param(IS_FDCAN_ID_TYPE(IdType));
3615 if (IdType == FDCAN_STANDARD_ID)
3617 assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x7FFU));
3619 else /* IdType == FDCAN_EXTENDED_ID */
3621 assert_param(IS_FDCAN_MAX_VALUE(Identifier, 0x1FFFFFFFU));
3623 assert_param(IS_FDCAN_TT_REFERENCE_MESSAGE_PAYLOAD(Payload));
3625 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3627 /* Configure reference message identifier type, identifier and payload */
3628 if (IdType == FDCAN_EXTENDED_ID)
3630 MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | Identifier));
3632 else /* IdType == FDCAN_STANDARD_ID */
3634 MODIFY_REG(hfdcan->ttcan->TTRMC, (FDCAN_TTRMC_RID | FDCAN_TTRMC_XTD | FDCAN_TTRMC_RMPS), (Payload | IdType | (Identifier << 18)));
3637 /* Return function status */
3638 return HAL_OK;
3640 else
3642 /* Update error code */
3643 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3645 return HAL_ERROR;
3650 * @brief Configure the FDCAN trigger according to the specified
3651 * parameters in the FDCAN_TriggerTypeDef structure.
3652 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3653 * the configuration information for the specified FDCAN.
3654 * @param sTriggerConfig pointer to an FDCAN_TriggerTypeDef structure that
3655 * contains the trigger configuration information
3656 * @retval HAL status
3658 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigTrigger(FDCAN_HandleTypeDef *hfdcan, FDCAN_TriggerTypeDef *sTriggerConfig)
3660 uint32_t CycleCode;
3661 uint32_t MessageNumber;
3662 uint32_t TriggerElementW1;
3663 uint32_t TriggerElementW2;
3664 uint32_t *TriggerAddress;
3666 /* Check function parameters */
3667 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3668 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TriggerIndex, 63U));
3669 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->TimeMark, 0xFFFFU));
3670 assert_param(IS_FDCAN_TT_REPEAT_FACTOR(sTriggerConfig->RepeatFactor));
3671 if (sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
3673 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->StartCycle, (sTriggerConfig->RepeatFactor - 1U)));
3675 assert_param(IS_FDCAN_TT_TM_EVENT_INTERNAL(sTriggerConfig->TmEventInt));
3676 assert_param(IS_FDCAN_TT_TM_EVENT_EXTERNAL(sTriggerConfig->TmEventExt));
3677 assert_param(IS_FDCAN_TT_TRIGGER_TYPE(sTriggerConfig->TriggerType));
3678 assert_param(IS_FDCAN_ID_TYPE(sTriggerConfig->FilterType));
3679 if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
3680 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
3681 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
3682 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
3684 assert_param(IS_FDCAN_TX_LOCATION(sTriggerConfig->TxBufferIndex));
3686 if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
3688 if (sTriggerConfig->FilterType == FDCAN_STANDARD_ID)
3690 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 63U));
3692 else /* sTriggerConfig->FilterType == FDCAN_EXTENDED_ID */
3694 assert_param(IS_FDCAN_MAX_VALUE(sTriggerConfig->FilterIndex, 127U));
3698 if (hfdcan->State == HAL_FDCAN_STATE_READY)
3700 /* Calculate cycle code */
3701 if (sTriggerConfig->RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
3703 CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
3705 else /* sTriggerConfig->RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
3707 CycleCode = sTriggerConfig->RepeatFactor + sTriggerConfig->StartCycle;
3710 /* Build first word of trigger element */
3711 TriggerElementW1 = ((sTriggerConfig->TimeMark << 16) | \
3712 (CycleCode << 8) | \
3713 sTriggerConfig->TmEventInt | \
3714 sTriggerConfig->TmEventExt | \
3715 sTriggerConfig->TriggerType);
3717 /* Select message number depending on trigger type (transmission or reception) */
3718 if (sTriggerConfig->TriggerType == FDCAN_TT_RX_TRIGGER)
3720 MessageNumber = sTriggerConfig->FilterIndex;
3722 else if ((sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_SINGLE) ||
3723 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_CONTINUOUS) ||
3724 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_ARBITRATION) ||
3725 (sTriggerConfig->TriggerType == FDCAN_TT_TX_TRIGGER_MERGED))
3727 MessageNumber = POSITION_VAL(sTriggerConfig->TxBufferIndex);
3729 else
3731 MessageNumber = 0U;
3734 /* Build second word of trigger element */
3735 TriggerElementW2 = ((sTriggerConfig->FilterType >> 7) | (MessageNumber << 16));
3737 /* Calculate trigger address */
3738 TriggerAddress = (uint32_t *)(hfdcan->msgRam.TTMemorySA + (sTriggerConfig->TriggerIndex * 4U * 2U));
3740 /* Write trigger element to the message RAM */
3741 *TriggerAddress = TriggerElementW1;
3742 TriggerAddress++;
3743 *TriggerAddress = TriggerElementW2;
3745 /* Return function status */
3746 return HAL_OK;
3748 else
3750 /* Update error code */
3751 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_READY;
3753 return HAL_ERROR;
3758 * @brief Schedule global time adjustment for the next reference message.
3759 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3760 * the configuration information for the specified FDCAN.
3761 * @param TimePreset time preset value.
3762 * This parameter must be a number between:
3763 * - 0x0000 and 0x7FFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark + TimePreset
3764 * or
3765 * - 0x8001 and 0xFFFF, Next_Master_Ref_Mark = Current_Master_Ref_Mark - (0x10000 - TimePreset)
3766 * @retval HAL status
3768 HAL_StatusTypeDef HAL_FDCAN_TT_SetGlobalTime(FDCAN_HandleTypeDef *hfdcan, uint32_t TimePreset)
3770 uint32_t Counter = 0U;
3771 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3773 /* Check function parameters */
3774 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3775 assert_param(IS_FDCAN_TT_TIME_PRESET(TimePreset));
3777 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3779 /* Check that the external clock synchronization is enabled */
3780 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
3782 /* Update error code */
3783 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
3785 return HAL_ERROR;
3788 /* Check that no global time preset is pending */
3789 if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WGTD) == FDCAN_TTOST_WGTD)
3791 /* Update error code */
3792 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
3794 return HAL_ERROR;
3797 /* Configure time preset */
3798 MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_TP, (TimePreset << FDCAN_TTGTP_TP_Pos));
3800 /* Wait until the LCKC bit into TTOCN register is reset */
3801 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3803 /* Check for the Timeout */
3804 if (Counter > FDCAN_TIMEOUT_VALUE)
3806 /* Update error code */
3807 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3809 /* Change FDCAN state */
3810 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3812 return HAL_ERROR;
3815 /* Increment counter */
3816 Counter++;
3819 /* Schedule time preset to take effect by the next reference message */
3820 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_SGT);
3822 /* Return function status */
3823 return HAL_OK;
3825 else
3827 /* Update error code */
3828 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3830 return HAL_ERROR;
3835 * @brief Schedule TUR numerator update for the next reference message.
3836 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3837 * the configuration information for the specified FDCAN.
3838 * @param NewTURNumerator new value of the TUR numerator.
3839 * This parameter must be a number between 0x10000 and 0x1FFFF.
3840 * @retval HAL status
3842 HAL_StatusTypeDef HAL_FDCAN_TT_SetClockSynchronization(FDCAN_HandleTypeDef *hfdcan, uint32_t NewTURNumerator)
3844 uint32_t Counter = 0U;
3845 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3847 /* Check function parameters */
3848 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3849 assert_param(IS_FDCAN_TT_TUR_NUMERATOR(NewTURNumerator));
3851 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3853 /* Check that the external clock synchronization is enabled */
3854 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_EECS) != FDCAN_TTOCF_EECS)
3856 /* Update error code */
3857 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
3859 return HAL_ERROR;
3862 /* Check that no external clock synchronization is pending */
3863 if ((hfdcan->ttcan->TTOST & FDCAN_TTOST_WECS) == FDCAN_TTOST_WECS)
3865 /* Update error code */
3866 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
3868 return HAL_ERROR;
3871 /* Configure new TUR numerator */
3872 MODIFY_REG(hfdcan->ttcan->TURCF, FDCAN_TURCF_NCL, (NewTURNumerator - 0x10000U));
3874 /* Wait until the LCKC bit into TTOCN register is reset */
3875 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3877 /* Check for the Timeout */
3878 if (Counter > FDCAN_TIMEOUT_VALUE)
3880 /* Update error code */
3881 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3883 /* Change FDCAN state */
3884 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3886 return HAL_ERROR;
3889 /* Increment counter */
3890 Counter++;
3893 /* Schedule TUR numerator update by the next reference message */
3894 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ECS);
3896 /* Return function status */
3897 return HAL_OK;
3899 else
3901 /* Update error code */
3902 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3904 return HAL_ERROR;
3909 * @brief Configure stop watch source and polarity.
3910 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3911 * the configuration information for the specified FDCAN.
3912 * @param Source stop watch source.
3913 * This parameter can be a value of @arg FDCAN_TT_stop_watch_source.
3914 * @param Polarity stop watch polarity.
3915 * This parameter can be a value of @arg FDCAN_TT_stop_watch_polarity.
3916 * @retval HAL status
3918 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigStopWatch(FDCAN_HandleTypeDef *hfdcan, uint32_t Source, uint32_t Polarity)
3920 uint32_t Counter = 0U;
3921 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3923 /* Check function parameters */
3924 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3925 assert_param(IS_FDCAN_TT_STOP_WATCH_SOURCE(Source));
3926 assert_param(IS_FDCAN_TT_STOP_WATCH_POLARITY(Polarity));
3928 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3930 /* Wait until the LCKC bit into TTOCN register is reset */
3931 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
3933 /* Check for the Timeout */
3934 if (Counter > FDCAN_TIMEOUT_VALUE)
3936 /* Update error code */
3937 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
3939 /* Change FDCAN state */
3940 hfdcan->State = HAL_FDCAN_STATE_ERROR;
3942 return HAL_ERROR;
3945 /* Increment counter */
3946 Counter++;
3949 /* Select stop watch source and polarity */
3950 MODIFY_REG(hfdcan->ttcan->TTOCN, (FDCAN_TTOCN_SWS | FDCAN_TTOCN_SWP), (Source | Polarity));
3952 /* Return function status */
3953 return HAL_OK;
3955 else
3957 /* Update error code */
3958 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
3960 return HAL_ERROR;
3965 * @brief Configure register time mark pulse generation.
3966 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
3967 * the configuration information for the specified FDCAN.
3968 * @param TimeMarkSource time mark source.
3969 * This parameter can be a value of @arg FDCAN_TT_time_mark_source.
3970 * @param TimeMarkValue time mark value (reference).
3971 * This parameter must be a number between 0 and 0xFFFF.
3972 * @param RepeatFactor repeat factor of the cycle for which the time mark is valid.
3973 * This parameter can be a value of @arg FDCAN_TT_Repeat_Factor.
3974 * @param StartCycle index of the first cycle in which the time mark becomes valid.
3975 * This parameter is ignored if RepeatFactor is set to FDCAN_TT_REPEAT_EVERY_CYCLE.
3976 * This parameter must be a number between 0 and RepeatFactor.
3977 * @retval HAL status
3979 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigRegisterTimeMark(FDCAN_HandleTypeDef *hfdcan,
3980 uint32_t TimeMarkSource, uint32_t TimeMarkValue,
3981 uint32_t RepeatFactor, uint32_t StartCycle)
3983 uint32_t Counter = 0U;
3984 uint32_t CycleCode;
3985 HAL_FDCAN_StateTypeDef state = hfdcan->State;
3987 /* Check function parameters */
3988 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
3989 assert_param(IS_FDCAN_TT_REGISTER_TIME_MARK_SOURCE(TimeMarkSource));
3990 assert_param(IS_FDCAN_MAX_VALUE(TimeMarkValue, 0xFFFFU));
3991 assert_param(IS_FDCAN_TT_REPEAT_FACTOR(RepeatFactor));
3992 if (RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE)
3994 assert_param(IS_FDCAN_MAX_VALUE(StartCycle, (RepeatFactor - 1U)));
3997 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
3999 /* Wait until the LCKC bit into TTOCN register is reset */
4000 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4002 /* Check for the Timeout */
4003 if (Counter > FDCAN_TIMEOUT_VALUE)
4005 /* Update error code */
4006 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4008 /* Change FDCAN state */
4009 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4011 return HAL_ERROR;
4014 /* Increment counter */
4015 Counter++;
4018 /* Disable the time mark compare function */
4019 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC);
4021 if (TimeMarkSource != FDCAN_TT_REG_TIMEMARK_DIABLED)
4023 /* Calculate cycle code */
4024 if (RepeatFactor == FDCAN_TT_REPEAT_EVERY_CYCLE)
4026 CycleCode = FDCAN_TT_REPEAT_EVERY_CYCLE;
4028 else /* RepeatFactor != FDCAN_TT_REPEAT_EVERY_CYCLE */
4030 CycleCode = RepeatFactor + StartCycle;
4033 Counter = 0U;
4035 /* Wait until the LCKM bit into TTTMK register is reset */
4036 while ((hfdcan->ttcan->TTTMK & FDCAN_TTTMK_LCKM) != 0U)
4038 /* Check for the Timeout */
4039 if (Counter > FDCAN_TIMEOUT_VALUE)
4041 /* Update error code */
4042 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4044 /* Change FDCAN state */
4045 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4047 return HAL_ERROR;
4050 /* Increment counter */
4051 Counter++;
4054 /* Configure time mark value and cycle code */
4055 hfdcan->ttcan->TTTMK = ((TimeMarkValue << FDCAN_TTTMK_TM_Pos) | (CycleCode << FDCAN_TTTMK_TICC_Pos));
4057 Counter = 0U;
4059 /* Wait until the LCKC bit into TTOCN register is reset */
4060 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4062 /* Check for the Timeout */
4063 if (Counter > FDCAN_TIMEOUT_VALUE)
4065 /* Update error code */
4066 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4068 /* Change FDCAN state */
4069 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4071 return HAL_ERROR;
4074 /* Increment counter */
4075 Counter++;
4078 /* Update the register time mark compare source */
4079 MODIFY_REG(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMC, TimeMarkSource);
4082 /* Return function status */
4083 return HAL_OK;
4085 else
4087 /* Update error code */
4088 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4090 return HAL_ERROR;
4095 * @brief Enable register time mark pulse generation.
4096 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4097 * the configuration information for the specified FDCAN.
4098 * @retval HAL status
4100 HAL_StatusTypeDef HAL_FDCAN_TT_EnableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4102 uint32_t Counter = 0U;
4103 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4105 /* Check function parameters */
4106 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4108 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4110 /* Wait until the LCKC bit into TTOCN register is reset */
4111 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4113 /* Check for the Timeout */
4114 if (Counter > FDCAN_TIMEOUT_VALUE)
4116 /* Update error code */
4117 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4119 /* Change FDCAN state */
4120 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4122 return HAL_ERROR;
4125 /* Increment counter */
4126 Counter++;
4129 /* Enable Register Time Mark Interrupt output on fdcan1_rtp */
4130 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
4132 /* Return function status */
4133 return HAL_OK;
4135 else
4137 /* Update error code */
4138 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4140 return HAL_ERROR;
4145 * @brief Disable register time mark pulse generation.
4146 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4147 * the configuration information for the specified FDCAN.
4148 * @retval HAL status
4150 HAL_StatusTypeDef HAL_FDCAN_TT_DisableRegisterTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4152 uint32_t Counter = 0U;
4153 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4155 /* Check function parameters */
4156 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4158 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4160 /* Wait until the LCKC bit into TTOCN register is reset */
4161 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4163 /* Check for the Timeout */
4164 if (Counter > FDCAN_TIMEOUT_VALUE)
4166 /* Update error code */
4167 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4169 /* Change FDCAN state */
4170 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4172 return HAL_ERROR;
4175 /* Increment counter */
4176 Counter++;
4179 /* Disable Register Time Mark Interrupt output on fdcan1_rtp */
4180 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_RTIE);
4182 /* Return function status */
4183 return HAL_OK;
4185 else
4187 /* Update error code */
4188 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4190 return HAL_ERROR;
4195 * @brief Enable trigger time mark pulse generation.
4196 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4197 * the configuration information for the specified FDCAN.
4198 * @retval HAL status
4200 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4202 uint32_t Counter = 0U;
4203 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4205 /* Check function parameters */
4206 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4208 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4210 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4212 /* Wait until the LCKC bit into TTOCN register is reset */
4213 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4215 /* Check for the Timeout */
4216 if (Counter > FDCAN_TIMEOUT_VALUE)
4218 /* Update error code */
4219 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4221 /* Change FDCAN state */
4222 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4224 return HAL_ERROR;
4227 /* Increment counter */
4228 Counter++;
4231 /* Enable Trigger Time Mark Interrupt output on fdcan1_tmp */
4232 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
4234 /* Return function status */
4235 return HAL_OK;
4237 else
4239 /* Update error code.
4240 Feature not supported for TT Level 0 */
4241 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4243 return HAL_ERROR;
4246 else
4248 /* Update error code */
4249 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4251 return HAL_ERROR;
4256 * @brief Disable trigger time mark pulse generation.
4257 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4258 * the configuration information for the specified FDCAN.
4259 * @retval HAL status
4261 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTriggerTimeMarkPulse(FDCAN_HandleTypeDef *hfdcan)
4263 uint32_t Counter = 0U;
4264 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4266 /* Check function parameters */
4267 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4269 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4271 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4273 /* Wait until the LCKC bit into TTOCN register is reset */
4274 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4276 /* Check for the Timeout */
4277 if (Counter > FDCAN_TIMEOUT_VALUE)
4279 /* Update error code */
4280 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4282 /* Change FDCAN state */
4283 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4285 return HAL_ERROR;
4288 /* Increment counter */
4289 Counter++;
4292 /* Disable Trigger Time Mark Interrupt output on fdcan1_rtp */
4293 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TTIE);
4295 /* Return function status */
4296 return HAL_OK;
4298 else
4300 /* Update error code.
4301 Feature not supported for TT Level 0 */
4302 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4304 return HAL_ERROR;
4307 else
4309 /* Update error code */
4310 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4312 return HAL_ERROR;
4317 * @brief Enable gap control by input pin fdcan1_evt.
4318 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4319 * the configuration information for the specified FDCAN.
4320 * @retval HAL status
4322 HAL_StatusTypeDef HAL_FDCAN_TT_EnableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
4324 uint32_t Counter = 0U;
4325 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4327 /* Check function parameters */
4328 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4330 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4332 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4334 /* Wait until the LCKC bit into TTOCN register is reset */
4335 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4337 /* Check for the Timeout */
4338 if (Counter > FDCAN_TIMEOUT_VALUE)
4340 /* Update error code */
4341 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4343 /* Change FDCAN state */
4344 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4346 return HAL_ERROR;
4349 /* Increment counter */
4350 Counter++;
4353 /* Enable gap control by pin fdcan1_evt */
4354 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
4356 /* Return function status */
4357 return HAL_OK;
4359 else
4361 /* Update error code.
4362 Feature not supported for TT Level 0 */
4363 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4365 return HAL_ERROR;
4368 else
4370 /* Update error code */
4371 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4373 return HAL_ERROR;
4378 * @brief Disable gap control by input pin fdcan1_evt.
4379 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4380 * the configuration information for the specified FDCAN.
4381 * @retval HAL status
4383 HAL_StatusTypeDef HAL_FDCAN_TT_DisableHardwareGapControl(FDCAN_HandleTypeDef *hfdcan)
4385 uint32_t Counter = 0U;
4386 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4388 /* Check function parameters */
4389 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4391 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4393 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4395 /* Wait until the LCKC bit into TTOCN register is reset */
4396 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4398 /* Check for the Timeout */
4399 if (Counter > FDCAN_TIMEOUT_VALUE)
4401 /* Update error code */
4402 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4404 /* Change FDCAN state */
4405 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4407 return HAL_ERROR;
4410 /* Increment counter */
4411 Counter++;
4414 /* Disable gap control by pin fdcan1_evt */
4415 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_GCS);
4417 /* Return function status */
4418 return HAL_OK;
4420 else
4422 /* Update error code.
4423 Feature not supported for TT Level 0 */
4424 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4426 return HAL_ERROR;
4429 else
4431 /* Update error code */
4432 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4434 return HAL_ERROR;
4439 * @brief Enable gap control (finish only) by register time mark interrupt.
4440 * The next register time mark interrupt (TTIR.RTMI = "1") will finish
4441 * the Gap and start the reference message.
4442 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4443 * the configuration information for the specified FDCAN.
4444 * @retval HAL status
4446 HAL_StatusTypeDef HAL_FDCAN_TT_EnableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
4448 uint32_t Counter = 0U;
4449 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4451 /* Check function parameters */
4452 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4454 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4456 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4458 /* Wait until the LCKC bit into TTOCN register is reset */
4459 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4461 /* Check for the Timeout */
4462 if (Counter > FDCAN_TIMEOUT_VALUE)
4464 /* Update error code */
4465 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4467 /* Change FDCAN state */
4468 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4470 return HAL_ERROR;
4473 /* Increment counter */
4474 Counter++;
4477 /* Enable gap control by register time mark interrupt */
4478 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
4480 /* Return function status */
4481 return HAL_OK;
4483 else
4485 /* Update error code.
4486 Feature not supported for TT Level 0 */
4487 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4489 return HAL_ERROR;
4492 else
4494 /* Update error code */
4495 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4497 return HAL_ERROR;
4502 * @brief Disable gap control by register time mark interrupt.
4503 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4504 * the configuration information for the specified FDCAN.
4505 * @retval HAL status
4507 HAL_StatusTypeDef HAL_FDCAN_TT_DisableTimeMarkGapControl(FDCAN_HandleTypeDef *hfdcan)
4509 uint32_t Counter = 0U;
4510 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4512 /* Check function parameters */
4513 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4515 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4517 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4519 /* Wait until the LCKC bit into TTOCN register is reset */
4520 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4522 /* Check for the Timeout */
4523 if (Counter > FDCAN_TIMEOUT_VALUE)
4525 /* Update error code */
4526 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4528 /* Change FDCAN state */
4529 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4531 return HAL_ERROR;
4534 /* Increment counter */
4535 Counter++;
4538 /* Disable gap control by register time mark interrupt */
4539 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_TMG);
4541 /* Return function status */
4542 return HAL_OK;
4544 else
4546 /* Update error code.
4547 Feature not supported for TT Level 0 */
4548 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4550 return HAL_ERROR;
4553 else
4555 /* Update error code */
4556 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4558 return HAL_ERROR;
4563 * @brief Transmit next reference message with Next_is_Gap = "1".
4564 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4565 * the configuration information for the specified FDCAN.
4566 * @retval HAL status
4568 HAL_StatusTypeDef HAL_FDCAN_TT_SetNextIsGap(FDCAN_HandleTypeDef *hfdcan)
4570 uint32_t Counter = 0U;
4571 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4573 /* Check function parameters */
4574 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4576 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4578 /* Check that the node is configured for external event-synchronized TT operation */
4579 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
4581 /* Update error code */
4582 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4584 return HAL_ERROR;
4587 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4589 /* Wait until the LCKC bit into TTOCN register is reset */
4590 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4592 /* Check for the Timeout */
4593 if (Counter > FDCAN_TIMEOUT_VALUE)
4595 /* Update error code */
4596 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4598 /* Change FDCAN state */
4599 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4601 return HAL_ERROR;
4604 /* Increment counter */
4605 Counter++;
4608 /* Set Next is Gap */
4609 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_NIG);
4611 /* Return function status */
4612 return HAL_OK;
4614 else
4616 /* Update error code.
4617 Feature not supported for TT Level 0 */
4618 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4620 return HAL_ERROR;
4623 else
4625 /* Update error code */
4626 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4628 return HAL_ERROR;
4633 * @brief Finish a Gap by requesting start of reference message.
4634 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4635 * the configuration information for the specified FDCAN.
4636 * @retval HAL status
4638 HAL_StatusTypeDef HAL_FDCAN_TT_SetEndOfGap(FDCAN_HandleTypeDef *hfdcan)
4640 uint32_t Counter = 0U;
4641 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4643 /* Check function parameters */
4644 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4646 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4648 /* Check that the node is configured for external event-synchronized TT operation */
4649 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_GEN) != FDCAN_TTOCF_GEN)
4651 /* Update error code */
4652 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4654 return HAL_ERROR;
4657 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != FDCAN_TT_COMMUNICATION_LEVEL0)
4659 /* Wait until the LCKC bit into TTOCN register is reset */
4660 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4662 /* Check for the Timeout */
4663 if (Counter > FDCAN_TIMEOUT_VALUE)
4665 /* Update error code */
4666 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4668 /* Change FDCAN state */
4669 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4671 return HAL_ERROR;
4674 /* Increment counter */
4675 Counter++;
4678 /* Set Finish Gap */
4679 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_FGP);
4681 /* Return function status */
4682 return HAL_OK;
4684 else
4686 /* Update error code.
4687 Feature not supported for TT Level 0 */
4688 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_SUPPORTED;
4690 return HAL_ERROR;
4693 else
4695 /* Update error code */
4696 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4698 return HAL_ERROR;
4703 * @brief Configure target phase used for external synchronization by event
4704 * trigger input pin fdcan1_evt.
4705 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4706 * the configuration information for the specified FDCAN.
4707 * @param TargetPhase defines target value of cycle time when a rising edge
4708 * of fdcan1_evt is expected.
4709 * This parameter must be a number between 0 and 0xFFFF.
4710 * @retval HAL status
4712 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigExternalSyncPhase(FDCAN_HandleTypeDef *hfdcan, uint32_t TargetPhase)
4714 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4716 /* Check function parameters */
4717 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4718 assert_param(IS_FDCAN_MAX_VALUE(TargetPhase, 0xFFFFU));
4720 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4722 /* Check that no external schedule synchronization is pending */
4723 if ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_ESCN) == FDCAN_TTOCN_ESCN)
4725 /* Update error code */
4726 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PENDING;
4728 return HAL_ERROR;
4731 /* Configure cycle time target phase */
4732 MODIFY_REG(hfdcan->ttcan->TTGTP, FDCAN_TTGTP_CTP, (TargetPhase << FDCAN_TTGTP_CTP_Pos));
4734 /* Return function status */
4735 return HAL_OK;
4737 else
4739 /* Update error code */
4740 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4742 return HAL_ERROR;
4747 * @brief Synchronize the phase of the FDCAN schedule to an external schedule
4748 * using event trigger input pin fdcan1_evt.
4749 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4750 * the configuration information for the specified FDCAN.
4751 * @retval HAL status
4753 HAL_StatusTypeDef HAL_FDCAN_TT_EnableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
4755 uint32_t Counter = 0U;
4756 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4758 /* Check function parameters */
4759 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4761 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4763 /* Wait until the LCKC bit into TTOCN register is reset */
4764 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4766 /* Check for the Timeout */
4767 if (Counter > FDCAN_TIMEOUT_VALUE)
4769 /* Update error code */
4770 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4772 /* Change FDCAN state */
4773 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4775 return HAL_ERROR;
4778 /* Increment counter */
4779 Counter++;
4782 /* Enable external synchronization */
4783 SET_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
4785 /* Return function status */
4786 return HAL_OK;
4788 else
4790 /* Update error code */
4791 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4793 return HAL_ERROR;
4798 * @brief Disable external schedule synchronization.
4799 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4800 * the configuration information for the specified FDCAN.
4801 * @retval HAL status
4803 HAL_StatusTypeDef HAL_FDCAN_TT_DisableExternalSynchronization(FDCAN_HandleTypeDef *hfdcan)
4805 uint32_t Counter = 0U;
4806 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4808 /* Check function parameters */
4809 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4811 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4813 /* Wait until the LCKC bit into TTOCN register is reset */
4814 while ((hfdcan->ttcan->TTOCN & FDCAN_TTOCN_LCKC) != 0U)
4816 /* Check for the Timeout */
4817 if (Counter > FDCAN_TIMEOUT_VALUE)
4819 /* Update error code */
4820 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_TIMEOUT;
4822 /* Change FDCAN state */
4823 hfdcan->State = HAL_FDCAN_STATE_ERROR;
4825 return HAL_ERROR;
4828 /* Increment counter */
4829 Counter++;
4832 /* Disable external synchronization */
4833 CLEAR_BIT(hfdcan->ttcan->TTOCN, FDCAN_TTOCN_ESCN);
4835 /* Return function status */
4836 return HAL_OK;
4838 else
4840 /* Update error code */
4841 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4843 return HAL_ERROR;
4848 * @brief Get TT operation status.
4849 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4850 * the configuration information for the specified FDCAN.
4851 * @param TTOpStatus pointer to an FDCAN_TTOperationStatusTypeDef structure.
4852 * @retval HAL status
4854 HAL_StatusTypeDef HAL_FDCAN_TT_GetOperationStatus(FDCAN_HandleTypeDef *hfdcan, FDCAN_TTOperationStatusTypeDef *TTOpStatus)
4856 uint32_t TTStatusReg;
4858 /* Check function parameters */
4859 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4861 /* Read the TT operation status register */
4862 TTStatusReg = READ_REG(hfdcan->ttcan->TTOST);
4864 /* Fill the TT operation status structure */
4865 TTOpStatus->ErrorLevel = (TTStatusReg & FDCAN_TTOST_EL);
4866 TTOpStatus->MasterState = (TTStatusReg & FDCAN_TTOST_MS);
4867 TTOpStatus->SyncState = (TTStatusReg & FDCAN_TTOST_SYS);
4868 TTOpStatus->GTimeQuality = ((TTStatusReg & FDCAN_TTOST_QGTP) >> FDCAN_TTOST_QGTP_Pos);
4869 TTOpStatus->ClockQuality = ((TTStatusReg & FDCAN_TTOST_QCS) >> FDCAN_TTOST_QCS_Pos);
4870 TTOpStatus->RefTrigOffset = ((TTStatusReg & FDCAN_TTOST_RTO) >> FDCAN_TTOST_RTO_Pos);
4871 TTOpStatus->GTimeDiscPending = ((TTStatusReg & FDCAN_TTOST_WGTD) >> FDCAN_TTOST_WGTD_Pos);
4872 TTOpStatus->GapFinished = ((TTStatusReg & FDCAN_TTOST_GFI) >> FDCAN_TTOST_GFI_Pos);
4873 TTOpStatus->MasterPriority = ((TTStatusReg & FDCAN_TTOST_TMP) >> FDCAN_TTOST_TMP_Pos);
4874 TTOpStatus->GapStarted = ((TTStatusReg & FDCAN_TTOST_GSI) >> FDCAN_TTOST_GSI_Pos);
4875 TTOpStatus->WaitForEvt = ((TTStatusReg & FDCAN_TTOST_WFE) >> FDCAN_TTOST_WFE_Pos);
4876 TTOpStatus->AppWdgEvt = ((TTStatusReg & FDCAN_TTOST_AWE) >> FDCAN_TTOST_AWE_Pos);
4877 TTOpStatus->ECSPending = ((TTStatusReg & FDCAN_TTOST_WECS) >> FDCAN_TTOST_WECS_Pos);
4878 TTOpStatus->PhaseLock = ((TTStatusReg & FDCAN_TTOST_SPL) >> FDCAN_TTOST_SPL_Pos);
4880 /* Return function status */
4881 return HAL_OK;
4885 * @}
4888 /** @defgroup FDCAN_Exported_Functions_Group5 Interrupts management
4889 * @brief Interrupts management
4891 @verbatim
4892 ==============================================================================
4893 ##### Interrupts management #####
4894 ==============================================================================
4895 [..] This section provides functions allowing to:
4896 (+) HAL_FDCAN_ConfigInterruptLines : Assign interrupts to either Interrupt line 0 or 1
4897 (+) HAL_FDCAN_TT_ConfigInterruptLines : Assign TT interrupts to either Interrupt line 0 or 1
4898 (+) HAL_FDCAN_ActivateNotification : Enable interrupts
4899 (+) HAL_FDCAN_DeactivateNotification : Disable interrupts
4900 (+) HAL_FDCAN_TT_ActivateNotification : Enable TT interrupts
4901 (+) HAL_FDCAN_TT_DeactivateNotification : Disable TT interrupts
4902 (+) HAL_FDCAN_IRQHandler : Handles FDCAN interrupt request
4904 @endverbatim
4905 * @{
4909 * @brief Assign interrupts to either Interrupt line 0 or 1.
4910 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4911 * the configuration information for the specified FDCAN.
4912 * @param ITList indicates which interrupts will be assigned to the selected interrupt line.
4913 * This parameter can be any combination of @arg FDCAN_Interrupts.
4914 * @param InterruptLine Interrupt line.
4915 * This parameter can be a value of @arg FDCAN_Interrupt_Line.
4916 * @retval HAL status
4918 HAL_StatusTypeDef HAL_FDCAN_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t ITList, uint32_t InterruptLine)
4920 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4922 /* Check function parameters */
4923 assert_param(IS_FDCAN_IT(ITList));
4924 assert_param(IS_FDCAN_IT_LINE(InterruptLine));
4926 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4928 /* Assign list of interrupts to the selected line */
4929 if (InterruptLine == FDCAN_INTERRUPT_LINE0)
4931 CLEAR_BIT(hfdcan->Instance->ILS, ITList);
4933 else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
4935 SET_BIT(hfdcan->Instance->ILS, ITList);
4938 /* Return function status */
4939 return HAL_OK;
4941 else
4943 /* Update error code */
4944 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4946 return HAL_ERROR;
4951 * @brief Assign TT interrupts to either Interrupt line 0 or 1.
4952 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4953 * the configuration information for the specified FDCAN.
4954 * @param TTITList indicates which interrupts will be assigned to the selected interrupt line.
4955 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
4956 * @param InterruptLine Interrupt line.
4957 * This parameter can be a value of @arg FDCAN_Interrupt_Line.
4958 * @retval HAL status
4960 HAL_StatusTypeDef HAL_FDCAN_TT_ConfigInterruptLines(FDCAN_HandleTypeDef *hfdcan, uint32_t TTITList, uint32_t InterruptLine)
4962 HAL_FDCAN_StateTypeDef state = hfdcan->State;
4964 /* Check function parameters */
4965 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
4966 assert_param(IS_FDCAN_TT_IT(TTITList));
4967 assert_param(IS_FDCAN_IT_LINE(InterruptLine));
4969 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
4971 /* Assign list of interrupts to the selected line */
4972 if (InterruptLine == FDCAN_INTERRUPT_LINE0)
4974 CLEAR_BIT(hfdcan->ttcan->TTILS, TTITList);
4976 else /* InterruptLine == FDCAN_INTERRUPT_LINE1 */
4978 SET_BIT(hfdcan->ttcan->TTILS, TTITList);
4981 /* Return function status */
4982 return HAL_OK;
4984 else
4986 /* Update error code */
4987 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
4989 return HAL_ERROR;
4994 * @brief Enable interrupts.
4995 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
4996 * the configuration information for the specified FDCAN.
4997 * @param ActiveITs indicates which interrupts will be enabled.
4998 * This parameter can be any combination of @arg FDCAN_Interrupts.
4999 * @param BufferIndexes Tx Buffer Indexes.
5000 * This parameter can be any combination of @arg FDCAN_Tx_location.
5001 * This parameter is ignored if ActiveITs does not include one of the following:
5002 * - FDCAN_IT_TX_COMPLETE
5003 * - FDCAN_IT_TX_ABORT_COMPLETE
5004 * @retval HAL status
5006 HAL_StatusTypeDef HAL_FDCAN_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveITs, uint32_t BufferIndexes)
5008 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5010 /* Check function parameters */
5011 assert_param(IS_FDCAN_IT(ActiveITs));
5013 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5015 /* Enable Interrupt lines */
5016 if ((ActiveITs & hfdcan->Instance->ILS) == 0U)
5018 /* Enable Interrupt line 0 */
5019 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5021 else if ((ActiveITs & hfdcan->Instance->ILS) == ActiveITs)
5023 /* Enable Interrupt line 1 */
5024 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5026 else
5028 /* Enable Interrupt lines 0 and 1 */
5029 hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
5032 if ((ActiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
5034 /* Enable Tx Buffer Transmission Interrupt to set TC flag in IR register,
5035 but interrupt will only occure if TC is enabled in IE register */
5036 SET_BIT(hfdcan->Instance->TXBTIE, BufferIndexes);
5039 if ((ActiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5041 /* Enable Tx Buffer Cancellation Finished Interrupt to set TCF flag in IR register,
5042 but interrupt will only occure if TCF is enabled in IE register */
5043 SET_BIT(hfdcan->Instance->TXBCIE, BufferIndexes);
5046 /* Enable the selected interrupts */
5047 __HAL_FDCAN_ENABLE_IT(hfdcan, ActiveITs);
5049 /* Return function status */
5050 return HAL_OK;
5052 else
5054 /* Update error code */
5055 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5057 return HAL_ERROR;
5062 * @brief Disable interrupts.
5063 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5064 * the configuration information for the specified FDCAN.
5065 * @param InactiveITs indicates which interrupts will be disabled.
5066 * This parameter can be any combination of @arg FDCAN_Interrupts.
5067 * @retval HAL status
5069 HAL_StatusTypeDef HAL_FDCAN_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveITs)
5071 uint32_t ITLineSelection;
5072 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5074 /* Check function parameters */
5075 assert_param(IS_FDCAN_IT(InactiveITs));
5077 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5079 /* Disable the selected interrupts */
5080 __HAL_FDCAN_DISABLE_IT(hfdcan, InactiveITs);
5082 if ((InactiveITs & FDCAN_IT_TX_COMPLETE) != 0U)
5084 /* Disable Tx Buffer Transmission Interrupts */
5085 CLEAR_REG(hfdcan->Instance->TXBTIE);
5088 if ((InactiveITs & FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5090 /* Disable Tx Buffer Cancellation Finished Interrupt */
5091 CLEAR_REG(hfdcan->Instance->TXBCIE);
5094 ITLineSelection = hfdcan->Instance->ILS;
5096 if ((hfdcan->Instance->IE | ITLineSelection) == ITLineSelection)
5098 /* Disable Interrupt line 0 */
5099 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5102 if ((hfdcan->Instance->IE & ITLineSelection) == 0U)
5104 /* Disable Interrupt line 1 */
5105 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5108 /* Return function status */
5109 return HAL_OK;
5111 else
5113 /* Update error code */
5114 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5116 return HAL_ERROR;
5121 * @brief Enable TT interrupts.
5122 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5123 * the configuration information for the specified FDCAN.
5124 * @param ActiveTTITs indicates which TT interrupts will be enabled.
5125 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
5126 * @retval HAL status
5128 HAL_StatusTypeDef HAL_FDCAN_TT_ActivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t ActiveTTITs)
5130 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5132 /* Check function parameters */
5133 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
5134 assert_param(IS_FDCAN_TT_IT(ActiveTTITs));
5136 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5138 /* Enable Interrupt lines */
5139 if ((ActiveTTITs & hfdcan->ttcan->TTILS) == 0U)
5141 /* Enable Interrupt line 0 */
5142 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5144 else if ((ActiveTTITs & hfdcan->ttcan->TTILS) == ActiveTTITs)
5146 /* Enable Interrupt line 1 */
5147 SET_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5149 else
5151 /* Enable Interrupt lines 0 and 1 */
5152 hfdcan->Instance->ILE = (FDCAN_INTERRUPT_LINE0 | FDCAN_INTERRUPT_LINE1);
5155 /* Enable the selected TT interrupts */
5156 __HAL_FDCAN_TT_ENABLE_IT(hfdcan, ActiveTTITs);
5158 /* Return function status */
5159 return HAL_OK;
5161 else
5163 /* Update error code */
5164 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5166 return HAL_ERROR;
5171 * @brief Disable TT interrupts.
5172 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5173 * the configuration information for the specified FDCAN.
5174 * @param InactiveTTITs indicates which TT interrupts will be disabled.
5175 * This parameter can be any combination of @arg FDCAN_TTInterrupts.
5176 * @retval HAL status
5178 HAL_StatusTypeDef HAL_FDCAN_TT_DeactivateNotification(FDCAN_HandleTypeDef *hfdcan, uint32_t InactiveTTITs)
5180 uint32_t ITLineSelection;
5181 HAL_FDCAN_StateTypeDef state = hfdcan->State;
5183 /* Check function parameters */
5184 assert_param(IS_FDCAN_TT_INSTANCE(hfdcan->Instance));
5185 assert_param(IS_FDCAN_TT_IT(InactiveTTITs));
5187 if ((state == HAL_FDCAN_STATE_READY) || (state == HAL_FDCAN_STATE_BUSY))
5189 /* Disable the selected TT interrupts */
5190 __HAL_FDCAN_TT_DISABLE_IT(hfdcan, InactiveTTITs);
5192 ITLineSelection = hfdcan->ttcan->TTILS;
5194 if ((hfdcan->ttcan->TTIE | ITLineSelection) == ITLineSelection)
5196 /* Disable Interrupt line 0 */
5197 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE0);
5200 if ((hfdcan->ttcan->TTIE & ITLineSelection) == 0U)
5202 /* Disable Interrupt line 1 */
5203 CLEAR_BIT(hfdcan->Instance->ILE, FDCAN_INTERRUPT_LINE1);
5206 /* Return function status */
5207 return HAL_OK;
5209 else
5211 /* Update error code */
5212 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_NOT_INITIALIZED;
5214 return HAL_ERROR;
5219 * @brief Handles FDCAN interrupt request.
5220 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5221 * the configuration information for the specified FDCAN.
5222 * @retval HAL status
5224 void HAL_FDCAN_IRQHandler(FDCAN_HandleTypeDef *hfdcan)
5226 uint32_t ClkCalibrationITs;
5227 uint32_t TxEventFifoITs;
5228 uint32_t RxFifo0ITs;
5229 uint32_t RxFifo1ITs;
5230 uint32_t Errors;
5231 uint32_t ErrorStatusITs;
5232 uint32_t TransmittedBuffers;
5233 uint32_t AbortedBuffers;
5234 uint32_t TTSchedSyncITs;
5235 uint32_t TTTimeMarkITs;
5236 uint32_t TTGlobTimeITs;
5237 uint32_t TTDistErrors;
5238 uint32_t TTFatalErrors;
5239 uint32_t SWTime;
5240 uint32_t SWCycleCount;
5242 ClkCalibrationITs = (FDCAN_CCU->IR << 30);
5243 ClkCalibrationITs &= (FDCAN_CCU->IE << 30);
5244 TxEventFifoITs = hfdcan->Instance->IR & FDCAN_TX_EVENT_FIFO_MASK;
5245 TxEventFifoITs &= hfdcan->Instance->IE;
5246 RxFifo0ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO0_MASK;
5247 RxFifo0ITs &= hfdcan->Instance->IE;
5248 RxFifo1ITs = hfdcan->Instance->IR & FDCAN_RX_FIFO1_MASK;
5249 RxFifo1ITs &= hfdcan->Instance->IE;
5250 Errors = hfdcan->Instance->IR & FDCAN_ERROR_MASK;
5251 Errors &= hfdcan->Instance->IE;
5252 ErrorStatusITs = hfdcan->Instance->IR & FDCAN_ERROR_STATUS_MASK;
5253 ErrorStatusITs &= hfdcan->Instance->IE;
5255 /* High Priority Message interrupt management *******************************/
5256 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_HIGH_PRIORITY_MSG) != 0U)
5258 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG) != 0U)
5260 /* Clear the High Priority Message flag */
5261 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_HIGH_PRIORITY_MSG);
5263 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5264 /* Call registered callback*/
5265 hfdcan->HighPriorityMessageCallback(hfdcan);
5266 #else
5267 /* High Priority Message Callback */
5268 HAL_FDCAN_HighPriorityMessageCallback(hfdcan);
5269 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5273 /* Transmission Abort interrupt management **********************************/
5274 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_ABORT_COMPLETE) != 0U)
5276 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE) != 0U)
5278 /* List of aborted monitored buffers */
5279 AbortedBuffers = hfdcan->Instance->TXBCF;
5280 AbortedBuffers &= hfdcan->Instance->TXBCIE;
5282 /* Clear the Transmission Cancellation flag */
5283 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_ABORT_COMPLETE);
5285 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5286 /* Call registered callback*/
5287 hfdcan->TxBufferAbortCallback(hfdcan, AbortedBuffers);
5288 #else
5289 /* Transmission Cancellation Callback */
5290 HAL_FDCAN_TxBufferAbortCallback(hfdcan, AbortedBuffers);
5291 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5295 /* Clock calibration unit interrupts management *****************************/
5296 if (ClkCalibrationITs != 0U)
5298 /* Clear the Clock Calibration flags */
5299 __HAL_FDCAN_CLEAR_FLAG(hfdcan, ClkCalibrationITs);
5301 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5302 /* Call registered callback*/
5303 hfdcan->ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
5304 #else
5305 /* Clock Calibration Callback */
5306 HAL_FDCAN_ClockCalibrationCallback(hfdcan, ClkCalibrationITs);
5307 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5310 /* Tx event FIFO interrupts management **************************************/
5311 if (TxEventFifoITs != 0U)
5313 /* Clear the Tx Event FIFO flags */
5314 __HAL_FDCAN_CLEAR_FLAG(hfdcan, TxEventFifoITs);
5316 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5317 /* Call registered callback*/
5318 hfdcan->TxEventFifoCallback(hfdcan, TxEventFifoITs);
5319 #else
5320 /* Tx Event FIFO Callback */
5321 HAL_FDCAN_TxEventFifoCallback(hfdcan, TxEventFifoITs);
5322 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5325 /* Rx FIFO 0 interrupts management ******************************************/
5326 if (RxFifo0ITs != 0U)
5328 /* Clear the Rx FIFO 0 flags */
5329 __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo0ITs);
5331 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5332 /* Call registered callback*/
5333 hfdcan->RxFifo0Callback(hfdcan, RxFifo0ITs);
5334 #else
5335 /* Rx FIFO 0 Callback */
5336 HAL_FDCAN_RxFifo0Callback(hfdcan, RxFifo0ITs);
5337 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5340 /* Rx FIFO 1 interrupts management ******************************************/
5341 if (RxFifo1ITs != 0U)
5343 /* Clear the Rx FIFO 1 flags */
5344 __HAL_FDCAN_CLEAR_FLAG(hfdcan, RxFifo1ITs);
5346 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5347 /* Call registered callback*/
5348 hfdcan->RxFifo1Callback(hfdcan, RxFifo1ITs);
5349 #else
5350 /* Rx FIFO 1 Callback */
5351 HAL_FDCAN_RxFifo1Callback(hfdcan, RxFifo1ITs);
5352 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5355 /* Tx FIFO empty interrupt management ***************************************/
5356 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_FIFO_EMPTY) != 0U)
5358 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY) != 0U)
5360 /* Clear the Tx FIFO empty flag */
5361 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_FIFO_EMPTY);
5363 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5364 /* Call registered callback*/
5365 hfdcan->TxFifoEmptyCallback(hfdcan);
5366 #else
5367 /* Tx FIFO empty Callback */
5368 HAL_FDCAN_TxFifoEmptyCallback(hfdcan);
5369 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5373 /* Transmission Complete interrupt management *******************************/
5374 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TX_COMPLETE) != 0U)
5376 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE) != 0U)
5378 /* List of transmitted monitored buffers */
5379 TransmittedBuffers = hfdcan->Instance->TXBTO;
5380 TransmittedBuffers &= hfdcan->Instance->TXBTIE;
5382 /* Clear the Transmission Complete flag */
5383 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TX_COMPLETE);
5385 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5386 /* Call registered callback*/
5387 hfdcan->TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
5388 #else
5389 /* Transmission Complete Callback */
5390 HAL_FDCAN_TxBufferCompleteCallback(hfdcan, TransmittedBuffers);
5391 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5395 /* Rx Buffer New Message interrupt management *******************************/
5396 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RX_BUFFER_NEW_MESSAGE) != 0U)
5398 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE) != 0U)
5400 /* Clear the Rx Buffer New Message flag */
5401 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RX_BUFFER_NEW_MESSAGE);
5403 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5404 /* Call registered callback*/
5405 hfdcan->RxBufferNewMessageCallback(hfdcan);
5406 #else
5407 /* Rx Buffer New Message Callback */
5408 HAL_FDCAN_RxBufferNewMessageCallback(hfdcan);
5409 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5413 /* Timestamp Wraparound interrupt management ********************************/
5414 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMESTAMP_WRAPAROUND) != 0U)
5416 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND) != 0U)
5418 /* Clear the Timestamp Wraparound flag */
5419 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMESTAMP_WRAPAROUND);
5421 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5422 /* Call registered callback*/
5423 hfdcan->TimestampWraparoundCallback(hfdcan);
5424 #else
5425 /* Timestamp Wraparound Callback */
5426 HAL_FDCAN_TimestampWraparoundCallback(hfdcan);
5427 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5431 /* Timeout Occurred interrupt management ************************************/
5432 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_TIMEOUT_OCCURRED) != 0U)
5434 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED) != 0U)
5436 /* Clear the Timeout Occurred flag */
5437 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_TIMEOUT_OCCURRED);
5439 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5440 /* Call registered callback*/
5441 hfdcan->TimeoutOccurredCallback(hfdcan);
5442 #else
5443 /* Timeout Occurred Callback */
5444 HAL_FDCAN_TimeoutOccurredCallback(hfdcan);
5445 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5449 /* Message RAM access failure interrupt management **************************/
5450 if (__HAL_FDCAN_GET_IT_SOURCE(hfdcan, FDCAN_IT_RAM_ACCESS_FAILURE) != 0U)
5452 if (__HAL_FDCAN_GET_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE) != 0U)
5454 /* Clear the Message RAM access failure flag */
5455 __HAL_FDCAN_CLEAR_FLAG(hfdcan, FDCAN_FLAG_RAM_ACCESS_FAILURE);
5457 /* Update error code */
5458 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_RAM_ACCESS;
5462 /* Error Status interrupts management ***************************************/
5463 if (ErrorStatusITs != 0U)
5465 /* Clear the Error flags */
5466 __HAL_FDCAN_CLEAR_FLAG(hfdcan, ErrorStatusITs);
5468 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5469 /* Call registered callback*/
5470 hfdcan->ErrorStatusCallback(hfdcan, ErrorStatusITs);
5471 #else
5472 /* Error Status Callback */
5473 HAL_FDCAN_ErrorStatusCallback(hfdcan, ErrorStatusITs);
5474 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5477 /* Error interrupts management **********************************************/
5478 if (Errors != 0U)
5480 /* Clear the Error flags */
5481 __HAL_FDCAN_CLEAR_FLAG(hfdcan, Errors);
5483 /* Update error code */
5484 hfdcan->ErrorCode |= Errors;
5487 if (hfdcan->Instance == FDCAN1)
5489 if ((hfdcan->ttcan->TTOCF & FDCAN_TTOCF_OM) != 0U)
5491 TTSchedSyncITs = hfdcan->ttcan->TTIR & FDCAN_TT_SCHEDULE_SYNC_MASK;
5492 TTSchedSyncITs &= hfdcan->ttcan->TTIE;
5493 TTTimeMarkITs = hfdcan->ttcan->TTIR & FDCAN_TT_TIME_MARK_MASK;
5494 TTTimeMarkITs &= hfdcan->ttcan->TTIE;
5495 TTGlobTimeITs = hfdcan->ttcan->TTIR & FDCAN_TT_GLOBAL_TIME_MASK;
5496 TTGlobTimeITs &= hfdcan->ttcan->TTIE;
5497 TTDistErrors = hfdcan->ttcan->TTIR & FDCAN_TT_DISTURBING_ERROR_MASK;
5498 TTDistErrors &= hfdcan->ttcan->TTIE;
5499 TTFatalErrors = hfdcan->ttcan->TTIR & FDCAN_TT_FATAL_ERROR_MASK;
5500 TTFatalErrors &= hfdcan->ttcan->TTIE;
5502 /* TT Schedule Synchronization interrupts management **********************/
5503 if (TTSchedSyncITs != 0U)
5505 /* Clear the TT Schedule Synchronization flags */
5506 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTSchedSyncITs);
5508 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5509 /* Call registered callback*/
5510 hfdcan->TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
5511 #else
5512 /* TT Schedule Synchronization Callback */
5513 HAL_FDCAN_TT_ScheduleSyncCallback(hfdcan, TTSchedSyncITs);
5514 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5517 /* TT Time Mark interrupts management *************************************/
5518 if (TTTimeMarkITs != 0U)
5520 /* Clear the TT Time Mark flags */
5521 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTTimeMarkITs);
5523 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5524 /* Call registered callback*/
5525 hfdcan->TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
5526 #else
5527 /* TT Time Mark Callback */
5528 HAL_FDCAN_TT_TimeMarkCallback(hfdcan, TTTimeMarkITs);
5529 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5532 /* TT Stop Watch interrupt management *************************************/
5533 if (__HAL_FDCAN_TT_GET_IT_SOURCE(hfdcan, FDCAN_TT_IT_STOP_WATCH) != 0U)
5535 if (__HAL_FDCAN_TT_GET_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH) != 0U)
5537 /* Retrieve Stop watch Time and Cycle count */
5538 SWTime = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_SWV) >> FDCAN_TTCPT_SWV_Pos);
5539 SWCycleCount = ((hfdcan->ttcan->TTCPT & FDCAN_TTCPT_CCV) >> FDCAN_TTCPT_CCV_Pos);
5541 /* Clear the TT Stop Watch flag */
5542 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, FDCAN_TT_FLAG_STOP_WATCH);
5544 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5545 /* Call registered callback*/
5546 hfdcan->TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
5547 #else
5548 /* TT Stop Watch Callback */
5549 HAL_FDCAN_TT_StopWatchCallback(hfdcan, SWTime, SWCycleCount);
5550 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5554 /* TT Global Time interrupts management ***********************************/
5555 if (TTGlobTimeITs != 0U)
5557 /* Clear the TT Global Time flags */
5558 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTGlobTimeITs);
5560 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5561 /* Call registered callback*/
5562 hfdcan->TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
5563 #else
5564 /* TT Global Time Callback */
5565 HAL_FDCAN_TT_GlobalTimeCallback(hfdcan, TTGlobTimeITs);
5566 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5569 /* TT Disturbing Error interrupts management ******************************/
5570 if (TTDistErrors != 0U)
5572 /* Clear the TT Disturbing Error flags */
5573 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTDistErrors);
5575 /* Update error code */
5576 hfdcan->ErrorCode |= TTDistErrors;
5579 /* TT Fatal Error interrupts management ***********************************/
5580 if (TTFatalErrors != 0U)
5582 /* Clear the TT Fatal Error flags */
5583 __HAL_FDCAN_TT_CLEAR_FLAG(hfdcan, TTFatalErrors);
5585 /* Update error code */
5586 hfdcan->ErrorCode |= TTFatalErrors;
5591 if (hfdcan->ErrorCode != HAL_FDCAN_ERROR_NONE)
5593 #if USE_HAL_FDCAN_REGISTER_CALLBACKS == 1
5594 /* Call registered callback*/
5595 hfdcan->ErrorCallback(hfdcan);
5596 #else
5597 /* Error Callback */
5598 HAL_FDCAN_ErrorCallback(hfdcan);
5599 #endif /* USE_HAL_FDCAN_REGISTER_CALLBACKS */
5604 * @}
5607 /** @defgroup FDCAN_Exported_Functions_Group6 Callback functions
5608 * @brief FDCAN Callback functions
5610 @verbatim
5611 ==============================================================================
5612 ##### Callback functions #####
5613 ==============================================================================
5614 [..]
5615 This subsection provides the following callback functions:
5616 (+) HAL_FDCAN_ClockCalibrationCallback
5617 (+) HAL_FDCAN_TxEventFifoCallback
5618 (+) HAL_FDCAN_RxFifo0Callback
5619 (+) HAL_FDCAN_RxFifo1Callback
5620 (+) HAL_FDCAN_TxFifoEmptyCallback
5621 (+) HAL_FDCAN_TxBufferCompleteCallback
5622 (+) HAL_FDCAN_TxBufferAbortCallback
5623 (+) HAL_FDCAN_RxBufferNewMessageCallback
5624 (+) HAL_FDCAN_HighPriorityMessageCallback
5625 (+) HAL_FDCAN_TimestampWraparoundCallback
5626 (+) HAL_FDCAN_TimeoutOccurredCallback
5627 (+) HAL_FDCAN_ErrorCallback
5628 (+) HAL_FDCAN_ErrorStatusCallback
5629 (+) HAL_FDCAN_TT_ScheduleSyncCallback
5630 (+) HAL_FDCAN_TT_TimeMarkCallback
5631 (+) HAL_FDCAN_TT_StopWatchCallback
5632 (+) HAL_FDCAN_TT_GlobalTimeCallback
5634 @endverbatim
5635 * @{
5639 * @brief Clock Calibration callback.
5640 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5641 * the configuration information for the specified FDCAN.
5642 * @param ClkCalibrationITs indicates which Clock Calibration interrupts are signaled.
5643 * This parameter can be any combination of @arg FDCAN_Clock_Calibration_Interrupts.
5644 * @retval None
5646 __weak void HAL_FDCAN_ClockCalibrationCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ClkCalibrationITs)
5648 /* Prevent unused argument(s) compilation warning */
5649 UNUSED(hfdcan);
5650 UNUSED(ClkCalibrationITs);
5652 /* NOTE : This function Should not be modified, when the callback is needed,
5653 the HAL_FDCAN_ClockCalibrationCallback could be implemented in the user file
5658 * @brief Tx Event callback.
5659 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5660 * the configuration information for the specified FDCAN.
5661 * @param TxEventFifoITs indicates which Tx Event FIFO interrupts are signaled.
5662 * This parameter can be any combination of @arg FDCAN_Tx_Event_Fifo_Interrupts.
5663 * @retval None
5665 __weak void HAL_FDCAN_TxEventFifoCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TxEventFifoITs)
5667 /* Prevent unused argument(s) compilation warning */
5668 UNUSED(hfdcan);
5669 UNUSED(TxEventFifoITs);
5671 /* NOTE : This function Should not be modified, when the callback is needed,
5672 the HAL_FDCAN_TxEventFifoCallback could be implemented in the user file
5677 * @brief Rx FIFO 0 callback.
5678 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5679 * the configuration information for the specified FDCAN.
5680 * @param RxFifo0ITs indicates which Rx FIFO 0 interrupts are signaled.
5681 * This parameter can be any combination of @arg FDCAN_Rx_Fifo0_Interrupts.
5682 * @retval None
5684 __weak void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
5686 /* Prevent unused argument(s) compilation warning */
5687 UNUSED(hfdcan);
5688 UNUSED(RxFifo0ITs);
5690 /* NOTE : This function Should not be modified, when the callback is needed,
5691 the HAL_FDCAN_RxFifo0Callback could be implemented in the user file
5696 * @brief Rx FIFO 1 callback.
5697 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5698 * the configuration information for the specified FDCAN.
5699 * @param RxFifo1ITs indicates which Rx FIFO 1 interrupts are signaled.
5700 * This parameter can be any combination of @arg FDCAN_Rx_Fifo1_Interrupts.
5701 * @retval None
5703 __weak void HAL_FDCAN_RxFifo1Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo1ITs)
5705 /* Prevent unused argument(s) compilation warning */
5706 UNUSED(hfdcan);
5707 UNUSED(RxFifo1ITs);
5709 /* NOTE : This function Should not be modified, when the callback is needed,
5710 the HAL_FDCAN_RxFifo1Callback could be implemented in the user file
5715 * @brief Tx FIFO Empty callback.
5716 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5717 * the configuration information for the specified FDCAN.
5718 * @retval None
5720 __weak void HAL_FDCAN_TxFifoEmptyCallback(FDCAN_HandleTypeDef *hfdcan)
5722 /* Prevent unused argument(s) compilation warning */
5723 UNUSED(hfdcan);
5725 /* NOTE : This function Should not be modified, when the callback is needed,
5726 the HAL_FDCAN_TxFifoEmptyCallback could be implemented in the user file
5731 * @brief Transmission Complete callback.
5732 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5733 * the configuration information for the specified FDCAN.
5734 * @param BufferIndexes Indexes of the transmitted buffers.
5735 * This parameter can be any combination of @arg FDCAN_Tx_location.
5736 * @retval None
5738 __weak void HAL_FDCAN_TxBufferCompleteCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
5740 /* Prevent unused argument(s) compilation warning */
5741 UNUSED(hfdcan);
5742 UNUSED(BufferIndexes);
5744 /* NOTE : This function Should not be modified, when the callback is needed,
5745 the HAL_FDCAN_TxBufferCompleteCallback could be implemented in the user file
5750 * @brief Transmission Cancellation callback.
5751 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5752 * the configuration information for the specified FDCAN.
5753 * @param BufferIndexes Indexes of the aborted buffers.
5754 * This parameter can be any combination of @arg FDCAN_Tx_location.
5755 * @retval None
5757 __weak void HAL_FDCAN_TxBufferAbortCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t BufferIndexes)
5759 /* Prevent unused argument(s) compilation warning */
5760 UNUSED(hfdcan);
5761 UNUSED(BufferIndexes);
5763 /* NOTE : This function Should not be modified, when the callback is needed,
5764 the HAL_FDCAN_TxBufferAbortCallback could be implemented in the user file
5769 * @brief Rx Buffer New Message callback.
5770 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5771 * the configuration information for the specified FDCAN.
5772 * @retval None
5774 __weak void HAL_FDCAN_RxBufferNewMessageCallback(FDCAN_HandleTypeDef *hfdcan)
5776 /* Prevent unused argument(s) compilation warning */
5777 UNUSED(hfdcan);
5779 /* NOTE : This function Should not be modified, when the callback is needed,
5780 the HAL_FDCAN_RxBufferNewMessageCallback could be implemented in the user file
5785 * @brief Timestamp Wraparound callback.
5786 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5787 * the configuration information for the specified FDCAN.
5788 * @retval None
5790 __weak void HAL_FDCAN_TimestampWraparoundCallback(FDCAN_HandleTypeDef *hfdcan)
5792 /* Prevent unused argument(s) compilation warning */
5793 UNUSED(hfdcan);
5795 /* NOTE : This function Should not be modified, when the callback is needed,
5796 the HAL_FDCAN_TimestampWraparoundCallback could be implemented in the user file
5801 * @brief Timeout Occurred callback.
5802 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5803 * the configuration information for the specified FDCAN.
5804 * @retval None
5806 __weak void HAL_FDCAN_TimeoutOccurredCallback(FDCAN_HandleTypeDef *hfdcan)
5808 /* Prevent unused argument(s) compilation warning */
5809 UNUSED(hfdcan);
5811 /* NOTE : This function Should not be modified, when the callback is needed,
5812 the HAL_FDCAN_TimeoutOccurredCallback could be implemented in the user file
5817 * @brief High Priority Message callback.
5818 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5819 * the configuration information for the specified FDCAN.
5820 * @retval None
5822 __weak void HAL_FDCAN_HighPriorityMessageCallback(FDCAN_HandleTypeDef *hfdcan)
5824 /* Prevent unused argument(s) compilation warning */
5825 UNUSED(hfdcan);
5827 /* NOTE : This function Should not be modified, when the callback is needed,
5828 the HAL_FDCAN_HighPriorityMessageCallback could be implemented in the user file
5833 * @brief Error callback.
5834 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5835 * the configuration information for the specified FDCAN.
5836 * @retval None
5838 __weak void HAL_FDCAN_ErrorCallback(FDCAN_HandleTypeDef *hfdcan)
5840 /* Prevent unused argument(s) compilation warning */
5841 UNUSED(hfdcan);
5843 /* NOTE : This function Should not be modified, when the callback is needed,
5844 the HAL_FDCAN_ErrorCallback could be implemented in the user file
5849 * @brief Error status callback.
5850 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5851 * the configuration information for the specified FDCAN.
5852 * @param ErrorStatusITs indicates which Error Status interrupts are signaled.
5853 * This parameter can be any combination of @arg FDCAN_Error_Status_Interrupts.
5854 * @retval None
5856 __weak void HAL_FDCAN_ErrorStatusCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t ErrorStatusITs)
5858 /* Prevent unused argument(s) compilation warning */
5859 UNUSED(hfdcan);
5860 UNUSED(ErrorStatusITs);
5862 /* NOTE : This function Should not be modified, when the callback is needed,
5863 the HAL_FDCAN_ErrorStatusCallback could be implemented in the user file
5868 * @brief TT Schedule Synchronization callback.
5869 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5870 * the configuration information for the specified FDCAN.
5871 * @param TTSchedSyncITs indicates which TT Schedule Synchronization interrupts are signaled.
5872 * This parameter can be any combination of @arg FDCAN_TTScheduleSynchronization_Interrupts.
5873 * @retval None
5875 __weak void HAL_FDCAN_TT_ScheduleSyncCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTSchedSyncITs)
5877 /* Prevent unused argument(s) compilation warning */
5878 UNUSED(hfdcan);
5879 UNUSED(TTSchedSyncITs);
5881 /* NOTE : This function Should not be modified, when the callback is needed,
5882 the HAL_FDCAN_TT_ScheduleSyncCallback could be implemented in the user file
5887 * @brief TT Time Mark callback.
5888 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5889 * the configuration information for the specified FDCAN.
5890 * @param TTTimeMarkITs indicates which TT Schedule Synchronization interrupts are signaled.
5891 * This parameter can be any combination of @arg FDCAN_TTTimeMark_Interrupts.
5892 * @retval None
5894 __weak void HAL_FDCAN_TT_TimeMarkCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTTimeMarkITs)
5896 /* Prevent unused argument(s) compilation warning */
5897 UNUSED(hfdcan);
5898 UNUSED(TTTimeMarkITs);
5900 /* NOTE : This function Should not be modified, when the callback is needed,
5901 the HAL_FDCAN_TT_TimeMarkCallback could be implemented in the user file
5906 * @brief TT Stop Watch callback.
5907 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5908 * the configuration information for the specified FDCAN.
5909 * @param SWTime Time Value captured at the Stop Watch Trigger pin (fdcan1_swt) falling/rising
5910 * edge (as configured via HAL_FDCAN_TTConfigStopWatch).
5911 * This parameter is a number between 0 and 0xFFFF.
5912 * @param SWCycleCount Cycle count value captured together with SWTime.
5913 * This parameter is a number between 0 and 0x3F.
5914 * @retval None
5916 __weak void HAL_FDCAN_TT_StopWatchCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t SWTime, uint32_t SWCycleCount)
5918 /* Prevent unused argument(s) compilation warning */
5919 UNUSED(hfdcan);
5920 UNUSED(SWTime);
5921 UNUSED(SWCycleCount);
5923 /* NOTE : This function Should not be modified, when the callback is needed,
5924 the HAL_FDCAN_TT_StopWatchCallback could be implemented in the user file
5929 * @brief TT Global Time callback.
5930 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5931 * the configuration information for the specified FDCAN.
5932 * @param TTGlobTimeITs indicates which TT Global Time interrupts are signaled.
5933 * This parameter can be any combination of @arg FDCAN_TTGlobalTime_Interrupts.
5934 * @retval None
5936 __weak void HAL_FDCAN_TT_GlobalTimeCallback(FDCAN_HandleTypeDef *hfdcan, uint32_t TTGlobTimeITs)
5938 /* Prevent unused argument(s) compilation warning */
5939 UNUSED(hfdcan);
5940 UNUSED(TTGlobTimeITs);
5942 /* NOTE : This function Should not be modified, when the callback is needed,
5943 the HAL_FDCAN_TT_GlobalTimeCallback could be implemented in the user file
5948 * @}
5951 /** @defgroup FDCAN_Exported_Functions_Group7 Peripheral State functions
5952 * @brief FDCAN Peripheral State functions
5954 @verbatim
5955 ==============================================================================
5956 ##### Peripheral State functions #####
5957 ==============================================================================
5958 [..]
5959 This subsection provides functions allowing to :
5960 (+) HAL_FDCAN_GetState() : Return the FDCAN state.
5961 (+) HAL_FDCAN_GetError() : Return the FDCAN error code if any.
5963 @endverbatim
5964 * @{
5967 * @brief Return the FDCAN state
5968 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5969 * the configuration information for the specified FDCAN.
5970 * @retval HAL state
5972 HAL_FDCAN_StateTypeDef HAL_FDCAN_GetState(FDCAN_HandleTypeDef *hfdcan)
5974 /* Return FDCAN state */
5975 return hfdcan->State;
5979 * @brief Return the FDCAN error code
5980 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
5981 * the configuration information for the specified FDCAN.
5982 * @retval FDCAN Error Code
5984 uint32_t HAL_FDCAN_GetError(FDCAN_HandleTypeDef *hfdcan)
5986 /* Return FDCAN error code */
5987 return hfdcan->ErrorCode;
5991 * @}
5995 * @}
5998 /** @addtogroup FDCAN_Private_Functions
5999 * @{
6003 * @brief Calculate each RAM block start address and size
6004 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
6005 * the configuration information for the specified FDCAN.
6006 * @retval HAL status
6008 static HAL_StatusTypeDef FDCAN_CalcultateRamBlockAddresses(FDCAN_HandleTypeDef *hfdcan)
6010 uint32_t RAMcounter;
6011 uint32_t StartAddress;
6013 StartAddress = hfdcan->Init.MessageRAMOffset;
6015 /* Standard filter list start address */
6016 MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_FLSSA, (StartAddress << FDCAN_SIDFC_FLSSA_Pos));
6018 /* Standard filter elements number */
6019 MODIFY_REG(hfdcan->Instance->SIDFC, FDCAN_SIDFC_LSS, (hfdcan->Init.StdFiltersNbr << FDCAN_SIDFC_LSS_Pos));
6021 /* Extended filter list start address */
6022 StartAddress += hfdcan->Init.StdFiltersNbr;
6023 MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_FLESA, (StartAddress << FDCAN_XIDFC_FLESA_Pos));
6025 /* Extended filter elements number */
6026 MODIFY_REG(hfdcan->Instance->XIDFC, FDCAN_XIDFC_LSE, (hfdcan->Init.ExtFiltersNbr << FDCAN_XIDFC_LSE_Pos));
6028 /* Rx FIFO 0 start address */
6029 StartAddress += (hfdcan->Init.ExtFiltersNbr * 2U);
6030 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0SA, (StartAddress << FDCAN_RXF0C_F0SA_Pos));
6032 /* Rx FIFO 0 elements number */
6033 MODIFY_REG(hfdcan->Instance->RXF0C, FDCAN_RXF0C_F0S, (hfdcan->Init.RxFifo0ElmtsNbr << FDCAN_RXF0C_F0S_Pos));
6035 /* Rx FIFO 1 start address */
6036 StartAddress += (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize);
6037 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1SA, (StartAddress << FDCAN_RXF1C_F1SA_Pos));
6039 /* Rx FIFO 1 elements number */
6040 MODIFY_REG(hfdcan->Instance->RXF1C, FDCAN_RXF1C_F1S, (hfdcan->Init.RxFifo1ElmtsNbr << FDCAN_RXF1C_F1S_Pos));
6042 /* Rx buffer list start address */
6043 StartAddress += (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize);
6044 MODIFY_REG(hfdcan->Instance->RXBC, FDCAN_RXBC_RBSA, (StartAddress << FDCAN_RXBC_RBSA_Pos));
6046 /* Tx event FIFO start address */
6047 StartAddress += (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize);
6048 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFSA, (StartAddress << FDCAN_TXEFC_EFSA_Pos));
6050 /* Tx event FIFO elements number */
6051 MODIFY_REG(hfdcan->Instance->TXEFC, FDCAN_TXEFC_EFS, (hfdcan->Init.TxEventsNbr << FDCAN_TXEFC_EFS_Pos));
6053 /* Tx buffer list start address */
6054 StartAddress += (hfdcan->Init.TxEventsNbr * 2U);
6055 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TBSA, (StartAddress << FDCAN_TXBC_TBSA_Pos));
6057 /* Dedicated Tx buffers number */
6058 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_NDTB, (hfdcan->Init.TxBuffersNbr << FDCAN_TXBC_NDTB_Pos));
6060 /* Tx FIFO/queue elements number */
6061 MODIFY_REG(hfdcan->Instance->TXBC, FDCAN_TXBC_TFQS, (hfdcan->Init.TxFifoQueueElmtsNbr << FDCAN_TXBC_TFQS_Pos));
6063 hfdcan->msgRam.StandardFilterSA = SRAMCAN_BASE + (hfdcan->Init.MessageRAMOffset * 4U);
6064 hfdcan->msgRam.ExtendedFilterSA = hfdcan->msgRam.StandardFilterSA + (hfdcan->Init.StdFiltersNbr * 4U);
6065 hfdcan->msgRam.RxFIFO0SA = hfdcan->msgRam.ExtendedFilterSA + (hfdcan->Init.ExtFiltersNbr * 2U * 4U);
6066 hfdcan->msgRam.RxFIFO1SA = hfdcan->msgRam.RxFIFO0SA + (hfdcan->Init.RxFifo0ElmtsNbr * hfdcan->Init.RxFifo0ElmtSize * 4U);
6067 hfdcan->msgRam.RxBufferSA = hfdcan->msgRam.RxFIFO1SA + (hfdcan->Init.RxFifo1ElmtsNbr * hfdcan->Init.RxFifo1ElmtSize * 4U);
6068 hfdcan->msgRam.TxEventFIFOSA = hfdcan->msgRam.RxBufferSA + (hfdcan->Init.RxBuffersNbr * hfdcan->Init.RxBufferSize * 4U);
6069 hfdcan->msgRam.TxBufferSA = hfdcan->msgRam.TxEventFIFOSA + (hfdcan->Init.TxEventsNbr * 2U * 4U);
6070 hfdcan->msgRam.TxFIFOQSA = hfdcan->msgRam.TxBufferSA + (hfdcan->Init.TxBuffersNbr * hfdcan->Init.TxElmtSize * 4U);
6072 hfdcan->msgRam.EndAddress = hfdcan->msgRam.TxFIFOQSA + (hfdcan->Init.TxFifoQueueElmtsNbr * hfdcan->Init.TxElmtSize * 4U);
6074 if (hfdcan->msgRam.EndAddress > FDCAN_MESSAGE_RAM_END_ADDRESS) /* Last address of the Message RAM */
6076 /* Update error code.
6077 Message RAM overflow */
6078 hfdcan->ErrorCode |= HAL_FDCAN_ERROR_PARAM;
6080 /* Change FDCAN state */
6081 hfdcan->State = HAL_FDCAN_STATE_ERROR;
6083 return HAL_ERROR;
6085 else
6087 /* Flush the allocated Message RAM area */
6088 for (RAMcounter = hfdcan->msgRam.StandardFilterSA; RAMcounter < hfdcan->msgRam.EndAddress; RAMcounter += 4U)
6090 *(uint32_t *)(RAMcounter) = 0x00000000;
6094 /* Return function status */
6095 return HAL_OK;
6099 * @brief Copy Tx message to the message RAM.
6100 * @param hfdcan pointer to an FDCAN_HandleTypeDef structure that contains
6101 * the configuration information for the specified FDCAN.
6102 * @param pTxHeader pointer to a FDCAN_TxHeaderTypeDef structure.
6103 * @param pTxData pointer to a buffer containing the payload of the Tx frame.
6104 * @param BufferIndex index of the buffer to be configured.
6105 * @retval HAL status
6107 static void FDCAN_CopyMessageToRAM(FDCAN_HandleTypeDef *hfdcan, FDCAN_TxHeaderTypeDef *pTxHeader, uint8_t *pTxData, uint32_t BufferIndex)
6109 uint32_t TxElementW1;
6110 uint32_t TxElementW2;
6111 uint32_t *TxAddress;
6112 uint32_t ByteCounter;
6114 /* Build first word of Tx header element */
6115 if (pTxHeader->IdType == FDCAN_STANDARD_ID)
6117 TxElementW1 = (pTxHeader->ErrorStateIndicator |
6118 FDCAN_STANDARD_ID |
6119 pTxHeader->TxFrameType |
6120 (pTxHeader->Identifier << 18));
6122 else /* pTxHeader->IdType == FDCAN_EXTENDED_ID */
6124 TxElementW1 = (pTxHeader->ErrorStateIndicator |
6125 FDCAN_EXTENDED_ID |
6126 pTxHeader->TxFrameType |
6127 pTxHeader->Identifier);
6130 /* Build second word of Tx header element */
6131 TxElementW2 = ((pTxHeader->MessageMarker << 24) |
6132 pTxHeader->TxEventFifoControl |
6133 pTxHeader->FDFormat |
6134 pTxHeader->BitRateSwitch |
6135 pTxHeader->DataLength);
6137 /* Calculate Tx element address */
6138 TxAddress = (uint32_t *)(hfdcan->msgRam.TxBufferSA + (BufferIndex * hfdcan->Init.TxElmtSize * 4U));
6140 /* Write Tx element header to the message RAM */
6141 *TxAddress = TxElementW1;
6142 TxAddress++;
6143 *TxAddress = TxElementW2;
6144 TxAddress++;
6146 /* Write Tx payload to the message RAM */
6147 for (ByteCounter = 0; ByteCounter < DLCtoBytes[pTxHeader->DataLength >> 16]; ByteCounter += 4U)
6149 *TxAddress = (((uint32_t)pTxData[ByteCounter + 3U] << 24) |
6150 ((uint32_t)pTxData[ByteCounter + 2U] << 16) |
6151 ((uint32_t)pTxData[ByteCounter + 1U] << 8) |
6152 (uint32_t)pTxData[ByteCounter]);
6153 TxAddress++;
6158 * @}
6160 #endif /* HAL_FDCAN_MODULE_ENABLED */
6162 * @}
6166 * @}
6169 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/