stm32f10x_can.h
Go to the documentation of this file.
1 
23 /* Define to prevent recursive inclusion -------------------------------------*/
24 #ifndef __STM32F10x_CAN_H
25 #define __STM32F10x_CAN_H
26 
27 #ifdef __cplusplus
28  extern "C" {
29 #endif
30 
31 /* Includes ------------------------------------------------------------------*/
32 #include "stm32f10x.h"
33 
46 #define IS_CAN_ALL_PERIPH(PERIPH) (((PERIPH) == CAN1) || \
47  ((PERIPH) == CAN2))
48 
53 typedef struct
54 {
55  uint16_t CAN_Prescaler;
58  uint8_t CAN_Mode;
62  uint8_t CAN_SJW;
68  uint8_t CAN_BS1;
72  uint8_t CAN_BS2;
77  FunctionalState CAN_TTCM;
81  FunctionalState CAN_ABOM;
85  FunctionalState CAN_AWUM;
89  FunctionalState CAN_NART;
93  FunctionalState CAN_RFLM;
97  FunctionalState CAN_TXFP;
101 
106 typedef struct
107 {
108  uint16_t CAN_FilterIdHigh;
112  uint16_t CAN_FilterIdLow;
116  uint16_t CAN_FilterMaskIdHigh;
121  uint16_t CAN_FilterMaskIdLow;
126  uint16_t CAN_FilterFIFOAssignment;
129  uint8_t CAN_FilterNumber;
131  uint8_t CAN_FilterMode;
134  uint8_t CAN_FilterScale;
137  FunctionalState CAN_FilterActivation;
140 
145 typedef struct
146 {
147  uint32_t StdId;
150  uint32_t ExtId;
153  uint8_t IDE;
157  uint8_t RTR;
161  uint8_t DLC;
165  uint8_t Data[8];
167 } CanTxMsg;
168 
173 typedef struct
174 {
175  uint32_t StdId;
178  uint32_t ExtId;
181  uint8_t IDE;
185  uint8_t RTR;
189  uint8_t DLC;
192  uint8_t Data[8];
195  uint8_t FMI;
198 } CanRxMsg;
199 
212 #define CAN_InitStatus_Failed ((uint8_t)0x00)
213 #define CAN_InitStatus_Success ((uint8_t)0x01)
223 #define CAN_Mode_Normal ((uint8_t)0x00)
224 #define CAN_Mode_LoopBack ((uint8_t)0x01)
225 #define CAN_Mode_Silent ((uint8_t)0x02)
226 #define CAN_Mode_Silent_LoopBack ((uint8_t)0x03)
228 #define IS_CAN_MODE(MODE) (((MODE) == CAN_Mode_Normal) || \
229  ((MODE) == CAN_Mode_LoopBack)|| \
230  ((MODE) == CAN_Mode_Silent) || \
231  ((MODE) == CAN_Mode_Silent_LoopBack))
232 
241 #define CAN_OperatingMode_Initialization ((uint8_t)0x00)
242 #define CAN_OperatingMode_Normal ((uint8_t)0x01)
243 #define CAN_OperatingMode_Sleep ((uint8_t)0x02)
246 #define IS_CAN_OPERATING_MODE(MODE) (((MODE) == CAN_OperatingMode_Initialization) ||\
247  ((MODE) == CAN_OperatingMode_Normal)|| \
248  ((MODE) == CAN_OperatingMode_Sleep))
249 
258 #define CAN_ModeStatus_Failed ((uint8_t)0x00)
259 #define CAN_ModeStatus_Success ((uint8_t)!CAN_ModeStatus_Failed)
270 #define CAN_SJW_1tq ((uint8_t)0x00)
271 #define CAN_SJW_2tq ((uint8_t)0x01)
272 #define CAN_SJW_3tq ((uint8_t)0x02)
273 #define CAN_SJW_4tq ((uint8_t)0x03)
275 #define IS_CAN_SJW(SJW) (((SJW) == CAN_SJW_1tq) || ((SJW) == CAN_SJW_2tq)|| \
276  ((SJW) == CAN_SJW_3tq) || ((SJW) == CAN_SJW_4tq))
277 
285 #define CAN_BS1_1tq ((uint8_t)0x00)
286 #define CAN_BS1_2tq ((uint8_t)0x01)
287 #define CAN_BS1_3tq ((uint8_t)0x02)
288 #define CAN_BS1_4tq ((uint8_t)0x03)
289 #define CAN_BS1_5tq ((uint8_t)0x04)
290 #define CAN_BS1_6tq ((uint8_t)0x05)
291 #define CAN_BS1_7tq ((uint8_t)0x06)
292 #define CAN_BS1_8tq ((uint8_t)0x07)
293 #define CAN_BS1_9tq ((uint8_t)0x08)
294 #define CAN_BS1_10tq ((uint8_t)0x09)
295 #define CAN_BS1_11tq ((uint8_t)0x0A)
296 #define CAN_BS1_12tq ((uint8_t)0x0B)
297 #define CAN_BS1_13tq ((uint8_t)0x0C)
298 #define CAN_BS1_14tq ((uint8_t)0x0D)
299 #define CAN_BS1_15tq ((uint8_t)0x0E)
300 #define CAN_BS1_16tq ((uint8_t)0x0F)
302 #define IS_CAN_BS1(BS1) ((BS1) <= CAN_BS1_16tq)
303 
311 #define CAN_BS2_1tq ((uint8_t)0x00)
312 #define CAN_BS2_2tq ((uint8_t)0x01)
313 #define CAN_BS2_3tq ((uint8_t)0x02)
314 #define CAN_BS2_4tq ((uint8_t)0x03)
315 #define CAN_BS2_5tq ((uint8_t)0x04)
316 #define CAN_BS2_6tq ((uint8_t)0x05)
317 #define CAN_BS2_7tq ((uint8_t)0x06)
318 #define CAN_BS2_8tq ((uint8_t)0x07)
320 #define IS_CAN_BS2(BS2) ((BS2) <= CAN_BS2_8tq)
321 
330 #define IS_CAN_PRESCALER(PRESCALER) (((PRESCALER) >= 1) && ((PRESCALER) <= 1024))
331 
339 #ifndef STM32F10X_CL
340  #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 13)
341 #else
342  #define IS_CAN_FILTER_NUMBER(NUMBER) ((NUMBER) <= 27)
343 #endif /* STM32F10X_CL */
344 
352 #define CAN_FilterMode_IdMask ((uint8_t)0x00)
353 #define CAN_FilterMode_IdList ((uint8_t)0x01)
355 #define IS_CAN_FILTER_MODE(MODE) (((MODE) == CAN_FilterMode_IdMask) || \
356  ((MODE) == CAN_FilterMode_IdList))
357 
365 #define CAN_FilterScale_16bit ((uint8_t)0x00)
366 #define CAN_FilterScale_32bit ((uint8_t)0x01)
368 #define IS_CAN_FILTER_SCALE(SCALE) (((SCALE) == CAN_FilterScale_16bit) || \
369  ((SCALE) == CAN_FilterScale_32bit))
370 
379 #define CAN_Filter_FIFO0 ((uint8_t)0x00)
380 #define CAN_Filter_FIFO1 ((uint8_t)0x01)
381 #define IS_CAN_FILTER_FIFO(FIFO) (((FIFO) == CAN_FilterFIFO0) || \
382  ((FIFO) == CAN_FilterFIFO1))
383 
390 #define IS_CAN_BANKNUMBER(BANKNUMBER) (((BANKNUMBER) >= 1) && ((BANKNUMBER) <= 27))
391 
399 #define IS_CAN_TRANSMITMAILBOX(TRANSMITMAILBOX) ((TRANSMITMAILBOX) <= ((uint8_t)0x02))
400 #define IS_CAN_STDID(STDID) ((STDID) <= ((uint32_t)0x7FF))
401 #define IS_CAN_EXTID(EXTID) ((EXTID) <= ((uint32_t)0x1FFFFFFF))
402 #define IS_CAN_DLC(DLC) ((DLC) <= ((uint8_t)0x08))
403 
412 #define CAN_Id_Standard ((uint32_t)0x00000000)
413 #define CAN_Id_Extended ((uint32_t)0x00000004)
414 #define IS_CAN_IDTYPE(IDTYPE) (((IDTYPE) == CAN_Id_Standard) || \
415  ((IDTYPE) == CAN_Id_Extended))
416 
424 #define CAN_RTR_Data ((uint32_t)0x00000000)
425 #define CAN_RTR_Remote ((uint32_t)0x00000002)
426 #define IS_CAN_RTR(RTR) (((RTR) == CAN_RTR_Data) || ((RTR) == CAN_RTR_Remote))
427 
436 #define CAN_TxStatus_Failed ((uint8_t)0x00)
437 #define CAN_TxStatus_Ok ((uint8_t)0x01)
438 #define CAN_TxStatus_Pending ((uint8_t)0x02)
439 #define CAN_TxStatus_NoMailBox ((uint8_t)0x04)
449 #define CAN_FIFO0 ((uint8_t)0x00)
450 #define CAN_FIFO1 ((uint8_t)0x01)
452 #define IS_CAN_FIFO(FIFO) (((FIFO) == CAN_FIFO0) || ((FIFO) == CAN_FIFO1))
453 
462 #define CAN_Sleep_Failed ((uint8_t)0x00)
463 #define CAN_Sleep_Ok ((uint8_t)0x01)
473 #define CAN_WakeUp_Failed ((uint8_t)0x00)
474 #define CAN_WakeUp_Ok ((uint8_t)0x01)
485 #define CAN_ErrorCode_NoErr ((uint8_t)0x00)
486 #define CAN_ErrorCode_StuffErr ((uint8_t)0x10)
487 #define CAN_ErrorCode_FormErr ((uint8_t)0x20)
488 #define CAN_ErrorCode_ACKErr ((uint8_t)0x30)
489 #define CAN_ErrorCode_BitRecessiveErr ((uint8_t)0x40)
490 #define CAN_ErrorCode_BitDominantErr ((uint8_t)0x50)
491 #define CAN_ErrorCode_CRCErr ((uint8_t)0x60)
492 #define CAN_ErrorCode_SoftwareSetErr ((uint8_t)0x70)
502 /* If the flag is 0x3XXXXXXX, it means that it can be used with CAN_GetFlagStatus()
503  and CAN_ClearFlag() functions. */
504 /* If the flag is 0x1XXXXXXX, it means that it can only be used with CAN_GetFlagStatus() function. */
505 
506 /* Transmit Flags */
507 #define CAN_FLAG_RQCP0 ((uint32_t)0x38000001)
508 #define CAN_FLAG_RQCP1 ((uint32_t)0x38000100)
509 #define CAN_FLAG_RQCP2 ((uint32_t)0x38010000)
511 /* Receive Flags */
512 #define CAN_FLAG_FMP0 ((uint32_t)0x12000003)
513 #define CAN_FLAG_FF0 ((uint32_t)0x32000008)
514 #define CAN_FLAG_FOV0 ((uint32_t)0x32000010)
515 #define CAN_FLAG_FMP1 ((uint32_t)0x14000003)
516 #define CAN_FLAG_FF1 ((uint32_t)0x34000008)
517 #define CAN_FLAG_FOV1 ((uint32_t)0x34000010)
519 /* Operating Mode Flags */
520 #define CAN_FLAG_WKU ((uint32_t)0x31000008)
521 #define CAN_FLAG_SLAK ((uint32_t)0x31000012)
522 /* Note: When SLAK intterupt is disabled (SLKIE=0), no polling on SLAKI is possible.
523  In this case the SLAK bit can be polled.*/
524 
525 /* Error Flags */
526 #define CAN_FLAG_EWG ((uint32_t)0x10F00001)
527 #define CAN_FLAG_EPV ((uint32_t)0x10F00002)
528 #define CAN_FLAG_BOF ((uint32_t)0x10F00004)
529 #define CAN_FLAG_LEC ((uint32_t)0x30F00070)
531 #define IS_CAN_GET_FLAG(FLAG) (((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_BOF) || \
532  ((FLAG) == CAN_FLAG_EPV) || ((FLAG) == CAN_FLAG_EWG) || \
533  ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_FOV0) || \
534  ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FMP0) || \
535  ((FLAG) == CAN_FLAG_FOV1) || ((FLAG) == CAN_FLAG_FF1) || \
536  ((FLAG) == CAN_FLAG_FMP1) || ((FLAG) == CAN_FLAG_RQCP2) || \
537  ((FLAG) == CAN_FLAG_RQCP1)|| ((FLAG) == CAN_FLAG_RQCP0) || \
538  ((FLAG) == CAN_FLAG_SLAK ))
539 
540 #define IS_CAN_CLEAR_FLAG(FLAG)(((FLAG) == CAN_FLAG_LEC) || ((FLAG) == CAN_FLAG_RQCP2) || \
541  ((FLAG) == CAN_FLAG_RQCP1) || ((FLAG) == CAN_FLAG_RQCP0) || \
542  ((FLAG) == CAN_FLAG_FF0) || ((FLAG) == CAN_FLAG_FOV0) ||\
543  ((FLAG) == CAN_FLAG_FF1) || ((FLAG) == CAN_FLAG_FOV1) || \
544  ((FLAG) == CAN_FLAG_WKU) || ((FLAG) == CAN_FLAG_SLAK))
545 
556 #define CAN_IT_TME ((uint32_t)0x00000001)
558 /* Receive Interrupts */
559 #define CAN_IT_FMP0 ((uint32_t)0x00000002)
560 #define CAN_IT_FF0 ((uint32_t)0x00000004)
561 #define CAN_IT_FOV0 ((uint32_t)0x00000008)
562 #define CAN_IT_FMP1 ((uint32_t)0x00000010)
563 #define CAN_IT_FF1 ((uint32_t)0x00000020)
564 #define CAN_IT_FOV1 ((uint32_t)0x00000040)
566 /* Operating Mode Interrupts */
567 #define CAN_IT_WKU ((uint32_t)0x00010000)
568 #define CAN_IT_SLK ((uint32_t)0x00020000)
570 /* Error Interrupts */
571 #define CAN_IT_EWG ((uint32_t)0x00000100)
572 #define CAN_IT_EPV ((uint32_t)0x00000200)
573 #define CAN_IT_BOF ((uint32_t)0x00000400)
574 #define CAN_IT_LEC ((uint32_t)0x00000800)
575 #define CAN_IT_ERR ((uint32_t)0x00008000)
577 /* Flags named as Interrupts : kept only for FW compatibility */
578 #define CAN_IT_RQCP0 CAN_IT_TME
579 #define CAN_IT_RQCP1 CAN_IT_TME
580 #define CAN_IT_RQCP2 CAN_IT_TME
581 
582 
583 #define IS_CAN_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FMP0) ||\
584  ((IT) == CAN_IT_FF0) || ((IT) == CAN_IT_FOV0) ||\
585  ((IT) == CAN_IT_FMP1) || ((IT) == CAN_IT_FF1) ||\
586  ((IT) == CAN_IT_FOV1) || ((IT) == CAN_IT_EWG) ||\
587  ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
588  ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
589  ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
590 
591 #define IS_CAN_CLEAR_IT(IT) (((IT) == CAN_IT_TME) || ((IT) == CAN_IT_FF0) ||\
592  ((IT) == CAN_IT_FOV0)|| ((IT) == CAN_IT_FF1) ||\
593  ((IT) == CAN_IT_FOV1)|| ((IT) == CAN_IT_EWG) ||\
594  ((IT) == CAN_IT_EPV) || ((IT) == CAN_IT_BOF) ||\
595  ((IT) == CAN_IT_LEC) || ((IT) == CAN_IT_ERR) ||\
596  ((IT) == CAN_IT_WKU) || ((IT) == CAN_IT_SLK))
597 
605 #define CANINITFAILED CAN_InitStatus_Failed
606 #define CANINITOK CAN_InitStatus_Success
607 #define CAN_FilterFIFO0 CAN_Filter_FIFO0
608 #define CAN_FilterFIFO1 CAN_Filter_FIFO1
609 #define CAN_ID_STD CAN_Id_Standard
610 #define CAN_ID_EXT CAN_Id_Extended
611 #define CAN_RTR_DATA CAN_RTR_Data
612 #define CAN_RTR_REMOTE CAN_RTR_Remote
613 #define CANTXFAILE CAN_TxStatus_Failed
614 #define CANTXOK CAN_TxStatus_Ok
615 #define CANTXPENDING CAN_TxStatus_Pending
616 #define CAN_NO_MB CAN_TxStatus_NoMailBox
617 #define CANSLEEPFAILED CAN_Sleep_Failed
618 #define CANSLEEPOK CAN_Sleep_Ok
619 #define CANWAKEUPFAILED CAN_WakeUp_Failed
620 #define CANWAKEUPOK CAN_WakeUp_Ok
621 
641 /* Function used to set the CAN configuration to the default reset state *****/
642 void CAN_DeInit(CAN_TypeDef* CANx);
643 
644 /* Initialization and Configuration functions *********************************/
645 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct);
646 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct);
647 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct);
648 void CAN_SlaveStartBank(uint8_t CAN_BankNumber);
649 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState);
650 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState);
651 
652 /* Transmit functions *********************************************************/
653 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage);
654 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox);
655 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox);
656 
657 /* Receive functions **********************************************************/
658 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage);
659 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber);
660 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber);
661 
662 
663 /* Operation modes functions **************************************************/
664 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode);
665 uint8_t CAN_Sleep(CAN_TypeDef* CANx);
666 uint8_t CAN_WakeUp(CAN_TypeDef* CANx);
667 
668 /* Error management functions *************************************************/
669 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx);
672 
673 /* Interrupts and flags management functions **********************************/
674 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState);
675 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
676 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG);
677 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT);
678 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT);
679 
680 #ifdef __cplusplus
681 }
682 #endif
683 
684 #endif /* __STM32F10x_CAN_H */
685 
697 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
FlagStatus
Definition: stm32f4xx.h:706
uint8_t CAN_GetLastErrorCode(CAN_TypeDef *CANx)
Returns the CANx&#39;s last error code (LEC).
void CAN_ITConfig(CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
Enables or disables the specified CANx interrupts.
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending received messages.
CAN init structure definition.
Definition: stm32f4xx_can.h:56
FunctionalState
Definition: stm32f4xx.h:708
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the Sleep (low power) mode.
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
uint8_t CAN_OperatingModeRequest(CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
Selects the CAN Operation mode.
uint8_t CAN_Transmit(CAN_TypeDef *CANx, CanTxMsg *TxMessage)
Initiates and transmits a CAN frame message.
void CAN_Receive(CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
Receives a correct CAN frame.
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN&#39;s pending flags.
enum FlagStatus ITStatus
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission status of a CAN Frame.
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
CAN filter init structure definition.
Definition: stm32f4xx_can.h:98
Controller Area Network.
Definition: stm32f4xx.h:796
void CAN_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx&#39;s interrupt pending bits.
CAN Tx message structure definition.
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes up the CAN peripheral from sleep mode .
CMSIS Cortex-M3 Device Peripheral Access Layer Header File. This file contains all the peripheral reg...
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified receive FIFO.
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the CAN Time TriggerOperation communication mode.
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct...
CAN Rx message structure definition.


rosflight_firmware
Author(s): Daniel Koch , James Jackson
autogenerated on Thu Oct 24 2019 03:17:19