CARME-M4 BSP  V1.5
stm32f4xx_can.c
Go to the documentation of this file.
1 
84 /* Includes ------------------------------------------------------------------*/
85 #include "stm32f4xx_can.h"
86 #include "stm32f4xx_rcc.h"
87 
96 /* Private typedef -----------------------------------------------------------*/
97 /* Private define ------------------------------------------------------------*/
98 
99 /* CAN Master Control Register bits */
100 #define MCR_DBF ((uint32_t)0x00010000) /* software master reset */
101 
102 /* CAN Mailbox Transmit Request */
103 #define TMIDxR_TXRQ ((uint32_t)0x00000001) /* Transmit mailbox request */
104 
105 /* CAN Filter Master Register bits */
106 #define FMR_FINIT ((uint32_t)0x00000001) /* Filter init mode */
107 
108 /* Time out for INAK bit */
109 #define INAK_TIMEOUT ((uint32_t)0x0000FFFF)
110 /* Time out for SLAK bit */
111 #define SLAK_TIMEOUT ((uint32_t)0x0000FFFF)
112 
113 /* Flags in TSR register */
114 #define CAN_FLAGS_TSR ((uint32_t)0x08000000)
115 /* Flags in RF1R register */
116 #define CAN_FLAGS_RF1R ((uint32_t)0x04000000)
117 /* Flags in RF0R register */
118 #define CAN_FLAGS_RF0R ((uint32_t)0x02000000)
119 /* Flags in MSR register */
120 #define CAN_FLAGS_MSR ((uint32_t)0x01000000)
121 /* Flags in ESR register */
122 #define CAN_FLAGS_ESR ((uint32_t)0x00F00000)
123 
124 /* Mailboxes definition */
125 #define CAN_TXMAILBOX_0 ((uint8_t)0x00)
126 #define CAN_TXMAILBOX_1 ((uint8_t)0x01)
127 #define CAN_TXMAILBOX_2 ((uint8_t)0x02)
128 
129 #define CAN_MODE_MASK ((uint32_t) 0x00000003)
130 
131 /* Private macro -------------------------------------------------------------*/
132 /* Private variables ---------------------------------------------------------*/
133 /* Private function prototypes -----------------------------------------------*/
134 /* Private functions ---------------------------------------------------------*/
135 static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit);
136 
167 void CAN_DeInit(CAN_TypeDef* CANx)
168 {
169  /* Check the parameters */
170  assert_param(IS_CAN_ALL_PERIPH(CANx));
171 
172  if (CANx == CAN1)
173  {
174  /* Enable CAN1 reset state */
175  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, ENABLE);
176  /* Release CAN1 from reset state */
177  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN1, DISABLE);
178  }
179  else
180  {
181  /* Enable CAN2 reset state */
182  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, ENABLE);
183  /* Release CAN2 from reset state */
184  RCC_APB1PeriphResetCmd(RCC_APB1Periph_CAN2, DISABLE);
185  }
186 }
187 
197 uint8_t CAN_Init(CAN_TypeDef* CANx, CAN_InitTypeDef* CAN_InitStruct)
198 {
199  uint8_t InitStatus = CAN_InitStatus_Failed;
200  uint32_t wait_ack = 0x00000000;
201  /* Check the parameters */
202  assert_param(IS_CAN_ALL_PERIPH(CANx));
203  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TTCM));
204  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_ABOM));
205  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_AWUM));
206  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_NART));
207  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_RFLM));
208  assert_param(IS_FUNCTIONAL_STATE(CAN_InitStruct->CAN_TXFP));
209  assert_param(IS_CAN_MODE(CAN_InitStruct->CAN_Mode));
210  assert_param(IS_CAN_SJW(CAN_InitStruct->CAN_SJW));
211  assert_param(IS_CAN_BS1(CAN_InitStruct->CAN_BS1));
212  assert_param(IS_CAN_BS2(CAN_InitStruct->CAN_BS2));
213  assert_param(IS_CAN_PRESCALER(CAN_InitStruct->CAN_Prescaler));
214 
215  /* Exit from sleep mode */
216  CANx->MCR &= (~(uint32_t)CAN_MCR_SLEEP);
217 
218  /* Request initialisation */
219  CANx->MCR |= CAN_MCR_INRQ ;
220 
221  /* Wait the acknowledge */
222  while (((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
223  {
224  wait_ack++;
225  }
226 
227  /* Check acknowledge */
228  if ((CANx->MSR & CAN_MSR_INAK) != CAN_MSR_INAK)
229  {
230  InitStatus = CAN_InitStatus_Failed;
231  }
232  else
233  {
234  /* Set the time triggered communication mode */
235  if (CAN_InitStruct->CAN_TTCM == ENABLE)
236  {
237  CANx->MCR |= CAN_MCR_TTCM;
238  }
239  else
240  {
241  CANx->MCR &= ~(uint32_t)CAN_MCR_TTCM;
242  }
243 
244  /* Set the automatic bus-off management */
245  if (CAN_InitStruct->CAN_ABOM == ENABLE)
246  {
247  CANx->MCR |= CAN_MCR_ABOM;
248  }
249  else
250  {
251  CANx->MCR &= ~(uint32_t)CAN_MCR_ABOM;
252  }
253 
254  /* Set the automatic wake-up mode */
255  if (CAN_InitStruct->CAN_AWUM == ENABLE)
256  {
257  CANx->MCR |= CAN_MCR_AWUM;
258  }
259  else
260  {
261  CANx->MCR &= ~(uint32_t)CAN_MCR_AWUM;
262  }
263 
264  /* Set the no automatic retransmission */
265  if (CAN_InitStruct->CAN_NART == ENABLE)
266  {
267  CANx->MCR |= CAN_MCR_NART;
268  }
269  else
270  {
271  CANx->MCR &= ~(uint32_t)CAN_MCR_NART;
272  }
273 
274  /* Set the receive FIFO locked mode */
275  if (CAN_InitStruct->CAN_RFLM == ENABLE)
276  {
277  CANx->MCR |= CAN_MCR_RFLM;
278  }
279  else
280  {
281  CANx->MCR &= ~(uint32_t)CAN_MCR_RFLM;
282  }
283 
284  /* Set the transmit FIFO priority */
285  if (CAN_InitStruct->CAN_TXFP == ENABLE)
286  {
287  CANx->MCR |= CAN_MCR_TXFP;
288  }
289  else
290  {
291  CANx->MCR &= ~(uint32_t)CAN_MCR_TXFP;
292  }
293 
294  /* Set the bit timing register */
295  CANx->BTR = (uint32_t)((uint32_t)CAN_InitStruct->CAN_Mode << 30) | \
296  ((uint32_t)CAN_InitStruct->CAN_SJW << 24) | \
297  ((uint32_t)CAN_InitStruct->CAN_BS1 << 16) | \
298  ((uint32_t)CAN_InitStruct->CAN_BS2 << 20) | \
299  ((uint32_t)CAN_InitStruct->CAN_Prescaler - 1);
300 
301  /* Request leave initialisation */
302  CANx->MCR &= ~(uint32_t)CAN_MCR_INRQ;
303 
304  /* Wait the acknowledge */
305  wait_ack = 0;
306 
307  while (((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK) && (wait_ack != INAK_TIMEOUT))
308  {
309  wait_ack++;
310  }
311 
312  /* ...and check acknowledged */
313  if ((CANx->MSR & CAN_MSR_INAK) == CAN_MSR_INAK)
314  {
315  InitStatus = CAN_InitStatus_Failed;
316  }
317  else
318  {
319  InitStatus = CAN_InitStatus_Success ;
320  }
321  }
322 
323  /* At this step, return the status of initialization */
324  return InitStatus;
325 }
326 
334 void CAN_FilterInit(CAN_FilterInitTypeDef* CAN_FilterInitStruct)
335 {
336  uint32_t filter_number_bit_pos = 0;
337  /* Check the parameters */
338  assert_param(IS_CAN_FILTER_NUMBER(CAN_FilterInitStruct->CAN_FilterNumber));
339  assert_param(IS_CAN_FILTER_MODE(CAN_FilterInitStruct->CAN_FilterMode));
340  assert_param(IS_CAN_FILTER_SCALE(CAN_FilterInitStruct->CAN_FilterScale));
341  assert_param(IS_CAN_FILTER_FIFO(CAN_FilterInitStruct->CAN_FilterFIFOAssignment));
342  assert_param(IS_FUNCTIONAL_STATE(CAN_FilterInitStruct->CAN_FilterActivation));
343 
344  filter_number_bit_pos = ((uint32_t)1) << CAN_FilterInitStruct->CAN_FilterNumber;
345 
346  /* Initialisation mode for the filter */
347  CAN1->FMR |= FMR_FINIT;
348 
349  /* Filter Deactivation */
350  CAN1->FA1R &= ~(uint32_t)filter_number_bit_pos;
351 
352  /* Filter Scale */
353  if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_16bit)
354  {
355  /* 16-bit scale for the filter */
356  CAN1->FS1R &= ~(uint32_t)filter_number_bit_pos;
357 
358  /* First 16-bit identifier and First 16-bit mask */
359  /* Or First 16-bit identifier and Second 16-bit identifier */
360  CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
361  ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow) << 16) |
362  (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
363 
364  /* Second 16-bit identifier and Second 16-bit mask */
365  /* Or Third 16-bit identifier and Fourth 16-bit identifier */
366  CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
367  ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
368  (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh);
369  }
370 
371  if (CAN_FilterInitStruct->CAN_FilterScale == CAN_FilterScale_32bit)
372  {
373  /* 32-bit scale for the filter */
374  CAN1->FS1R |= filter_number_bit_pos;
375  /* 32-bit identifier or First 32-bit identifier */
376  CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR1 =
377  ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdHigh) << 16) |
378  (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterIdLow);
379  /* 32-bit mask or Second 32-bit identifier */
380  CAN1->sFilterRegister[CAN_FilterInitStruct->CAN_FilterNumber].FR2 =
381  ((0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdHigh) << 16) |
382  (0x0000FFFF & (uint32_t)CAN_FilterInitStruct->CAN_FilterMaskIdLow);
383  }
384 
385  /* Filter Mode */
386  if (CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdMask)
387  {
388  /*Id/Mask mode for the filter*/
389  CAN1->FM1R &= ~(uint32_t)filter_number_bit_pos;
390  }
391  else /* CAN_FilterInitStruct->CAN_FilterMode == CAN_FilterMode_IdList */
392  {
393  /*Identifier list mode for the filter*/
394  CAN1->FM1R |= (uint32_t)filter_number_bit_pos;
395  }
396 
397  /* Filter FIFO assignment */
398  if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO0)
399  {
400  /* FIFO 0 assignation for the filter */
401  CAN1->FFA1R &= ~(uint32_t)filter_number_bit_pos;
402  }
403 
404  if (CAN_FilterInitStruct->CAN_FilterFIFOAssignment == CAN_Filter_FIFO1)
405  {
406  /* FIFO 1 assignation for the filter */
407  CAN1->FFA1R |= (uint32_t)filter_number_bit_pos;
408  }
409 
410  /* Filter activation */
411  if (CAN_FilterInitStruct->CAN_FilterActivation == ENABLE)
412  {
413  CAN1->FA1R |= filter_number_bit_pos;
414  }
415 
416  /* Leave the initialisation mode for the filter */
417  CAN1->FMR &= ~FMR_FINIT;
418 }
419 
425 void CAN_StructInit(CAN_InitTypeDef* CAN_InitStruct)
426 {
427  /* Reset CAN init structure parameters values */
428 
429  /* Initialize the time triggered communication mode */
430  CAN_InitStruct->CAN_TTCM = DISABLE;
431 
432  /* Initialize the automatic bus-off management */
433  CAN_InitStruct->CAN_ABOM = DISABLE;
434 
435  /* Initialize the automatic wake-up mode */
436  CAN_InitStruct->CAN_AWUM = DISABLE;
437 
438  /* Initialize the no automatic retransmission */
439  CAN_InitStruct->CAN_NART = DISABLE;
440 
441  /* Initialize the receive FIFO locked mode */
442  CAN_InitStruct->CAN_RFLM = DISABLE;
443 
444  /* Initialize the transmit FIFO priority */
445  CAN_InitStruct->CAN_TXFP = DISABLE;
446 
447  /* Initialize the CAN_Mode member */
448  CAN_InitStruct->CAN_Mode = CAN_Mode_Normal;
449 
450  /* Initialize the CAN_SJW member */
451  CAN_InitStruct->CAN_SJW = CAN_SJW_1tq;
452 
453  /* Initialize the CAN_BS1 member */
454  CAN_InitStruct->CAN_BS1 = CAN_BS1_4tq;
455 
456  /* Initialize the CAN_BS2 member */
457  CAN_InitStruct->CAN_BS2 = CAN_BS2_3tq;
458 
459  /* Initialize the CAN_Prescaler member */
460  CAN_InitStruct->CAN_Prescaler = 1;
461 }
462 
468 void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
469 {
470  /* Check the parameters */
471  assert_param(IS_CAN_BANKNUMBER(CAN_BankNumber));
472 
473  /* Enter Initialisation mode for the filter */
474  CAN1->FMR |= FMR_FINIT;
475 
476  /* Select the start slave bank */
477  CAN1->FMR &= (uint32_t)0xFFFFC0F1 ;
478  CAN1->FMR |= (uint32_t)(CAN_BankNumber)<<8;
479 
480  /* Leave Initialisation mode for the filter */
481  CAN1->FMR &= ~FMR_FINIT;
482 }
483 
493 void CAN_DBGFreeze(CAN_TypeDef* CANx, FunctionalState NewState)
494 {
495  /* Check the parameters */
496  assert_param(IS_CAN_ALL_PERIPH(CANx));
497  assert_param(IS_FUNCTIONAL_STATE(NewState));
498 
499  if (NewState != DISABLE)
500  {
501  /* Enable Debug Freeze */
502  CANx->MCR |= MCR_DBF;
503  }
504  else
505  {
506  /* Disable Debug Freeze */
507  CANx->MCR &= ~MCR_DBF;
508  }
509 }
510 
511 
523 void CAN_TTComModeCmd(CAN_TypeDef* CANx, FunctionalState NewState)
524 {
525  /* Check the parameters */
526  assert_param(IS_CAN_ALL_PERIPH(CANx));
527  assert_param(IS_FUNCTIONAL_STATE(NewState));
528  if (NewState != DISABLE)
529  {
530  /* Enable the TTCM mode */
531  CANx->MCR |= CAN_MCR_TTCM;
532 
533  /* Set TGT bits */
534  CANx->sTxMailBox[0].TDTR |= ((uint32_t)CAN_TDT0R_TGT);
535  CANx->sTxMailBox[1].TDTR |= ((uint32_t)CAN_TDT1R_TGT);
536  CANx->sTxMailBox[2].TDTR |= ((uint32_t)CAN_TDT2R_TGT);
537  }
538  else
539  {
540  /* Disable the TTCM mode */
541  CANx->MCR &= (uint32_t)(~(uint32_t)CAN_MCR_TTCM);
542 
543  /* Reset TGT bits */
544  CANx->sTxMailBox[0].TDTR &= ((uint32_t)~CAN_TDT0R_TGT);
545  CANx->sTxMailBox[1].TDTR &= ((uint32_t)~CAN_TDT1R_TGT);
546  CANx->sTxMailBox[2].TDTR &= ((uint32_t)~CAN_TDT2R_TGT);
547  }
548 }
577 uint8_t CAN_Transmit(CAN_TypeDef* CANx, CanTxMsg* TxMessage)
578 {
579  uint8_t transmit_mailbox = 0;
580  /* Check the parameters */
581  assert_param(IS_CAN_ALL_PERIPH(CANx));
582  assert_param(IS_CAN_IDTYPE(TxMessage->IDE));
583  assert_param(IS_CAN_RTR(TxMessage->RTR));
584  assert_param(IS_CAN_DLC(TxMessage->DLC));
585 
586  /* Select one empty transmit mailbox */
587  if ((CANx->TSR&CAN_TSR_TME0) == CAN_TSR_TME0)
588  {
589  transmit_mailbox = 0;
590  }
591  else if ((CANx->TSR&CAN_TSR_TME1) == CAN_TSR_TME1)
592  {
593  transmit_mailbox = 1;
594  }
595  else if ((CANx->TSR&CAN_TSR_TME2) == CAN_TSR_TME2)
596  {
597  transmit_mailbox = 2;
598  }
599  else
600  {
601  transmit_mailbox = CAN_TxStatus_NoMailBox;
602  }
603 
604  if (transmit_mailbox != CAN_TxStatus_NoMailBox)
605  {
606  /* Set up the Id */
607  CANx->sTxMailBox[transmit_mailbox].TIR &= TMIDxR_TXRQ;
608  if (TxMessage->IDE == CAN_Id_Standard)
609  {
610  assert_param(IS_CAN_STDID(TxMessage->StdId));
611  CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->StdId << 21) | \
612  TxMessage->RTR);
613  }
614  else
615  {
616  assert_param(IS_CAN_EXTID(TxMessage->ExtId));
617  CANx->sTxMailBox[transmit_mailbox].TIR |= ((TxMessage->ExtId << 3) | \
618  TxMessage->IDE | \
619  TxMessage->RTR);
620  }
621 
622  /* Set up the DLC */
623  TxMessage->DLC &= (uint8_t)0x0000000F;
624  CANx->sTxMailBox[transmit_mailbox].TDTR &= (uint32_t)0xFFFFFFF0;
625  CANx->sTxMailBox[transmit_mailbox].TDTR |= TxMessage->DLC;
626 
627  /* Set up the data field */
628  CANx->sTxMailBox[transmit_mailbox].TDLR = (((uint32_t)TxMessage->Data[3] << 24) |
629  ((uint32_t)TxMessage->Data[2] << 16) |
630  ((uint32_t)TxMessage->Data[1] << 8) |
631  ((uint32_t)TxMessage->Data[0]));
632  CANx->sTxMailBox[transmit_mailbox].TDHR = (((uint32_t)TxMessage->Data[7] << 24) |
633  ((uint32_t)TxMessage->Data[6] << 16) |
634  ((uint32_t)TxMessage->Data[5] << 8) |
635  ((uint32_t)TxMessage->Data[4]));
636  /* Request transmission */
637  CANx->sTxMailBox[transmit_mailbox].TIR |= TMIDxR_TXRQ;
638  }
639  return transmit_mailbox;
640 }
641 
649 uint8_t CAN_TransmitStatus(CAN_TypeDef* CANx, uint8_t TransmitMailbox)
650 {
651  uint32_t state = 0;
652 
653  /* Check the parameters */
654  assert_param(IS_CAN_ALL_PERIPH(CANx));
655  assert_param(IS_CAN_TRANSMITMAILBOX(TransmitMailbox));
656 
657  switch (TransmitMailbox)
658  {
659  case (CAN_TXMAILBOX_0):
660  state = CANx->TSR & (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0);
661  break;
662  case (CAN_TXMAILBOX_1):
663  state = CANx->TSR & (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1);
664  break;
665  case (CAN_TXMAILBOX_2):
666  state = CANx->TSR & (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2);
667  break;
668  default:
669  state = CAN_TxStatus_Failed;
670  break;
671  }
672  switch (state)
673  {
674  /* transmit pending */
675  case (0x0): state = CAN_TxStatus_Pending;
676  break;
677  /* transmit failed */
678  case (CAN_TSR_RQCP0 | CAN_TSR_TME0): state = CAN_TxStatus_Failed;
679  break;
680  case (CAN_TSR_RQCP1 | CAN_TSR_TME1): state = CAN_TxStatus_Failed;
681  break;
682  case (CAN_TSR_RQCP2 | CAN_TSR_TME2): state = CAN_TxStatus_Failed;
683  break;
684  /* transmit succeeded */
685  case (CAN_TSR_RQCP0 | CAN_TSR_TXOK0 | CAN_TSR_TME0):state = CAN_TxStatus_Ok;
686  break;
687  case (CAN_TSR_RQCP1 | CAN_TSR_TXOK1 | CAN_TSR_TME1):state = CAN_TxStatus_Ok;
688  break;
689  case (CAN_TSR_RQCP2 | CAN_TSR_TXOK2 | CAN_TSR_TME2):state = CAN_TxStatus_Ok;
690  break;
691  default: state = CAN_TxStatus_Failed;
692  break;
693  }
694  return (uint8_t) state;
695 }
696 
703 void CAN_CancelTransmit(CAN_TypeDef* CANx, uint8_t Mailbox)
704 {
705  /* Check the parameters */
706  assert_param(IS_CAN_ALL_PERIPH(CANx));
707  assert_param(IS_CAN_TRANSMITMAILBOX(Mailbox));
708  /* abort transmission */
709  switch (Mailbox)
710  {
711  case (CAN_TXMAILBOX_0): CANx->TSR |= CAN_TSR_ABRQ0;
712  break;
713  case (CAN_TXMAILBOX_1): CANx->TSR |= CAN_TSR_ABRQ1;
714  break;
715  case (CAN_TXMAILBOX_2): CANx->TSR |= CAN_TSR_ABRQ2;
716  break;
717  default:
718  break;
719  }
720 }
750 void CAN_Receive(CAN_TypeDef* CANx, uint8_t FIFONumber, CanRxMsg* RxMessage)
751 {
752  /* Check the parameters */
753  assert_param(IS_CAN_ALL_PERIPH(CANx));
754  assert_param(IS_CAN_FIFO(FIFONumber));
755  /* Get the Id */
756  RxMessage->IDE = (uint8_t)0x04 & CANx->sFIFOMailBox[FIFONumber].RIR;
757  if (RxMessage->IDE == CAN_Id_Standard)
758  {
759  RxMessage->StdId = (uint32_t)0x000007FF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 21);
760  }
761  else
762  {
763  RxMessage->ExtId = (uint32_t)0x1FFFFFFF & (CANx->sFIFOMailBox[FIFONumber].RIR >> 3);
764  }
765 
766  RxMessage->RTR = (uint8_t)0x02 & CANx->sFIFOMailBox[FIFONumber].RIR;
767  /* Get the DLC */
768  RxMessage->DLC = (uint8_t)0x0F & CANx->sFIFOMailBox[FIFONumber].RDTR;
769  /* Get the FMI */
770  RxMessage->FMI = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDTR >> 8);
771  /* Get the data field */
772  RxMessage->Data[0] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDLR;
773  RxMessage->Data[1] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 8);
774  RxMessage->Data[2] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 16);
775  RxMessage->Data[3] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDLR >> 24);
776  RxMessage->Data[4] = (uint8_t)0xFF & CANx->sFIFOMailBox[FIFONumber].RDHR;
777  RxMessage->Data[5] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 8);
778  RxMessage->Data[6] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 16);
779  RxMessage->Data[7] = (uint8_t)0xFF & (CANx->sFIFOMailBox[FIFONumber].RDHR >> 24);
780  /* Release the FIFO */
781  /* Release FIFO0 */
782  if (FIFONumber == CAN_FIFO0)
783  {
784  CANx->RF0R |= CAN_RF0R_RFOM0;
785  }
786  /* Release FIFO1 */
787  else /* FIFONumber == CAN_FIFO1 */
788  {
789  CANx->RF1R |= CAN_RF1R_RFOM1;
790  }
791 }
792 
799 void CAN_FIFORelease(CAN_TypeDef* CANx, uint8_t FIFONumber)
800 {
801  /* Check the parameters */
802  assert_param(IS_CAN_ALL_PERIPH(CANx));
803  assert_param(IS_CAN_FIFO(FIFONumber));
804  /* Release FIFO0 */
805  if (FIFONumber == CAN_FIFO0)
806  {
807  CANx->RF0R |= CAN_RF0R_RFOM0;
808  }
809  /* Release FIFO1 */
810  else /* FIFONumber == CAN_FIFO1 */
811  {
812  CANx->RF1R |= CAN_RF1R_RFOM1;
813  }
814 }
815 
822 uint8_t CAN_MessagePending(CAN_TypeDef* CANx, uint8_t FIFONumber)
823 {
824  uint8_t message_pending=0;
825  /* Check the parameters */
826  assert_param(IS_CAN_ALL_PERIPH(CANx));
827  assert_param(IS_CAN_FIFO(FIFONumber));
828  if (FIFONumber == CAN_FIFO0)
829  {
830  message_pending = (uint8_t)(CANx->RF0R&(uint32_t)0x03);
831  }
832  else if (FIFONumber == CAN_FIFO1)
833  {
834  message_pending = (uint8_t)(CANx->RF1R&(uint32_t)0x03);
835  }
836  else
837  {
838  message_pending = 0;
839  }
840  return message_pending;
841 }
872 uint8_t CAN_OperatingModeRequest(CAN_TypeDef* CANx, uint8_t CAN_OperatingMode)
873 {
874  uint8_t status = CAN_ModeStatus_Failed;
875 
876  /* Timeout for INAK or also for SLAK bits*/
877  uint32_t timeout = INAK_TIMEOUT;
878 
879  /* Check the parameters */
880  assert_param(IS_CAN_ALL_PERIPH(CANx));
881  assert_param(IS_CAN_OPERATING_MODE(CAN_OperatingMode));
882 
883  if (CAN_OperatingMode == CAN_OperatingMode_Initialization)
884  {
885  /* Request initialisation */
886  CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_SLEEP)) | CAN_MCR_INRQ);
887 
888  /* Wait the acknowledge */
889  while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK) && (timeout != 0))
890  {
891  timeout--;
892  }
893  if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_INAK)
894  {
895  status = CAN_ModeStatus_Failed;
896  }
897  else
898  {
899  status = CAN_ModeStatus_Success;
900  }
901  }
902  else if (CAN_OperatingMode == CAN_OperatingMode_Normal)
903  {
904  /* Request leave initialisation and sleep mode and enter Normal mode */
905  CANx->MCR &= (uint32_t)(~(CAN_MCR_SLEEP|CAN_MCR_INRQ));
906 
907  /* Wait the acknowledge */
908  while (((CANx->MSR & CAN_MODE_MASK) != 0) && (timeout!=0))
909  {
910  timeout--;
911  }
912  if ((CANx->MSR & CAN_MODE_MASK) != 0)
913  {
914  status = CAN_ModeStatus_Failed;
915  }
916  else
917  {
918  status = CAN_ModeStatus_Success;
919  }
920  }
921  else if (CAN_OperatingMode == CAN_OperatingMode_Sleep)
922  {
923  /* Request Sleep mode */
924  CANx->MCR = (uint32_t)((CANx->MCR & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
925 
926  /* Wait the acknowledge */
927  while (((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK) && (timeout!=0))
928  {
929  timeout--;
930  }
931  if ((CANx->MSR & CAN_MODE_MASK) != CAN_MSR_SLAK)
932  {
933  status = CAN_ModeStatus_Failed;
934  }
935  else
936  {
937  status = CAN_ModeStatus_Success;
938  }
939  }
940  else
941  {
942  status = CAN_ModeStatus_Failed;
943  }
944 
945  return (uint8_t) status;
946 }
947 
953 uint8_t CAN_Sleep(CAN_TypeDef* CANx)
954 {
955  uint8_t sleepstatus = CAN_Sleep_Failed;
956 
957  /* Check the parameters */
958  assert_param(IS_CAN_ALL_PERIPH(CANx));
959 
960  /* Request Sleep mode */
961  CANx->MCR = (((CANx->MCR) & (uint32_t)(~(uint32_t)CAN_MCR_INRQ)) | CAN_MCR_SLEEP);
962 
963  /* Sleep mode status */
964  if ((CANx->MSR & (CAN_MSR_SLAK|CAN_MSR_INAK)) == CAN_MSR_SLAK)
965  {
966  /* Sleep mode not entered */
967  sleepstatus = CAN_Sleep_Ok;
968  }
969  /* return sleep mode status */
970  return (uint8_t)sleepstatus;
971 }
972 
978 uint8_t CAN_WakeUp(CAN_TypeDef* CANx)
979 {
980  uint32_t wait_slak = SLAK_TIMEOUT;
981  uint8_t wakeupstatus = CAN_WakeUp_Failed;
982 
983  /* Check the parameters */
984  assert_param(IS_CAN_ALL_PERIPH(CANx));
985 
986  /* Wake up request */
987  CANx->MCR &= ~(uint32_t)CAN_MCR_SLEEP;
988 
989  /* Sleep mode status */
990  while(((CANx->MSR & CAN_MSR_SLAK) == CAN_MSR_SLAK)&&(wait_slak!=0x00))
991  {
992  wait_slak--;
993  }
994  if((CANx->MSR & CAN_MSR_SLAK) != CAN_MSR_SLAK)
995  {
996  /* wake up done : Sleep mode exited */
997  wakeupstatus = CAN_WakeUp_Ok;
998  }
999  /* return wakeup status */
1000  return (uint8_t)wakeupstatus;
1001 }
1040 uint8_t CAN_GetLastErrorCode(CAN_TypeDef* CANx)
1041 {
1042  uint8_t errorcode=0;
1043 
1044  /* Check the parameters */
1045  assert_param(IS_CAN_ALL_PERIPH(CANx));
1046 
1047  /* Get the error code*/
1048  errorcode = (((uint8_t)CANx->ESR) & (uint8_t)CAN_ESR_LEC);
1049 
1050  /* Return the error code*/
1051  return errorcode;
1052 }
1053 
1065 uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef* CANx)
1066 {
1067  uint8_t counter=0;
1068 
1069  /* Check the parameters */
1070  assert_param(IS_CAN_ALL_PERIPH(CANx));
1071 
1072  /* Get the Receive Error Counter*/
1073  counter = (uint8_t)((CANx->ESR & CAN_ESR_REC)>> 24);
1074 
1075  /* Return the Receive Error Counter*/
1076  return counter;
1077 }
1078 
1079 
1085 uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef* CANx)
1086 {
1087  uint8_t counter=0;
1088 
1089  /* Check the parameters */
1090  assert_param(IS_CAN_ALL_PERIPH(CANx));
1091 
1092  /* Get the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
1093  counter = (uint8_t)((CANx->ESR & CAN_ESR_TEC)>> 16);
1094 
1095  /* Return the LSB of the 9-bit CANx Transmit Error Counter(TEC) */
1096  return counter;
1097 }
1290 void CAN_ITConfig(CAN_TypeDef* CANx, uint32_t CAN_IT, FunctionalState NewState)
1291 {
1292  /* Check the parameters */
1293  assert_param(IS_CAN_ALL_PERIPH(CANx));
1294  assert_param(IS_CAN_IT(CAN_IT));
1295  assert_param(IS_FUNCTIONAL_STATE(NewState));
1296 
1297  if (NewState != DISABLE)
1298  {
1299  /* Enable the selected CANx interrupt */
1300  CANx->IER |= CAN_IT;
1301  }
1302  else
1303  {
1304  /* Disable the selected CANx interrupt */
1305  CANx->IER &= ~CAN_IT;
1306  }
1307 }
1330 FlagStatus CAN_GetFlagStatus(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
1331 {
1332  FlagStatus bitstatus = RESET;
1333 
1334  /* Check the parameters */
1335  assert_param(IS_CAN_ALL_PERIPH(CANx));
1336  assert_param(IS_CAN_GET_FLAG(CAN_FLAG));
1337 
1338 
1339  if((CAN_FLAG & CAN_FLAGS_ESR) != (uint32_t)RESET)
1340  {
1341  /* Check the status of the specified CAN flag */
1342  if ((CANx->ESR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1343  {
1344  /* CAN_FLAG is set */
1345  bitstatus = SET;
1346  }
1347  else
1348  {
1349  /* CAN_FLAG is reset */
1350  bitstatus = RESET;
1351  }
1352  }
1353  else if((CAN_FLAG & CAN_FLAGS_MSR) != (uint32_t)RESET)
1354  {
1355  /* Check the status of the specified CAN flag */
1356  if ((CANx->MSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1357  {
1358  /* CAN_FLAG is set */
1359  bitstatus = SET;
1360  }
1361  else
1362  {
1363  /* CAN_FLAG is reset */
1364  bitstatus = RESET;
1365  }
1366  }
1367  else if((CAN_FLAG & CAN_FLAGS_TSR) != (uint32_t)RESET)
1368  {
1369  /* Check the status of the specified CAN flag */
1370  if ((CANx->TSR & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1371  {
1372  /* CAN_FLAG is set */
1373  bitstatus = SET;
1374  }
1375  else
1376  {
1377  /* CAN_FLAG is reset */
1378  bitstatus = RESET;
1379  }
1380  }
1381  else if((CAN_FLAG & CAN_FLAGS_RF0R) != (uint32_t)RESET)
1382  {
1383  /* Check the status of the specified CAN flag */
1384  if ((CANx->RF0R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1385  {
1386  /* CAN_FLAG is set */
1387  bitstatus = SET;
1388  }
1389  else
1390  {
1391  /* CAN_FLAG is reset */
1392  bitstatus = RESET;
1393  }
1394  }
1395  else /* If(CAN_FLAG & CAN_FLAGS_RF1R != (uint32_t)RESET) */
1396  {
1397  /* Check the status of the specified CAN flag */
1398  if ((uint32_t)(CANx->RF1R & (CAN_FLAG & 0x000FFFFF)) != (uint32_t)RESET)
1399  {
1400  /* CAN_FLAG is set */
1401  bitstatus = SET;
1402  }
1403  else
1404  {
1405  /* CAN_FLAG is reset */
1406  bitstatus = RESET;
1407  }
1408  }
1409  /* Return the CAN_FLAG status */
1410  return bitstatus;
1411 }
1412 
1430 void CAN_ClearFlag(CAN_TypeDef* CANx, uint32_t CAN_FLAG)
1431 {
1432  uint32_t flagtmp=0;
1433  /* Check the parameters */
1434  assert_param(IS_CAN_ALL_PERIPH(CANx));
1435  assert_param(IS_CAN_CLEAR_FLAG(CAN_FLAG));
1436 
1437  if (CAN_FLAG == CAN_FLAG_LEC) /* ESR register */
1438  {
1439  /* Clear the selected CAN flags */
1440  CANx->ESR = (uint32_t)RESET;
1441  }
1442  else /* MSR or TSR or RF0R or RF1R */
1443  {
1444  flagtmp = CAN_FLAG & 0x000FFFFF;
1445 
1446  if ((CAN_FLAG & CAN_FLAGS_RF0R)!=(uint32_t)RESET)
1447  {
1448  /* Receive Flags */
1449  CANx->RF0R = (uint32_t)(flagtmp);
1450  }
1451  else if ((CAN_FLAG & CAN_FLAGS_RF1R)!=(uint32_t)RESET)
1452  {
1453  /* Receive Flags */
1454  CANx->RF1R = (uint32_t)(flagtmp);
1455  }
1456  else if ((CAN_FLAG & CAN_FLAGS_TSR)!=(uint32_t)RESET)
1457  {
1458  /* Transmit Flags */
1459  CANx->TSR = (uint32_t)(flagtmp);
1460  }
1461  else /* If((CAN_FLAG & CAN_FLAGS_MSR)!=(uint32_t)RESET) */
1462  {
1463  /* Operating mode Flags */
1464  CANx->MSR = (uint32_t)(flagtmp);
1465  }
1466  }
1467 }
1468 
1490 ITStatus CAN_GetITStatus(CAN_TypeDef* CANx, uint32_t CAN_IT)
1491 {
1492  ITStatus itstatus = RESET;
1493  /* Check the parameters */
1494  assert_param(IS_CAN_ALL_PERIPH(CANx));
1495  assert_param(IS_CAN_IT(CAN_IT));
1496 
1497  /* check the interrupt enable bit */
1498  if((CANx->IER & CAN_IT) != RESET)
1499  {
1500  /* in case the Interrupt is enabled, .... */
1501  switch (CAN_IT)
1502  {
1503  case CAN_IT_TME:
1504  /* Check CAN_TSR_RQCPx bits */
1505  itstatus = CheckITStatus(CANx->TSR, CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2);
1506  break;
1507  case CAN_IT_FMP0:
1508  /* Check CAN_RF0R_FMP0 bit */
1509  itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FMP0);
1510  break;
1511  case CAN_IT_FF0:
1512  /* Check CAN_RF0R_FULL0 bit */
1513  itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FULL0);
1514  break;
1515  case CAN_IT_FOV0:
1516  /* Check CAN_RF0R_FOVR0 bit */
1517  itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FOVR0);
1518  break;
1519  case CAN_IT_FMP1:
1520  /* Check CAN_RF1R_FMP1 bit */
1521  itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FMP1);
1522  break;
1523  case CAN_IT_FF1:
1524  /* Check CAN_RF1R_FULL1 bit */
1525  itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FULL1);
1526  break;
1527  case CAN_IT_FOV1:
1528  /* Check CAN_RF1R_FOVR1 bit */
1529  itstatus = CheckITStatus(CANx->RF1R, CAN_RF1R_FOVR1);
1530  break;
1531  case CAN_IT_WKU:
1532  /* Check CAN_MSR_WKUI bit */
1533  itstatus = CheckITStatus(CANx->MSR, CAN_MSR_WKUI);
1534  break;
1535  case CAN_IT_SLK:
1536  /* Check CAN_MSR_SLAKI bit */
1537  itstatus = CheckITStatus(CANx->MSR, CAN_MSR_SLAKI);
1538  break;
1539  case CAN_IT_EWG:
1540  /* Check CAN_ESR_EWGF bit */
1541  itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EWGF);
1542  break;
1543  case CAN_IT_EPV:
1544  /* Check CAN_ESR_EPVF bit */
1545  itstatus = CheckITStatus(CANx->ESR, CAN_ESR_EPVF);
1546  break;
1547  case CAN_IT_BOF:
1548  /* Check CAN_ESR_BOFF bit */
1549  itstatus = CheckITStatus(CANx->ESR, CAN_ESR_BOFF);
1550  break;
1551  case CAN_IT_LEC:
1552  /* Check CAN_ESR_LEC bit */
1553  itstatus = CheckITStatus(CANx->ESR, CAN_ESR_LEC);
1554  break;
1555  case CAN_IT_ERR:
1556  /* Check CAN_MSR_ERRI bit */
1557  itstatus = CheckITStatus(CANx->MSR, CAN_MSR_ERRI);
1558  break;
1559  default:
1560  /* in case of error, return RESET */
1561  itstatus = RESET;
1562  break;
1563  }
1564  }
1565  else
1566  {
1567  /* in case the Interrupt is not enabled, return RESET */
1568  itstatus = RESET;
1569  }
1570 
1571  /* Return the CAN_IT status */
1572  return itstatus;
1573 }
1574 
1594 void CAN_ClearITPendingBit(CAN_TypeDef* CANx, uint32_t CAN_IT)
1595 {
1596  /* Check the parameters */
1597  assert_param(IS_CAN_ALL_PERIPH(CANx));
1598  assert_param(IS_CAN_CLEAR_IT(CAN_IT));
1599 
1600  switch (CAN_IT)
1601  {
1602  case CAN_IT_TME:
1603  /* Clear CAN_TSR_RQCPx (rc_w1)*/
1604  CANx->TSR = CAN_TSR_RQCP0|CAN_TSR_RQCP1|CAN_TSR_RQCP2;
1605  break;
1606  case CAN_IT_FF0:
1607  /* Clear CAN_RF0R_FULL0 (rc_w1)*/
1608  CANx->RF0R = CAN_RF0R_FULL0;
1609  break;
1610  case CAN_IT_FOV0:
1611  /* Clear CAN_RF0R_FOVR0 (rc_w1)*/
1612  CANx->RF0R = CAN_RF0R_FOVR0;
1613  break;
1614  case CAN_IT_FF1:
1615  /* Clear CAN_RF1R_FULL1 (rc_w1)*/
1616  CANx->RF1R = CAN_RF1R_FULL1;
1617  break;
1618  case CAN_IT_FOV1:
1619  /* Clear CAN_RF1R_FOVR1 (rc_w1)*/
1620  CANx->RF1R = CAN_RF1R_FOVR1;
1621  break;
1622  case CAN_IT_WKU:
1623  /* Clear CAN_MSR_WKUI (rc_w1)*/
1624  CANx->MSR = CAN_MSR_WKUI;
1625  break;
1626  case CAN_IT_SLK:
1627  /* Clear CAN_MSR_SLAKI (rc_w1)*/
1628  CANx->MSR = CAN_MSR_SLAKI;
1629  break;
1630  case CAN_IT_EWG:
1631  /* Clear CAN_MSR_ERRI (rc_w1) */
1632  CANx->MSR = CAN_MSR_ERRI;
1633  /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
1634  break;
1635  case CAN_IT_EPV:
1636  /* Clear CAN_MSR_ERRI (rc_w1) */
1637  CANx->MSR = CAN_MSR_ERRI;
1638  /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
1639  break;
1640  case CAN_IT_BOF:
1641  /* Clear CAN_MSR_ERRI (rc_w1) */
1642  CANx->MSR = CAN_MSR_ERRI;
1643  /* @note the corresponding Flag is cleared by hardware depending on the CAN Bus status*/
1644  break;
1645  case CAN_IT_LEC:
1646  /* Clear LEC bits */
1647  CANx->ESR = RESET;
1648  /* Clear CAN_MSR_ERRI (rc_w1) */
1649  CANx->MSR = CAN_MSR_ERRI;
1650  break;
1651  case CAN_IT_ERR:
1652  /*Clear LEC bits */
1653  CANx->ESR = RESET;
1654  /* Clear CAN_MSR_ERRI (rc_w1) */
1655  CANx->MSR = CAN_MSR_ERRI;
1656  /* @note BOFF, EPVF and EWGF Flags are cleared by hardware depending on the CAN Bus status*/
1657  break;
1658  default:
1659  break;
1660  }
1661 }
1672 static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
1673 {
1674  ITStatus pendingbitstatus = RESET;
1675 
1676  if ((CAN_Reg & It_Bit) != (uint32_t)RESET)
1677  {
1678  /* CAN_IT is set */
1679  pendingbitstatus = SET;
1680  }
1681  else
1682  {
1683  /* CAN_IT is reset */
1684  pendingbitstatus = RESET;
1685  }
1686  return pendingbitstatus;
1687 }
1688 
1701 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
This file contains all the functions prototypes for the RCC firmware library.
uint8_t IDE
#define CAN_FIFO0
uint8_t RTR
uint8_t IDE
uint8_t CAN_MessagePending(CAN_TypeDef *CANx, uint8_t FIFONumber)
Returns the number of pending received messages.
#define CAN_TxStatus_Ok
uint8_t RTR
void CAN_DBGFreeze(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the DBG Freeze for CAN.
uint32_t StdId
uint8_t CAN_Init(CAN_TypeDef *CANx, CAN_InitTypeDef *CAN_InitStruct)
Initializes the CAN peripheral according to the specified parameters in the CAN_InitStruct.
uint8_t CAN_OperatingModeRequest(CAN_TypeDef *CANx, uint8_t CAN_OperatingMode)
Selects the CAN Operation mode.
uint32_t StdId
uint8_t CAN_GetReceiveErrorCounter(CAN_TypeDef *CANx)
Returns the CANx Receive Error Counter (REC).
uint8_t FMI
#define CAN_IT_EWG
#define CAN_IT_ERR
void CAN_StructInit(CAN_InitTypeDef *CAN_InitStruct)
Fills each CAN_InitStruct member with its default value.
uint16_t CAN_Prescaler
Definition: stm32f4xx_can.h:58
#define CAN_IT_FOV0
#define CAN_Id_Standard
#define CAN_FLAG_LEC
#define CAN_IT_SLK
#define CAN_IT_TME
#define CAN_ModeStatus_Success
#define CAN_InitStatus_Failed
#define CAN_FilterScale_32bit
FlagStatus CAN_GetFlagStatus(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Checks whether the specified CAN flag is set or not.
#define CAN_SJW_1tq
CAN Tx message structure definition.
#define CAN_Filter_FIFO1
FunctionalState CAN_NART
Definition: stm32f4xx_can.h:85
void CAN_CancelTransmit(CAN_TypeDef *CANx, uint8_t Mailbox)
Cancels a transmit request.
#define CAN_Sleep_Ok
uint8_t Data[8]
#define CAN_TxStatus_NoMailBox
This file contains all the functions prototypes for the CAN firmware library.
#define CAN_TxStatus_Pending
void CAN_DeInit(CAN_TypeDef *CANx)
Deinitializes the CAN peripheral registers to their default reset values.
uint8_t Data[8]
#define CAN_WakeUp_Ok
CAN Rx message structure definition.
CAN init structure definition.
Definition: stm32f4xx_can.h:56
CAN filter init structure definition.
Definition: stm32f4xx_can.h:98
#define CAN_IT_BOF
void CAN_SlaveStartBank(uint8_t CAN_BankNumber)
Select the start bank filter for slave CAN.
uint16_t CAN_FilterFIFOAssignment
uint8_t CAN_TransmitStatus(CAN_TypeDef *CANx, uint8_t TransmitMailbox)
Checks the transmission status of a CAN Frame.
#define CAN_Mode_Normal
void CAN_ClearITPendingBit(CAN_TypeDef *CANx, uint32_t CAN_IT)
Clears the CANx's interrupt pending bits.
FunctionalState CAN_ABOM
Definition: stm32f4xx_can.h:79
#define CAN_OperatingMode_Initialization
#define CAN_InitStatus_Success
static ITStatus CheckITStatus(uint32_t CAN_Reg, uint32_t It_Bit)
Checks whether the CAN interrupt has occurred or not.
#define CAN_OperatingMode_Normal
#define CAN_IT_WKU
void CAN_ClearFlag(CAN_TypeDef *CANx, uint32_t CAN_FLAG)
Clears the CAN's pending flags.
#define CAN_IT_LEC
#define CAN_IT_FF1
#define CAN_Sleep_Failed
uint32_t ExtId
#define CAN_TxStatus_Failed
uint8_t DLC
uint8_t CAN_WakeUp(CAN_TypeDef *CANx)
Wakes up the CAN peripheral from sleep mode .
void CAN_FilterInit(CAN_FilterInitTypeDef *CAN_FilterInitStruct)
Configures the CAN reception filter according to the specified parameters in the CAN_FilterInitStruct...
uint32_t ExtId
#define CAN_IT_EPV
uint8_t CAN_GetLSBTransmitErrorCounter(CAN_TypeDef *CANx)
Returns the LSB of the 9-bit CANx Transmit Error Counter(TEC).
uint8_t DLC
ITStatus CAN_GetITStatus(CAN_TypeDef *CANx, uint32_t CAN_IT)
Checks whether the specified CANx interrupt has occurred or not.
void CAN_FIFORelease(CAN_TypeDef *CANx, uint8_t FIFONumber)
Releases the specified receive FIFO.
#define CAN_FilterMode_IdMask
uint8_t CAN_Sleep(CAN_TypeDef *CANx)
Enters the Sleep (low power) mode.
uint8_t CAN_GetLastErrorCode(CAN_TypeDef *CANx)
Returns the CANx's last error code (LEC).
FunctionalState CAN_TTCM
Definition: stm32f4xx_can.h:76
FunctionalState CAN_RFLM
Definition: stm32f4xx_can.h:88
#define CAN_IT_FF0
FunctionalState CAN_TXFP
Definition: stm32f4xx_can.h:91
uint8_t CAN_Transmit(CAN_TypeDef *CANx, CanTxMsg *TxMessage)
Initiates and transmits a CAN frame message.
#define CAN_Filter_FIFO0
void CAN_Receive(CAN_TypeDef *CANx, uint8_t FIFONumber, CanRxMsg *RxMessage)
Receives a correct CAN frame.
#define CAN_FilterScale_16bit
#define CAN_IT_FMP0
#define CAN_FIFO1
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
#define CAN_BS1_4tq
#define CAN_OperatingMode_Sleep
#define CAN_ModeStatus_Failed
#define CAN_BS2_3tq
#define CAN_IT_FMP1
void CAN_TTComModeCmd(CAN_TypeDef *CANx, FunctionalState NewState)
Enables or disables the CAN Time TriggerOperation communication mode.
FunctionalState CAN_FilterActivation
void CAN_ITConfig(CAN_TypeDef *CANx, uint32_t CAN_IT, FunctionalState NewState)
Enables or disables the specified CANx interrupts.
#define CAN_IT_FOV1
FunctionalState CAN_AWUM
Definition: stm32f4xx_can.h:82
#define CAN_WakeUp_Failed