2 ******************************************************************************
3 * @file stm32f0xx_hal_can.c
4 * @author MCD Application Team
6 * @date 11-December-2014
7 * @brief CAN HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the Controller Area Network (CAN) peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral Control functions
13 * + Peripheral State and Error functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 (#) Enable the CAN controller interface clock using __CAN_CLK_ENABLE();
22 (#) CAN pins configuration
23 (++) Enable the clock for the CAN GPIOs using the following function:
25 (++) Connect and configure the involved CAN pins to AF9 using the
26 following function HAL_GPIO_Init();
28 (#) Initialise and configure the CAN using HAL_CAN_Init() function.
30 (#) Transmit the desired CAN frame using HAL_CAN_Transmit() function.
32 (#) Receive a CAN frame using HAL_CAN_Receive() function.
34 *** Polling mode IO operation ***
35 =================================
37 (+) Start the CAN peripheral transmission and wait the end of this operation
38 using HAL_CAN_Transmit(), at this stage user can specify the value of timeout
39 according to his end application
40 (+) Start the CAN peripheral reception and wait the end of this operation
41 using HAL_CAN_Receive(), at this stage user can specify the value of timeout
42 according to his end application
44 *** Interrupt mode IO operation ***
45 ===================================
47 (+) Start the CAN peripheral transmission using HAL_CAN_Transmit_IT()
48 (+) Start the CAN peripheral reception using HAL_CAN_Receive_IT()
49 (+) Use HAL_CAN_IRQHandler() called under the used CAN Interrupt subroutine
50 (+) At CAN end of transmission HAL_CAN_TxCpltCallback() function is executed and user can
51 add his own code by customization of function pointer HAL_CAN_TxCpltCallback
52 (+) In case of CAN Error, HAL_CAN_ErrorCallback() function is executed and user can
53 add his own code by customization of function pointer HAL_CAN_ErrorCallback
55 *** CAN HAL driver macros list ***
56 =============================================
58 Below the list of most used macros in CAN HAL driver.
60 (+) __HAL_CAN_ENABLE_IT: Enable the specified CAN interrupts
61 (+) __HAL_CAN_DISABLE_IT: Disable the specified CAN interrupts
62 (+) __HAL_CAN_GET_IT_SOURCE: Check if the specified CAN interrupt source is enabled or disabled
63 (+) __HAL_CAN_CLEAR_FLAG: Clear the CAN's pending flags
64 (+) __HAL_CAN_GET_FLAG: Get the selected CAN's flag status
67 (@) You can refer to the CAN HAL driver header file for more useful macros
71 ******************************************************************************
74 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
76 * Redistribution and use in source and binary forms, with or without modification,
77 * are permitted provided that the following conditions are met:
78 * 1. Redistributions of source code must retain the above copyright notice,
79 * this list of conditions and the following disclaimer.
80 * 2. Redistributions in binary form must reproduce the above copyright notice,
81 * this list of conditions and the following disclaimer in the documentation
82 * and/or other materials provided with the distribution.
83 * 3. Neither the name of STMicroelectronics nor the names of its contributors
84 * may be used to endorse or promote products derived from this software
85 * without specific prior written permission.
87 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
90 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
91 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
92 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
93 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
94 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
95 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
96 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
98 ******************************************************************************
101 /* Includes ------------------------------------------------------------------*/
102 #include "stm32f0xx_hal.h"
104 #ifdef HAL_CAN_MODULE_ENABLED
106 #if defined(STM32F072xB) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F091xC) || defined(STM32F098xx)
108 /** @addtogroup STM32F0xx_HAL_Driver
112 /** @defgroup CAN CAN HAL Module Driver
113 * @brief CAN driver modules
117 /* Private typedef -----------------------------------------------------------*/
118 /* Private define ------------------------------------------------------------*/
119 /** @defgroup CAN_Private_Constants CAN Private Constants
122 #define HAL_CAN_DEFAULT_TIMEOUT 10
126 /* Private macro -------------------------------------------------------------*/
127 /* Private variables ---------------------------------------------------------*/
128 /* Private function prototypes -----------------------------------------------*/
129 /** @defgroup CAN_Private_Functions CAN Private Functions
132 static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber);
133 static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan);
138 /* Exported functions ---------------------------------------------------------*/
140 /** @defgroup CAN_Exported_Functions CAN Exported Functions
144 /** @defgroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions
145 * @brief Initialization and Configuration functions
148 ==============================================================================
149 ##### Initialization and de-initialization functions #####
150 ==============================================================================
151 [..] This section provides functions allowing to:
152 (+) Initialize and configure the CAN.
153 (+) De-initialize the CAN.
160 * @brief Initializes the CAN peripheral according to the specified
161 * parameters in the CAN_InitStruct.
162 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
163 * the configuration information for the specified CAN.
166 HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan)
168 uint32_t status = CAN_INITSTATUS_FAILED; /* Default init status */
169 uint32_t tickstart = 0;
171 /* Check CAN handle */
177 /* Check the parameters */
178 assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance));
179 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TTCM));
180 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ABOM));
181 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AWUM));
182 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.NART));
183 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.RFLM));
184 assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TXFP));
185 assert_param(IS_CAN_MODE(hcan->Init.Mode));
186 assert_param(IS_CAN_SJW(hcan->Init.SJW));
187 assert_param(IS_CAN_BS1(hcan->Init.BS1));
188 assert_param(IS_CAN_BS2(hcan->Init.BS2));
189 assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler));
191 if(hcan->State == HAL_CAN_STATE_RESET)
193 /* Init the low level hardware */
194 HAL_CAN_MspInit(hcan);
197 /* Initialize the CAN state*/
198 hcan->State = HAL_CAN_STATE_BUSY;
200 /* Exit from sleep mode */
201 hcan->Instance->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
203 /* Request initialisation */
204 hcan->Instance->MCR |= CAN_MCR_INRQ ;
207 tickstart = HAL_GetTick();
209 /* Wait the acknowledge */
210 while((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
212 if((HAL_GetTick() - tickstart) > HAL_CAN_DEFAULT_TIMEOUT)
214 hcan->State= HAL_CAN_STATE_TIMEOUT;
219 /* Check acknowledge */
220 if ((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
222 /* Set the time triggered communication mode */
223 if (hcan->Init.TTCM == ENABLE)
225 hcan->Instance->MCR |= CAN_MCR_TTCM;
229 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TTCM;
232 /* Set the automatic bus-off management */
233 if (hcan->Init.ABOM == ENABLE)
235 hcan->Instance->MCR |= CAN_MCR_ABOM;
239 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_ABOM;
242 /* Set the automatic wake-up mode */
243 if (hcan->Init.AWUM == ENABLE)
245 hcan->Instance->MCR |= CAN_MCR_AWUM;
249 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_AWUM;
252 /* Set the no automatic retransmission */
253 if (hcan->Init.NART == ENABLE)
255 hcan->Instance->MCR |= CAN_MCR_NART;
259 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_NART;
262 /* Set the receive FIFO locked mode */
263 if (hcan->Init.RFLM == ENABLE)
265 hcan->Instance->MCR |= CAN_MCR_RFLM;
269 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_RFLM;
272 /* Set the transmit FIFO priority */
273 if (hcan->Init.TXFP == ENABLE)
275 hcan->Instance->MCR |= CAN_MCR_TXFP;
279 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TXFP;
282 /* Set the bit timing register */
283 hcan->Instance->BTR = (uint32_t)((uint32_t)hcan->Init.Mode) | \
284 ((uint32_t)hcan->Init.SJW) | \
285 ((uint32_t)hcan->Init.BS1) | \
286 ((uint32_t)hcan->Init.BS2) | \
287 ((uint32_t)hcan->Init.Prescaler - 1);
289 /* Request leave initialisation */
290 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ;
293 tickstart = HAL_GetTick();
295 /* Wait the acknowledge */
296 while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
298 if((HAL_GetTick() - tickstart) > HAL_CAN_DEFAULT_TIMEOUT)
300 hcan->State= HAL_CAN_STATE_TIMEOUT;
305 /* Check acknowledged */
306 if ((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
308 status = CAN_INITSTATUS_SUCCESS;
312 if(status == CAN_INITSTATUS_SUCCESS)
314 /* Set CAN error code to none */
315 hcan->ErrorCode = HAL_CAN_ERROR_NONE;
317 /* Initialize the CAN state */
318 hcan->State = HAL_CAN_STATE_READY;
320 /* Return function status */
325 /* Initialize the CAN state */
326 hcan->State = HAL_CAN_STATE_ERROR;
328 /* Return function status */
334 * @brief Configures the CAN reception filter according to the specified
335 * parameters in the CAN_FilterInitStruct.
336 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
337 * the configuration information for the specified CAN.
338 * @param sFilterConfig: pointer to a CAN_FilterConfTypeDef structure that
339 * contains the filter configuration information.
342 HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig)
344 uint32_t filternbrbitpos = 0;
346 /* Check the parameters */
347 assert_param(IS_CAN_FILTER_NUMBER(sFilterConfig->FilterNumber));
348 assert_param(IS_CAN_FILTER_MODE(sFilterConfig->FilterMode));
349 assert_param(IS_CAN_FILTER_SCALE(sFilterConfig->FilterScale));
350 assert_param(IS_CAN_FILTER_FIFO(sFilterConfig->FilterFIFOAssignment));
351 assert_param(IS_FUNCTIONAL_STATE(sFilterConfig->FilterActivation));
352 assert_param(IS_CAN_BANKNUMBER(sFilterConfig->BankNumber));
354 filternbrbitpos = ((uint32_t)1) << sFilterConfig->FilterNumber;
356 /* Initialisation mode for the filter */
357 hcan->Instance->FMR |= (uint32_t)CAN_FMR_FINIT;
359 /* Filter Deactivation */
360 hcan->Instance->FA1R &= ~(uint32_t)filternbrbitpos;
363 if (sFilterConfig->FilterScale == CAN_FILTERSCALE_16BIT)
365 /* 16-bit scale for the filter */
366 hcan->Instance->FS1R &= ~(uint32_t)filternbrbitpos;
368 /* First 16-bit identifier and First 16-bit mask */
369 /* Or First 16-bit identifier and Second 16-bit identifier */
370 hcan->Instance->sFilterRegister[sFilterConfig->FilterNumber].FR1 =
371 ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdLow) << 16) |
372 (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdLow);
374 /* Second 16-bit identifier and Second 16-bit mask */
375 /* Or Third 16-bit identifier and Fourth 16-bit identifier */
376 hcan->Instance->sFilterRegister[sFilterConfig->FilterNumber].FR2 =
377 ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16) |
378 (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdHigh);
381 if (sFilterConfig->FilterScale == CAN_FILTERSCALE_32BIT)
383 /* 32-bit scale for the filter */
384 hcan->Instance->FS1R |= filternbrbitpos;
385 /* 32-bit identifier or First 32-bit identifier */
386 hcan->Instance->sFilterRegister[sFilterConfig->FilterNumber].FR1 =
387 ((0x0000FFFF & (uint32_t)sFilterConfig->FilterIdHigh) << 16) |
388 (0x0000FFFF & (uint32_t)sFilterConfig->FilterIdLow);
389 /* 32-bit mask or Second 32-bit identifier */
390 hcan->Instance->sFilterRegister[sFilterConfig->FilterNumber].FR2 =
391 ((0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16) |
392 (0x0000FFFF & (uint32_t)sFilterConfig->FilterMaskIdLow);
396 if (sFilterConfig->FilterMode == CAN_FILTERMODE_IDMASK)
398 /*Id/Mask mode for the filter*/
399 hcan->Instance->FM1R &= ~(uint32_t)filternbrbitpos;
401 else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
403 /*Identifier list mode for the filter*/
404 hcan->Instance->FM1R |= (uint32_t)filternbrbitpos;
407 /* Filter FIFO assignment */
408 if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO0)
410 /* FIFO 0 assignation for the filter */
411 hcan->Instance->FFA1R &= ~(uint32_t)filternbrbitpos;
414 if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO1)
416 /* FIFO 1 assignation for the filter */
417 hcan->Instance->FFA1R |= (uint32_t)filternbrbitpos;
420 /* Filter activation */
421 if (sFilterConfig->FilterActivation == ENABLE)
423 hcan->Instance->FA1R |= filternbrbitpos;
426 /* Leave the initialisation mode for the filter */
427 hcan->Instance->FMR &= ~((uint32_t)CAN_FMR_FINIT);
429 /* Return function status */
434 * @brief Deinitializes the CANx peripheral registers to their default reset values.
435 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
436 * the configuration information for the specified CAN.
439 HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan)
441 /* Check CAN handle */
447 /* Check the parameters */
448 assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance));
450 /* Change CAN state */
451 hcan->State = HAL_CAN_STATE_BUSY;
453 /* DeInit the low level hardware */
454 HAL_CAN_MspDeInit(hcan);
456 /* Change CAN state */
457 hcan->State = HAL_CAN_STATE_RESET;
462 /* Return function status */
467 * @brief Initializes the CAN MSP.
468 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
469 * the configuration information for the specified CAN.
472 __weak void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan)
474 /* NOTE : This function Should not be modified, when the callback is needed,
475 the HAL_CAN_MspInit could be implemented in the user file
480 * @brief DeInitializes the CAN MSP.
481 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
482 * the configuration information for the specified CAN.
485 __weak void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan)
487 /* NOTE : This function Should not be modified, when the callback is needed,
488 the HAL_CAN_MspDeInit could be implemented in the user file
496 /** @defgroup CAN_Exported_Functions_Group2 I/O operation functions
497 * @brief I/O operation functions
500 ==============================================================================
501 ##### IO operation functions #####
502 ==============================================================================
503 [..] This section provides functions allowing to:
504 (+) Transmit a CAN frame message.
505 (+) Receive a CAN frame message.
506 (+) Enter CAN peripheral in sleep mode.
507 (+) Wake up the CAN peripheral from sleep mode.
514 * @brief Initiates and transmits a CAN frame message.
515 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
516 * the configuration information for the specified CAN.
517 * @param Timeout: Timeout duration.
520 HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef* hcan, uint32_t Timeout)
522 uint32_t transmitmailbox = CAN_TXSTATUS_NOMAILBOX;
523 uint32_t tickstart = 0;
525 /* Check the parameters */
526 assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE));
527 assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR));
528 assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC));
533 if(hcan->State == HAL_CAN_STATE_BUSY_RX)
535 /* Change CAN state */
536 hcan->State = HAL_CAN_STATE_BUSY_TX_RX;
540 /* Change CAN state */
541 hcan->State = HAL_CAN_STATE_BUSY_TX;
544 /* Select one empty transmit mailbox */
545 if ((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
549 else if ((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
553 else if ((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
558 if (transmitmailbox != CAN_TXSTATUS_NOMAILBOX)
561 hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ;
562 if (hcan->pTxMsg->IDE == CAN_ID_STD)
564 assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId));
565 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21) | \
570 assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId));
571 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3) | \
572 hcan->pTxMsg->IDE | \
577 hcan->pTxMsg->DLC &= (uint8_t)0x0000000F;
578 hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0;
579 hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC;
581 /* Set up the data field */
582 hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3] << 24) |
583 ((uint32_t)hcan->pTxMsg->Data[2] << 16) |
584 ((uint32_t)hcan->pTxMsg->Data[1] << 8) |
585 ((uint32_t)hcan->pTxMsg->Data[0]));
586 hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7] << 24) |
587 ((uint32_t)hcan->pTxMsg->Data[6] << 16) |
588 ((uint32_t)hcan->pTxMsg->Data[5] << 8) |
589 ((uint32_t)hcan->pTxMsg->Data[4]));
590 /* Request transmission */
591 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ;
594 tickstart = HAL_GetTick();
596 /* Check End of transmission flag */
597 while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox)))
599 /* Check for the Timeout */
600 if(Timeout != HAL_MAX_DELAY)
602 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
604 hcan->State = HAL_CAN_STATE_TIMEOUT;
605 /* Process unlocked */
611 if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX)
613 /* Change CAN state */
614 hcan->State = HAL_CAN_STATE_BUSY_RX;
618 /* Change CAN state */
619 hcan->State = HAL_CAN_STATE_READY;
622 /* Process unlocked */
625 /* Return function status */
630 /* Change CAN state */
631 hcan->State = HAL_CAN_STATE_ERROR;
633 /* Process unlocked */
636 /* Return function status */
642 * @brief Initiates and transmits a CAN frame message.
643 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
644 * the configuration information for the specified CAN.
647 HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef* hcan)
649 uint32_t transmitmailbox = CAN_TXSTATUS_NOMAILBOX;
651 /* Check the parameters */
652 assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE));
653 assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR));
654 assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC));
656 if((hcan->State == HAL_CAN_STATE_READY) || (hcan->State == HAL_CAN_STATE_BUSY_RX))
661 /* Select one empty transmit mailbox */
662 if((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
666 else if((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
670 else if((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
675 if(transmitmailbox != CAN_TXSTATUS_NOMAILBOX)
678 hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ;
679 if(hcan->pTxMsg->IDE == CAN_ID_STD)
681 assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId));
682 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21) | \
687 assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId));
688 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3) | \
689 hcan->pTxMsg->IDE | \
694 hcan->pTxMsg->DLC &= (uint8_t)0x0000000F;
695 hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0;
696 hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC;
698 /* Set up the data field */
699 hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3] << 24) |
700 ((uint32_t)hcan->pTxMsg->Data[2] << 16) |
701 ((uint32_t)hcan->pTxMsg->Data[1] << 8) |
702 ((uint32_t)hcan->pTxMsg->Data[0]));
703 hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7] << 24) |
704 ((uint32_t)hcan->pTxMsg->Data[6] << 16) |
705 ((uint32_t)hcan->pTxMsg->Data[5] << 8) |
706 ((uint32_t)hcan->pTxMsg->Data[4]));
708 if(hcan->State == HAL_CAN_STATE_BUSY_RX)
710 /* Change CAN state */
711 hcan->State = HAL_CAN_STATE_BUSY_TX_RX;
715 /* Change CAN state */
716 hcan->State = HAL_CAN_STATE_BUSY_TX;
719 /* Set CAN error code to none */
720 hcan->ErrorCode = HAL_CAN_ERROR_NONE;
722 /* Process Unlocked */
725 /* Enable Error warning Interrupt */
726 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG);
728 /* Enable Error passive Interrupt */
729 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV);
731 /* Enable Bus-off Interrupt */
732 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF);
734 /* Enable Last error code Interrupt */
735 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC);
737 /* Enable Error Interrupt */
738 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR);
740 /* Enable Transmit mailbox empty Interrupt */
741 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME);
743 /* Request transmission */
744 hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ;
756 * @brief Receives a correct CAN frame.
757 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
758 * the configuration information for the specified CAN.
759 * @param FIFONumber: FIFO number.
760 * @param Timeout: Timeout duration.
764 HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef* hcan, uint8_t FIFONumber, uint32_t Timeout)
766 uint32_t tickstart = 0;
768 /* Check the parameters */
769 assert_param(IS_CAN_FIFO(FIFONumber));
774 if(hcan->State == HAL_CAN_STATE_BUSY_TX)
776 /* Change CAN state */
777 hcan->State = HAL_CAN_STATE_BUSY_TX_RX;
781 /* Change CAN state */
782 hcan->State = HAL_CAN_STATE_BUSY_RX;
786 tickstart = HAL_GetTick();
788 /* Check pending message */
789 while(__HAL_CAN_MSG_PENDING(hcan, FIFONumber) == 0)
791 /* Check for the Timeout */
792 if(Timeout != HAL_MAX_DELAY)
794 if((Timeout == 0) || ((HAL_GetTick() - tickstart) > Timeout))
796 hcan->State = HAL_CAN_STATE_TIMEOUT;
797 /* Process unlocked */
805 hcan->pRxMsg->IDE = (uint8_t)0x04 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR;
806 if (hcan->pRxMsg->IDE == CAN_ID_STD)
808 hcan->pRxMsg->StdId = (uint32_t)0x000007FF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21);
812 hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3);
815 hcan->pRxMsg->RTR = (uint8_t)0x02 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR;
817 hcan->pRxMsg->DLC = (uint8_t)0x0F & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR;
819 hcan->pRxMsg->FMI = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8);
820 /* Get the data field */
821 hcan->pRxMsg->Data[0] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR;
822 hcan->pRxMsg->Data[1] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8);
823 hcan->pRxMsg->Data[2] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16);
824 hcan->pRxMsg->Data[3] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24);
825 hcan->pRxMsg->Data[4] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR;
826 hcan->pRxMsg->Data[5] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8);
827 hcan->pRxMsg->Data[6] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16);
828 hcan->pRxMsg->Data[7] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24);
830 /* Release the FIFO */
831 if(FIFONumber == CAN_FIFO0)
834 __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0);
836 else /* FIFONumber == CAN_FIFO1 */
839 __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1);
842 if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX)
844 /* Change CAN state */
845 hcan->State = HAL_CAN_STATE_BUSY_TX;
849 /* Change CAN state */
850 hcan->State = HAL_CAN_STATE_READY;
853 /* Process unlocked */
856 /* Return function status */
861 * @brief Receives a correct CAN frame.
862 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
863 * the configuration information for the specified CAN.
864 * @param FIFONumber: FIFO number.
868 HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber)
870 /* Check the parameters */
871 assert_param(IS_CAN_FIFO(FIFONumber));
873 if((hcan->State == HAL_CAN_STATE_READY) || (hcan->State == HAL_CAN_STATE_BUSY_TX))
878 if(hcan->State == HAL_CAN_STATE_BUSY_TX)
880 /* Change CAN state */
881 hcan->State = HAL_CAN_STATE_BUSY_TX_RX;
885 /* Change CAN state */
886 hcan->State = HAL_CAN_STATE_BUSY_RX;
889 /* Set CAN error code to none */
890 hcan->ErrorCode = HAL_CAN_ERROR_NONE;
892 /* Enable Error warning Interrupt */
893 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG);
895 /* Enable Error passive Interrupt */
896 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV);
898 /* Enable Bus-off Interrupt */
899 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF);
901 /* Enable Last error code Interrupt */
902 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC);
904 /* Enable Error Interrupt */
905 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR);
907 /* Process unlocked */
910 if(FIFONumber == CAN_FIFO0)
912 /* Enable FIFO 0 message pending Interrupt */
913 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0);
917 /* Enable FIFO 1 message pending Interrupt */
918 __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP1);
927 /* Return function status */
932 * @brief Enters the Sleep (low power) mode.
933 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
934 * the configuration information for the specified CAN.
935 * @retval HAL status.
937 HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef* hcan)
939 uint32_t tickstart = 0;
944 /* Change CAN state */
945 hcan->State = HAL_CAN_STATE_BUSY;
947 /* Request Sleep mode */
948 hcan->Instance->MCR = (((hcan->Instance->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
950 /* Sleep mode status */
951 if ((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK)
953 /* Process unlocked */
956 /* Return function status */
961 tickstart = HAL_GetTick();
963 /* Wait the acknowledge */
964 while((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK)
966 if((HAL_GetTick() - tickstart) > HAL_CAN_DEFAULT_TIMEOUT)
968 hcan->State = HAL_CAN_STATE_TIMEOUT;
969 /* Process unlocked */
975 /* Change CAN state */
976 hcan->State = HAL_CAN_STATE_READY;
978 /* Process unlocked */
981 /* Return function status */
986 * @brief Wakes up the CAN peripheral from sleep mode, after that the CAN peripheral
987 * is in the normal mode.
988 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
989 * the configuration information for the specified CAN.
990 * @retval HAL status.
992 HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef* hcan)
994 uint32_t tickstart = 0;
999 /* Change CAN state */
1000 hcan->State = HAL_CAN_STATE_BUSY;
1002 /* Wake up request */
1003 hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_SLEEP;
1006 tickstart = HAL_GetTick();
1008 /* Sleep mode status */
1009 while((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)
1011 if((HAL_GetTick() - tickstart) > HAL_CAN_DEFAULT_TIMEOUT)
1013 hcan->State= HAL_CAN_STATE_TIMEOUT;
1014 /* Process unlocked */
1019 if((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)
1021 /* Process unlocked */
1024 /* Return function status */
1028 /* Change CAN state */
1029 hcan->State = HAL_CAN_STATE_READY;
1031 /* Process unlocked */
1034 /* Return function status */
1039 * @brief Handles CAN interrupt request
1040 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1041 * the configuration information for the specified CAN.
1044 void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan)
1046 /* Check End of transmission flag */
1047 if(__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_TME))
1049 if((__HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_0)) ||
1050 (__HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_1)) ||
1051 (__HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_2)))
1053 /* Call transmit function */
1054 CAN_Transmit_IT(hcan);
1058 /* Check End of reception flag for FIFO0 */
1059 if((__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP0)) &&
1060 (__HAL_CAN_MSG_PENDING(hcan, CAN_FIFO0) != 0))
1062 /* Call receive function */
1063 CAN_Receive_IT(hcan, CAN_FIFO0);
1066 /* Check End of reception flag for FIFO1 */
1067 if((__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP1)) &&
1068 (__HAL_CAN_MSG_PENDING(hcan, CAN_FIFO1) != 0))
1070 /* Call receive function */
1071 CAN_Receive_IT(hcan, CAN_FIFO1);
1074 /* Check Error Warning Flag */
1075 if((__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EWG)) &&
1076 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EWG)) &&
1077 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR)))
1079 /* Set CAN error code to EWG error */
1080 hcan->ErrorCode |= HAL_CAN_ERROR_EWG;
1081 /* No need for clear of Error Warning Flag as read-only */
1084 /* Check Error Passive Flag */
1085 if((__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EPV)) &&
1086 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EPV)) &&
1087 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR)))
1089 /* Set CAN error code to EPV error */
1090 hcan->ErrorCode |= HAL_CAN_ERROR_EPV;
1091 /* No need for clear of Error Passive Flag as read-only */
1094 /* Check Bus-Off Flag */
1095 if((__HAL_CAN_GET_FLAG(hcan, CAN_FLAG_BOF)) &&
1096 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_BOF)) &&
1097 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR)))
1099 /* Set CAN error code to BOF error */
1100 hcan->ErrorCode |= HAL_CAN_ERROR_BOF;
1101 /* No need for clear of Bus-Off Flag as read-only */
1104 /* Check Last error code Flag */
1105 if((!HAL_IS_BIT_CLR(hcan->Instance->ESR, CAN_ESR_LEC)) &&
1106 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_LEC)) &&
1107 (__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR)))
1109 switch(hcan->Instance->ESR & CAN_ESR_LEC)
1111 case(CAN_ESR_LEC_0):
1112 /* Set CAN error code to STF error */
1113 hcan->ErrorCode |= HAL_CAN_ERROR_STF;
1115 case(CAN_ESR_LEC_1):
1116 /* Set CAN error code to FOR error */
1117 hcan->ErrorCode |= HAL_CAN_ERROR_FOR;
1119 case(CAN_ESR_LEC_1 | CAN_ESR_LEC_0):
1120 /* Set CAN error code to ACK error */
1121 hcan->ErrorCode |= HAL_CAN_ERROR_ACK;
1123 case(CAN_ESR_LEC_2):
1124 /* Set CAN error code to BR error */
1125 hcan->ErrorCode |= HAL_CAN_ERROR_BR;
1127 case(CAN_ESR_LEC_2 | CAN_ESR_LEC_0):
1128 /* Set CAN error code to BD error */
1129 hcan->ErrorCode |= HAL_CAN_ERROR_BD;
1131 case(CAN_ESR_LEC_2 | CAN_ESR_LEC_1):
1132 /* Set CAN error code to CRC error */
1133 hcan->ErrorCode |= HAL_CAN_ERROR_CRC;
1139 /* Clear Last error code Flag */
1140 hcan->Instance->ESR &= ~(CAN_ESR_LEC);
1143 /* Call the Error call Back in case of Errors */
1144 if(hcan->ErrorCode != HAL_CAN_ERROR_NONE)
1146 /* Set the CAN state ready to be able to start again the process */
1147 hcan->State = HAL_CAN_STATE_READY;
1148 /* Call Error callback function */
1149 HAL_CAN_ErrorCallback(hcan);
1154 * @brief Transmission complete callback in non blocking mode
1155 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1156 * the configuration information for the specified CAN.
1159 __weak void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan)
1161 /* NOTE : This function Should not be modified, when the callback is needed,
1162 the HAL_CAN_TxCpltCallback could be implemented in the user file
1167 * @brief Transmission complete callback in non blocking mode
1168 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1169 * the configuration information for the specified CAN.
1172 __weak void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan)
1174 /* NOTE : This function Should not be modified, when the callback is needed,
1175 the HAL_CAN_RxCpltCallback could be implemented in the user file
1180 * @brief Error CAN callback.
1181 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1182 * the configuration information for the specified CAN.
1185 __weak void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan)
1187 /* NOTE : This function Should not be modified, when the callback is needed,
1188 the HAL_CAN_ErrorCallback could be implemented in the user file
1196 /** @defgroup CAN_Exported_Functions_Group3 Peripheral State and Error functions
1197 * @brief CAN Peripheral State functions
1200 ==============================================================================
1201 ##### Peripheral State and Error functions #####
1202 ==============================================================================
1204 This subsection provides functions allowing to :
1205 (+) Check the CAN state.
1206 (+) Check CAN Errors detected during interrupt process
1213 * @brief return the CAN state
1214 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1215 * the configuration information for the specified CAN.
1218 HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan)
1220 /* Return CAN state */
1225 * @brief Return the CAN error code
1226 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1227 * the configuration information for the specified CAN.
1228 * @retval CAN Error Code
1230 uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan)
1232 return hcan->ErrorCode;
1243 /** @addtogroup CAN_Private_Functions CAN Private Functions
1244 * @brief CAN Frame message Rx/Tx functions
1250 * @brief Initiates and transmits a CAN frame message.
1251 * @param hcan: pointer to a CAN_HandleTypeDef structure that contains
1252 * the configuration information for the specified CAN.
1253 * @retval HAL status
1255 static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan)
1257 /* Disable Transmit mailbox empty Interrupt */
1258 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_TME);
1260 if(hcan->State == HAL_CAN_STATE_BUSY_TX)
1262 /* Disable Error warning Interrupt */
1263 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG);
1265 /* Disable Error passive Interrupt */
1266 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV);
1268 /* Disable Bus-off Interrupt */
1269 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF);
1271 /* Disable Last error code Interrupt */
1272 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC);
1274 /* Disable Error Interrupt */
1275 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR);
1278 if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX)
1280 /* Change CAN state */
1281 hcan->State = HAL_CAN_STATE_BUSY_RX;
1285 /* Change CAN state */
1286 hcan->State = HAL_CAN_STATE_READY;
1289 /* Transmission complete callback */
1290 HAL_CAN_TxCpltCallback(hcan);
1296 * @brief Receives a correct CAN frame.
1297 * @param hcan: Pointer to a CAN_HandleTypeDef structure that contains
1298 * the configuration information for the specified CAN.
1299 * @param FIFONumber: Specify the FIFO number
1300 * @retval HAL status
1303 static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber)
1306 hcan->pRxMsg->IDE = (uint8_t)0x04 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR;
1307 if (hcan->pRxMsg->IDE == CAN_ID_STD)
1309 hcan->pRxMsg->StdId = (uint32_t)0x000007FF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21);
1313 hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3);
1316 hcan->pRxMsg->RTR = (uint8_t)0x02 & hcan->Instance->sFIFOMailBox[FIFONumber].RIR;
1318 hcan->pRxMsg->DLC = (uint8_t)0x0F & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR;
1320 hcan->pRxMsg->FMI = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8);
1321 /* Get the data field */
1322 hcan->pRxMsg->Data[0] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR;
1323 hcan->pRxMsg->Data[1] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8);
1324 hcan->pRxMsg->Data[2] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16);
1325 hcan->pRxMsg->Data[3] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24);
1326 hcan->pRxMsg->Data[4] = (uint8_t)0xFF & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR;
1327 hcan->pRxMsg->Data[5] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8);
1328 hcan->pRxMsg->Data[6] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16);
1329 hcan->pRxMsg->Data[7] = (uint8_t)0xFF & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24);
1330 /* Release the FIFO */
1332 if (FIFONumber == CAN_FIFO0)
1334 __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0);
1336 /* Disable FIFO 0 message pending Interrupt */
1337 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP0);
1340 else /* FIFONumber == CAN_FIFO1 */
1342 __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1);
1344 /* Disable FIFO 1 message pending Interrupt */
1345 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP1);
1348 if(hcan->State == HAL_CAN_STATE_BUSY_RX)
1350 /* Disable Error warning Interrupt */
1351 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG);
1353 /* Disable Error passive Interrupt */
1354 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV);
1356 /* Disable Bus-off Interrupt */
1357 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF);
1359 /* Disable Last error code Interrupt */
1360 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC);
1362 /* Disable Error Interrupt */
1363 __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR);
1366 if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX)
1368 /* Disable CAN state */
1369 hcan->State = HAL_CAN_STATE_BUSY_TX;
1373 /* Change CAN state */
1374 hcan->State = HAL_CAN_STATE_READY;
1377 /* Receive complete callback */
1378 HAL_CAN_RxCpltCallback(hcan);
1380 /* Return function status */
1396 #endif /* defined(STM32F072xB) || defined(STM32F042x6) || defined(STM32F048xx) || defined(STM32F091xC) || defined(STM32F098xx) */
1398 #endif /* HAL_CAN_MODULE_ENABLED */
1400 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/