Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_can.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f4xx_hal_can.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.5.0 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 06-May-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 8 | * functionalities of the Controller Area Network (CAN) peripheral: |
sahilmgandhi | 18:6a4db94011d3 | 9 | * + Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 10 | * + IO operation functions |
sahilmgandhi | 18:6a4db94011d3 | 11 | * + Peripheral Control functions |
sahilmgandhi | 18:6a4db94011d3 | 12 | * + Peripheral State and Error functions |
sahilmgandhi | 18:6a4db94011d3 | 13 | * |
sahilmgandhi | 18:6a4db94011d3 | 14 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 15 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 16 | ##### How to use this driver ##### |
sahilmgandhi | 18:6a4db94011d3 | 17 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 18 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 19 | (#) Enable the CAN controller interface clock using |
sahilmgandhi | 18:6a4db94011d3 | 20 | __HAL_RCC_CAN1_CLK_ENABLE() for CAN1 and __HAL_RCC_CAN2_CLK_ENABLE() for CAN2 |
sahilmgandhi | 18:6a4db94011d3 | 21 | -@- In case you are using CAN2 only, you have to enable the CAN1 clock. |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | (#) CAN pins configuration |
sahilmgandhi | 18:6a4db94011d3 | 24 | (++) Enable the clock for the CAN GPIOs using the following function: |
sahilmgandhi | 18:6a4db94011d3 | 25 | __GPIOx_CLK_ENABLE() |
sahilmgandhi | 18:6a4db94011d3 | 26 | (++) Connect and configure the involved CAN pins to AF9 using the |
sahilmgandhi | 18:6a4db94011d3 | 27 | following function HAL_GPIO_Init() |
sahilmgandhi | 18:6a4db94011d3 | 28 | |
sahilmgandhi | 18:6a4db94011d3 | 29 | (#) Initialize and configure the CAN using CAN_Init() function. |
sahilmgandhi | 18:6a4db94011d3 | 30 | |
sahilmgandhi | 18:6a4db94011d3 | 31 | (#) Transmit the desired CAN frame using HAL_CAN_Transmit() function. |
sahilmgandhi | 18:6a4db94011d3 | 32 | |
sahilmgandhi | 18:6a4db94011d3 | 33 | (#) Receive a CAN frame using HAL_CAN_Receive() function. |
sahilmgandhi | 18:6a4db94011d3 | 34 | |
sahilmgandhi | 18:6a4db94011d3 | 35 | *** Polling mode IO operation *** |
sahilmgandhi | 18:6a4db94011d3 | 36 | ================================= |
sahilmgandhi | 18:6a4db94011d3 | 37 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 38 | (+) Start the CAN peripheral transmission and wait the end of this operation |
sahilmgandhi | 18:6a4db94011d3 | 39 | using HAL_CAN_Transmit(), at this stage user can specify the value of timeout |
sahilmgandhi | 18:6a4db94011d3 | 40 | according to his end application |
sahilmgandhi | 18:6a4db94011d3 | 41 | (+) Start the CAN peripheral reception and wait the end of this operation |
sahilmgandhi | 18:6a4db94011d3 | 42 | using HAL_CAN_Receive(), at this stage user can specify the value of timeout |
sahilmgandhi | 18:6a4db94011d3 | 43 | according to his end application |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | *** Interrupt mode IO operation *** |
sahilmgandhi | 18:6a4db94011d3 | 46 | =================================== |
sahilmgandhi | 18:6a4db94011d3 | 47 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 48 | (+) Start the CAN peripheral transmission using HAL_CAN_Transmit_IT() |
sahilmgandhi | 18:6a4db94011d3 | 49 | (+) Start the CAN peripheral reception using HAL_CAN_Receive_IT() |
sahilmgandhi | 18:6a4db94011d3 | 50 | (+) Use HAL_CAN_IRQHandler() called under the used CAN Interrupt subroutine |
sahilmgandhi | 18:6a4db94011d3 | 51 | (+) At CAN end of transmission HAL_CAN_TxCpltCallback() function is executed and user can |
sahilmgandhi | 18:6a4db94011d3 | 52 | add his own code by customization of function pointer HAL_CAN_TxCpltCallback |
sahilmgandhi | 18:6a4db94011d3 | 53 | (+) In case of CAN Error, HAL_CAN_ErrorCallback() function is executed and user can |
sahilmgandhi | 18:6a4db94011d3 | 54 | add his own code by customization of function pointer HAL_CAN_ErrorCallback |
sahilmgandhi | 18:6a4db94011d3 | 55 | |
sahilmgandhi | 18:6a4db94011d3 | 56 | *** CAN HAL driver macros list *** |
sahilmgandhi | 18:6a4db94011d3 | 57 | ============================================= |
sahilmgandhi | 18:6a4db94011d3 | 58 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 59 | Below the list of most used macros in CAN HAL driver. |
sahilmgandhi | 18:6a4db94011d3 | 60 | |
sahilmgandhi | 18:6a4db94011d3 | 61 | (+) __HAL_CAN_ENABLE_IT: Enable the specified CAN interrupts |
sahilmgandhi | 18:6a4db94011d3 | 62 | (+) __HAL_CAN_DISABLE_IT: Disable the specified CAN interrupts |
sahilmgandhi | 18:6a4db94011d3 | 63 | (+) __HAL_CAN_GET_IT_SOURCE: Check if the specified CAN interrupt source is enabled or disabled |
sahilmgandhi | 18:6a4db94011d3 | 64 | (+) __HAL_CAN_CLEAR_FLAG: Clear the CAN's pending flags |
sahilmgandhi | 18:6a4db94011d3 | 65 | (+) __HAL_CAN_GET_FLAG: Get the selected CAN's flag status |
sahilmgandhi | 18:6a4db94011d3 | 66 | |
sahilmgandhi | 18:6a4db94011d3 | 67 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 68 | (@) You can refer to the CAN HAL driver header file for more useful macros |
sahilmgandhi | 18:6a4db94011d3 | 69 | |
sahilmgandhi | 18:6a4db94011d3 | 70 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 71 | |
sahilmgandhi | 18:6a4db94011d3 | 72 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 73 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 74 | * |
sahilmgandhi | 18:6a4db94011d3 | 75 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 76 | * |
sahilmgandhi | 18:6a4db94011d3 | 77 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 78 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 79 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 80 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 81 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 82 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 83 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 84 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 85 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 86 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 87 | * |
sahilmgandhi | 18:6a4db94011d3 | 88 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 89 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 90 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 91 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 92 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 93 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 94 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 95 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 96 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 97 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 98 | * |
sahilmgandhi | 18:6a4db94011d3 | 99 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 100 | */ |
sahilmgandhi | 18:6a4db94011d3 | 101 | |
sahilmgandhi | 18:6a4db94011d3 | 102 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 103 | #include "stm32f4xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 104 | |
sahilmgandhi | 18:6a4db94011d3 | 105 | /** @addtogroup STM32F4xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 106 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 107 | */ |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | /** @defgroup CAN CAN |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @brief CAN driver modules |
sahilmgandhi | 18:6a4db94011d3 | 111 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 112 | */ |
sahilmgandhi | 18:6a4db94011d3 | 113 | |
sahilmgandhi | 18:6a4db94011d3 | 114 | #ifdef HAL_CAN_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 115 | |
sahilmgandhi | 18:6a4db94011d3 | 116 | #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) ||\ |
sahilmgandhi | 18:6a4db94011d3 | 117 | defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) ||\ |
sahilmgandhi | 18:6a4db94011d3 | 118 | defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) ||\ |
sahilmgandhi | 18:6a4db94011d3 | 119 | defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) |
sahilmgandhi | 18:6a4db94011d3 | 120 | |
sahilmgandhi | 18:6a4db94011d3 | 121 | /* Private typedef -----------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 122 | /* Private define ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 123 | /** @addtogroup CAN_Private_Constants |
sahilmgandhi | 18:6a4db94011d3 | 124 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 125 | */ |
sahilmgandhi | 18:6a4db94011d3 | 126 | #define CAN_TIMEOUT_VALUE 10U |
sahilmgandhi | 18:6a4db94011d3 | 127 | /** |
sahilmgandhi | 18:6a4db94011d3 | 128 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 129 | */ |
sahilmgandhi | 18:6a4db94011d3 | 130 | /* Private macro -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 131 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 132 | /* Private function prototypes -----------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 133 | /** @addtogroup CAN_Private_Functions |
sahilmgandhi | 18:6a4db94011d3 | 134 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 135 | */ |
sahilmgandhi | 18:6a4db94011d3 | 136 | static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber); |
sahilmgandhi | 18:6a4db94011d3 | 137 | static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan); |
sahilmgandhi | 18:6a4db94011d3 | 138 | /** |
sahilmgandhi | 18:6a4db94011d3 | 139 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 140 | */ |
sahilmgandhi | 18:6a4db94011d3 | 141 | |
sahilmgandhi | 18:6a4db94011d3 | 142 | /* Exported functions --------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 143 | /** @defgroup CAN_Exported_Functions CAN Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 144 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 145 | */ |
sahilmgandhi | 18:6a4db94011d3 | 146 | |
sahilmgandhi | 18:6a4db94011d3 | 147 | /** @defgroup CAN_Exported_Functions_Group1 Initialization and de-initialization functions |
sahilmgandhi | 18:6a4db94011d3 | 148 | * @brief Initialization and Configuration functions |
sahilmgandhi | 18:6a4db94011d3 | 149 | * |
sahilmgandhi | 18:6a4db94011d3 | 150 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 151 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 152 | ##### Initialization and de-initialization functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 153 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 154 | [..] This section provides functions allowing to: |
sahilmgandhi | 18:6a4db94011d3 | 155 | (+) Initialize and configure the CAN. |
sahilmgandhi | 18:6a4db94011d3 | 156 | (+) De-initialize the CAN. |
sahilmgandhi | 18:6a4db94011d3 | 157 | |
sahilmgandhi | 18:6a4db94011d3 | 158 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 159 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 160 | */ |
sahilmgandhi | 18:6a4db94011d3 | 161 | |
sahilmgandhi | 18:6a4db94011d3 | 162 | /** |
sahilmgandhi | 18:6a4db94011d3 | 163 | * @brief Initializes the CAN peripheral according to the specified |
sahilmgandhi | 18:6a4db94011d3 | 164 | * parameters in the CAN_InitStruct. |
sahilmgandhi | 18:6a4db94011d3 | 165 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 166 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 167 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 168 | */ |
sahilmgandhi | 18:6a4db94011d3 | 169 | HAL_StatusTypeDef HAL_CAN_Init(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 170 | { |
sahilmgandhi | 18:6a4db94011d3 | 171 | uint32_t InitStatus = 3U; |
sahilmgandhi | 18:6a4db94011d3 | 172 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 173 | |
sahilmgandhi | 18:6a4db94011d3 | 174 | /* Check CAN handle */ |
sahilmgandhi | 18:6a4db94011d3 | 175 | if(hcan == NULL) |
sahilmgandhi | 18:6a4db94011d3 | 176 | { |
sahilmgandhi | 18:6a4db94011d3 | 177 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 178 | } |
sahilmgandhi | 18:6a4db94011d3 | 179 | |
sahilmgandhi | 18:6a4db94011d3 | 180 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 181 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
sahilmgandhi | 18:6a4db94011d3 | 182 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TTCM)); |
sahilmgandhi | 18:6a4db94011d3 | 183 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.ABOM)); |
sahilmgandhi | 18:6a4db94011d3 | 184 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.AWUM)); |
sahilmgandhi | 18:6a4db94011d3 | 185 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.NART)); |
sahilmgandhi | 18:6a4db94011d3 | 186 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.RFLM)); |
sahilmgandhi | 18:6a4db94011d3 | 187 | assert_param(IS_FUNCTIONAL_STATE(hcan->Init.TXFP)); |
sahilmgandhi | 18:6a4db94011d3 | 188 | assert_param(IS_CAN_MODE(hcan->Init.Mode)); |
sahilmgandhi | 18:6a4db94011d3 | 189 | assert_param(IS_CAN_SJW(hcan->Init.SJW)); |
sahilmgandhi | 18:6a4db94011d3 | 190 | assert_param(IS_CAN_BS1(hcan->Init.BS1)); |
sahilmgandhi | 18:6a4db94011d3 | 191 | assert_param(IS_CAN_BS2(hcan->Init.BS2)); |
sahilmgandhi | 18:6a4db94011d3 | 192 | assert_param(IS_CAN_PRESCALER(hcan->Init.Prescaler)); |
sahilmgandhi | 18:6a4db94011d3 | 193 | |
sahilmgandhi | 18:6a4db94011d3 | 194 | |
sahilmgandhi | 18:6a4db94011d3 | 195 | if(hcan->State == HAL_CAN_STATE_RESET) |
sahilmgandhi | 18:6a4db94011d3 | 196 | { |
sahilmgandhi | 18:6a4db94011d3 | 197 | /* Allocate lock resource and initialize it */ |
sahilmgandhi | 18:6a4db94011d3 | 198 | hcan->Lock = HAL_UNLOCKED; |
sahilmgandhi | 18:6a4db94011d3 | 199 | /* Init the low level hardware */ |
sahilmgandhi | 18:6a4db94011d3 | 200 | HAL_CAN_MspInit(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 201 | } |
sahilmgandhi | 18:6a4db94011d3 | 202 | |
sahilmgandhi | 18:6a4db94011d3 | 203 | /* Initialize the CAN state*/ |
sahilmgandhi | 18:6a4db94011d3 | 204 | hcan->State = HAL_CAN_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 205 | |
sahilmgandhi | 18:6a4db94011d3 | 206 | /* Exit from sleep mode */ |
sahilmgandhi | 18:6a4db94011d3 | 207 | hcan->Instance->MCR &= (~(uint32_t)CAN_MCR_SLEEP); |
sahilmgandhi | 18:6a4db94011d3 | 208 | |
sahilmgandhi | 18:6a4db94011d3 | 209 | /* Request initialisation */ |
sahilmgandhi | 18:6a4db94011d3 | 210 | hcan->Instance->MCR |= CAN_MCR_INRQ ; |
sahilmgandhi | 18:6a4db94011d3 | 211 | |
sahilmgandhi | 18:6a4db94011d3 | 212 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 213 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 214 | |
sahilmgandhi | 18:6a4db94011d3 | 215 | /* Wait the acknowledge */ |
sahilmgandhi | 18:6a4db94011d3 | 216 | while((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) |
sahilmgandhi | 18:6a4db94011d3 | 217 | { |
sahilmgandhi | 18:6a4db94011d3 | 218 | if((HAL_GetTick() - tickstart ) > CAN_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 219 | { |
sahilmgandhi | 18:6a4db94011d3 | 220 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 221 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 222 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 223 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 224 | } |
sahilmgandhi | 18:6a4db94011d3 | 225 | } |
sahilmgandhi | 18:6a4db94011d3 | 226 | |
sahilmgandhi | 18:6a4db94011d3 | 227 | /* Check acknowledge */ |
sahilmgandhi | 18:6a4db94011d3 | 228 | if ((hcan->Instance->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) |
sahilmgandhi | 18:6a4db94011d3 | 229 | { |
sahilmgandhi | 18:6a4db94011d3 | 230 | InitStatus = CAN_INITSTATUS_FAILED; |
sahilmgandhi | 18:6a4db94011d3 | 231 | } |
sahilmgandhi | 18:6a4db94011d3 | 232 | else |
sahilmgandhi | 18:6a4db94011d3 | 233 | { |
sahilmgandhi | 18:6a4db94011d3 | 234 | /* Set the time triggered communication mode */ |
sahilmgandhi | 18:6a4db94011d3 | 235 | if (hcan->Init.TTCM == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 236 | { |
sahilmgandhi | 18:6a4db94011d3 | 237 | hcan->Instance->MCR |= CAN_MCR_TTCM; |
sahilmgandhi | 18:6a4db94011d3 | 238 | } |
sahilmgandhi | 18:6a4db94011d3 | 239 | else |
sahilmgandhi | 18:6a4db94011d3 | 240 | { |
sahilmgandhi | 18:6a4db94011d3 | 241 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TTCM; |
sahilmgandhi | 18:6a4db94011d3 | 242 | } |
sahilmgandhi | 18:6a4db94011d3 | 243 | |
sahilmgandhi | 18:6a4db94011d3 | 244 | /* Set the automatic bus-off management */ |
sahilmgandhi | 18:6a4db94011d3 | 245 | if (hcan->Init.ABOM == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 246 | { |
sahilmgandhi | 18:6a4db94011d3 | 247 | hcan->Instance->MCR |= CAN_MCR_ABOM; |
sahilmgandhi | 18:6a4db94011d3 | 248 | } |
sahilmgandhi | 18:6a4db94011d3 | 249 | else |
sahilmgandhi | 18:6a4db94011d3 | 250 | { |
sahilmgandhi | 18:6a4db94011d3 | 251 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_ABOM; |
sahilmgandhi | 18:6a4db94011d3 | 252 | } |
sahilmgandhi | 18:6a4db94011d3 | 253 | |
sahilmgandhi | 18:6a4db94011d3 | 254 | /* Set the automatic wake-up mode */ |
sahilmgandhi | 18:6a4db94011d3 | 255 | if (hcan->Init.AWUM == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 256 | { |
sahilmgandhi | 18:6a4db94011d3 | 257 | hcan->Instance->MCR |= CAN_MCR_AWUM; |
sahilmgandhi | 18:6a4db94011d3 | 258 | } |
sahilmgandhi | 18:6a4db94011d3 | 259 | else |
sahilmgandhi | 18:6a4db94011d3 | 260 | { |
sahilmgandhi | 18:6a4db94011d3 | 261 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_AWUM; |
sahilmgandhi | 18:6a4db94011d3 | 262 | } |
sahilmgandhi | 18:6a4db94011d3 | 263 | |
sahilmgandhi | 18:6a4db94011d3 | 264 | /* Set the no automatic retransmission */ |
sahilmgandhi | 18:6a4db94011d3 | 265 | if (hcan->Init.NART == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 266 | { |
sahilmgandhi | 18:6a4db94011d3 | 267 | hcan->Instance->MCR |= CAN_MCR_NART; |
sahilmgandhi | 18:6a4db94011d3 | 268 | } |
sahilmgandhi | 18:6a4db94011d3 | 269 | else |
sahilmgandhi | 18:6a4db94011d3 | 270 | { |
sahilmgandhi | 18:6a4db94011d3 | 271 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_NART; |
sahilmgandhi | 18:6a4db94011d3 | 272 | } |
sahilmgandhi | 18:6a4db94011d3 | 273 | |
sahilmgandhi | 18:6a4db94011d3 | 274 | /* Set the receive FIFO locked mode */ |
sahilmgandhi | 18:6a4db94011d3 | 275 | if (hcan->Init.RFLM == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 276 | { |
sahilmgandhi | 18:6a4db94011d3 | 277 | hcan->Instance->MCR |= CAN_MCR_RFLM; |
sahilmgandhi | 18:6a4db94011d3 | 278 | } |
sahilmgandhi | 18:6a4db94011d3 | 279 | else |
sahilmgandhi | 18:6a4db94011d3 | 280 | { |
sahilmgandhi | 18:6a4db94011d3 | 281 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_RFLM; |
sahilmgandhi | 18:6a4db94011d3 | 282 | } |
sahilmgandhi | 18:6a4db94011d3 | 283 | |
sahilmgandhi | 18:6a4db94011d3 | 284 | /* Set the transmit FIFO priority */ |
sahilmgandhi | 18:6a4db94011d3 | 285 | if (hcan->Init.TXFP == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 286 | { |
sahilmgandhi | 18:6a4db94011d3 | 287 | hcan->Instance->MCR |= CAN_MCR_TXFP; |
sahilmgandhi | 18:6a4db94011d3 | 288 | } |
sahilmgandhi | 18:6a4db94011d3 | 289 | else |
sahilmgandhi | 18:6a4db94011d3 | 290 | { |
sahilmgandhi | 18:6a4db94011d3 | 291 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_TXFP; |
sahilmgandhi | 18:6a4db94011d3 | 292 | } |
sahilmgandhi | 18:6a4db94011d3 | 293 | |
sahilmgandhi | 18:6a4db94011d3 | 294 | /* Set the bit timing register */ |
sahilmgandhi | 18:6a4db94011d3 | 295 | hcan->Instance->BTR = (uint32_t)((uint32_t)hcan->Init.Mode) | \ |
sahilmgandhi | 18:6a4db94011d3 | 296 | ((uint32_t)hcan->Init.SJW) | \ |
sahilmgandhi | 18:6a4db94011d3 | 297 | ((uint32_t)hcan->Init.BS1) | \ |
sahilmgandhi | 18:6a4db94011d3 | 298 | ((uint32_t)hcan->Init.BS2) | \ |
sahilmgandhi | 18:6a4db94011d3 | 299 | ((uint32_t)hcan->Init.Prescaler - 1U); |
sahilmgandhi | 18:6a4db94011d3 | 300 | |
sahilmgandhi | 18:6a4db94011d3 | 301 | /* Request leave initialisation */ |
sahilmgandhi | 18:6a4db94011d3 | 302 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_INRQ; |
sahilmgandhi | 18:6a4db94011d3 | 303 | |
sahilmgandhi | 18:6a4db94011d3 | 304 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 305 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 306 | |
sahilmgandhi | 18:6a4db94011d3 | 307 | /* Wait the acknowledge */ |
sahilmgandhi | 18:6a4db94011d3 | 308 | while((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) |
sahilmgandhi | 18:6a4db94011d3 | 309 | { |
sahilmgandhi | 18:6a4db94011d3 | 310 | if((HAL_GetTick() - tickstart ) > CAN_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 311 | { |
sahilmgandhi | 18:6a4db94011d3 | 312 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 313 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 314 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 315 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 316 | } |
sahilmgandhi | 18:6a4db94011d3 | 317 | } |
sahilmgandhi | 18:6a4db94011d3 | 318 | |
sahilmgandhi | 18:6a4db94011d3 | 319 | /* Check acknowledged */ |
sahilmgandhi | 18:6a4db94011d3 | 320 | if ((hcan->Instance->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) |
sahilmgandhi | 18:6a4db94011d3 | 321 | { |
sahilmgandhi | 18:6a4db94011d3 | 322 | InitStatus = CAN_INITSTATUS_FAILED; |
sahilmgandhi | 18:6a4db94011d3 | 323 | } |
sahilmgandhi | 18:6a4db94011d3 | 324 | else |
sahilmgandhi | 18:6a4db94011d3 | 325 | { |
sahilmgandhi | 18:6a4db94011d3 | 326 | InitStatus = CAN_INITSTATUS_SUCCESS; |
sahilmgandhi | 18:6a4db94011d3 | 327 | } |
sahilmgandhi | 18:6a4db94011d3 | 328 | } |
sahilmgandhi | 18:6a4db94011d3 | 329 | |
sahilmgandhi | 18:6a4db94011d3 | 330 | if(InitStatus == CAN_INITSTATUS_SUCCESS) |
sahilmgandhi | 18:6a4db94011d3 | 331 | { |
sahilmgandhi | 18:6a4db94011d3 | 332 | /* Set CAN error code to none */ |
sahilmgandhi | 18:6a4db94011d3 | 333 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 334 | |
sahilmgandhi | 18:6a4db94011d3 | 335 | /* Initialize the CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 336 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 337 | |
sahilmgandhi | 18:6a4db94011d3 | 338 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 339 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 340 | } |
sahilmgandhi | 18:6a4db94011d3 | 341 | else |
sahilmgandhi | 18:6a4db94011d3 | 342 | { |
sahilmgandhi | 18:6a4db94011d3 | 343 | /* Initialize the CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 344 | hcan->State = HAL_CAN_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 345 | |
sahilmgandhi | 18:6a4db94011d3 | 346 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 347 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 348 | } |
sahilmgandhi | 18:6a4db94011d3 | 349 | } |
sahilmgandhi | 18:6a4db94011d3 | 350 | |
sahilmgandhi | 18:6a4db94011d3 | 351 | /** |
sahilmgandhi | 18:6a4db94011d3 | 352 | * @brief Configures the CAN reception filter according to the specified |
sahilmgandhi | 18:6a4db94011d3 | 353 | * parameters in the CAN_FilterInitStruct. |
sahilmgandhi | 18:6a4db94011d3 | 354 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 355 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 356 | * @param sFilterConfig: pointer to a CAN_FilterConfTypeDef structure that |
sahilmgandhi | 18:6a4db94011d3 | 357 | * contains the filter configuration information. |
sahilmgandhi | 18:6a4db94011d3 | 358 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 359 | */ |
sahilmgandhi | 18:6a4db94011d3 | 360 | HAL_StatusTypeDef HAL_CAN_ConfigFilter(CAN_HandleTypeDef* hcan, CAN_FilterConfTypeDef* sFilterConfig) |
sahilmgandhi | 18:6a4db94011d3 | 361 | { |
sahilmgandhi | 18:6a4db94011d3 | 362 | uint32_t filternbrbitpos = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 363 | |
sahilmgandhi | 18:6a4db94011d3 | 364 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 365 | assert_param(IS_CAN_FILTER_NUMBER(sFilterConfig->FilterNumber)); |
sahilmgandhi | 18:6a4db94011d3 | 366 | assert_param(IS_CAN_FILTER_MODE(sFilterConfig->FilterMode)); |
sahilmgandhi | 18:6a4db94011d3 | 367 | assert_param(IS_CAN_FILTER_SCALE(sFilterConfig->FilterScale)); |
sahilmgandhi | 18:6a4db94011d3 | 368 | assert_param(IS_CAN_FILTER_FIFO(sFilterConfig->FilterFIFOAssignment)); |
sahilmgandhi | 18:6a4db94011d3 | 369 | assert_param(IS_FUNCTIONAL_STATE(sFilterConfig->FilterActivation)); |
sahilmgandhi | 18:6a4db94011d3 | 370 | assert_param(IS_CAN_BANKNUMBER(sFilterConfig->BankNumber)); |
sahilmgandhi | 18:6a4db94011d3 | 371 | |
sahilmgandhi | 18:6a4db94011d3 | 372 | filternbrbitpos = ((uint32_t)1U) << sFilterConfig->FilterNumber; |
sahilmgandhi | 18:6a4db94011d3 | 373 | |
sahilmgandhi | 18:6a4db94011d3 | 374 | /* Initialisation mode for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 375 | CAN1->FMR |= (uint32_t)CAN_FMR_FINIT; |
sahilmgandhi | 18:6a4db94011d3 | 376 | |
sahilmgandhi | 18:6a4db94011d3 | 377 | /* Select the start slave bank */ |
sahilmgandhi | 18:6a4db94011d3 | 378 | CAN1->FMR &= ~((uint32_t)CAN_FMR_CAN2SB); |
sahilmgandhi | 18:6a4db94011d3 | 379 | CAN1->FMR |= (uint32_t)(sFilterConfig->BankNumber << 8U); |
sahilmgandhi | 18:6a4db94011d3 | 380 | |
sahilmgandhi | 18:6a4db94011d3 | 381 | /* Filter Deactivation */ |
sahilmgandhi | 18:6a4db94011d3 | 382 | CAN1->FA1R &= ~(uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 383 | |
sahilmgandhi | 18:6a4db94011d3 | 384 | /* Filter Scale */ |
sahilmgandhi | 18:6a4db94011d3 | 385 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_16BIT) |
sahilmgandhi | 18:6a4db94011d3 | 386 | { |
sahilmgandhi | 18:6a4db94011d3 | 387 | /* 16-bit scale for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 388 | CAN1->FS1R &= ~(uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 389 | |
sahilmgandhi | 18:6a4db94011d3 | 390 | /* First 16-bit identifier and First 16-bit mask */ |
sahilmgandhi | 18:6a4db94011d3 | 391 | /* Or First 16-bit identifier and Second 16-bit identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 392 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR1 = |
sahilmgandhi | 18:6a4db94011d3 | 393 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdLow) << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 394 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdLow); |
sahilmgandhi | 18:6a4db94011d3 | 395 | |
sahilmgandhi | 18:6a4db94011d3 | 396 | /* Second 16-bit identifier and Second 16-bit mask */ |
sahilmgandhi | 18:6a4db94011d3 | 397 | /* Or Third 16-bit identifier and Fourth 16-bit identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 398 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR2 = |
sahilmgandhi | 18:6a4db94011d3 | 399 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 400 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdHigh); |
sahilmgandhi | 18:6a4db94011d3 | 401 | } |
sahilmgandhi | 18:6a4db94011d3 | 402 | |
sahilmgandhi | 18:6a4db94011d3 | 403 | if (sFilterConfig->FilterScale == CAN_FILTERSCALE_32BIT) |
sahilmgandhi | 18:6a4db94011d3 | 404 | { |
sahilmgandhi | 18:6a4db94011d3 | 405 | /* 32-bit scale for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 406 | CAN1->FS1R |= filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 407 | /* 32-bit identifier or First 32-bit identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 408 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR1 = |
sahilmgandhi | 18:6a4db94011d3 | 409 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdHigh) << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 410 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterIdLow); |
sahilmgandhi | 18:6a4db94011d3 | 411 | /* 32-bit mask or Second 32-bit identifier */ |
sahilmgandhi | 18:6a4db94011d3 | 412 | CAN1->sFilterRegister[sFilterConfig->FilterNumber].FR2 = |
sahilmgandhi | 18:6a4db94011d3 | 413 | ((0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdHigh) << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 414 | (0x0000FFFFU & (uint32_t)sFilterConfig->FilterMaskIdLow); |
sahilmgandhi | 18:6a4db94011d3 | 415 | } |
sahilmgandhi | 18:6a4db94011d3 | 416 | |
sahilmgandhi | 18:6a4db94011d3 | 417 | /* Filter Mode */ |
sahilmgandhi | 18:6a4db94011d3 | 418 | if (sFilterConfig->FilterMode == CAN_FILTERMODE_IDMASK) |
sahilmgandhi | 18:6a4db94011d3 | 419 | { |
sahilmgandhi | 18:6a4db94011d3 | 420 | /*Id/Mask mode for the filter*/ |
sahilmgandhi | 18:6a4db94011d3 | 421 | CAN1->FM1R &= ~(uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 422 | } |
sahilmgandhi | 18:6a4db94011d3 | 423 | else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */ |
sahilmgandhi | 18:6a4db94011d3 | 424 | { |
sahilmgandhi | 18:6a4db94011d3 | 425 | /*Identifier list mode for the filter*/ |
sahilmgandhi | 18:6a4db94011d3 | 426 | CAN1->FM1R |= (uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 427 | } |
sahilmgandhi | 18:6a4db94011d3 | 428 | |
sahilmgandhi | 18:6a4db94011d3 | 429 | /* Filter FIFO assignment */ |
sahilmgandhi | 18:6a4db94011d3 | 430 | if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO0) |
sahilmgandhi | 18:6a4db94011d3 | 431 | { |
sahilmgandhi | 18:6a4db94011d3 | 432 | /* FIFO 0 assignation for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 433 | CAN1->FFA1R &= ~(uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 434 | } |
sahilmgandhi | 18:6a4db94011d3 | 435 | |
sahilmgandhi | 18:6a4db94011d3 | 436 | if (sFilterConfig->FilterFIFOAssignment == CAN_FILTER_FIFO1) |
sahilmgandhi | 18:6a4db94011d3 | 437 | { |
sahilmgandhi | 18:6a4db94011d3 | 438 | /* FIFO 1 assignation for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 439 | CAN1->FFA1R |= (uint32_t)filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 440 | } |
sahilmgandhi | 18:6a4db94011d3 | 441 | |
sahilmgandhi | 18:6a4db94011d3 | 442 | /* Filter activation */ |
sahilmgandhi | 18:6a4db94011d3 | 443 | if (sFilterConfig->FilterActivation == ENABLE) |
sahilmgandhi | 18:6a4db94011d3 | 444 | { |
sahilmgandhi | 18:6a4db94011d3 | 445 | CAN1->FA1R |= filternbrbitpos; |
sahilmgandhi | 18:6a4db94011d3 | 446 | } |
sahilmgandhi | 18:6a4db94011d3 | 447 | |
sahilmgandhi | 18:6a4db94011d3 | 448 | /* Leave the initialisation mode for the filter */ |
sahilmgandhi | 18:6a4db94011d3 | 449 | CAN1->FMR &= ~((uint32_t)CAN_FMR_FINIT); |
sahilmgandhi | 18:6a4db94011d3 | 450 | |
sahilmgandhi | 18:6a4db94011d3 | 451 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 452 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 453 | } |
sahilmgandhi | 18:6a4db94011d3 | 454 | |
sahilmgandhi | 18:6a4db94011d3 | 455 | /** |
sahilmgandhi | 18:6a4db94011d3 | 456 | * @brief Deinitializes the CANx peripheral registers to their default reset values. |
sahilmgandhi | 18:6a4db94011d3 | 457 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 458 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 459 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 460 | */ |
sahilmgandhi | 18:6a4db94011d3 | 461 | HAL_StatusTypeDef HAL_CAN_DeInit(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 462 | { |
sahilmgandhi | 18:6a4db94011d3 | 463 | /* Check CAN handle */ |
sahilmgandhi | 18:6a4db94011d3 | 464 | if(hcan == NULL) |
sahilmgandhi | 18:6a4db94011d3 | 465 | { |
sahilmgandhi | 18:6a4db94011d3 | 466 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 467 | } |
sahilmgandhi | 18:6a4db94011d3 | 468 | |
sahilmgandhi | 18:6a4db94011d3 | 469 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 470 | assert_param(IS_CAN_ALL_INSTANCE(hcan->Instance)); |
sahilmgandhi | 18:6a4db94011d3 | 471 | |
sahilmgandhi | 18:6a4db94011d3 | 472 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 473 | hcan->State = HAL_CAN_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 474 | |
sahilmgandhi | 18:6a4db94011d3 | 475 | /* DeInit the low level hardware */ |
sahilmgandhi | 18:6a4db94011d3 | 476 | HAL_CAN_MspDeInit(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 477 | |
sahilmgandhi | 18:6a4db94011d3 | 478 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 479 | hcan->State = HAL_CAN_STATE_RESET; |
sahilmgandhi | 18:6a4db94011d3 | 480 | |
sahilmgandhi | 18:6a4db94011d3 | 481 | /* Release Lock */ |
sahilmgandhi | 18:6a4db94011d3 | 482 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 483 | |
sahilmgandhi | 18:6a4db94011d3 | 484 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 485 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 486 | } |
sahilmgandhi | 18:6a4db94011d3 | 487 | |
sahilmgandhi | 18:6a4db94011d3 | 488 | /** |
sahilmgandhi | 18:6a4db94011d3 | 489 | * @brief Initializes the CAN MSP. |
sahilmgandhi | 18:6a4db94011d3 | 490 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 491 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 492 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 493 | */ |
sahilmgandhi | 18:6a4db94011d3 | 494 | __weak void HAL_CAN_MspInit(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 495 | { |
sahilmgandhi | 18:6a4db94011d3 | 496 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 497 | UNUSED(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 498 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 499 | the HAL_CAN_MspInit could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 500 | */ |
sahilmgandhi | 18:6a4db94011d3 | 501 | } |
sahilmgandhi | 18:6a4db94011d3 | 502 | |
sahilmgandhi | 18:6a4db94011d3 | 503 | /** |
sahilmgandhi | 18:6a4db94011d3 | 504 | * @brief DeInitializes the CAN MSP. |
sahilmgandhi | 18:6a4db94011d3 | 505 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 506 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 507 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 508 | */ |
sahilmgandhi | 18:6a4db94011d3 | 509 | __weak void HAL_CAN_MspDeInit(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 510 | { |
sahilmgandhi | 18:6a4db94011d3 | 511 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 512 | UNUSED(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 513 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 514 | the HAL_CAN_MspDeInit could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 515 | */ |
sahilmgandhi | 18:6a4db94011d3 | 516 | } |
sahilmgandhi | 18:6a4db94011d3 | 517 | |
sahilmgandhi | 18:6a4db94011d3 | 518 | /** |
sahilmgandhi | 18:6a4db94011d3 | 519 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 520 | */ |
sahilmgandhi | 18:6a4db94011d3 | 521 | |
sahilmgandhi | 18:6a4db94011d3 | 522 | /** @defgroup CAN_Exported_Functions_Group2 IO operation functions |
sahilmgandhi | 18:6a4db94011d3 | 523 | * @brief IO operation functions |
sahilmgandhi | 18:6a4db94011d3 | 524 | * |
sahilmgandhi | 18:6a4db94011d3 | 525 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 526 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 527 | ##### IO operation functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 528 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 529 | [..] This section provides functions allowing to: |
sahilmgandhi | 18:6a4db94011d3 | 530 | (+) Transmit a CAN frame message. |
sahilmgandhi | 18:6a4db94011d3 | 531 | (+) Receive a CAN frame message. |
sahilmgandhi | 18:6a4db94011d3 | 532 | (+) Enter CAN peripheral in sleep mode. |
sahilmgandhi | 18:6a4db94011d3 | 533 | (+) Wake up the CAN peripheral from sleep mode. |
sahilmgandhi | 18:6a4db94011d3 | 534 | |
sahilmgandhi | 18:6a4db94011d3 | 535 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 536 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 537 | */ |
sahilmgandhi | 18:6a4db94011d3 | 538 | |
sahilmgandhi | 18:6a4db94011d3 | 539 | /** |
sahilmgandhi | 18:6a4db94011d3 | 540 | * @brief Initiates and transmits a CAN frame message. |
sahilmgandhi | 18:6a4db94011d3 | 541 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 542 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 543 | * @param Timeout: Specify Timeout value |
sahilmgandhi | 18:6a4db94011d3 | 544 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 545 | */ |
sahilmgandhi | 18:6a4db94011d3 | 546 | HAL_StatusTypeDef HAL_CAN_Transmit(CAN_HandleTypeDef* hcan, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 547 | { |
sahilmgandhi | 18:6a4db94011d3 | 548 | uint32_t transmitmailbox = 5U; |
sahilmgandhi | 18:6a4db94011d3 | 549 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 550 | |
sahilmgandhi | 18:6a4db94011d3 | 551 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 552 | assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE)); |
sahilmgandhi | 18:6a4db94011d3 | 553 | assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR)); |
sahilmgandhi | 18:6a4db94011d3 | 554 | assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC)); |
sahilmgandhi | 18:6a4db94011d3 | 555 | |
sahilmgandhi | 18:6a4db94011d3 | 556 | if(((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) || \ |
sahilmgandhi | 18:6a4db94011d3 | 557 | ((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) || \ |
sahilmgandhi | 18:6a4db94011d3 | 558 | ((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)) |
sahilmgandhi | 18:6a4db94011d3 | 559 | { |
sahilmgandhi | 18:6a4db94011d3 | 560 | /* Process locked */ |
sahilmgandhi | 18:6a4db94011d3 | 561 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 562 | |
sahilmgandhi | 18:6a4db94011d3 | 563 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
sahilmgandhi | 18:6a4db94011d3 | 564 | { |
sahilmgandhi | 18:6a4db94011d3 | 565 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 566 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
sahilmgandhi | 18:6a4db94011d3 | 567 | } |
sahilmgandhi | 18:6a4db94011d3 | 568 | else |
sahilmgandhi | 18:6a4db94011d3 | 569 | { |
sahilmgandhi | 18:6a4db94011d3 | 570 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 571 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
sahilmgandhi | 18:6a4db94011d3 | 572 | } |
sahilmgandhi | 18:6a4db94011d3 | 573 | |
sahilmgandhi | 18:6a4db94011d3 | 574 | /* Select one empty transmit mailbox */ |
sahilmgandhi | 18:6a4db94011d3 | 575 | if ((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) |
sahilmgandhi | 18:6a4db94011d3 | 576 | { |
sahilmgandhi | 18:6a4db94011d3 | 577 | transmitmailbox = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 578 | } |
sahilmgandhi | 18:6a4db94011d3 | 579 | else if ((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) |
sahilmgandhi | 18:6a4db94011d3 | 580 | { |
sahilmgandhi | 18:6a4db94011d3 | 581 | transmitmailbox = 1U; |
sahilmgandhi | 18:6a4db94011d3 | 582 | } |
sahilmgandhi | 18:6a4db94011d3 | 583 | else |
sahilmgandhi | 18:6a4db94011d3 | 584 | { |
sahilmgandhi | 18:6a4db94011d3 | 585 | transmitmailbox = 2U; |
sahilmgandhi | 18:6a4db94011d3 | 586 | } |
sahilmgandhi | 18:6a4db94011d3 | 587 | |
sahilmgandhi | 18:6a4db94011d3 | 588 | /* Set up the Id */ |
sahilmgandhi | 18:6a4db94011d3 | 589 | hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ; |
sahilmgandhi | 18:6a4db94011d3 | 590 | if (hcan->pTxMsg->IDE == CAN_ID_STD) |
sahilmgandhi | 18:6a4db94011d3 | 591 | { |
sahilmgandhi | 18:6a4db94011d3 | 592 | assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId)); |
sahilmgandhi | 18:6a4db94011d3 | 593 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21U) | \ |
sahilmgandhi | 18:6a4db94011d3 | 594 | hcan->pTxMsg->RTR); |
sahilmgandhi | 18:6a4db94011d3 | 595 | } |
sahilmgandhi | 18:6a4db94011d3 | 596 | else |
sahilmgandhi | 18:6a4db94011d3 | 597 | { |
sahilmgandhi | 18:6a4db94011d3 | 598 | assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId)); |
sahilmgandhi | 18:6a4db94011d3 | 599 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3U) | \ |
sahilmgandhi | 18:6a4db94011d3 | 600 | hcan->pTxMsg->IDE | \ |
sahilmgandhi | 18:6a4db94011d3 | 601 | hcan->pTxMsg->RTR); |
sahilmgandhi | 18:6a4db94011d3 | 602 | } |
sahilmgandhi | 18:6a4db94011d3 | 603 | |
sahilmgandhi | 18:6a4db94011d3 | 604 | /* Set up the DLC */ |
sahilmgandhi | 18:6a4db94011d3 | 605 | hcan->pTxMsg->DLC &= (uint8_t)0x0000000FU; |
sahilmgandhi | 18:6a4db94011d3 | 606 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0U; |
sahilmgandhi | 18:6a4db94011d3 | 607 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC; |
sahilmgandhi | 18:6a4db94011d3 | 608 | |
sahilmgandhi | 18:6a4db94011d3 | 609 | /* Set up the data field */ |
sahilmgandhi | 18:6a4db94011d3 | 610 | hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3U] << 24U) | |
sahilmgandhi | 18:6a4db94011d3 | 611 | ((uint32_t)hcan->pTxMsg->Data[2U] << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 612 | ((uint32_t)hcan->pTxMsg->Data[1U] << 8U) | |
sahilmgandhi | 18:6a4db94011d3 | 613 | ((uint32_t)hcan->pTxMsg->Data[0U])); |
sahilmgandhi | 18:6a4db94011d3 | 614 | hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7U] << 24U) | |
sahilmgandhi | 18:6a4db94011d3 | 615 | ((uint32_t)hcan->pTxMsg->Data[6U] << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 616 | ((uint32_t)hcan->pTxMsg->Data[5U] << 8U) | |
sahilmgandhi | 18:6a4db94011d3 | 617 | ((uint32_t)hcan->pTxMsg->Data[4U])); |
sahilmgandhi | 18:6a4db94011d3 | 618 | /* Request transmission */ |
sahilmgandhi | 18:6a4db94011d3 | 619 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; |
sahilmgandhi | 18:6a4db94011d3 | 620 | |
sahilmgandhi | 18:6a4db94011d3 | 621 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 622 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 623 | |
sahilmgandhi | 18:6a4db94011d3 | 624 | /* Check End of transmission flag */ |
sahilmgandhi | 18:6a4db94011d3 | 625 | while(!(__HAL_CAN_TRANSMIT_STATUS(hcan, transmitmailbox))) |
sahilmgandhi | 18:6a4db94011d3 | 626 | { |
sahilmgandhi | 18:6a4db94011d3 | 627 | /* Check for the Timeout */ |
sahilmgandhi | 18:6a4db94011d3 | 628 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 629 | { |
sahilmgandhi | 18:6a4db94011d3 | 630 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 631 | { |
sahilmgandhi | 18:6a4db94011d3 | 632 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 633 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 634 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 635 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 636 | } |
sahilmgandhi | 18:6a4db94011d3 | 637 | } |
sahilmgandhi | 18:6a4db94011d3 | 638 | } |
sahilmgandhi | 18:6a4db94011d3 | 639 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
sahilmgandhi | 18:6a4db94011d3 | 640 | { |
sahilmgandhi | 18:6a4db94011d3 | 641 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 642 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
sahilmgandhi | 18:6a4db94011d3 | 643 | } |
sahilmgandhi | 18:6a4db94011d3 | 644 | else |
sahilmgandhi | 18:6a4db94011d3 | 645 | { |
sahilmgandhi | 18:6a4db94011d3 | 646 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 647 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 648 | } |
sahilmgandhi | 18:6a4db94011d3 | 649 | |
sahilmgandhi | 18:6a4db94011d3 | 650 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 651 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 652 | |
sahilmgandhi | 18:6a4db94011d3 | 653 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 654 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 655 | } |
sahilmgandhi | 18:6a4db94011d3 | 656 | else |
sahilmgandhi | 18:6a4db94011d3 | 657 | { |
sahilmgandhi | 18:6a4db94011d3 | 658 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 659 | hcan->State = HAL_CAN_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 660 | |
sahilmgandhi | 18:6a4db94011d3 | 661 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 662 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 663 | } |
sahilmgandhi | 18:6a4db94011d3 | 664 | } |
sahilmgandhi | 18:6a4db94011d3 | 665 | |
sahilmgandhi | 18:6a4db94011d3 | 666 | /** |
sahilmgandhi | 18:6a4db94011d3 | 667 | * @brief Initiates and transmits a CAN frame message. |
sahilmgandhi | 18:6a4db94011d3 | 668 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 669 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 670 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 671 | */ |
sahilmgandhi | 18:6a4db94011d3 | 672 | HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 673 | { |
sahilmgandhi | 18:6a4db94011d3 | 674 | uint32_t transmitmailbox = 5U; |
sahilmgandhi | 18:6a4db94011d3 | 675 | |
sahilmgandhi | 18:6a4db94011d3 | 676 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 677 | assert_param(IS_CAN_IDTYPE(hcan->pTxMsg->IDE)); |
sahilmgandhi | 18:6a4db94011d3 | 678 | assert_param(IS_CAN_RTR(hcan->pTxMsg->RTR)); |
sahilmgandhi | 18:6a4db94011d3 | 679 | assert_param(IS_CAN_DLC(hcan->pTxMsg->DLC)); |
sahilmgandhi | 18:6a4db94011d3 | 680 | |
sahilmgandhi | 18:6a4db94011d3 | 681 | if(((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) || \ |
sahilmgandhi | 18:6a4db94011d3 | 682 | ((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) || \ |
sahilmgandhi | 18:6a4db94011d3 | 683 | ((hcan->Instance->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)) |
sahilmgandhi | 18:6a4db94011d3 | 684 | { |
sahilmgandhi | 18:6a4db94011d3 | 685 | /* Process Locked */ |
sahilmgandhi | 18:6a4db94011d3 | 686 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 687 | |
sahilmgandhi | 18:6a4db94011d3 | 688 | /* Select one empty transmit mailbox */ |
sahilmgandhi | 18:6a4db94011d3 | 689 | if((hcan->Instance->TSR&CAN_TSR_TME0) == CAN_TSR_TME0) |
sahilmgandhi | 18:6a4db94011d3 | 690 | { |
sahilmgandhi | 18:6a4db94011d3 | 691 | transmitmailbox = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 692 | } |
sahilmgandhi | 18:6a4db94011d3 | 693 | else if((hcan->Instance->TSR&CAN_TSR_TME1) == CAN_TSR_TME1) |
sahilmgandhi | 18:6a4db94011d3 | 694 | { |
sahilmgandhi | 18:6a4db94011d3 | 695 | transmitmailbox = 1U; |
sahilmgandhi | 18:6a4db94011d3 | 696 | } |
sahilmgandhi | 18:6a4db94011d3 | 697 | else |
sahilmgandhi | 18:6a4db94011d3 | 698 | { |
sahilmgandhi | 18:6a4db94011d3 | 699 | transmitmailbox = 2U; |
sahilmgandhi | 18:6a4db94011d3 | 700 | } |
sahilmgandhi | 18:6a4db94011d3 | 701 | |
sahilmgandhi | 18:6a4db94011d3 | 702 | /* Set up the Id */ |
sahilmgandhi | 18:6a4db94011d3 | 703 | hcan->Instance->sTxMailBox[transmitmailbox].TIR &= CAN_TI0R_TXRQ; |
sahilmgandhi | 18:6a4db94011d3 | 704 | if(hcan->pTxMsg->IDE == CAN_ID_STD) |
sahilmgandhi | 18:6a4db94011d3 | 705 | { |
sahilmgandhi | 18:6a4db94011d3 | 706 | assert_param(IS_CAN_STDID(hcan->pTxMsg->StdId)); |
sahilmgandhi | 18:6a4db94011d3 | 707 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->StdId << 21U) | \ |
sahilmgandhi | 18:6a4db94011d3 | 708 | hcan->pTxMsg->RTR); |
sahilmgandhi | 18:6a4db94011d3 | 709 | } |
sahilmgandhi | 18:6a4db94011d3 | 710 | else |
sahilmgandhi | 18:6a4db94011d3 | 711 | { |
sahilmgandhi | 18:6a4db94011d3 | 712 | assert_param(IS_CAN_EXTID(hcan->pTxMsg->ExtId)); |
sahilmgandhi | 18:6a4db94011d3 | 713 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= ((hcan->pTxMsg->ExtId << 3U) | \ |
sahilmgandhi | 18:6a4db94011d3 | 714 | hcan->pTxMsg->IDE | \ |
sahilmgandhi | 18:6a4db94011d3 | 715 | hcan->pTxMsg->RTR); |
sahilmgandhi | 18:6a4db94011d3 | 716 | } |
sahilmgandhi | 18:6a4db94011d3 | 717 | |
sahilmgandhi | 18:6a4db94011d3 | 718 | /* Set up the DLC */ |
sahilmgandhi | 18:6a4db94011d3 | 719 | hcan->pTxMsg->DLC &= (uint8_t)0x0000000FU; |
sahilmgandhi | 18:6a4db94011d3 | 720 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR &= (uint32_t)0xFFFFFFF0U; |
sahilmgandhi | 18:6a4db94011d3 | 721 | hcan->Instance->sTxMailBox[transmitmailbox].TDTR |= hcan->pTxMsg->DLC; |
sahilmgandhi | 18:6a4db94011d3 | 722 | |
sahilmgandhi | 18:6a4db94011d3 | 723 | /* Set up the data field */ |
sahilmgandhi | 18:6a4db94011d3 | 724 | hcan->Instance->sTxMailBox[transmitmailbox].TDLR = (((uint32_t)hcan->pTxMsg->Data[3U] << 24U) | |
sahilmgandhi | 18:6a4db94011d3 | 725 | ((uint32_t)hcan->pTxMsg->Data[2U] << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 726 | ((uint32_t)hcan->pTxMsg->Data[1U] << 8U) | |
sahilmgandhi | 18:6a4db94011d3 | 727 | ((uint32_t)hcan->pTxMsg->Data[0U])); |
sahilmgandhi | 18:6a4db94011d3 | 728 | hcan->Instance->sTxMailBox[transmitmailbox].TDHR = (((uint32_t)hcan->pTxMsg->Data[7U] << 24U) | |
sahilmgandhi | 18:6a4db94011d3 | 729 | ((uint32_t)hcan->pTxMsg->Data[6U] << 16U) | |
sahilmgandhi | 18:6a4db94011d3 | 730 | ((uint32_t)hcan->pTxMsg->Data[5U] << 8U) | |
sahilmgandhi | 18:6a4db94011d3 | 731 | ((uint32_t)hcan->pTxMsg->Data[4U])); |
sahilmgandhi | 18:6a4db94011d3 | 732 | |
sahilmgandhi | 18:6a4db94011d3 | 733 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
sahilmgandhi | 18:6a4db94011d3 | 734 | { |
sahilmgandhi | 18:6a4db94011d3 | 735 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 736 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
sahilmgandhi | 18:6a4db94011d3 | 737 | } |
sahilmgandhi | 18:6a4db94011d3 | 738 | else |
sahilmgandhi | 18:6a4db94011d3 | 739 | { |
sahilmgandhi | 18:6a4db94011d3 | 740 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 741 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
sahilmgandhi | 18:6a4db94011d3 | 742 | } |
sahilmgandhi | 18:6a4db94011d3 | 743 | |
sahilmgandhi | 18:6a4db94011d3 | 744 | /* Set CAN error code to none */ |
sahilmgandhi | 18:6a4db94011d3 | 745 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 746 | |
sahilmgandhi | 18:6a4db94011d3 | 747 | /* Process Unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 748 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 749 | |
sahilmgandhi | 18:6a4db94011d3 | 750 | /* Enable Error warning Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 751 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 752 | |
sahilmgandhi | 18:6a4db94011d3 | 753 | /* Enable Error passive Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 754 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 755 | |
sahilmgandhi | 18:6a4db94011d3 | 756 | /* Enable Bus-off Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 757 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 758 | |
sahilmgandhi | 18:6a4db94011d3 | 759 | /* Enable Last error code Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 760 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 761 | |
sahilmgandhi | 18:6a4db94011d3 | 762 | /* Enable Error Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 763 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 764 | |
sahilmgandhi | 18:6a4db94011d3 | 765 | /* Enable Transmit mailbox empty Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 766 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_TME); |
sahilmgandhi | 18:6a4db94011d3 | 767 | |
sahilmgandhi | 18:6a4db94011d3 | 768 | /* Request transmission */ |
sahilmgandhi | 18:6a4db94011d3 | 769 | hcan->Instance->sTxMailBox[transmitmailbox].TIR |= CAN_TI0R_TXRQ; |
sahilmgandhi | 18:6a4db94011d3 | 770 | } |
sahilmgandhi | 18:6a4db94011d3 | 771 | else |
sahilmgandhi | 18:6a4db94011d3 | 772 | { |
sahilmgandhi | 18:6a4db94011d3 | 773 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 774 | hcan->State = HAL_CAN_STATE_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 775 | |
sahilmgandhi | 18:6a4db94011d3 | 776 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 777 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 778 | } |
sahilmgandhi | 18:6a4db94011d3 | 779 | |
sahilmgandhi | 18:6a4db94011d3 | 780 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 781 | } |
sahilmgandhi | 18:6a4db94011d3 | 782 | |
sahilmgandhi | 18:6a4db94011d3 | 783 | /** |
sahilmgandhi | 18:6a4db94011d3 | 784 | * @brief Receives a correct CAN frame. |
sahilmgandhi | 18:6a4db94011d3 | 785 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 786 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 787 | * @param FIFONumber: FIFO Number value |
sahilmgandhi | 18:6a4db94011d3 | 788 | * @param Timeout: Specify Timeout value |
sahilmgandhi | 18:6a4db94011d3 | 789 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 790 | */ |
sahilmgandhi | 18:6a4db94011d3 | 791 | HAL_StatusTypeDef HAL_CAN_Receive(CAN_HandleTypeDef* hcan, uint8_t FIFONumber, uint32_t Timeout) |
sahilmgandhi | 18:6a4db94011d3 | 792 | { |
sahilmgandhi | 18:6a4db94011d3 | 793 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 794 | |
sahilmgandhi | 18:6a4db94011d3 | 795 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 796 | assert_param(IS_CAN_FIFO(FIFONumber)); |
sahilmgandhi | 18:6a4db94011d3 | 797 | |
sahilmgandhi | 18:6a4db94011d3 | 798 | /* Process locked */ |
sahilmgandhi | 18:6a4db94011d3 | 799 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 800 | |
sahilmgandhi | 18:6a4db94011d3 | 801 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
sahilmgandhi | 18:6a4db94011d3 | 802 | { |
sahilmgandhi | 18:6a4db94011d3 | 803 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 804 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
sahilmgandhi | 18:6a4db94011d3 | 805 | } |
sahilmgandhi | 18:6a4db94011d3 | 806 | else |
sahilmgandhi | 18:6a4db94011d3 | 807 | { |
sahilmgandhi | 18:6a4db94011d3 | 808 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 809 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
sahilmgandhi | 18:6a4db94011d3 | 810 | } |
sahilmgandhi | 18:6a4db94011d3 | 811 | |
sahilmgandhi | 18:6a4db94011d3 | 812 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 813 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 814 | |
sahilmgandhi | 18:6a4db94011d3 | 815 | /* Check pending message */ |
sahilmgandhi | 18:6a4db94011d3 | 816 | while(__HAL_CAN_MSG_PENDING(hcan, FIFONumber) == 0U) |
sahilmgandhi | 18:6a4db94011d3 | 817 | { |
sahilmgandhi | 18:6a4db94011d3 | 818 | /* Check for the Timeout */ |
sahilmgandhi | 18:6a4db94011d3 | 819 | if(Timeout != HAL_MAX_DELAY) |
sahilmgandhi | 18:6a4db94011d3 | 820 | { |
sahilmgandhi | 18:6a4db94011d3 | 821 | if((Timeout == 0U)||((HAL_GetTick() - tickstart ) > Timeout)) |
sahilmgandhi | 18:6a4db94011d3 | 822 | { |
sahilmgandhi | 18:6a4db94011d3 | 823 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 824 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 825 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 826 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 827 | } |
sahilmgandhi | 18:6a4db94011d3 | 828 | } |
sahilmgandhi | 18:6a4db94011d3 | 829 | } |
sahilmgandhi | 18:6a4db94011d3 | 830 | |
sahilmgandhi | 18:6a4db94011d3 | 831 | /* Get the Id */ |
sahilmgandhi | 18:6a4db94011d3 | 832 | hcan->pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
sahilmgandhi | 18:6a4db94011d3 | 833 | if (hcan->pRxMsg->IDE == CAN_ID_STD) |
sahilmgandhi | 18:6a4db94011d3 | 834 | { |
sahilmgandhi | 18:6a4db94011d3 | 835 | hcan->pRxMsg->StdId = (uint32_t)0x000007FFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21U); |
sahilmgandhi | 18:6a4db94011d3 | 836 | } |
sahilmgandhi | 18:6a4db94011d3 | 837 | else |
sahilmgandhi | 18:6a4db94011d3 | 838 | { |
sahilmgandhi | 18:6a4db94011d3 | 839 | hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3U); |
sahilmgandhi | 18:6a4db94011d3 | 840 | } |
sahilmgandhi | 18:6a4db94011d3 | 841 | |
sahilmgandhi | 18:6a4db94011d3 | 842 | hcan->pRxMsg->RTR = (uint8_t)0x02U & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
sahilmgandhi | 18:6a4db94011d3 | 843 | /* Get the DLC */ |
sahilmgandhi | 18:6a4db94011d3 | 844 | hcan->pRxMsg->DLC = (uint8_t)0x0FU & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR; |
sahilmgandhi | 18:6a4db94011d3 | 845 | /* Get the FMI */ |
sahilmgandhi | 18:6a4db94011d3 | 846 | hcan->pRxMsg->FMI = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 847 | /* Get the data field */ |
sahilmgandhi | 18:6a4db94011d3 | 848 | hcan->pRxMsg->Data[0U] = (uint8_t)0xFFU & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR; |
sahilmgandhi | 18:6a4db94011d3 | 849 | hcan->pRxMsg->Data[1U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 850 | hcan->pRxMsg->Data[2U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 851 | hcan->pRxMsg->Data[3U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24U); |
sahilmgandhi | 18:6a4db94011d3 | 852 | hcan->pRxMsg->Data[4U] = (uint8_t)0xFFU & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR; |
sahilmgandhi | 18:6a4db94011d3 | 853 | hcan->pRxMsg->Data[5U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 854 | hcan->pRxMsg->Data[6U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 855 | hcan->pRxMsg->Data[7U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24U); |
sahilmgandhi | 18:6a4db94011d3 | 856 | |
sahilmgandhi | 18:6a4db94011d3 | 857 | /* Release the FIFO */ |
sahilmgandhi | 18:6a4db94011d3 | 858 | if(FIFONumber == CAN_FIFO0) |
sahilmgandhi | 18:6a4db94011d3 | 859 | { |
sahilmgandhi | 18:6a4db94011d3 | 860 | /* Release FIFO0 */ |
sahilmgandhi | 18:6a4db94011d3 | 861 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0); |
sahilmgandhi | 18:6a4db94011d3 | 862 | } |
sahilmgandhi | 18:6a4db94011d3 | 863 | else /* FIFONumber == CAN_FIFO1 */ |
sahilmgandhi | 18:6a4db94011d3 | 864 | { |
sahilmgandhi | 18:6a4db94011d3 | 865 | /* Release FIFO1 */ |
sahilmgandhi | 18:6a4db94011d3 | 866 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1); |
sahilmgandhi | 18:6a4db94011d3 | 867 | } |
sahilmgandhi | 18:6a4db94011d3 | 868 | |
sahilmgandhi | 18:6a4db94011d3 | 869 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
sahilmgandhi | 18:6a4db94011d3 | 870 | { |
sahilmgandhi | 18:6a4db94011d3 | 871 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 872 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
sahilmgandhi | 18:6a4db94011d3 | 873 | |
sahilmgandhi | 18:6a4db94011d3 | 874 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 875 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 876 | } |
sahilmgandhi | 18:6a4db94011d3 | 877 | else |
sahilmgandhi | 18:6a4db94011d3 | 878 | { |
sahilmgandhi | 18:6a4db94011d3 | 879 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 880 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 881 | |
sahilmgandhi | 18:6a4db94011d3 | 882 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 883 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 884 | } |
sahilmgandhi | 18:6a4db94011d3 | 885 | |
sahilmgandhi | 18:6a4db94011d3 | 886 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 887 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 888 | } |
sahilmgandhi | 18:6a4db94011d3 | 889 | |
sahilmgandhi | 18:6a4db94011d3 | 890 | /** |
sahilmgandhi | 18:6a4db94011d3 | 891 | * @brief Receives a correct CAN frame. |
sahilmgandhi | 18:6a4db94011d3 | 892 | * @param hcan: Pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 893 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 894 | * @param FIFONumber: Specify the FIFO number |
sahilmgandhi | 18:6a4db94011d3 | 895 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 896 | */ |
sahilmgandhi | 18:6a4db94011d3 | 897 | HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber) |
sahilmgandhi | 18:6a4db94011d3 | 898 | { |
sahilmgandhi | 18:6a4db94011d3 | 899 | uint32_t tmp = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 900 | |
sahilmgandhi | 18:6a4db94011d3 | 901 | /* Check the parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 902 | assert_param(IS_CAN_FIFO(FIFONumber)); |
sahilmgandhi | 18:6a4db94011d3 | 903 | |
sahilmgandhi | 18:6a4db94011d3 | 904 | tmp = hcan->State; |
sahilmgandhi | 18:6a4db94011d3 | 905 | if((tmp == HAL_CAN_STATE_READY) || (tmp == HAL_CAN_STATE_BUSY_TX)) |
sahilmgandhi | 18:6a4db94011d3 | 906 | { |
sahilmgandhi | 18:6a4db94011d3 | 907 | /* Process locked */ |
sahilmgandhi | 18:6a4db94011d3 | 908 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 909 | |
sahilmgandhi | 18:6a4db94011d3 | 910 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
sahilmgandhi | 18:6a4db94011d3 | 911 | { |
sahilmgandhi | 18:6a4db94011d3 | 912 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 913 | hcan->State = HAL_CAN_STATE_BUSY_TX_RX; |
sahilmgandhi | 18:6a4db94011d3 | 914 | } |
sahilmgandhi | 18:6a4db94011d3 | 915 | else |
sahilmgandhi | 18:6a4db94011d3 | 916 | { |
sahilmgandhi | 18:6a4db94011d3 | 917 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 918 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
sahilmgandhi | 18:6a4db94011d3 | 919 | } |
sahilmgandhi | 18:6a4db94011d3 | 920 | |
sahilmgandhi | 18:6a4db94011d3 | 921 | /* Set CAN error code to none */ |
sahilmgandhi | 18:6a4db94011d3 | 922 | hcan->ErrorCode = HAL_CAN_ERROR_NONE; |
sahilmgandhi | 18:6a4db94011d3 | 923 | |
sahilmgandhi | 18:6a4db94011d3 | 924 | /* Enable Error warning Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 925 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 926 | |
sahilmgandhi | 18:6a4db94011d3 | 927 | /* Enable Error passive Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 928 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 929 | |
sahilmgandhi | 18:6a4db94011d3 | 930 | /* Enable Bus-off Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 931 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 932 | |
sahilmgandhi | 18:6a4db94011d3 | 933 | /* Enable Last error code Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 934 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 935 | |
sahilmgandhi | 18:6a4db94011d3 | 936 | /* Enable Error Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 937 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 938 | |
sahilmgandhi | 18:6a4db94011d3 | 939 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 940 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 941 | |
sahilmgandhi | 18:6a4db94011d3 | 942 | if(FIFONumber == CAN_FIFO0) |
sahilmgandhi | 18:6a4db94011d3 | 943 | { |
sahilmgandhi | 18:6a4db94011d3 | 944 | /* Enable FIFO 0 message pending Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 945 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0); |
sahilmgandhi | 18:6a4db94011d3 | 946 | } |
sahilmgandhi | 18:6a4db94011d3 | 947 | else |
sahilmgandhi | 18:6a4db94011d3 | 948 | { |
sahilmgandhi | 18:6a4db94011d3 | 949 | /* Enable FIFO 1 message pending Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 950 | __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP1); |
sahilmgandhi | 18:6a4db94011d3 | 951 | } |
sahilmgandhi | 18:6a4db94011d3 | 952 | |
sahilmgandhi | 18:6a4db94011d3 | 953 | } |
sahilmgandhi | 18:6a4db94011d3 | 954 | else |
sahilmgandhi | 18:6a4db94011d3 | 955 | { |
sahilmgandhi | 18:6a4db94011d3 | 956 | return HAL_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 957 | } |
sahilmgandhi | 18:6a4db94011d3 | 958 | |
sahilmgandhi | 18:6a4db94011d3 | 959 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 960 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 961 | } |
sahilmgandhi | 18:6a4db94011d3 | 962 | |
sahilmgandhi | 18:6a4db94011d3 | 963 | /** |
sahilmgandhi | 18:6a4db94011d3 | 964 | * @brief Enters the Sleep (low power) mode. |
sahilmgandhi | 18:6a4db94011d3 | 965 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 966 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 967 | * @retval HAL status. |
sahilmgandhi | 18:6a4db94011d3 | 968 | */ |
sahilmgandhi | 18:6a4db94011d3 | 969 | HAL_StatusTypeDef HAL_CAN_Sleep(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 970 | { |
sahilmgandhi | 18:6a4db94011d3 | 971 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 972 | |
sahilmgandhi | 18:6a4db94011d3 | 973 | /* Process locked */ |
sahilmgandhi | 18:6a4db94011d3 | 974 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 975 | |
sahilmgandhi | 18:6a4db94011d3 | 976 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 977 | hcan->State = HAL_CAN_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 978 | |
sahilmgandhi | 18:6a4db94011d3 | 979 | /* Request Sleep mode */ |
sahilmgandhi | 18:6a4db94011d3 | 980 | hcan->Instance->MCR = (((hcan->Instance->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP); |
sahilmgandhi | 18:6a4db94011d3 | 981 | |
sahilmgandhi | 18:6a4db94011d3 | 982 | /* Sleep mode status */ |
sahilmgandhi | 18:6a4db94011d3 | 983 | if ((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK) |
sahilmgandhi | 18:6a4db94011d3 | 984 | { |
sahilmgandhi | 18:6a4db94011d3 | 985 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 986 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 987 | |
sahilmgandhi | 18:6a4db94011d3 | 988 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 989 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 990 | } |
sahilmgandhi | 18:6a4db94011d3 | 991 | |
sahilmgandhi | 18:6a4db94011d3 | 992 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 993 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 994 | |
sahilmgandhi | 18:6a4db94011d3 | 995 | /* Wait the acknowledge */ |
sahilmgandhi | 18:6a4db94011d3 | 996 | while((hcan->Instance->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) != CAN_MSR_SLAK) |
sahilmgandhi | 18:6a4db94011d3 | 997 | { |
sahilmgandhi | 18:6a4db94011d3 | 998 | if((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 999 | { |
sahilmgandhi | 18:6a4db94011d3 | 1000 | hcan->State = HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1001 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1002 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1003 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1004 | } |
sahilmgandhi | 18:6a4db94011d3 | 1005 | } |
sahilmgandhi | 18:6a4db94011d3 | 1006 | |
sahilmgandhi | 18:6a4db94011d3 | 1007 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1008 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1009 | |
sahilmgandhi | 18:6a4db94011d3 | 1010 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1011 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1012 | |
sahilmgandhi | 18:6a4db94011d3 | 1013 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 1014 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1015 | } |
sahilmgandhi | 18:6a4db94011d3 | 1016 | |
sahilmgandhi | 18:6a4db94011d3 | 1017 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1018 | * @brief Wakes up the CAN peripheral from sleep mode, after that the CAN peripheral |
sahilmgandhi | 18:6a4db94011d3 | 1019 | * is in the normal mode. |
sahilmgandhi | 18:6a4db94011d3 | 1020 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1021 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1022 | * @retval HAL status. |
sahilmgandhi | 18:6a4db94011d3 | 1023 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1024 | HAL_StatusTypeDef HAL_CAN_WakeUp(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1025 | { |
sahilmgandhi | 18:6a4db94011d3 | 1026 | uint32_t tickstart = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1027 | |
sahilmgandhi | 18:6a4db94011d3 | 1028 | /* Process locked */ |
sahilmgandhi | 18:6a4db94011d3 | 1029 | __HAL_LOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1030 | |
sahilmgandhi | 18:6a4db94011d3 | 1031 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1032 | hcan->State = HAL_CAN_STATE_BUSY; |
sahilmgandhi | 18:6a4db94011d3 | 1033 | |
sahilmgandhi | 18:6a4db94011d3 | 1034 | /* Wake up request */ |
sahilmgandhi | 18:6a4db94011d3 | 1035 | hcan->Instance->MCR &= ~(uint32_t)CAN_MCR_SLEEP; |
sahilmgandhi | 18:6a4db94011d3 | 1036 | |
sahilmgandhi | 18:6a4db94011d3 | 1037 | /* Get tick */ |
sahilmgandhi | 18:6a4db94011d3 | 1038 | tickstart = HAL_GetTick(); |
sahilmgandhi | 18:6a4db94011d3 | 1039 | |
sahilmgandhi | 18:6a4db94011d3 | 1040 | /* Sleep mode status */ |
sahilmgandhi | 18:6a4db94011d3 | 1041 | while((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK) |
sahilmgandhi | 18:6a4db94011d3 | 1042 | { |
sahilmgandhi | 18:6a4db94011d3 | 1043 | if((HAL_GetTick() - tickstart) > CAN_TIMEOUT_VALUE) |
sahilmgandhi | 18:6a4db94011d3 | 1044 | { |
sahilmgandhi | 18:6a4db94011d3 | 1045 | hcan->State= HAL_CAN_STATE_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1046 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1047 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1048 | return HAL_TIMEOUT; |
sahilmgandhi | 18:6a4db94011d3 | 1049 | } |
sahilmgandhi | 18:6a4db94011d3 | 1050 | } |
sahilmgandhi | 18:6a4db94011d3 | 1051 | if((hcan->Instance->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK) |
sahilmgandhi | 18:6a4db94011d3 | 1052 | { |
sahilmgandhi | 18:6a4db94011d3 | 1053 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1054 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1055 | |
sahilmgandhi | 18:6a4db94011d3 | 1056 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 1057 | return HAL_ERROR; |
sahilmgandhi | 18:6a4db94011d3 | 1058 | } |
sahilmgandhi | 18:6a4db94011d3 | 1059 | |
sahilmgandhi | 18:6a4db94011d3 | 1060 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1061 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1062 | |
sahilmgandhi | 18:6a4db94011d3 | 1063 | /* Process unlocked */ |
sahilmgandhi | 18:6a4db94011d3 | 1064 | __HAL_UNLOCK(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1065 | |
sahilmgandhi | 18:6a4db94011d3 | 1066 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 1067 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1068 | } |
sahilmgandhi | 18:6a4db94011d3 | 1069 | |
sahilmgandhi | 18:6a4db94011d3 | 1070 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1071 | * @brief Handles CAN interrupt request |
sahilmgandhi | 18:6a4db94011d3 | 1072 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1073 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1074 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1075 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1076 | void HAL_CAN_IRQHandler(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1077 | { |
sahilmgandhi | 18:6a4db94011d3 | 1078 | uint32_t tmp1 = 0U, tmp2 = 0U, tmp3 = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 1079 | |
sahilmgandhi | 18:6a4db94011d3 | 1080 | /* Check End of transmission flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1081 | if(__HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_TME)) |
sahilmgandhi | 18:6a4db94011d3 | 1082 | { |
sahilmgandhi | 18:6a4db94011d3 | 1083 | tmp1 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_0); |
sahilmgandhi | 18:6a4db94011d3 | 1084 | tmp2 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_1); |
sahilmgandhi | 18:6a4db94011d3 | 1085 | tmp3 = __HAL_CAN_TRANSMIT_STATUS(hcan, CAN_TXMAILBOX_2); |
sahilmgandhi | 18:6a4db94011d3 | 1086 | if(tmp1 || tmp2 || tmp3) |
sahilmgandhi | 18:6a4db94011d3 | 1087 | { |
sahilmgandhi | 18:6a4db94011d3 | 1088 | /* Call transmit function */ |
sahilmgandhi | 18:6a4db94011d3 | 1089 | CAN_Transmit_IT(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1090 | } |
sahilmgandhi | 18:6a4db94011d3 | 1091 | } |
sahilmgandhi | 18:6a4db94011d3 | 1092 | |
sahilmgandhi | 18:6a4db94011d3 | 1093 | tmp1 = __HAL_CAN_MSG_PENDING(hcan, CAN_FIFO0); |
sahilmgandhi | 18:6a4db94011d3 | 1094 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP0); |
sahilmgandhi | 18:6a4db94011d3 | 1095 | /* Check End of reception flag for FIFO0 */ |
sahilmgandhi | 18:6a4db94011d3 | 1096 | if((tmp1 != 0U) && tmp2) |
sahilmgandhi | 18:6a4db94011d3 | 1097 | { |
sahilmgandhi | 18:6a4db94011d3 | 1098 | /* Call receive function */ |
sahilmgandhi | 18:6a4db94011d3 | 1099 | CAN_Receive_IT(hcan, CAN_FIFO0); |
sahilmgandhi | 18:6a4db94011d3 | 1100 | } |
sahilmgandhi | 18:6a4db94011d3 | 1101 | |
sahilmgandhi | 18:6a4db94011d3 | 1102 | tmp1 = __HAL_CAN_MSG_PENDING(hcan, CAN_FIFO1); |
sahilmgandhi | 18:6a4db94011d3 | 1103 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_FMP1); |
sahilmgandhi | 18:6a4db94011d3 | 1104 | /* Check End of reception flag for FIFO1 */ |
sahilmgandhi | 18:6a4db94011d3 | 1105 | if((tmp1 != 0U) && tmp2) |
sahilmgandhi | 18:6a4db94011d3 | 1106 | { |
sahilmgandhi | 18:6a4db94011d3 | 1107 | /* Call receive function */ |
sahilmgandhi | 18:6a4db94011d3 | 1108 | CAN_Receive_IT(hcan, CAN_FIFO1); |
sahilmgandhi | 18:6a4db94011d3 | 1109 | } |
sahilmgandhi | 18:6a4db94011d3 | 1110 | |
sahilmgandhi | 18:6a4db94011d3 | 1111 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 1112 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 1113 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1114 | /* Check Error Warning Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1115 | if(tmp1 && tmp2 && tmp3) |
sahilmgandhi | 18:6a4db94011d3 | 1116 | { |
sahilmgandhi | 18:6a4db94011d3 | 1117 | /* Set CAN error code to EWG error */ |
sahilmgandhi | 18:6a4db94011d3 | 1118 | hcan->ErrorCode |= HAL_CAN_ERROR_EWG; |
sahilmgandhi | 18:6a4db94011d3 | 1119 | } |
sahilmgandhi | 18:6a4db94011d3 | 1120 | |
sahilmgandhi | 18:6a4db94011d3 | 1121 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 1122 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 1123 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1124 | /* Check Error Passive Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1125 | if(tmp1 && tmp2 && tmp3) |
sahilmgandhi | 18:6a4db94011d3 | 1126 | { |
sahilmgandhi | 18:6a4db94011d3 | 1127 | /* Set CAN error code to EPV error */ |
sahilmgandhi | 18:6a4db94011d3 | 1128 | hcan->ErrorCode |= HAL_CAN_ERROR_EPV; |
sahilmgandhi | 18:6a4db94011d3 | 1129 | } |
sahilmgandhi | 18:6a4db94011d3 | 1130 | |
sahilmgandhi | 18:6a4db94011d3 | 1131 | tmp1 = __HAL_CAN_GET_FLAG(hcan, CAN_FLAG_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 1132 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 1133 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1134 | /* Check Bus-Off Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1135 | if(tmp1 && tmp2 && tmp3) |
sahilmgandhi | 18:6a4db94011d3 | 1136 | { |
sahilmgandhi | 18:6a4db94011d3 | 1137 | /* Set CAN error code to BOF error */ |
sahilmgandhi | 18:6a4db94011d3 | 1138 | hcan->ErrorCode |= HAL_CAN_ERROR_BOF; |
sahilmgandhi | 18:6a4db94011d3 | 1139 | } |
sahilmgandhi | 18:6a4db94011d3 | 1140 | |
sahilmgandhi | 18:6a4db94011d3 | 1141 | tmp1 = HAL_IS_BIT_CLR(hcan->Instance->ESR, CAN_ESR_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 1142 | tmp2 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 1143 | tmp3 = __HAL_CAN_GET_IT_SOURCE(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1144 | /* Check Last error code Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1145 | if((!tmp1) && tmp2 && tmp3) |
sahilmgandhi | 18:6a4db94011d3 | 1146 | { |
sahilmgandhi | 18:6a4db94011d3 | 1147 | tmp1 = (hcan->Instance->ESR) & CAN_ESR_LEC; |
sahilmgandhi | 18:6a4db94011d3 | 1148 | switch(tmp1) |
sahilmgandhi | 18:6a4db94011d3 | 1149 | { |
sahilmgandhi | 18:6a4db94011d3 | 1150 | case(CAN_ESR_LEC_0): |
sahilmgandhi | 18:6a4db94011d3 | 1151 | /* Set CAN error code to STF error */ |
sahilmgandhi | 18:6a4db94011d3 | 1152 | hcan->ErrorCode |= HAL_CAN_ERROR_STF; |
sahilmgandhi | 18:6a4db94011d3 | 1153 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1154 | case(CAN_ESR_LEC_1): |
sahilmgandhi | 18:6a4db94011d3 | 1155 | /* Set CAN error code to FOR error */ |
sahilmgandhi | 18:6a4db94011d3 | 1156 | hcan->ErrorCode |= HAL_CAN_ERROR_FOR; |
sahilmgandhi | 18:6a4db94011d3 | 1157 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1158 | case(CAN_ESR_LEC_1 | CAN_ESR_LEC_0): |
sahilmgandhi | 18:6a4db94011d3 | 1159 | /* Set CAN error code to ACK error */ |
sahilmgandhi | 18:6a4db94011d3 | 1160 | hcan->ErrorCode |= HAL_CAN_ERROR_ACK; |
sahilmgandhi | 18:6a4db94011d3 | 1161 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1162 | case(CAN_ESR_LEC_2): |
sahilmgandhi | 18:6a4db94011d3 | 1163 | /* Set CAN error code to BR error */ |
sahilmgandhi | 18:6a4db94011d3 | 1164 | hcan->ErrorCode |= HAL_CAN_ERROR_BR; |
sahilmgandhi | 18:6a4db94011d3 | 1165 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1166 | case(CAN_ESR_LEC_2 | CAN_ESR_LEC_0): |
sahilmgandhi | 18:6a4db94011d3 | 1167 | /* Set CAN error code to BD error */ |
sahilmgandhi | 18:6a4db94011d3 | 1168 | hcan->ErrorCode |= HAL_CAN_ERROR_BD; |
sahilmgandhi | 18:6a4db94011d3 | 1169 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1170 | case(CAN_ESR_LEC_2 | CAN_ESR_LEC_1): |
sahilmgandhi | 18:6a4db94011d3 | 1171 | /* Set CAN error code to CRC error */ |
sahilmgandhi | 18:6a4db94011d3 | 1172 | hcan->ErrorCode |= HAL_CAN_ERROR_CRC; |
sahilmgandhi | 18:6a4db94011d3 | 1173 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1174 | default: |
sahilmgandhi | 18:6a4db94011d3 | 1175 | break; |
sahilmgandhi | 18:6a4db94011d3 | 1176 | } |
sahilmgandhi | 18:6a4db94011d3 | 1177 | |
sahilmgandhi | 18:6a4db94011d3 | 1178 | /* Clear Last error code Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1179 | hcan->Instance->ESR &= ~(CAN_ESR_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 1180 | } |
sahilmgandhi | 18:6a4db94011d3 | 1181 | |
sahilmgandhi | 18:6a4db94011d3 | 1182 | /* Call the Error call Back in case of Errors */ |
sahilmgandhi | 18:6a4db94011d3 | 1183 | if(hcan->ErrorCode != HAL_CAN_ERROR_NONE) |
sahilmgandhi | 18:6a4db94011d3 | 1184 | { |
sahilmgandhi | 18:6a4db94011d3 | 1185 | /* Clear ERRI Flag */ |
sahilmgandhi | 18:6a4db94011d3 | 1186 | hcan->Instance->MSR = CAN_MSR_ERRI; |
sahilmgandhi | 18:6a4db94011d3 | 1187 | /* Set the CAN state ready to be able to start again the process */ |
sahilmgandhi | 18:6a4db94011d3 | 1188 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1189 | /* Call Error callback function */ |
sahilmgandhi | 18:6a4db94011d3 | 1190 | HAL_CAN_ErrorCallback(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1191 | } |
sahilmgandhi | 18:6a4db94011d3 | 1192 | } |
sahilmgandhi | 18:6a4db94011d3 | 1193 | |
sahilmgandhi | 18:6a4db94011d3 | 1194 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1195 | * @brief Transmission complete callback in non blocking mode |
sahilmgandhi | 18:6a4db94011d3 | 1196 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1197 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1198 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1199 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1200 | __weak void HAL_CAN_TxCpltCallback(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1201 | { |
sahilmgandhi | 18:6a4db94011d3 | 1202 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 1203 | UNUSED(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1204 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 1205 | the HAL_CAN_TxCpltCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 1206 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1207 | } |
sahilmgandhi | 18:6a4db94011d3 | 1208 | |
sahilmgandhi | 18:6a4db94011d3 | 1209 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1210 | * @brief Transmission complete callback in non blocking mode |
sahilmgandhi | 18:6a4db94011d3 | 1211 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1212 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1213 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1214 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1215 | __weak void HAL_CAN_RxCpltCallback(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1216 | { |
sahilmgandhi | 18:6a4db94011d3 | 1217 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 1218 | UNUSED(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1219 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 1220 | the HAL_CAN_RxCpltCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 1221 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1222 | } |
sahilmgandhi | 18:6a4db94011d3 | 1223 | |
sahilmgandhi | 18:6a4db94011d3 | 1224 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1225 | * @brief Error CAN callback. |
sahilmgandhi | 18:6a4db94011d3 | 1226 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1227 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1228 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1229 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1230 | __weak void HAL_CAN_ErrorCallback(CAN_HandleTypeDef *hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1231 | { |
sahilmgandhi | 18:6a4db94011d3 | 1232 | /* Prevent unused argument(s) compilation warning */ |
sahilmgandhi | 18:6a4db94011d3 | 1233 | UNUSED(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1234 | /* NOTE : This function Should not be modified, when the callback is needed, |
sahilmgandhi | 18:6a4db94011d3 | 1235 | the HAL_CAN_ErrorCallback could be implemented in the user file |
sahilmgandhi | 18:6a4db94011d3 | 1236 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1237 | } |
sahilmgandhi | 18:6a4db94011d3 | 1238 | |
sahilmgandhi | 18:6a4db94011d3 | 1239 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1240 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1241 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1242 | |
sahilmgandhi | 18:6a4db94011d3 | 1243 | /** @defgroup CAN_Exported_Functions_Group3 Peripheral State and Error functions |
sahilmgandhi | 18:6a4db94011d3 | 1244 | * @brief CAN Peripheral State functions |
sahilmgandhi | 18:6a4db94011d3 | 1245 | * |
sahilmgandhi | 18:6a4db94011d3 | 1246 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 1247 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1248 | ##### Peripheral State and Error functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 1249 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 1250 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 1251 | This subsection provides functions allowing to : |
sahilmgandhi | 18:6a4db94011d3 | 1252 | (+) Check the CAN state. |
sahilmgandhi | 18:6a4db94011d3 | 1253 | (+) Check CAN Errors detected during interrupt process |
sahilmgandhi | 18:6a4db94011d3 | 1254 | |
sahilmgandhi | 18:6a4db94011d3 | 1255 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 1256 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 1257 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1258 | |
sahilmgandhi | 18:6a4db94011d3 | 1259 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1260 | * @brief return the CAN state |
sahilmgandhi | 18:6a4db94011d3 | 1261 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1262 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1263 | * @retval HAL state |
sahilmgandhi | 18:6a4db94011d3 | 1264 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1265 | HAL_CAN_StateTypeDef HAL_CAN_GetState(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1266 | { |
sahilmgandhi | 18:6a4db94011d3 | 1267 | /* Return CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1268 | return hcan->State; |
sahilmgandhi | 18:6a4db94011d3 | 1269 | } |
sahilmgandhi | 18:6a4db94011d3 | 1270 | |
sahilmgandhi | 18:6a4db94011d3 | 1271 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1272 | * @brief Return the CAN error code |
sahilmgandhi | 18:6a4db94011d3 | 1273 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1274 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1275 | * @retval CAN Error Code |
sahilmgandhi | 18:6a4db94011d3 | 1276 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1277 | uint32_t HAL_CAN_GetError(CAN_HandleTypeDef *hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1278 | { |
sahilmgandhi | 18:6a4db94011d3 | 1279 | return hcan->ErrorCode; |
sahilmgandhi | 18:6a4db94011d3 | 1280 | } |
sahilmgandhi | 18:6a4db94011d3 | 1281 | |
sahilmgandhi | 18:6a4db94011d3 | 1282 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1283 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1284 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1285 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1286 | * @brief Initiates and transmits a CAN frame message. |
sahilmgandhi | 18:6a4db94011d3 | 1287 | * @param hcan: pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1288 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1289 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1290 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1291 | static HAL_StatusTypeDef CAN_Transmit_IT(CAN_HandleTypeDef* hcan) |
sahilmgandhi | 18:6a4db94011d3 | 1292 | { |
sahilmgandhi | 18:6a4db94011d3 | 1293 | /* Disable Transmit mailbox empty Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1294 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_TME); |
sahilmgandhi | 18:6a4db94011d3 | 1295 | |
sahilmgandhi | 18:6a4db94011d3 | 1296 | if(hcan->State == HAL_CAN_STATE_BUSY_TX) |
sahilmgandhi | 18:6a4db94011d3 | 1297 | { |
sahilmgandhi | 18:6a4db94011d3 | 1298 | /* Disable Error warning Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1299 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 1300 | |
sahilmgandhi | 18:6a4db94011d3 | 1301 | /* Disable Error passive Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1302 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 1303 | |
sahilmgandhi | 18:6a4db94011d3 | 1304 | /* Disable Bus-off Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1305 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 1306 | |
sahilmgandhi | 18:6a4db94011d3 | 1307 | /* Disable Last error code Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1308 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 1309 | |
sahilmgandhi | 18:6a4db94011d3 | 1310 | /* Disable Error Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1311 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1312 | } |
sahilmgandhi | 18:6a4db94011d3 | 1313 | |
sahilmgandhi | 18:6a4db94011d3 | 1314 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
sahilmgandhi | 18:6a4db94011d3 | 1315 | { |
sahilmgandhi | 18:6a4db94011d3 | 1316 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1317 | hcan->State = HAL_CAN_STATE_BUSY_RX; |
sahilmgandhi | 18:6a4db94011d3 | 1318 | } |
sahilmgandhi | 18:6a4db94011d3 | 1319 | else |
sahilmgandhi | 18:6a4db94011d3 | 1320 | { |
sahilmgandhi | 18:6a4db94011d3 | 1321 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1322 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1323 | } |
sahilmgandhi | 18:6a4db94011d3 | 1324 | |
sahilmgandhi | 18:6a4db94011d3 | 1325 | /* Transmission complete callback */ |
sahilmgandhi | 18:6a4db94011d3 | 1326 | HAL_CAN_TxCpltCallback(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1327 | |
sahilmgandhi | 18:6a4db94011d3 | 1328 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1329 | } |
sahilmgandhi | 18:6a4db94011d3 | 1330 | |
sahilmgandhi | 18:6a4db94011d3 | 1331 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1332 | * @brief Receives a correct CAN frame. |
sahilmgandhi | 18:6a4db94011d3 | 1333 | * @param hcan: Pointer to a CAN_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 1334 | * the configuration information for the specified CAN. |
sahilmgandhi | 18:6a4db94011d3 | 1335 | * @param FIFONumber: Specify the FIFO number |
sahilmgandhi | 18:6a4db94011d3 | 1336 | * @retval HAL status |
sahilmgandhi | 18:6a4db94011d3 | 1337 | * @retval None |
sahilmgandhi | 18:6a4db94011d3 | 1338 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1339 | static HAL_StatusTypeDef CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber) |
sahilmgandhi | 18:6a4db94011d3 | 1340 | { |
sahilmgandhi | 18:6a4db94011d3 | 1341 | /* Get the Id */ |
sahilmgandhi | 18:6a4db94011d3 | 1342 | hcan->pRxMsg->IDE = (uint8_t)0x04U & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
sahilmgandhi | 18:6a4db94011d3 | 1343 | if (hcan->pRxMsg->IDE == CAN_ID_STD) |
sahilmgandhi | 18:6a4db94011d3 | 1344 | { |
sahilmgandhi | 18:6a4db94011d3 | 1345 | hcan->pRxMsg->StdId = (uint32_t)0x000007FFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 21U); |
sahilmgandhi | 18:6a4db94011d3 | 1346 | } |
sahilmgandhi | 18:6a4db94011d3 | 1347 | else |
sahilmgandhi | 18:6a4db94011d3 | 1348 | { |
sahilmgandhi | 18:6a4db94011d3 | 1349 | hcan->pRxMsg->ExtId = (uint32_t)0x1FFFFFFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RIR >> 3U); |
sahilmgandhi | 18:6a4db94011d3 | 1350 | } |
sahilmgandhi | 18:6a4db94011d3 | 1351 | |
sahilmgandhi | 18:6a4db94011d3 | 1352 | hcan->pRxMsg->RTR = (uint8_t)0x02U & hcan->Instance->sFIFOMailBox[FIFONumber].RIR; |
sahilmgandhi | 18:6a4db94011d3 | 1353 | /* Get the DLC */ |
sahilmgandhi | 18:6a4db94011d3 | 1354 | hcan->pRxMsg->DLC = (uint8_t)0x0FU & hcan->Instance->sFIFOMailBox[FIFONumber].RDTR; |
sahilmgandhi | 18:6a4db94011d3 | 1355 | /* Get the FMI */ |
sahilmgandhi | 18:6a4db94011d3 | 1356 | hcan->pRxMsg->FMI = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDTR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 1357 | /* Get the data field */ |
sahilmgandhi | 18:6a4db94011d3 | 1358 | hcan->pRxMsg->Data[0U] = (uint8_t)0xFFU & hcan->Instance->sFIFOMailBox[FIFONumber].RDLR; |
sahilmgandhi | 18:6a4db94011d3 | 1359 | hcan->pRxMsg->Data[1U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 1360 | hcan->pRxMsg->Data[2U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 1361 | hcan->pRxMsg->Data[3U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDLR >> 24U); |
sahilmgandhi | 18:6a4db94011d3 | 1362 | hcan->pRxMsg->Data[4U] = (uint8_t)0xFFU & hcan->Instance->sFIFOMailBox[FIFONumber].RDHR; |
sahilmgandhi | 18:6a4db94011d3 | 1363 | hcan->pRxMsg->Data[5U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 8U); |
sahilmgandhi | 18:6a4db94011d3 | 1364 | hcan->pRxMsg->Data[6U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 16U); |
sahilmgandhi | 18:6a4db94011d3 | 1365 | hcan->pRxMsg->Data[7U] = (uint8_t)0xFFU & (hcan->Instance->sFIFOMailBox[FIFONumber].RDHR >> 24U); |
sahilmgandhi | 18:6a4db94011d3 | 1366 | /* Release the FIFO */ |
sahilmgandhi | 18:6a4db94011d3 | 1367 | /* Release FIFO0 */ |
sahilmgandhi | 18:6a4db94011d3 | 1368 | if (FIFONumber == CAN_FIFO0) |
sahilmgandhi | 18:6a4db94011d3 | 1369 | { |
sahilmgandhi | 18:6a4db94011d3 | 1370 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO0); |
sahilmgandhi | 18:6a4db94011d3 | 1371 | |
sahilmgandhi | 18:6a4db94011d3 | 1372 | /* Disable FIFO 0 message pending Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1373 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP0); |
sahilmgandhi | 18:6a4db94011d3 | 1374 | } |
sahilmgandhi | 18:6a4db94011d3 | 1375 | /* Release FIFO1 */ |
sahilmgandhi | 18:6a4db94011d3 | 1376 | else /* FIFONumber == CAN_FIFO1 */ |
sahilmgandhi | 18:6a4db94011d3 | 1377 | { |
sahilmgandhi | 18:6a4db94011d3 | 1378 | __HAL_CAN_FIFO_RELEASE(hcan, CAN_FIFO1); |
sahilmgandhi | 18:6a4db94011d3 | 1379 | |
sahilmgandhi | 18:6a4db94011d3 | 1380 | /* Disable FIFO 1 message pending Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1381 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_FMP1); |
sahilmgandhi | 18:6a4db94011d3 | 1382 | } |
sahilmgandhi | 18:6a4db94011d3 | 1383 | |
sahilmgandhi | 18:6a4db94011d3 | 1384 | if(hcan->State == HAL_CAN_STATE_BUSY_RX) |
sahilmgandhi | 18:6a4db94011d3 | 1385 | { |
sahilmgandhi | 18:6a4db94011d3 | 1386 | /* Disable Error warning Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1387 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EWG); |
sahilmgandhi | 18:6a4db94011d3 | 1388 | |
sahilmgandhi | 18:6a4db94011d3 | 1389 | /* Disable Error passive Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1390 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_EPV); |
sahilmgandhi | 18:6a4db94011d3 | 1391 | |
sahilmgandhi | 18:6a4db94011d3 | 1392 | /* Disable Bus-off Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1393 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_BOF); |
sahilmgandhi | 18:6a4db94011d3 | 1394 | |
sahilmgandhi | 18:6a4db94011d3 | 1395 | /* Disable Last error code Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1396 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_LEC); |
sahilmgandhi | 18:6a4db94011d3 | 1397 | |
sahilmgandhi | 18:6a4db94011d3 | 1398 | /* Disable Error Interrupt */ |
sahilmgandhi | 18:6a4db94011d3 | 1399 | __HAL_CAN_DISABLE_IT(hcan, CAN_IT_ERR); |
sahilmgandhi | 18:6a4db94011d3 | 1400 | } |
sahilmgandhi | 18:6a4db94011d3 | 1401 | |
sahilmgandhi | 18:6a4db94011d3 | 1402 | if(hcan->State == HAL_CAN_STATE_BUSY_TX_RX) |
sahilmgandhi | 18:6a4db94011d3 | 1403 | { |
sahilmgandhi | 18:6a4db94011d3 | 1404 | /* Disable CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1405 | hcan->State = HAL_CAN_STATE_BUSY_TX; |
sahilmgandhi | 18:6a4db94011d3 | 1406 | } |
sahilmgandhi | 18:6a4db94011d3 | 1407 | else |
sahilmgandhi | 18:6a4db94011d3 | 1408 | { |
sahilmgandhi | 18:6a4db94011d3 | 1409 | /* Change CAN state */ |
sahilmgandhi | 18:6a4db94011d3 | 1410 | hcan->State = HAL_CAN_STATE_READY; |
sahilmgandhi | 18:6a4db94011d3 | 1411 | } |
sahilmgandhi | 18:6a4db94011d3 | 1412 | |
sahilmgandhi | 18:6a4db94011d3 | 1413 | /* Receive complete callback */ |
sahilmgandhi | 18:6a4db94011d3 | 1414 | HAL_CAN_RxCpltCallback(hcan); |
sahilmgandhi | 18:6a4db94011d3 | 1415 | |
sahilmgandhi | 18:6a4db94011d3 | 1416 | /* Return function status */ |
sahilmgandhi | 18:6a4db94011d3 | 1417 | return HAL_OK; |
sahilmgandhi | 18:6a4db94011d3 | 1418 | } |
sahilmgandhi | 18:6a4db94011d3 | 1419 | |
sahilmgandhi | 18:6a4db94011d3 | 1420 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1421 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1422 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1423 | #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx ||\ |
sahilmgandhi | 18:6a4db94011d3 | 1424 | STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx ||\ |
sahilmgandhi | 18:6a4db94011d3 | 1425 | STM32F412Vx || STM32F412Rx || STM32F412Cx */ |
sahilmgandhi | 18:6a4db94011d3 | 1426 | |
sahilmgandhi | 18:6a4db94011d3 | 1427 | #endif /* HAL_CAN_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 1428 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1429 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1430 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1431 | |
sahilmgandhi | 18:6a4db94011d3 | 1432 | /** |
sahilmgandhi | 18:6a4db94011d3 | 1433 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 1434 | */ |
sahilmgandhi | 18:6a4db94011d3 | 1435 | |
sahilmgandhi | 18:6a4db94011d3 | 1436 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |