stm32f30x_usart.c
Go to the documentation of this file.
1 
80 /* Includes ------------------------------------------------------------------*/
81 #include "stm32f30x_usart.h"
82 #include "stm32f30x_rcc.h"
83 
93 /* Private typedef -----------------------------------------------------------*/
94 /* Private define ------------------------------------------------------------*/
95 
97 #define CR1_CLEAR_MASK ((uint32_t)(USART_CR1_M | USART_CR1_PCE | \
98  USART_CR1_PS | USART_CR1_TE | \
99  USART_CR1_RE))
100 
102 #define CR2_CLOCK_CLEAR_MASK ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \
103  USART_CR2_CPHA | USART_CR2_LBCL))
104 
106 #define CR3_CLEAR_MASK ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE))
107 
109 #define IT_MASK ((uint32_t)0x000000FF)
110 
111 /* Private macro -------------------------------------------------------------*/
112 /* Private variables ---------------------------------------------------------*/
113 /* Private function prototypes -----------------------------------------------*/
114 /* Private functions ---------------------------------------------------------*/
115 
174 {
175  /* Check the parameters */
177 
178  if (USARTx == USART1)
179  {
182  }
183  else if (USARTx == USART2)
184  {
187  }
188  else if (USARTx == USART3)
189  {
192  }
193  else if (USARTx == UART4)
194  {
197  }
198  else
199  {
200  if (USARTx == UART5)
201  {
204  }
205  }
206 }
207 
217 void USART_Init(USART_TypeDef* USARTx, USART_InitTypeDef* USART_InitStruct)
218 {
219  uint32_t divider = 0, apbclock = 0, tmpreg = 0;
220  RCC_ClocksTypeDef RCC_ClocksStatus;
221 
222  /* Check the parameters */
224  assert_param(IS_USART_BAUDRATE(USART_InitStruct->USART_BaudRate));
226  assert_param(IS_USART_STOPBITS(USART_InitStruct->USART_StopBits));
227  assert_param(IS_USART_PARITY(USART_InitStruct->USART_Parity));
228  assert_param(IS_USART_MODE(USART_InitStruct->USART_Mode));
230 
231  /* Disable USART */
232  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
233 
234  /*---------------------------- USART CR2 Configuration -----------------------*/
235  tmpreg = USARTx->CR2;
236  /* Clear STOP[13:12] bits */
237  tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
238 
239  /* Configure the USART Stop Bits, Clock, CPOL, CPHA and LastBit ------------*/
240  /* Set STOP[13:12] bits according to USART_StopBits value */
241  tmpreg |= (uint32_t)USART_InitStruct->USART_StopBits;
242 
243  /* Write to USART CR2 */
244  USARTx->CR2 = tmpreg;
245 
246  /*---------------------------- USART CR1 Configuration -----------------------*/
247  tmpreg = USARTx->CR1;
248  /* Clear M, PCE, PS, TE and RE bits */
249  tmpreg &= (uint32_t)~((uint32_t)CR1_CLEAR_MASK);
250 
251  /* Configure the USART Word Length, Parity and mode ----------------------- */
252  /* Set the M bits according to USART_WordLength value */
253  /* Set PCE and PS bits according to USART_Parity value */
254  /* Set TE and RE bits according to USART_Mode value */
255  tmpreg |= (uint32_t)USART_InitStruct->USART_WordLength | USART_InitStruct->USART_Parity |
256  USART_InitStruct->USART_Mode;
257 
258  /* Write to USART CR1 */
259  USARTx->CR1 = tmpreg;
260 
261  /*---------------------------- USART CR3 Configuration -----------------------*/
262  tmpreg = USARTx->CR3;
263  /* Clear CTSE and RTSE bits */
264  tmpreg &= (uint32_t)~((uint32_t)CR3_CLEAR_MASK);
265 
266  /* Configure the USART HFC -------------------------------------------------*/
267  /* Set CTSE and RTSE bits according to USART_HardwareFlowControl value */
268  tmpreg |= USART_InitStruct->USART_HardwareFlowControl;
269 
270  /* Write to USART CR3 */
271  USARTx->CR3 = tmpreg;
272 
273  /*---------------------------- USART BRR Configuration -----------------------*/
274  /* Configure the USART Baud Rate -------------------------------------------*/
275  RCC_GetClocksFreq(&RCC_ClocksStatus);
276 
277  if (USARTx == USART1)
278  {
279  apbclock = RCC_ClocksStatus.USART1CLK_Frequency;
280  }
281  else if (USARTx == USART2)
282  {
283  apbclock = RCC_ClocksStatus.USART2CLK_Frequency;
284  }
285  else if (USARTx == USART3)
286  {
287  apbclock = RCC_ClocksStatus.USART3CLK_Frequency;
288  }
289  else if (USARTx == UART4)
290  {
291  apbclock = RCC_ClocksStatus.UART4CLK_Frequency;
292  }
293  else
294  {
295  apbclock = RCC_ClocksStatus.UART5CLK_Frequency;
296  }
297 
298  /* Determine the integer part */
299  if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
300  {
301  /* (divider * 10) computing in case Oversampling mode is 8 Samples */
302  divider = (uint32_t)((2 * apbclock) / (USART_InitStruct->USART_BaudRate));
303  tmpreg = (uint32_t)((2 * apbclock) % (USART_InitStruct->USART_BaudRate));
304  }
305  else /* if ((USARTx->CR1 & CR1_OVER8_Set) == 0) */
306  {
307  /* (divider * 10) computing in case Oversampling mode is 16 Samples */
308  divider = (uint32_t)((apbclock) / (USART_InitStruct->USART_BaudRate));
309  tmpreg = (uint32_t)((apbclock) % (USART_InitStruct->USART_BaudRate));
310  }
311 
312  /* round the divider : if fractional part i greater than 0.5 increment divider */
313  if (tmpreg >= (USART_InitStruct->USART_BaudRate) / 2)
314  {
315  divider++;
316  }
317 
318  /* Implement the divider in case Oversampling mode is 8 Samples */
319  if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
320  {
321  /* get the LSB of divider and shift it to the right by 1 bit */
322  tmpreg = (divider & (uint16_t)0x000F) >> 1;
323 
324  /* update the divider value */
325  divider = (divider & (uint16_t)0xFFF0) | tmpreg;
326  }
327 
328  /* Write to USART BRR */
329  USARTx->BRR = (uint16_t)divider;
330 }
331 
338 void USART_StructInit(USART_InitTypeDef* USART_InitStruct)
339 {
340  /* USART_InitStruct members default value */
341  USART_InitStruct->USART_BaudRate = 9600;
342  USART_InitStruct->USART_WordLength = USART_WordLength_8b;
343  USART_InitStruct->USART_StopBits = USART_StopBits_1;
344  USART_InitStruct->USART_Parity = USART_Parity_No ;
345  USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
347 }
348 
359 void USART_ClockInit(USART_TypeDef* USARTx, USART_ClockInitTypeDef* USART_ClockInitStruct)
360 {
361  uint32_t tmpreg = 0;
362  /* Check the parameters */
364  assert_param(IS_USART_CLOCK(USART_ClockInitStruct->USART_Clock));
365  assert_param(IS_USART_CPOL(USART_ClockInitStruct->USART_CPOL));
366  assert_param(IS_USART_CPHA(USART_ClockInitStruct->USART_CPHA));
367  assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->USART_LastBit));
368 /*---------------------------- USART CR2 Configuration -----------------------*/
369  tmpreg = USARTx->CR2;
370  /* Clear CLKEN, CPOL, CPHA, LBCL and SSM bits */
371  tmpreg &= (uint32_t)~((uint32_t)CR2_CLOCK_CLEAR_MASK);
372  /* Configure the USART Clock, CPOL, CPHA, LastBit and SSM ------------*/
373  /* Set CLKEN bit according to USART_Clock value */
374  /* Set CPOL bit according to USART_CPOL value */
375  /* Set CPHA bit according to USART_CPHA value */
376  /* Set LBCL bit according to USART_LastBit value */
377  tmpreg |= (uint32_t)(USART_ClockInitStruct->USART_Clock | USART_ClockInitStruct->USART_CPOL |
378  USART_ClockInitStruct->USART_CPHA | USART_ClockInitStruct->USART_LastBit);
379  /* Write to USART CR2 */
380  USARTx->CR2 = tmpreg;
381 }
382 
389 void USART_ClockStructInit(USART_ClockInitTypeDef* USART_ClockInitStruct)
390 {
391  /* USART_ClockInitStruct members default value */
392  USART_ClockInitStruct->USART_Clock = USART_Clock_Disable;
393  USART_ClockInitStruct->USART_CPOL = USART_CPOL_Low;
394  USART_ClockInitStruct->USART_CPHA = USART_CPHA_1Edge;
395  USART_ClockInitStruct->USART_LastBit = USART_LastBit_Disable;
396 }
397 
406 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
407 {
408  /* Check the parameters */
411 
412  if (NewState != DISABLE)
413  {
414  /* Enable the selected USART by setting the UE bit in the CR1 register */
415  USARTx->CR1 |= USART_CR1_UE;
416  }
417  else
418  {
419  /* Disable the selected USART by clearing the UE bit in the CR1 register */
420  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UE);
421  }
422 }
423 
436 void USART_DirectionModeCmd(USART_TypeDef* USARTx, uint32_t USART_DirectionMode, FunctionalState NewState)
437 {
438  /* Check the parameters */
440  assert_param(IS_USART_MODE(USART_DirectionMode));
441  assert_param(IS_FUNCTIONAL_STATE(NewState));
442 
443  if (NewState != DISABLE)
444  {
445  /* Enable the USART's transfer interface by setting the TE and/or RE bits
446  in the USART CR1 register */
447  USARTx->CR1 |= USART_DirectionMode;
448  }
449  else
450  {
451  /* Disable the USART's transfer interface by clearing the TE and/or RE bits
452  in the USART CR3 register */
453  USARTx->CR1 &= (uint32_t)~USART_DirectionMode;
454  }
455 }
456 
469 {
470  /* Check the parameters */
473 
474  if (NewState != DISABLE)
475  {
476  /* Enable the 8x Oversampling mode by setting the OVER8 bit in the CR1 register */
477  USARTx->CR1 |= USART_CR1_OVER8;
478  }
479  else
480  {
481  /* Disable the 8x Oversampling mode by clearing the OVER8 bit in the CR1 register */
482  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_OVER8);
483  }
484 }
485 
497 {
498  /* Check the parameters */
501 
502  if (NewState != DISABLE)
503  {
504  /* Enable the one bit method by setting the ONEBIT bit in the CR3 register */
505  USARTx->CR3 |= USART_CR3_ONEBIT;
506  }
507  else
508  {
509  /* Disable the one bit method by clearing the ONEBIT bit in the CR3 register */
510  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT);
511  }
512 }
513 
527 {
528  /* Check the parameters */
531 
532  if (NewState != DISABLE)
533  {
534  /* Enable the most significant bit first transmitted/received following the
535  start bit by setting the MSBFIRST bit in the CR2 register */
536  USARTx->CR2 |= USART_CR2_MSBFIRST;
537  }
538  else
539  {
540  /* Disable the most significant bit first transmitted/received following the
541  start bit by clearing the MSBFIRST bit in the CR2 register */
542  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_MSBFIRST);
543  }
544 }
545 
561 {
562  /* Check the parameters */
565 
566  if (NewState != DISABLE)
567  {
568  /* Enable the binary data inversion feature by setting the DATAINV bit in
569  the CR2 register */
570  USARTx->CR2 |= USART_CR2_DATAINV;
571  }
572  else
573  {
574  /* Disable the binary data inversion feature by clearing the DATAINV bit in
575  the CR2 register */
576  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_DATAINV);
577  }
578 }
579 
596 void USART_InvPinCmd(USART_TypeDef* USARTx, uint32_t USART_InvPin, FunctionalState NewState)
597 {
598  /* Check the parameters */
600  assert_param(IS_USART_INVERSTION_PIN(USART_InvPin));
601  assert_param(IS_FUNCTIONAL_STATE(NewState));
602 
603  if (NewState != DISABLE)
604  {
605  /* Enable the active level inversion for selected pins by setting the TXINV
606  and/or RXINV bits in the USART CR2 register */
607  USARTx->CR2 |= USART_InvPin;
608  }
609  else
610  {
611  /* Disable the active level inversion for selected requests by clearing the
612  TXINV and/or RXINV bits in the USART CR2 register */
613  USARTx->CR2 &= (uint32_t)~USART_InvPin;
614  }
615 }
616 
630 {
631  /* Check the parameters */
634 
635  if (NewState != DISABLE)
636  {
637  /* Enable the SWAP feature by setting the SWAP bit in the CR2 register */
638  USARTx->CR2 |= USART_CR2_SWAP;
639  }
640  else
641  {
642  /* Disable the SWAP feature by clearing the SWAP bit in the CR2 register */
643  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_SWAP);
644  }
645 }
646 
656 {
657  /* Check the parameters */
660 
661  if (NewState != DISABLE)
662  {
663  /* Enable the receiver time out feature by setting the RTOEN bit in the CR2
664  register */
665  USARTx->CR2 |= USART_CR2_RTOEN;
666  }
667  else
668  {
669  /* Disable the receiver time out feature by clearing the RTOEN bit in the CR2
670  register */
671  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_RTOEN);
672  }
673 }
674 
682 void USART_SetReceiverTimeOut(USART_TypeDef* USARTx, uint32_t USART_ReceiverTimeOut)
683 {
684  /* Check the parameters */
686  assert_param(IS_USART_TIMEOUT(USART_ReceiverTimeOut));
687 
688  /* Clear the receiver Time Out value by clearing the RTO[23:0] bits in the RTOR
689  register */
690  USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_RTO);
691  /* Set the receiver Time Out value by setting the RTO[23:0] bits in the RTOR
692  register */
693  USARTx->RTOR |= USART_ReceiverTimeOut;
694 }
695 
705 void USART_SetPrescaler(USART_TypeDef* USARTx, uint8_t USART_Prescaler)
706 {
707  /* Check the parameters */
709 
710  /* Clear the USART prescaler */
711  USARTx->GTPR &= USART_GTPR_GT;
712  /* Set the USART prescaler */
713  USARTx->GTPR |= USART_Prescaler;
714 }
715 
755 {
756  /* Check the parameters */
759 
760  if (NewState != DISABLE)
761  {
762  /* Enable the selected USART in STOP mode by setting the UESM bit in the CR1
763  register */
764  USARTx->CR1 |= USART_CR1_UESM;
765  }
766  else
767  {
768  /* Disable the selected USART in STOP mode by clearing the UE bit in the CR1
769  register */
770  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_UESM);
771  }
772 }
773 
787 void USART_StopModeWakeUpSourceConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUpSource)
788 {
789  /* Check the parameters */
791  assert_param(IS_USART_STOPMODE_WAKEUPSOURCE(USART_WakeUpSource));
792 
793  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_WUS);
794  USARTx->CR3 |= USART_WakeUpSource;
795 }
796 
839 {
840  /* Check the parameters */
843 
844  if (NewState != DISABLE)
845  {
846  /* Enable the auto baud rate feature by setting the ABREN bit in the CR2
847  register */
848  USARTx->CR2 |= USART_CR2_ABREN;
849  }
850  else
851  {
852  /* Disable the auto baud rate feature by clearing the ABREN bit in the CR2
853  register */
854  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABREN);
855  }
856 }
857 
872 void USART_AutoBaudRateConfig(USART_TypeDef* USARTx, uint32_t USART_AutoBaudRate)
873 {
874  /* Check the parameters */
876  assert_param(IS_USART_AUTOBAUDRATE_MODE(USART_AutoBaudRate));
877 
878  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABRMODE);
879  USARTx->CR2 |= USART_AutoBaudRate;
880 }
881 
915 void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
916 {
917  /* Check the parameters */
919  assert_param(IS_USART_DATA(Data));
920 
921  /* Transmit Data */
922  USARTx->TDR = (Data & (uint16_t)0x01FF);
923 }
924 
932 {
933  /* Check the parameters */
935 
936  /* Receive Data */
937  return (uint16_t)(USARTx->RDR & (uint16_t)0x01FF);
938 }
939 
981 void USART_SetAddress(USART_TypeDef* USARTx, uint8_t USART_Address)
982 {
983  /* Check the parameters */
985 
986  /* Clear the USART address */
987  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ADD);
988  /* Set the USART address node */
989  USARTx->CR2 |=((uint32_t)USART_Address << (uint32_t)0x18);
990 }
991 
1001 {
1002  /* Check the parameters */
1004  assert_param(IS_FUNCTIONAL_STATE(NewState));
1005 
1006  if (NewState != DISABLE)
1007  {
1008  /* Enable the USART mute mode by setting the MME bit in the CR1 register */
1009  USARTx->CR1 |= USART_CR1_MME;
1010  }
1011  else
1012  {
1013  /* Disable the USART mute mode by clearing the MME bit in the CR1 register */
1014  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_MME);
1015  }
1016 }
1017 
1028 void USART_MuteModeWakeUpConfig(USART_TypeDef* USARTx, uint32_t USART_WakeUp)
1029 {
1030  /* Check the parameters */
1032  assert_param(IS_USART_MUTEMODE_WAKEUP(USART_WakeUp));
1033 
1034  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_WAKE);
1035  USARTx->CR1 |= USART_WakeUp;
1036 }
1037 
1048 void USART_AddressDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_AddressLength)
1049 {
1050  /* Check the parameters */
1052  assert_param(IS_USART_ADDRESS_DETECTION(USART_AddressLength));
1053 
1054  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_ADDM7);
1055  USARTx->CR2 |= USART_AddressLength;
1056 }
1057 
1113 void USART_LINBreakDetectLengthConfig(USART_TypeDef* USARTx, uint32_t USART_LINBreakDetectLength)
1114 {
1115  /* Check the parameters */
1117  assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
1118 
1119  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_LBDL);
1120  USARTx->CR2 |= USART_LINBreakDetectLength;
1121 }
1122 
1132 {
1133  /* Check the parameters */
1135  assert_param(IS_FUNCTIONAL_STATE(NewState));
1136 
1137  if (NewState != DISABLE)
1138  {
1139  /* Enable the LIN mode by setting the LINEN bit in the CR2 register */
1140  USARTx->CR2 |= USART_CR2_LINEN;
1141  }
1142  else
1143  {
1144  /* Disable the LIN mode by clearing the LINEN bit in the CR2 register */
1145  USARTx->CR2 &= (uint32_t)~((uint32_t)USART_CR2_LINEN);
1146  }
1147 }
1148 
1190 {
1191  /* Check the parameters */
1193  assert_param(IS_FUNCTIONAL_STATE(NewState));
1194 
1195  if (NewState != DISABLE)
1196  {
1197  /* Enable the Half-Duplex mode by setting the HDSEL bit in the CR3 register */
1198  USARTx->CR3 |= USART_CR3_HDSEL;
1199  }
1200  else
1201  {
1202  /* Disable the Half-Duplex mode by clearing the HDSEL bit in the CR3 register */
1203  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_HDSEL);
1204  }
1205 }
1206 
1270 void USART_SetGuardTime(USART_TypeDef* USARTx, uint8_t USART_GuardTime)
1271 {
1272  /* Check the parameters */
1274 
1275  /* Clear the USART Guard time */
1276  USARTx->GTPR &= USART_GTPR_PSC;
1277  /* Set the USART guard time */
1278  USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
1279 }
1280 
1290 {
1291  /* Check the parameters */
1293  assert_param(IS_FUNCTIONAL_STATE(NewState));
1294  if (NewState != DISABLE)
1295  {
1296  /* Enable the SC mode by setting the SCEN bit in the CR3 register */
1297  USARTx->CR3 |= USART_CR3_SCEN;
1298  }
1299  else
1300  {
1301  /* Disable the SC mode by clearing the SCEN bit in the CR3 register */
1302  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_SCEN);
1303  }
1304 }
1305 
1315 {
1316  /* Check the parameters */
1318  assert_param(IS_FUNCTIONAL_STATE(NewState));
1319  if (NewState != DISABLE)
1320  {
1321  /* Enable the NACK transmission by setting the NACK bit in the CR3 register */
1322  USARTx->CR3 |= USART_CR3_NACK;
1323  }
1324  else
1325  {
1326  /* Disable the NACK transmission by clearing the NACK bit in the CR3 register */
1327  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_NACK);
1328  }
1329 }
1330 
1338 void USART_SetAutoRetryCount(USART_TypeDef* USARTx, uint8_t USART_AutoCount)
1339 {
1340  /* Check the parameters */
1342  assert_param(IS_USART_AUTO_RETRY_COUNTER(USART_AutoCount));
1343  /* Clear the USART auto retry count */
1344  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_SCARCNT);
1345  /* Set the USART auto retry count*/
1346  USARTx->CR3 |= (uint32_t)((uint32_t)USART_AutoCount << 0x11);
1347 }
1348 
1356 void USART_SetBlockLength(USART_TypeDef* USARTx, uint8_t USART_BlockLength)
1357 {
1358  /* Check the parameters */
1360 
1361  /* Clear the Smart card block length */
1362  USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_BLEN);
1363  /* Set the Smart Card block length */
1364  USARTx->RTOR |= (uint32_t)((uint32_t)USART_BlockLength << 0x18);
1365 }
1366 
1419 void USART_IrDAConfig(USART_TypeDef* USARTx, uint32_t USART_IrDAMode)
1420 {
1421  /* Check the parameters */
1423  assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
1424 
1425  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_IRLP);
1426  USARTx->CR3 |= USART_IrDAMode;
1427 }
1428 
1438 {
1439  /* Check the parameters */
1441  assert_param(IS_FUNCTIONAL_STATE(NewState));
1442 
1443  if (NewState != DISABLE)
1444  {
1445  /* Enable the IrDA mode by setting the IREN bit in the CR3 register */
1446  USARTx->CR3 |= USART_CR3_IREN;
1447  }
1448  else
1449  {
1450  /* Disable the IrDA mode by clearing the IREN bit in the CR3 register */
1451  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_IREN);
1452  }
1453 }
1496 {
1497  /* Check the parameters */
1499  assert_param(IS_FUNCTIONAL_STATE(NewState));
1500  if (NewState != DISABLE)
1501  {
1502  /* Enable the DE functionality by setting the DEM bit in the CR3 register */
1503  USARTx->CR3 |= USART_CR3_DEM;
1504  }
1505  else
1506  {
1507  /* Disable the DE functionality by clearing the DEM bit in the CR3 register */
1508  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEM);
1509  }
1510 }
1511 
1522 void USART_DEPolarityConfig(USART_TypeDef* USARTx, uint32_t USART_DEPolarity)
1523 {
1524  /* Check the parameters */
1526  assert_param(IS_USART_DE_POLARITY(USART_DEPolarity));
1527 
1528  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEP);
1529  USARTx->CR3 |= USART_DEPolarity;
1530 }
1531 
1540 void USART_SetDEAssertionTime(USART_TypeDef* USARTx, uint32_t USART_DEAssertionTime)
1541 {
1542  /* Check the parameters */
1544  assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEAssertionTime));
1545 
1546  /* Clear the DE assertion time */
1547  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEAT);
1548  /* Set the new value for the DE assertion time */
1549  USARTx->CR1 |=((uint32_t)USART_DEAssertionTime << (uint32_t)0x15);
1550 }
1551 
1560 void USART_SetDEDeassertionTime(USART_TypeDef* USARTx, uint32_t USART_DEDeassertionTime)
1561 {
1562  /* Check the parameters */
1564  assert_param(IS_USART_DE_ASSERTION_DEASSERTION_TIME(USART_DEDeassertionTime));
1565 
1566  /* Clear the DE deassertion time */
1567  USARTx->CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEDT);
1568  /* Set the new value for the DE deassertion time */
1569  USARTx->CR1 |=((uint32_t)USART_DEDeassertionTime << (uint32_t)0x10);
1570 }
1571 
1607 void USART_DMACmd(USART_TypeDef* USARTx, uint32_t USART_DMAReq, FunctionalState NewState)
1608 {
1609  /* Check the parameters */
1611  assert_param(IS_USART_DMAREQ(USART_DMAReq));
1612  assert_param(IS_FUNCTIONAL_STATE(NewState));
1613 
1614  if (NewState != DISABLE)
1615  {
1616  /* Enable the DMA transfer for selected requests by setting the DMAT and/or
1617  DMAR bits in the USART CR3 register */
1618  USARTx->CR3 |= USART_DMAReq;
1619  }
1620  else
1621  {
1622  /* Disable the DMA transfer for selected requests by clearing the DMAT and/or
1623  DMAR bits in the USART CR3 register */
1624  USARTx->CR3 &= (uint32_t)~USART_DMAReq;
1625  }
1626 }
1627 
1640 void USART_DMAReceptionErrorConfig(USART_TypeDef* USARTx, uint32_t USART_DMAOnError)
1641 {
1642  /* Check the parameters */
1644  assert_param(IS_USART_DMAONERROR(USART_DMAOnError));
1645 
1646  /* Clear the DMA Reception error detection bit */
1647  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DDRE);
1648  /* Set the new value for the DMA Reception error detection bit */
1649  USARTx->CR3 |= USART_DMAOnError;
1650 }
1651 
1773 void USART_ITConfig(USART_TypeDef* USARTx, uint32_t USART_IT, FunctionalState NewState)
1774 {
1775  uint32_t usartreg = 0, itpos = 0, itmask = 0;
1776  uint32_t usartxbase = 0;
1777  /* Check the parameters */
1779  assert_param(IS_USART_CONFIG_IT(USART_IT));
1780  assert_param(IS_FUNCTIONAL_STATE(NewState));
1781 
1782  usartxbase = (uint32_t)USARTx;
1783 
1784  /* Get the USART register index */
1785  usartreg = (((uint16_t)USART_IT) >> 0x08);
1786 
1787  /* Get the interrupt position */
1788  itpos = USART_IT & IT_MASK;
1789  itmask = (((uint32_t)0x01) << itpos);
1790 
1791  if (usartreg == 0x02) /* The IT is in CR2 register */
1792  {
1793  usartxbase += 0x04;
1794  }
1795  else if (usartreg == 0x03) /* The IT is in CR3 register */
1796  {
1797  usartxbase += 0x08;
1798  }
1799  else /* The IT is in CR1 register */
1800  {
1801  }
1802  if (NewState != DISABLE)
1803  {
1804  *(__IO uint32_t*)usartxbase |= itmask;
1805  }
1806  else
1807  {
1808  *(__IO uint32_t*)usartxbase &= ~itmask;
1809  }
1810 }
1811 
1827 void USART_RequestCmd(USART_TypeDef* USARTx, uint32_t USART_Request, FunctionalState NewState)
1828 {
1829  /* Check the parameters */
1831  assert_param(IS_USART_REQUEST(USART_Request));
1832  assert_param(IS_FUNCTIONAL_STATE(NewState));
1833 
1834  if (NewState != DISABLE)
1835  {
1836  /* Enable the USART ReQuest by setting the dedicated request bit in the RQR
1837  register.*/
1838  USARTx->RQR |= USART_Request;
1839  }
1840  else
1841  {
1842  /* Disable the USART ReQuest by clearing the dedicated request bit in the RQR
1843  register.*/
1844  USARTx->RQR &= (uint32_t)~USART_Request;
1845  }
1846 }
1847 
1860 void USART_OverrunDetectionConfig(USART_TypeDef* USARTx, uint32_t USART_OVRDetection)
1861 {
1862  /* Check the parameters */
1864  assert_param(IS_USART_OVRDETECTION(USART_OVRDetection));
1865 
1866  /* Clear the OVR detection bit */
1867  USARTx->CR3 &= (uint32_t)~((uint32_t)USART_CR3_OVRDIS);
1868  /* Set the new value for the OVR detection bit */
1869  USARTx->CR3 |= USART_OVRDetection;
1870 }
1871 
1902 FlagStatus USART_GetFlagStatus(USART_TypeDef* USARTx, uint32_t USART_FLAG)
1903 {
1904  FlagStatus bitstatus = RESET;
1905  /* Check the parameters */
1907  assert_param(IS_USART_FLAG(USART_FLAG));
1908 
1909  if ((USARTx->ISR & USART_FLAG) != (uint16_t)RESET)
1910  {
1911  bitstatus = SET;
1912  }
1913  else
1914  {
1915  bitstatus = RESET;
1916  }
1917  return bitstatus;
1918 }
1919 
1953 void USART_ClearFlag(USART_TypeDef* USARTx, uint32_t USART_FLAG)
1954 {
1955  /* Check the parameters */
1957  assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
1958 
1959  USARTx->ICR = USART_FLAG;
1960 }
1961 
1984 ITStatus USART_GetITStatus(USART_TypeDef* USARTx, uint32_t USART_IT)
1985 {
1986  uint32_t bitpos = 0, itmask = 0, usartreg = 0;
1987  ITStatus bitstatus = RESET;
1988  /* Check the parameters */
1990  assert_param(IS_USART_GET_IT(USART_IT));
1991 
1992  /* Get the USART register index */
1993  usartreg = (((uint16_t)USART_IT) >> 0x08);
1994  /* Get the interrupt position */
1995  itmask = USART_IT & IT_MASK;
1996  itmask = (uint32_t)0x01 << itmask;
1997 
1998  if (usartreg == 0x01) /* The IT is in CR1 register */
1999  {
2000  itmask &= USARTx->CR1;
2001  }
2002  else if (usartreg == 0x02) /* The IT is in CR2 register */
2003  {
2004  itmask &= USARTx->CR2;
2005  }
2006  else /* The IT is in CR3 register */
2007  {
2008  itmask &= USARTx->CR3;
2009  }
2010 
2011  bitpos = USART_IT >> 0x10;
2012  bitpos = (uint32_t)0x01 << bitpos;
2013  bitpos &= USARTx->ISR;
2014  if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
2015  {
2016  bitstatus = SET;
2017  }
2018  else
2019  {
2020  bitstatus = RESET;
2021  }
2022 
2023  return bitstatus;
2024 }
2025 
2056 void USART_ClearITPendingBit(USART_TypeDef* USARTx, uint32_t USART_IT)
2057 {
2058  uint32_t bitpos = 0, itmask = 0;
2059  /* Check the parameters */
2061  assert_param(IS_USART_CLEAR_IT(USART_IT));
2062 
2063  bitpos = USART_IT >> 0x10;
2064  itmask = ((uint32_t)0x01 << (uint32_t)bitpos);
2065  USARTx->ICR = (uint32_t)itmask;
2066 }
2067 
2084 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
#define USART_LastBit_Disable
FlagStatus
Definition: stm32f4xx.h:706
#define USART_CR1_UE
Definition: stm32f4xx.h:10841
#define USART_Clock_Disable
#define IS_USART_DATA(DATA)
FunctionalState
Definition: stm32f4xx.h:708
uint32_t USART3CLK_Frequency
Definition: stm32f30x_rcc.h:66
#define IS_USART_CLOCK(CLOCK)
#define USART_Parity_No
uint16_t USART_HardwareFlowControl
#define USART_CR3_ONEBIT
Definition: stm32f4xx.h:10871
Universal Synchronous Asynchronous Receiver Transmitter.
Definition: stm32f4xx.h:1710
#define USART_Mode_Tx
#define IT_MASK
void USART_SetAutoRetryCount(USART_TypeDef *USARTx, uint8_t USART_AutoCount)
Sets the Smart Card number of retries in transmit and receive.
#define IS_USART_CLEAR_FLAG(FLAG)
void USART_InvPinCmd(USART_TypeDef *USARTx, uint32_t USART_InvPin, FunctionalState NewState)
Enables or disables the Pin(s) active level inversion.
#define IS_USART_STOPBITS(STOPBITS)
#define USART_CR2_ADD
Definition: stm32f4xx.h:10845
void USART_SetReceiverTimeOut(USART_TypeDef *USARTx, uint32_t USART_ReceiverTimeOut)
Sets the receiver Time Out value.
void USART_SetDEDeassertionTime(USART_TypeDef *USARTx, uint32_t USART_DEDeassertionTime)
Sets the specified RS485 DE deassertion time.
#define IS_USART_MODE(MODE)
#define USART_GTPR_GT
Definition: stm32f4xx.h:10884
void USART_DeInit(USART_TypeDef *USARTx)
Deinitializes the USARTx peripheral registers to their default reset values.
void USART_MuteModeCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s mute mode.
#define USART_CR3_NACK
Definition: stm32f4xx.h:10864
void USART_SWAPPinCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the swap Tx/Rx pins.
#define IS_USART_CPOL(CPOL)
void USART_SmartCardNACKCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables NACK transmission.
#define USART_Mode_Rx
void assert_param(int val)
#define IS_USART_LASTBIT(LASTBIT)
__IO uint16_t BRR
Definition: stm32f4xx.h:1716
void USART_DECmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s DE functionality.
#define IS_FUNCTIONAL_STATE(STATE)
Definition: stm32f4xx.h:709
void USART_DMAReceptionErrorConfig(USART_TypeDef *USARTx, uint32_t USART_DMAOnError)
Enables or disables the USART&#39;s DMA interface when reception error occurs.
void USART_StopModeWakeUpSourceConfig(USART_TypeDef *USARTx, uint32_t USART_WakeUpSource)
Selects the USART WakeUp method form stop mode.
void USART_ReceiverTimeOutCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the receiver Time Out feature.
__IO uint16_t GTPR
Definition: stm32f4xx.h:1724
void USART_DataInvCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the binary data inversion.
#define IS_USART_1234_PERIPH(PERIPH)
#define IS_USART_PARITY(PARITY)
#define USART_HardwareFlowControl_None
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s 8x oversampling mode.
#define USART_WordLength_8b
Definition: stm32f4xx.h:706
#define USART_CR2_STOP
Definition: stm32f4xx.h:10853
#define UART5
Definition: stm32f4xx.h:2059
uint32_t USART2CLK_Frequency
Definition: stm32f30x_rcc.h:65
uint32_t UART4CLK_Frequency
Definition: stm32f30x_rcc.h:67
void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint32_t USART_LINBreakDetectLength)
Sets the USART LIN Break detection length.
enum FlagStatus ITStatus
#define USART_CR3_HDSEL
Definition: stm32f4xx.h:10863
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
void USART_AddressDetectionConfig(USART_TypeDef *USARTx, uint32_t USART_AddressLength)
Configure the the USART Address detection length.
void USART_ITConfig(USART_TypeDef *USARTx, uint32_t USART_IT, FunctionalState NewState)
Enables or disables the specified USART interrupts.
#define USART1
Definition: stm32f4xx.h:2080
This file contains all the functions prototypes for the RCC firmware library.
void USART_OneBitMethodCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s one bit sampling method.
#define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH)
USART Clock Init Structure definition.
#define IS_USART_BAUDRATE(BAUDRATE)
#define __IO
Definition: core_cm0.h:198
void USART_SendData(USART_TypeDef *USARTx, uint16_t Data)
Transmits single data through the USARTx peripheral.
#define IS_USART_DMAREQ(DMAREQ)
void USART_MSBFirstCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s most significant bit first transmitted/received following the start b...
#define IS_USART_ALL_PERIPH(PERIPH)
void USART_STOPModeCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral in STOP Mode.
uint32_t USART1CLK_Frequency
Definition: stm32f30x_rcc.h:64
#define IS_USART_CPHA(CPHA)
void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler)
Sets the system clock prescaler.
void USART_SetAddress(USART_TypeDef *USARTx, uint8_t USART_Address)
Sets the address of the USART node.
#define USART_CPOL_Low
This file contains all the functions prototypes for the USART firmware library.
#define IS_USART_ADDRESS_DETECTION(ADDRESS)
void USART_StructInit(USART_InitTypeDef *USART_InitStruct)
Fills each USART_InitStruct member with its default value.
void USART_DirectionModeCmd(USART_TypeDef *USARTx, uint32_t USART_DirectionMode, FunctionalState NewState)
Enables or disables the USART&#39;s transmitter or receiver.
void USART_MuteModeWakeUpConfig(USART_TypeDef *USARTx, uint32_t USART_WakeUp)
Selects the USART WakeUp method from mute mode.
uint16_t USART_WordLength
#define IS_USART_OVRDETECTION(OVR)
__IO uint16_t CR2
Definition: stm32f4xx.h:1720
#define USART_CR2_LBDL
Definition: stm32f4xx.h:10846
#define USART_CR3_IREN
Definition: stm32f4xx.h:10861
#define IS_USART_AUTO_RETRY_COUNTER(COUNTER)
#define CR1_CLEAR_MASK
#define IS_USART_FLAG(FLAG)
#define USART_GTPR_PSC
Definition: stm32f4xx.h:10874
#define CR2_CLOCK_CLEAR_MASK
void USART_Init(USART_TypeDef *USARTx, USART_InitTypeDef *USART_InitStruct)
Initializes the USARTx peripheral according to the specified parameters in the USART_InitStruct ...
FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint32_t USART_FLAG)
Checks whether the specified USART flag is set or not.
#define IS_USART_TIMEOUT(TIMEOUT)
#define CR3_CLEAR_MASK
void USART_SetGuardTime(USART_TypeDef *USARTx, uint8_t USART_GuardTime)
Sets the specified USART guard time.
void USART_OverrunDetectionConfig(USART_TypeDef *USARTx, uint32_t USART_OVRDetection)
Enables or disables the USART&#39;s Overrun detection.
#define IS_USART_DE_ASSERTION_DEASSERTION_TIME(TIME)
void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Forces or releases High Speed APB (APB2) peripheral reset.
#define IS_USART_DE_POLARITY(POLARITY)
#define USART_CR1_WAKE
Definition: stm32f4xx.h:10839
void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral.
uint16_t USART_ReceiveData(USART_TypeDef *USARTx)
Returns the most recent received data by the USARTx peripheral.
#define IS_USART_REQUEST(REQUEST)
#define IS_USART_123_PERIPH(PERIPH)
#define USART3
Definition: stm32f4xx.h:2057
void USART_RequestCmd(USART_TypeDef *USARTx, uint32_t USART_Request, FunctionalState NewState)
Enables the specified USART&#39;s Request.
void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s IrDA interface.
#define IS_USART_STOPMODE_WAKEUPSOURCE(SOURCE)
uint32_t UART5CLK_Frequency
Definition: stm32f30x_rcc.h:68
void USART_SetDEAssertionTime(USART_TypeDef *USARTx, uint32_t USART_DEAssertionTime)
Sets the specified RS485 DE assertion time.
void USART_DEPolarityConfig(USART_TypeDef *USARTx, uint32_t USART_DEPolarity)
Configures the USART&#39;s DE polarity.
void USART_AutoBaudRateCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the Auto Baud Rate.
void USART_DMACmd(USART_TypeDef *USARTx, uint32_t USART_DMAReq, FunctionalState NewState)
Enables or disables the USART&#39;s DMA interface.
void USART_ClearFlag(USART_TypeDef *USARTx, uint32_t USART_FLAG)
Clears the USARTx&#39;s pending flags.
#define IS_USART_CONFIG_IT(IT)
void USART_IrDAConfig(USART_TypeDef *USARTx, uint32_t USART_IrDAMode)
Configures the USART&#39;s IrDA interface.
void USART_AutoBaudRateConfig(USART_TypeDef *USARTx, uint32_t USART_AutoBaudRate)
Selects the USART auto baud rate method.
#define USART_CPHA_1Edge
#define USART_CR2_LINEN
Definition: stm32f4xx.h:10857
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint32_t USART_IT)
Checks whether the specified USART interrupt has occurred or not.
#define USART_CR1_OVER8
Definition: stm32f4xx.h:10842
#define USART_CR3_SCEN
Definition: stm32f4xx.h:10865
#define USART_StopBits_1
void USART_SetBlockLength(USART_TypeDef *USARTx, uint8_t USART_BlockLength)
Sets the Smart Card Block length.
void USART_SmartCardCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s Smart Card mode.
#define IS_USART_GET_IT(IT)
#define IS_USART_DMAONERROR(DMAERROR)
#define IS_USART_IRDA_MODE(MODE)
#define USART_CR3_IRLP
Definition: stm32f4xx.h:10862
#define IS_USART_AUTOBAUDRATE_MODE(MODE)
void RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks)
Returns the frequencies of different on chip clocks; SYSCLK, HCLK, PCLK1 and PCLK2.
void USART_ClockInit(USART_TypeDef *USARTx, USART_ClockInitTypeDef *USART_ClockInitStruct)
Initializes the USARTx peripheral Clock according to the specified parameters in the USART_ClockInitS...
#define UART4
Definition: stm32f4xx.h:2058
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint32_t USART_IT)
Clears the USARTx&#39;s interrupt pending bits.
void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s LIN mode.
#define IS_USART_MUTEMODE_WAKEUP(WAKEUP)
__IO uint16_t CR3
Definition: stm32f4xx.h:1722
#define IS_USART_WORD_LENGTH(LENGTH)
USART Init Structure definition.
#define IS_USART_INVERSTION_PIN(PIN)
#define IS_USART_HARDWARE_FLOW_CONTROL(CONTROL)
void USART_ClockStructInit(USART_ClockInitTypeDef *USART_ClockInitStruct)
Fills each USART_ClockInitStruct member with its default value.
#define USART2
Definition: stm32f4xx.h:2056
void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART&#39;s Half Duplex communication.
__IO uint16_t CR1
Definition: stm32f4xx.h:1718
#define IS_USART_CLEAR_IT(IT)


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