stm32f30x_can.h
Go to the documentation of this file.
1 
29 /* Define to prevent recursive inclusion -------------------------------------*/
30 #ifndef __STM32F30x_CAN_H
31 #define __STM32F30x_CAN_H
32 
33 #ifdef __cplusplus
34  extern "C" {
35 #endif
36 
37 /* Includes ------------------------------------------------------------------*/
38 #include "stm32f30x.h"
39 
48 /* Exported types ------------------------------------------------------------*/
49 
50 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1))
51 
55 typedef struct
56 {
57  uint16_t CAN_Prescaler;
60  uint8_t CAN_Mode;
63  uint8_t CAN_SJW;
68  uint8_t CAN_BS1;
72  uint8_t CAN_BS2;
75  FunctionalState CAN_TTCM;
78  FunctionalState CAN_ABOM;
81  FunctionalState CAN_AWUM;
84  FunctionalState CAN_NART;
87  FunctionalState CAN_RFLM;
90  FunctionalState CAN_TXFP;
93 
97 typedef struct
98 {
99  uint16_t CAN_FilterIdHigh;
103  uint16_t CAN_FilterIdLow;
107  uint16_t CAN_FilterMaskIdHigh;
112  uint16_t CAN_FilterMaskIdLow;
117  uint16_t CAN_FilterFIFOAssignment;
120  uint8_t CAN_FilterNumber;
122  uint8_t CAN_FilterMode;
125  uint8_t CAN_FilterScale;
128  FunctionalState CAN_FilterActivation;
131 
135 typedef struct
136 {
137  uint32_t StdId;
140  uint32_t ExtId;
143  uint8_t IDE;
147  uint8_t RTR;
151  uint8_t DLC;
155  uint8_t Data[8];
157 } CanTxMsg;
158 
162 typedef struct
163 {
164  uint32_t StdId;
167  uint32_t ExtId;
170  uint8_t IDE;
174  uint8_t RTR;
178  uint8_t DLC;
181  uint8_t Data[8];
184  uint8_t FMI;
187 } CanRxMsg;
188 
189 /* Exported constants --------------------------------------------------------*/
190 
199 #define CAN_InitStatus_Failed ((uint8_t)0x00)
200 #define CAN_InitStatus_Success ((uint8_t)0x01)
203 /* Legacy defines */
204 #define CANINITFAILED CAN_InitStatus_Failed
205 #define CANINITOK CAN_InitStatus_Success
206 
214 #define CAN_Mode_Normal ((uint8_t)0x00)
215 #define CAN_Mode_LoopBack ((uint8_t)0x01)
216 #define CAN_Mode_Silent ((uint8_t)0x02)
217 #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03)
219 #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
220  ((MODE) == CAN_Mode_LoopBack)|| \
221  ((MODE) == CAN_Mode_Silent) || \
222  ((MODE) == CAN_Mode_Silent_LoopBack))
223 
232 #define CAN_OperatingMode_Initialization ((uint8_t)0x00)
233 #define CAN_OperatingMode_Normal ((uint8_t)0x01)
234 #define CAN_OperatingMode_Sleep ((uint8_t)0x02)
237 #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
238  ((MODE) == CAN_OperatingMode_Normal)|| \
239  ((MODE) == CAN_OperatingMode_Sleep))
240 
249 #define CAN_ModeStatus_Failed ((uint8_t)0x00)
250 #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed)
258 #define CAN_SJW_1tq ((uint8_t)0x00)
259 #define CAN_SJW_2tq ((uint8_t)0x01)
260 #define CAN_SJW_3tq ((uint8_t)0x02)
261 #define CAN_SJW_4tq ((uint8_t)0x03)
263 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
264  ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
265 
272 #define CAN_BS1_1tq ((uint8_t)0x00)
273 #define CAN_BS1_2tq ((uint8_t)0x01)
274 #define CAN_BS1_3tq ((uint8_t)0x02)
275 #define CAN_BS1_4tq ((uint8_t)0x03)
276 #define CAN_BS1_5tq ((uint8_t)0x04)
277 #define CAN_BS1_6tq ((uint8_t)0x05)
278 #define CAN_BS1_7tq ((uint8_t)0x06)
279 #define CAN_BS1_8tq ((uint8_t)0x07)
280 #define CAN_BS1_9tq ((uint8_t)0x08)
281 #define CAN_BS1_10tq ((uint8_t)0x09)
282 #define CAN_BS1_11tq ((uint8_t)0x0A)
283 #define CAN_BS1_12tq ((uint8_t)0x0B)
284 #define CAN_BS1_13tq ((uint8_t)0x0C)
285 #define CAN_BS1_14tq ((uint8_t)0x0D)
286 #define CAN_BS1_15tq ((uint8_t)0x0E)
287 #define CAN_BS1_16tq ((uint8_t)0x0F)
289 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
290 
297 #define CAN_BS2_1tq ((uint8_t)0x00)
298 #define CAN_BS2_2tq ((uint8_t)0x01)
299 #define CAN_BS2_3tq ((uint8_t)0x02)
300 #define CAN_BS2_4tq ((uint8_t)0x03)
301 #define CAN_BS2_5tq ((uint8_t)0x04)
302 #define CAN_BS2_6tq ((uint8_t)0x05)
303 #define CAN_BS2_7tq ((uint8_t)0x06)
304 #define CAN_BS2_8tq ((uint8_t)0x07)
306 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
307 
314 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
315 
322 #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
323 
330 #define CAN_FilterMode_IdMask ((uint8_t)0x00)
331 #define CAN_FilterMode_IdList ((uint8_t)0x01)
333 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
334  ((MODE) == CAN_FilterMode_IdList))
335 
342 #define CAN_FilterScale_16bit ((uint8_t)0x00)
343 #define CAN_FilterScale_32bit ((uint8_t)0x01)
345 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
346  ((SCALE) == CAN_FilterScale_32bit))
347 
354 #define CAN_Filter_FIFO0 ((uint8_t)0x00)
355 #define CAN_Filter_FIFO1 ((uint8_t)0x01)
356 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
357  ((FIFO) == CAN_FilterFIFO1))
358 
359 /* Legacy defines */
360 #define CAN_FilterFIFO0 CAN_Filter_FIFO0
361 #define CAN_FilterFIFO1 CAN_Filter_FIFO1
362 
369 #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
370 
377 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
378 #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
379 #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
380 #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
381 
388 #define CAN_Id_Standard ((uint32_t)0x00000000)
389 #define CAN_Id_Extended ((uint32_t)0x00000004)
390 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
391  ((IDTYPE) == CAN_Id_Extended))
392 
393 /* Legacy defines */
394 #define CAN_ID_STD CAN_Id_Standard
395 #define CAN_ID_EXT CAN_Id_Extended
396 
403 #define CAN_RTR_Data ((uint32_t)0x00000000)
404 #define CAN_RTR_Remote ((uint32_t)0x00000002)
405 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
406 
407 /* Legacy defines */
408 #define CAN_RTR_DATA CAN_RTR_Data
409 #define CAN_RTR_REMOTE CAN_RTR_Remote
410 
417 #define CAN_TxStatus_Failed ((uint8_t)0x00)
418 #define CAN_TxStatus_Ok ((uint8_t)0x01)
419 #define CAN_TxStatus_Pending ((uint8_t)0x02)
420 #define CAN_TxStatus_NoMailBox ((uint8_t)0x04)
422 /* Legacy defines */
423 #define CANTXFAILED CAN_TxStatus_Failed
424 #define CANTXOK CAN_TxStatus_Ok
425 #define CANTXPENDING CAN_TxStatus_Pending
426 #define CAN_NO_MB CAN_TxStatus_NoMailBox
434 #define CAN_FIFO0 ((uint8_t)0x00)
435 #define CAN_FIFO1 ((uint8_t)0x01)
437 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
445 #define CAN_Sleep_Failed ((uint8_t)0x00)
446 #define CAN_Sleep_Ok ((uint8_t)0x01)
448 /* Legacy defines */
449 #define CANSLEEPFAILED CAN_Sleep_Failed
450 #define CANSLEEPOK CAN_Sleep_Ok
458 #define CAN_WakeUp_Failed ((uint8_t)0x00)
459 #define CAN_WakeUp_Ok ((uint8_t)0x01)
461 /* Legacy defines */
462 #define CANWAKEUPFAILED CAN_WakeUp_Failed
463 #define CANWAKEUPOK CAN_WakeUp_Ok
472 #define CAN_ErrorCode_NoErr ((uint8_t)0x00)
473 #define CAN_ErrorCode_StuffErr ((uint8_t)0x10)
474 #define CAN_ErrorCode_FormErr ((uint8_t)0x20)
475 #define CAN_ErrorCode_ACKErr ((uint8_t)0x30)
476 #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40)
477 #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50)
478 #define CAN_ErrorCode_CRCErr ((uint8_t)0x60)
479 #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70)
487 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
488  and CAN_ClearFlag() functions. */
489 /* If the flag is 0x1XXXXXXX, it means that it can only be used with
490  CAN_GetFlagStatus() function. */
491 
492 /* Transmit Flags */
493 #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001)
494 #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100)
495 #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000)
497 /* Receive Flags */
498 #define CAN_FLAG_FMP0 ((uint32_t)0x12000003)
499 #define CAN_FLAG_FF0 ((uint32_t)0x32000008)
500 #define CAN_FLAG_FOV0 ((uint32_t)0x32000010)
501 #define CAN_FLAG_FMP1 ((uint32_t)0x14000003)
502 #define CAN_FLAG_FF1 ((uint32_t)0x34000008)
503 #define CAN_FLAG_FOV1 ((uint32_t)0x34000010)
505 /* Operating Mode Flags */
506 #define CAN_FLAG_WKU ((uint32_t)0x31000008)
507 #define CAN_FLAG_SLAK ((uint32_t)0x31000012)
508 /* @note When SLAK interrupt is disabled (SLKIE=0), no polling on SLAKI is possible.
509  In this case the SLAK bit can be polled.*/
510 
511 /* Error Flags */
512 #define CAN_FLAG_EWG ((uint32_t)0x10F00001)
513 #define CAN_FLAG_EPV ((uint32_t)0x10F00002)
514 #define CAN_FLAG_BOF ((uint32_t)0x10F00004)
515 #define CAN_FLAG_LEC ((uint32_t)0x30F00070)
517 #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \
518  ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \
519  ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \
520  ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \
521  ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \
522  ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
523  ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
524  ((FLAG) == CAN_FLAG_SLAK ))
525 
526 #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
527  ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \
528  ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\
529  ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
530  ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
531 
539 #define CAN_IT_TME ((uint32_t)0x00000001)
541 /* Receive Interrupts */
542 #define CAN_IT_FMP0 ((uint32_t)0x00000002)
543 #define CAN_IT_FF0 ((uint32_t)0x00000004)
544 #define CAN_IT_FOV0 ((uint32_t)0x00000008)
545 #define CAN_IT_FMP1 ((uint32_t)0x00000010)
546 #define CAN_IT_FF1 ((uint32_t)0x00000020)
547 #define CAN_IT_FOV1 ((uint32_t)0x00000040)
549 /* Operating Mode Interrupts */
550 #define CAN_IT_WKU ((uint32_t)0x00010000)
551 #define CAN_IT_SLK ((uint32_t)0x00020000)
553 /* Error Interrupts */
554 #define CAN_IT_EWG ((uint32_t)0x00000100)
555 #define CAN_IT_EPV ((uint32_t)0x00000200)
556 #define CAN_IT_BOF ((uint32_t)0x00000400)
557 #define CAN_IT_LEC ((uint32_t)0x00000800)
558 #define CAN_IT_ERR ((uint32_t)0x00008000)
560 /* Flags named as Interrupts : kept only for FW compatibility */
561 #define CAN_IT_RQCP0 CAN_IT_TME
562 #define CAN_IT_RQCP1 CAN_IT_TME
563 #define CAN_IT_RQCP2 CAN_IT_TME
565 
566 #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\
567  ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\
568  ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\
569  ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\
570  ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
571  ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
572  ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
573 
574 #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\
575  ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\
576  ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\
577  ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
578  ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
579  ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
580 
588 /* Exported macro ------------------------------------------------------------*/
589 /* Exported functions --------------------------------------------------------*/
590 
591 /* Function used to set the CAN configuration to the default reset state *****/
592 void CAN_DeInit(CAN_TypeDef* CANx);
593 
594 /* Initialization and Configuration functions *********************************/
595 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
596 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
597 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
598 void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
599 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
600 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
601 
602 /* CAN Frames Transmission functions ******************************************/
603 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
604 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
605 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
606 
607 /* CAN Frames Reception functions *********************************************/
608 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
609 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
610 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
611 
612 /* Operation modes functions **************************************************/
613 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
614 uint8_t CAN_Sleep(CAN_TypeDef* CANx);
615 uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
616 
617 /* CAN Bus Error management functions *****************************************/
618 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
621 
622 /* Interrupts and flags management functions **********************************/
623 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
624 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
625 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
626 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
627 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
628 
629 #ifdef __cplusplus
630 }
631 #endif
632 
633 #endif /* __STM32F30x_CAN_H */
634 
643 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void CAN_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx&#39;s interrupt pending bits.
FlagStatus
Definition: stm32f4xx.h:706
CAN init structure definition.
Definition: stm32f4xx_can.h:56
FunctionalState
Definition: stm32f4xx.h:708
uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
uint8_t CAN_OperatingModeRequest(CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
Selects the CAN Operation mode.
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending received messages.
enum FlagStatus ITStatus
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified receive FIFO.
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission status of a CAN Frame.
void CAN_Receive(CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
Receives a correct CAN frame.
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes up the CAN peripheral from sleep mode .
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN&#39;s pending flags.
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the CAN Time TriggerOperation communication mode.
void CAN_ITConfig(CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
Enables or disables the specified CANx interrupts.
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
uint8_t CAN_GetLastErrorCode(CAN_TypeDef *CANx)
Returns the CANx&#39;s last error code (LEC).
CAN filter init structure definition.
Definition: stm32f4xx_can.h:98
Controller Area Network.
Definition: stm32f4xx.h:796
CAN Tx message structure definition.
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the Sleep (low power) mode.
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct...
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
uint8_t CAN_Transmit(CAN_TypeDef *CANx, CanTxMsg *TxMessage)
Initiates and transmits a CAN frame message.
CAN Rx message structure definition.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Wed Jul 3 2019 19:59:25