stm32f4xx_can.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657
  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_can.h
  4. * @author MCD Application Team
  5. * @version V1.8.0
  6. * @date 04-November-2016
  7. * @brief This file contains all the functions prototypes for the CAN firmware
  8. * library.
  9. ******************************************************************************
  10. * @attention
  11. *
  12. * <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
  13. *
  14. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  15. * You may not use this file except in compliance with the License.
  16. * You may obtain a copy of the License at:
  17. *
  18. * http://www.st.com/software_license_agreement_liberty_v2
  19. *
  20. * Unless required by applicable law or agreed to in writing, software
  21. * distributed under the License is distributed on an "AS IS" BASIS,
  22. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  23. * See the License for the specific language governing permissions and
  24. * limitations under the License.
  25. *
  26. ******************************************************************************
  27. */
  28. /* Define to prevent recursive inclusion -------------------------------------*/
  29. #ifndef __STM32F4xx_CAN_H
  30. #define __STM32F4xx_CAN_H
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f4xx.h"
  36. /** @addtogroup STM32F4xx_StdPeriph_Driver
  37. * @{
  38. */
  39. /** @addtogroup CAN
  40. * @{
  41. */
  42. /* Exported types ------------------------------------------------------------*/
  43. #if defined(STM32F413_423xx)
  44. #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
  45. ((PERIPH) == CAN2) || \
  46. ((PERIPH) == CAN3))
  47. #else
  48. #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
  49. ((PERIPH) == CAN2))
  50. #endif /* STM32F413_423xx */
  51. /**
  52. * @brief CAN init structure definition
  53. */
  54. typedef struct
  55. {
  56. uint16_t CAN_Prescaler; /*!< Specifies the length of a time quantum.
  57. It ranges from 1 to 1024. */
  58. uint8_t CAN_Mode; /*!< Specifies the CAN operating mode.
  59. This parameter can be a value of @ref CAN_operating_mode */
  60. uint8_t CAN_SJW; /*!< Specifies the maximum number of time quanta
  61. the CAN hardware is allowed to lengthen or
  62. shorten a bit to perform resynchronization.
  63. This parameter can be a value of @ref CAN_synchronisation_jump_width */
  64. uint8_t CAN_BS1; /*!< Specifies the number of time quanta in Bit
  65. Segment 1. This parameter can be a value of
  66. @ref CAN_time_quantum_in_bit_segment_1 */
  67. uint8_t CAN_BS2; /*!< Specifies the number of time quanta in Bit Segment 2.
  68. This parameter can be a value of @ref CAN_time_quantum_in_bit_segment_2 */
  69. FunctionalState CAN_TTCM; /*!< Enable or disable the time triggered communication mode.
  70. This parameter can be set either to ENABLE or DISABLE. */
  71. FunctionalState CAN_ABOM; /*!< Enable or disable the automatic bus-off management.
  72. This parameter can be set either to ENABLE or DISABLE. */
  73. FunctionalState CAN_AWUM; /*!< Enable or disable the automatic wake-up mode.
  74. This parameter can be set either to ENABLE or DISABLE. */
  75. FunctionalState CAN_NART; /*!< Enable or disable the non-automatic retransmission mode.
  76. This parameter can be set either to ENABLE or DISABLE. */
  77. FunctionalState CAN_RFLM; /*!< Enable or disable the Receive FIFO Locked mode.
  78. This parameter can be set either to ENABLE or DISABLE. */
  79. FunctionalState CAN_TXFP; /*!< Enable or disable the transmit FIFO priority.
  80. This parameter can be set either to ENABLE or DISABLE. */
  81. } CAN_InitTypeDef;
  82. /**
  83. * @brief CAN filter init structure definition
  84. */
  85. typedef struct
  86. {
  87. uint16_t CAN_FilterIdHigh; /*!< Specifies the filter identification number (MSBs for a 32-bit
  88. configuration, first one for a 16-bit configuration).
  89. This parameter can be a value between 0x0000 and 0xFFFF */
  90. uint16_t CAN_FilterIdLow; /*!< Specifies the filter identification number (LSBs for a 32-bit
  91. configuration, second one for a 16-bit configuration).
  92. This parameter can be a value between 0x0000 and 0xFFFF */
  93. uint16_t CAN_FilterMaskIdHigh; /*!< Specifies the filter mask number or identification number,
  94. according to the mode (MSBs for a 32-bit configuration,
  95. first one for a 16-bit configuration).
  96. This parameter can be a value between 0x0000 and 0xFFFF */
  97. uint16_t CAN_FilterMaskIdLow; /*!< Specifies the filter mask number or identification number,
  98. according to the mode (LSBs for a 32-bit configuration,
  99. second one for a 16-bit configuration).
  100. This parameter can be a value between 0x0000 and 0xFFFF */
  101. uint16_t CAN_FilterFIFOAssignment; /*!< Specifies the FIFO (0 or 1) which will be assigned to the filter.
  102. This parameter can be a value of @ref CAN_filter_FIFO */
  103. uint8_t CAN_FilterNumber; /*!< Specifies the filter which will be initialized. It ranges from 0 to 13. */
  104. uint8_t CAN_FilterMode; /*!< Specifies the filter mode to be initialized.
  105. This parameter can be a value of @ref CAN_filter_mode */
  106. uint8_t CAN_FilterScale; /*!< Specifies the filter scale.
  107. This parameter can be a value of @ref CAN_filter_scale */
  108. FunctionalState CAN_FilterActivation; /*!< Enable or disable the filter.
  109. This parameter can be set either to ENABLE or DISABLE. */
  110. } CAN_FilterInitTypeDef;
  111. /**
  112. * @brief CAN Tx message structure definition
  113. */
  114. typedef struct
  115. {
  116. uint32_t StdId; /*!< Specifies the standard identifier.
  117. This parameter can be a value between 0 to 0x7FF. */
  118. uint32_t ExtId; /*!< Specifies the extended identifier.
  119. This parameter can be a value between 0 to 0x1FFFFFFF. */
  120. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  121. will be transmitted. This parameter can be a value
  122. of @ref CAN_identifier_type */
  123. uint8_t RTR; /*!< Specifies the type of frame for the message that will
  124. be transmitted. This parameter can be a value of
  125. @ref CAN_remote_transmission_request */
  126. uint8_t DLC; /*!< Specifies the length of the frame that will be
  127. transmitted. This parameter can be a value between
  128. 0 to 8 */
  129. uint8_t Data[8]; /*!< Contains the data to be transmitted. It ranges from 0
  130. to 0xFF. */
  131. } CanTxMsg;
  132. /**
  133. * @brief CAN Rx message structure definition
  134. */
  135. typedef struct
  136. {
  137. uint32_t StdId; /*!< Specifies the standard identifier.
  138. This parameter can be a value between 0 to 0x7FF. */
  139. uint32_t ExtId; /*!< Specifies the extended identifier.
  140. This parameter can be a value between 0 to 0x1FFFFFFF. */
  141. uint8_t IDE; /*!< Specifies the type of identifier for the message that
  142. will be received. This parameter can be a value of
  143. @ref CAN_identifier_type */
  144. uint8_t RTR; /*!< Specifies the type of frame for the received message.
  145. This parameter can be a value of
  146. @ref CAN_remote_transmission_request */
  147. uint8_t DLC; /*!< Specifies the length of the frame that will be received.
  148. This parameter can be a value between 0 to 8 */
  149. uint8_t Data[8]; /*!< Contains the data to be received. It ranges from 0 to
  150. 0xFF. */
  151. uint8_t FMI; /*!< Specifies the index of the filter the message stored in
  152. the mailbox passes through. This parameter can be a
  153. value between 0 to 0xFF */
  154. } CanRxMsg;
  155. /* Exported constants --------------------------------------------------------*/
  156. /** @defgroup CAN_Exported_Constants
  157. * @{
  158. */
  159. /** @defgroup CAN_InitStatus
  160. * @{
  161. */
  162. #define CAN_InitStatus_Failed ((uint8_t)0x00) /*!< CAN initialization failed */
  163. #define CAN_InitStatus_Success ((uint8_t)0x01) /*!< CAN initialization OK */
  164. /* Legacy defines */
  165. #define CANINITFAILED CAN_InitStatus_Failed
  166. #define CANINITOK CAN_InitStatus_Success
  167. /**
  168. * @}
  169. */
  170. /** @defgroup CAN_operating_mode
  171. * @{
  172. */
  173. #define CAN_Mode_Normal ((uint8_t)0x00) /*!< normal mode */
  174. #define CAN_Mode_LoopBack ((uint8_t)0x01) /*!< loopback mode */
  175. #define CAN_Mode_Silent ((uint8_t)0x02) /*!< silent mode */
  176. #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03) /*!< loopback combined with silent mode */
  177. #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
  178. ((MODE) == CAN_Mode_LoopBack)|| \
  179. ((MODE) == CAN_Mode_Silent) || \
  180. ((MODE) == CAN_Mode_Silent_LoopBack))
  181. /**
  182. * @}
  183. */
  184. /**
  185. * @defgroup CAN_operating_mode
  186. * @{
  187. */
  188. #define CAN_OperatingMode_Initialization ((uint8_t)0x00) /*!< Initialization mode */
  189. #define CAN_OperatingMode_Normal ((uint8_t)0x01) /*!< Normal mode */
  190. #define CAN_OperatingMode_Sleep ((uint8_t)0x02) /*!< sleep mode */
  191. #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
  192. ((MODE) == CAN_OperatingMode_Normal)|| \
  193. ((MODE) == CAN_OperatingMode_Sleep))
  194. /**
  195. * @}
  196. */
  197. /**
  198. * @defgroup CAN_operating_mode_status
  199. * @{
  200. */
  201. #define CAN_ModeStatus_Failed ((uint8_t)0x00) /*!< CAN entering the specific mode failed */
  202. #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed) /*!< CAN entering the specific mode Succeed */
  203. /**
  204. * @}
  205. */
  206. /** @defgroup CAN_synchronisation_jump_width
  207. * @{
  208. */
  209. #define CAN_SJW_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  210. #define CAN_SJW_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  211. #define CAN_SJW_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  212. #define CAN_SJW_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  213. #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
  214. ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
  215. /**
  216. * @}
  217. */
  218. /** @defgroup CAN_time_quantum_in_bit_segment_1
  219. * @{
  220. */
  221. #define CAN_BS1_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  222. #define CAN_BS1_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  223. #define CAN_BS1_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  224. #define CAN_BS1_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  225. #define CAN_BS1_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  226. #define CAN_BS1_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  227. #define CAN_BS1_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  228. #define CAN_BS1_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  229. #define CAN_BS1_9tq ((uint8_t)0x08) /*!< 9 time quantum */
  230. #define CAN_BS1_10tq ((uint8_t)0x09) /*!< 10 time quantum */
  231. #define CAN_BS1_11tq ((uint8_t)0x0A) /*!< 11 time quantum */
  232. #define CAN_BS1_12tq ((uint8_t)0x0B) /*!< 12 time quantum */
  233. #define CAN_BS1_13tq ((uint8_t)0x0C) /*!< 13 time quantum */
  234. #define CAN_BS1_14tq ((uint8_t)0x0D) /*!< 14 time quantum */
  235. #define CAN_BS1_15tq ((uint8_t)0x0E) /*!< 15 time quantum */
  236. #define CAN_BS1_16tq ((uint8_t)0x0F) /*!< 16 time quantum */
  237. #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
  238. /**
  239. * @}
  240. */
  241. /** @defgroup CAN_time_quantum_in_bit_segment_2
  242. * @{
  243. */
  244. #define CAN_BS2_1tq ((uint8_t)0x00) /*!< 1 time quantum */
  245. #define CAN_BS2_2tq ((uint8_t)0x01) /*!< 2 time quantum */
  246. #define CAN_BS2_3tq ((uint8_t)0x02) /*!< 3 time quantum */
  247. #define CAN_BS2_4tq ((uint8_t)0x03) /*!< 4 time quantum */
  248. #define CAN_BS2_5tq ((uint8_t)0x04) /*!< 5 time quantum */
  249. #define CAN_BS2_6tq ((uint8_t)0x05) /*!< 6 time quantum */
  250. #define CAN_BS2_7tq ((uint8_t)0x06) /*!< 7 time quantum */
  251. #define CAN_BS2_8tq ((uint8_t)0x07) /*!< 8 time quantum */
  252. #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
  253. /**
  254. * @}
  255. */
  256. /** @defgroup CAN_clock_prescaler
  257. * @{
  258. */
  259. #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
  260. /**
  261. * @}
  262. */
  263. /** @defgroup CAN_filter_number
  264. * @{
  265. */
  266. #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
  267. /**
  268. * @}
  269. */
  270. /** @defgroup CAN_filter_mode
  271. * @{
  272. */
  273. #define CAN_FilterMode_IdMask ((uint8_t)0x00) /*!< identifier/mask mode */
  274. #define CAN_FilterMode_IdList ((uint8_t)0x01) /*!< identifier list mode */
  275. #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
  276. ((MODE) == CAN_FilterMode_IdList))
  277. /**
  278. * @}
  279. */
  280. /** @defgroup CAN_filter_scale
  281. * @{
  282. */
  283. #define CAN_FilterScale_16bit ((uint8_t)0x00) /*!< Two 16-bit filters */
  284. #define CAN_FilterScale_32bit ((uint8_t)0x01) /*!< One 32-bit filter */
  285. #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
  286. ((SCALE) == CAN_FilterScale_32bit))
  287. /**
  288. * @}
  289. */
  290. /** @defgroup CAN_filter_FIFO
  291. * @{
  292. */
  293. #define CAN_Filter_FIFO0 ((uint8_t)0x00) /*!< Filter FIFO 0 assignment for filter x */
  294. #define CAN_Filter_FIFO1 ((uint8_t)0x01) /*!< Filter FIFO 1 assignment for filter x */
  295. #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
  296. ((FIFO) == CAN_FilterFIFO1))
  297. /* Legacy defines */
  298. #define CAN_FilterFIFO0 CAN_Filter_FIFO0
  299. #define CAN_FilterFIFO1 CAN_Filter_FIFO1
  300. /**
  301. * @}
  302. */
  303. /** @defgroup CAN_Start_bank_filter_for_slave_CAN
  304. * @{
  305. */
  306. #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
  307. /**
  308. * @}
  309. */
  310. /** @defgroup CAN_Tx
  311. * @{
  312. */
  313. #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
  314. #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
  315. #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
  316. #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
  317. /**
  318. * @}
  319. */
  320. /** @defgroup CAN_identifier_type
  321. * @{
  322. */
  323. #define CAN_Id_Standard ((uint32_t)0x00000000) /*!< Standard Id */
  324. #define CAN_Id_Extended ((uint32_t)0x00000004) /*!< Extended Id */
  325. #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
  326. ((IDTYPE) == CAN_Id_Extended))
  327. /* Legacy defines */
  328. #define CAN_ID_STD CAN_Id_Standard
  329. #define CAN_ID_EXT CAN_Id_Extended
  330. /**
  331. * @}
  332. */
  333. /** @defgroup CAN_remote_transmission_request
  334. * @{
  335. */
  336. #define CAN_RTR_Data ((uint32_t)0x00000000) /*!< Data frame */
  337. #define CAN_RTR_Remote ((uint32_t)0x00000002) /*!< Remote frame */
  338. #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
  339. /* Legacy defines */
  340. #define CAN_RTR_DATA CAN_RTR_Data
  341. #define CAN_RTR_REMOTE CAN_RTR_Remote
  342. /**
  343. * @}
  344. */
  345. /** @defgroup CAN_transmit_constants
  346. * @{
  347. */
  348. #define CAN_TxStatus_Failed ((uint8_t)0x00)/*!< CAN transmission failed */
  349. #define CAN_TxStatus_Ok ((uint8_t)0x01) /*!< CAN transmission succeeded */
  350. #define CAN_TxStatus_Pending ((uint8_t)0x02) /*!< CAN transmission pending */
  351. #define CAN_TxStatus_NoMailBox ((uint8_t)0x04) /*!< CAN cell did not provide
  352. an empty mailbox */
  353. /* Legacy defines */
  354. #define CANTXFAILED CAN_TxStatus_Failed
  355. #define CANTXOK CAN_TxStatus_Ok
  356. #define CANTXPENDING CAN_TxStatus_Pending
  357. #define CAN_NO_MB CAN_TxStatus_NoMailBox
  358. /**
  359. * @}
  360. */
  361. /** @defgroup CAN_receive_FIFO_number_constants
  362. * @{
  363. */
  364. #define CAN_FIFO0 ((uint8_t)0x00) /*!< CAN FIFO 0 used to receive */
  365. #define CAN_FIFO1 ((uint8_t)0x01) /*!< CAN FIFO 1 used to receive */
  366. #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
  367. /**
  368. * @}
  369. */
  370. /** @defgroup CAN_sleep_constants
  371. * @{
  372. */
  373. #define CAN_Sleep_Failed ((uint8_t)0x00) /*!< CAN did not enter the sleep mode */
  374. #define CAN_Sleep_Ok ((uint8_t)0x01) /*!< CAN entered the sleep mode */
  375. /* Legacy defines */
  376. #define CANSLEEPFAILED CAN_Sleep_Failed
  377. #define CANSLEEPOK CAN_Sleep_Ok
  378. /**
  379. * @}
  380. */
  381. /** @defgroup CAN_wake_up_constants
  382. * @{
  383. */
  384. #define CAN_WakeUp_Failed ((uint8_t)0x00) /*!< CAN did not leave the sleep mode */
  385. #define CAN_WakeUp_Ok ((uint8_t)0x01) /*!< CAN leaved the sleep mode */
  386. /* Legacy defines */
  387. #define CANWAKEUPFAILED CAN_WakeUp_Failed
  388. #define CANWAKEUPOK CAN_WakeUp_Ok
  389. /**
  390. * @}
  391. */
  392. /**
  393. * @defgroup CAN_Error_Code_constants
  394. * @{
  395. */
  396. #define CAN_ErrorCode_NoErr ((uint8_t)0x00) /*!< No Error */
  397. #define CAN_ErrorCode_StuffErr ((uint8_t)0x10) /*!< Stuff Error */
  398. #define CAN_ErrorCode_FormErr ((uint8_t)0x20) /*!< Form Error */
  399. #define CAN_ErrorCode_ACKErr ((uint8_t)0x30) /*!< Acknowledgment Error */
  400. #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40) /*!< Bit Recessive Error */
  401. #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50) /*!< Bit Dominant Error */
  402. #define CAN_ErrorCode_CRCErr ((uint8_t)0x60) /*!< CRC Error */
  403. #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70) /*!< Software Set Error */
  404. /**
  405. * @}
  406. */
  407. /** @defgroup CAN_flags
  408. * @{
  409. */
  410. /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
  411. and CAN_ClearFlag() functions. */
  412. /* If the flag is 0x1XXXXXXX, it means that it can only be used with
  413. CAN_GetFlagStatus() function. */
  414. /* Transmit Flags */
  415. #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001) /*!< Request MailBox0 Flag */
  416. #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100) /*!< Request MailBox1 Flag */
  417. #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000) /*!< Request MailBox2 Flag */
  418. /* Receive Flags */
  419. #define CAN_FLAG_FMP0 ((uint32_t)0x12000003) /*!< FIFO 0 Message Pending Flag */
  420. #define CAN_FLAG_FF0 ((uint32_t)0x32000008) /*!< FIFO 0 Full Flag */
  421. #define CAN_FLAG_FOV0 ((uint32_t)0x32000010) /*!< FIFO 0 Overrun Flag */
  422. #define CAN_FLAG_FMP1 ((uint32_t)0x14000003) /*!< FIFO 1 Message Pending Flag */
  423. #define CAN_FLAG_FF1 ((uint32_t)0x34000008) /*!< FIFO 1 Full Flag */
  424. #define CAN_FLAG_FOV1 ((uint32_t)0x34000010) /*!< FIFO 1 Overrun Flag */
  425. /* Operating Mode Flags */
  426. #define CAN_FLAG_WKU ((uint32_t)0x31000008) /*!< Wake up Flag */
  427. #define CAN_FLAG_SLAK ((uint32_t)0x31000012) /*!< Sleep acknowledge Flag */
  428. /* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible.
  429. In this case the SLAK bit can be polled.*/
  430. /* Error Flags */
  431. #define CAN_FLAG_EWG ((uint32_t)0x10F00001) /*!< Error Warning Flag */
  432. #define CAN_FLAG_EPV ((uint32_t)0x10F00002) /*!< Error Passive Flag */
  433. #define CAN_FLAG_BOF ((uint32_t)0x10F00004) /*!< Bus-Off Flag */
  434. #define CAN_FLAG_LEC ((uint32_t)0x30F00070) /*!< Last error code Flag */
  435. #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \
  436. ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \
  437. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \
  438. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \
  439. ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \
  440. ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
  441. ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
  442. ((FLAG) == CAN_FLAG_SLAK ))
  443. #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
  444. ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \
  445. ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\
  446. ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
  447. ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
  448. /**
  449. * @}
  450. */
  451. /** @defgroup CAN_interrupts
  452. * @{
  453. */
  454. #define CAN_IT_TME ((uint32_t)0x00000001) /*!< Transmit mailbox empty Interrupt*/
  455. /* Receive Interrupts */
  456. #define CAN_IT_FMP0 ((uint32_t)0x00000002) /*!< FIFO 0 message pending Interrupt*/
  457. #define CAN_IT_FF0 ((uint32_t)0x00000004) /*!< FIFO 0 full Interrupt*/
  458. #define CAN_IT_FOV0 ((uint32_t)0x00000008) /*!< FIFO 0 overrun Interrupt*/
  459. #define CAN_IT_FMP1 ((uint32_t)0x00000010) /*!< FIFO 1 message pending Interrupt*/
  460. #define CAN_IT_FF1 ((uint32_t)0x00000020) /*!< FIFO 1 full Interrupt*/
  461. #define CAN_IT_FOV1 ((uint32_t)0x00000040) /*!< FIFO 1 overrun Interrupt*/
  462. /* Operating Mode Interrupts */
  463. #define CAN_IT_WKU ((uint32_t)0x00010000) /*!< Wake-up Interrupt*/
  464. #define CAN_IT_SLK ((uint32_t)0x00020000) /*!< Sleep acknowledge Interrupt*/
  465. /* Error Interrupts */
  466. #define CAN_IT_EWG ((uint32_t)0x00000100) /*!< Error warning Interrupt*/
  467. #define CAN_IT_EPV ((uint32_t)0x00000200) /*!< Error passive Interrupt*/
  468. #define CAN_IT_BOF ((uint32_t)0x00000400) /*!< Bus-off Interrupt*/
  469. #define CAN_IT_LEC ((uint32_t)0x00000800) /*!< Last error code Interrupt*/
  470. #define CAN_IT_ERR ((uint32_t)0x00008000) /*!< Error Interrupt*/
  471. /* Flags named as Interrupts : kept only for FW compatibility */
  472. #define CAN_IT_RQCP0 CAN_IT_TME
  473. #define CAN_IT_RQCP1 CAN_IT_TME
  474. #define CAN_IT_RQCP2 CAN_IT_TME
  475. #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\
  476. ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\
  477. ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\
  478. ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\
  479. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  480. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  481. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  482. #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\
  483. ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\
  484. ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\
  485. ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
  486. ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
  487. ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
  488. /**
  489. * @}
  490. */
  491. /**
  492. * @}
  493. */
  494. /* Exported macro ------------------------------------------------------------*/
  495. /* Exported functions --------------------------------------------------------*/
  496. /* Function used to set the CAN configuration to the default reset state *****/
  497. void CAN_DeInit(CAN_TypeDef* CANx);
  498. /* Initialization and Configuration functions *********************************/
  499. uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
  500. #if defined(STM32F413_423xx)
  501. void CAN_FilterInit(CAN_TypeDef* CANx, CAN_FilterInitTypeDef* CAN_FilterInitStruct);
  502. #else
  503. void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
  504. #endif /* STM32F413_423xx */
  505. void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
  506. #if defined(STM32F413_423xx)
  507. void CAN_SlaveStartBank(CAN_TypeDef* CANx, uint8_t CAN_BankNumber);
  508. #else
  509. void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
  510. #endif /* STM32F413_423xx */
  511. void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
  512. void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
  513. /* CAN Frames Transmission functions ******************************************/
  514. uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
  515. uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
  516. void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
  517. /* CAN Frames Reception functions *********************************************/
  518. void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
  519. void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
  520. uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
  521. /* Operation modes functions **************************************************/
  522. uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
  523. uint8_t CAN_Sleep(CAN_TypeDef* CANx);
  524. uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
  525. /* CAN Bus Error management functions *****************************************/
  526. uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
  527. uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx);
  528. uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx);
  529. /* Interrupts and flags management functions **********************************/
  530. void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
  531. FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  532. void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
  533. ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
  534. void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
  535. #ifdef __cplusplus
  536. }
  537. #endif
  538. #endif /* __STM32F4xx_CAN_H */
  539. /**
  540. * @}
  541. */
  542. /**
  543. * @}
  544. */
  545. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/