108 #define CR1_CLEAR_MASK ((uint16_t)(USART_CR1_M | USART_CR1_PCE | \
109 USART_CR1_PS | USART_CR1_TE | \
113 #define CR2_CLOCK_CLEAR_MASK ((uint16_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \
114 USART_CR2_CPHA | USART_CR2_LBCL))
117 #define CR3_CLEAR_MASK ((uint16_t)(USART_CR3_RTSE | USART_CR3_CTSE))
120 #define IT_MASK ((uint16_t)0x001F)
190 assert_param(IS_USART_ALL_PERIPH(USARTx));
192 if (USARTx == USART1)
197 else if (USARTx == USART2)
202 else if (USARTx == USART3)
207 else if (USARTx == UART4)
212 else if (USARTx == UART5)
217 else if (USARTx == USART6)
222 else if (USARTx == UART7)
248 uint32_t tmpreg = 0x00, apbclock = 0x00;
249 uint32_t integerdivider = 0x00;
250 uint32_t fractionaldivider = 0x00;
254 assert_param(IS_USART_ALL_PERIPH(USARTx));
255 assert_param(IS_USART_BAUDRATE(USART_InitStruct->
USART_BaudRate));
257 assert_param(IS_USART_STOPBITS(USART_InitStruct->
USART_StopBits));
258 assert_param(IS_USART_PARITY(USART_InitStruct->
USART_Parity));
259 assert_param(IS_USART_MODE(USART_InitStruct->
USART_Mode));
265 assert_param(IS_USART_1236_PERIPH(USARTx));
269 tmpreg = USARTx->CR2;
272 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
279 USARTx->CR2 = (uint16_t)tmpreg;
282 tmpreg = USARTx->CR1;
295 USARTx->CR1 = (uint16_t)tmpreg;
298 tmpreg = USARTx->CR3;
308 USARTx->CR3 = (uint16_t)tmpreg;
314 if ((USARTx == USART1) || (USARTx == USART6))
324 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
327 integerdivider = ((25 * apbclock) / (2 * (USART_InitStruct->
USART_BaudRate)));
332 integerdivider = ((25 * apbclock) / (4 * (USART_InitStruct->
USART_BaudRate)));
334 tmpreg = (integerdivider / 100) << 4;
337 fractionaldivider = integerdivider - (100 * (tmpreg >> 4));
340 if ((USARTx->CR1 & USART_CR1_OVER8) != 0)
342 tmpreg |= ((((fractionaldivider * 8) + 50) / 100)) & ((uint8_t)0x07);
346 tmpreg |= ((((fractionaldivider * 16) + 50) / 100)) & ((uint8_t)0x0F);
350 USARTx->BRR = (uint16_t)tmpreg;
366 USART_InitStruct->
USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
381 uint32_t tmpreg = 0x00;
383 assert_param(IS_USART_1236_PERIPH(USARTx));
384 assert_param(IS_USART_CLOCK(USART_ClockInitStruct->
USART_Clock));
385 assert_param(IS_USART_CPOL(USART_ClockInitStruct->
USART_CPOL));
386 assert_param(IS_USART_CPHA(USART_ClockInitStruct->
USART_CPHA));
387 assert_param(IS_USART_LASTBIT(USART_ClockInitStruct->
USART_LastBit));
390 tmpreg = USARTx->CR2;
401 USARTx->CR2 = (uint16_t)tmpreg;
413 USART_ClockInitStruct->
USART_Clock = USART_Clock_Disable;
414 USART_ClockInitStruct->
USART_CPOL = USART_CPOL_Low;
415 USART_ClockInitStruct->
USART_CPHA = USART_CPHA_1Edge;
416 USART_ClockInitStruct->
USART_LastBit = USART_LastBit_Disable;
427 void USART_Cmd(USART_TypeDef* USARTx, FunctionalState NewState)
430 assert_param(IS_USART_ALL_PERIPH(USARTx));
431 assert_param(IS_FUNCTIONAL_STATE(NewState));
433 if (NewState != DISABLE)
436 USARTx->CR1 |= USART_CR1_UE;
441 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_UE);
456 assert_param(IS_USART_ALL_PERIPH(USARTx));
459 USARTx->GTPR &= USART_GTPR_GT;
461 USARTx->GTPR |= USART_Prescaler;
477 assert_param(IS_USART_ALL_PERIPH(USARTx));
478 assert_param(IS_FUNCTIONAL_STATE(NewState));
480 if (NewState != DISABLE)
483 USARTx->CR1 |= USART_CR1_OVER8;
488 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_OVER8);
503 assert_param(IS_USART_ALL_PERIPH(USARTx));
504 assert_param(IS_FUNCTIONAL_STATE(NewState));
506 if (NewState != DISABLE)
509 USARTx->CR3 |= USART_CR3_ONEBIT;
514 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT);
560 assert_param(IS_USART_ALL_PERIPH(USARTx));
561 assert_param(IS_USART_DATA(Data));
564 USARTx->DR = (Data & (uint16_t)0x01FF);
576 assert_param(IS_USART_ALL_PERIPH(USARTx));
579 return (uint16_t)(USARTx->DR & (uint16_t)0x01FF);
628 assert_param(IS_USART_ALL_PERIPH(USARTx));
629 assert_param(IS_USART_ADDRESS(USART_Address));
632 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_ADD);
634 USARTx->CR2 |= USART_Address;
648 assert_param(IS_USART_ALL_PERIPH(USARTx));
649 assert_param(IS_FUNCTIONAL_STATE(NewState));
651 if (NewState != DISABLE)
654 USARTx->CR1 |= USART_CR1_RWU;
659 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_RWU);
675 assert_param(IS_USART_ALL_PERIPH(USARTx));
676 assert_param(IS_USART_WAKEUP(USART_WakeUp));
678 USARTx->CR1 &= (uint16_t)~((uint16_t)USART_CR1_WAKE);
679 USARTx->CR1 |= USART_WakeUp;
744 assert_param(IS_USART_ALL_PERIPH(USARTx));
745 assert_param(IS_USART_LIN_BREAK_DETECT_LENGTH(USART_LINBreakDetectLength));
747 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LBDL);
748 USARTx->CR2 |= USART_LINBreakDetectLength;
762 assert_param(IS_USART_ALL_PERIPH(USARTx));
763 assert_param(IS_FUNCTIONAL_STATE(NewState));
765 if (NewState != DISABLE)
768 USARTx->CR2 |= USART_CR2_LINEN;
773 USARTx->CR2 &= (uint16_t)~((uint16_t)USART_CR2_LINEN);
786 assert_param(IS_USART_ALL_PERIPH(USARTx));
789 USARTx->CR1 |= USART_CR1_SBK;
839 assert_param(IS_USART_ALL_PERIPH(USARTx));
840 assert_param(IS_FUNCTIONAL_STATE(NewState));
842 if (NewState != DISABLE)
845 USARTx->CR3 |= USART_CR3_HDSEL;
850 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_HDSEL);
923 assert_param(IS_USART_1236_PERIPH(USARTx));
926 USARTx->GTPR &= USART_GTPR_PSC;
928 USARTx->GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
942 assert_param(IS_USART_1236_PERIPH(USARTx));
943 assert_param(IS_FUNCTIONAL_STATE(NewState));
944 if (NewState != DISABLE)
947 USARTx->CR3 |= USART_CR3_SCEN;
952 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_SCEN);
967 assert_param(IS_USART_1236_PERIPH(USARTx));
968 assert_param(IS_FUNCTIONAL_STATE(NewState));
969 if (NewState != DISABLE)
972 USARTx->CR3 |= USART_CR3_NACK;
977 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_NACK);
1038 assert_param(IS_USART_ALL_PERIPH(USARTx));
1039 assert_param(IS_USART_IRDA_MODE(USART_IrDAMode));
1041 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_IRLP);
1042 USARTx->CR3 |= USART_IrDAMode;
1056 assert_param(IS_USART_ALL_PERIPH(USARTx));
1057 assert_param(IS_FUNCTIONAL_STATE(NewState));
1059 if (NewState != DISABLE)
1062 USARTx->CR3 |= USART_CR3_IREN;
1067 USARTx->CR3 &= (uint16_t)~((uint16_t)USART_CR3_IREN);
1099 void USART_DMACmd(USART_TypeDef* USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
1102 assert_param(IS_USART_ALL_PERIPH(USARTx));
1103 assert_param(IS_USART_DMAREQ(USART_DMAReq));
1104 assert_param(IS_FUNCTIONAL_STATE(NewState));
1106 if (NewState != DISABLE)
1110 USARTx->CR3 |= USART_DMAReq;
1116 USARTx->CR3 &= (uint16_t)~USART_DMAReq;
1231 void USART_ITConfig(USART_TypeDef* USARTx, uint16_t USART_IT, FunctionalState NewState)
1233 uint32_t usartreg = 0x00, itpos = 0x00, itmask = 0x00;
1234 uint32_t usartxbase = 0x00;
1236 assert_param(IS_USART_ALL_PERIPH(USARTx));
1237 assert_param(IS_USART_CONFIG_IT(USART_IT));
1238 assert_param(IS_FUNCTIONAL_STATE(NewState));
1241 if (USART_IT == USART_IT_CTS)
1243 assert_param(IS_USART_1236_PERIPH(USARTx));
1246 usartxbase = (uint32_t)USARTx;
1249 usartreg = (((uint8_t)USART_IT) >> 0x05);
1252 itpos = USART_IT & IT_MASK;
1253 itmask = (((uint32_t)0x01) << itpos);
1255 if (usartreg == 0x01)
1259 else if (usartreg == 0x02)
1267 if (NewState != DISABLE)
1269 *(__IO uint32_t*)usartxbase |= itmask;
1273 *(__IO uint32_t*)usartxbase &= ~itmask;
1297 FlagStatus bitstatus = RESET;
1299 assert_param(IS_USART_ALL_PERIPH(USARTx));
1300 assert_param(IS_USART_FLAG(USART_FLAG));
1303 if (USART_FLAG == USART_FLAG_CTS)
1305 assert_param(IS_USART_1236_PERIPH(USARTx));
1308 if ((USARTx->SR & USART_FLAG) != (uint16_t)RESET)
1347 assert_param(IS_USART_ALL_PERIPH(USARTx));
1348 assert_param(IS_USART_CLEAR_FLAG(USART_FLAG));
1351 if ((USART_FLAG & USART_FLAG_CTS) == USART_FLAG_CTS)
1353 assert_param(IS_USART_1236_PERIPH(USARTx));
1356 USARTx->SR = (uint16_t)~USART_FLAG;
1380 uint32_t bitpos = 0x00, itmask = 0x00, usartreg = 0x00;
1381 ITStatus bitstatus = RESET;
1383 assert_param(IS_USART_ALL_PERIPH(USARTx));
1384 assert_param(IS_USART_GET_IT(USART_IT));
1387 if (USART_IT == USART_IT_CTS)
1389 assert_param(IS_USART_1236_PERIPH(USARTx));
1393 usartreg = (((uint8_t)USART_IT) >> 0x05);
1395 itmask = USART_IT & IT_MASK;
1396 itmask = (uint32_t)0x01 << itmask;
1398 if (usartreg == 0x01)
1400 itmask &= USARTx->CR1;
1402 else if (usartreg == 0x02)
1404 itmask &= USARTx->CR2;
1408 itmask &= USARTx->CR3;
1411 bitpos = USART_IT >> 0x08;
1412 bitpos = (uint32_t)0x01 << bitpos;
1413 bitpos &= USARTx->SR;
1414 if ((itmask != (uint16_t)RESET)&&(bitpos != (uint16_t)RESET))
1454 uint16_t bitpos = 0x00, itmask = 0x00;
1456 assert_param(IS_USART_ALL_PERIPH(USARTx));
1457 assert_param(IS_USART_CLEAR_IT(USART_IT));
1460 if (USART_IT == USART_IT_CTS)
1462 assert_param(IS_USART_1236_PERIPH(USARTx));
1465 bitpos = USART_IT >> 0x08;
1466 itmask = ((uint16_t)0x01 << (uint16_t)bitpos);
1467 USARTx->SR = (uint16_t)~itmask;
This file contains all the functions prototypes for the RCC firmware library.
void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's IrDA interface.
USART Clock Init Structure definition.
void USART_ITConfig(USART_TypeDef *USARTx, uint16_t USART_IT, FunctionalState NewState)
Enables or disables the specified USART interrupts.
void USART_SetPrescaler(USART_TypeDef *USARTx, uint8_t USART_Prescaler)
Sets the system clock prescaler.
void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Half Duplex communication.
void USART_Init(USART_TypeDef *USARTx, USART_InitTypeDef *USART_InitStruct)
Initializes the USARTx peripheral according to the specified parameters in the USART_InitStruct ...
void USART_ReceiverWakeUpCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Determines if the USART is in mute mode or not.
void USART_ClockStructInit(USART_ClockInitTypeDef *USART_ClockInitStruct)
Fills each USART_ClockInitStruct member with its default value.
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint16_t USART_IT)
Clears the USARTx's interrupt pending bits.
void USART_SmartCardNACKCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables NACK transmission.
uint16_t USART_WordLength
void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint16_t USART_LINBreakDetectLength)
Sets the USART LIN Break detection length.
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint16_t USART_IT)
Checks whether the specified USART interrupt has occurred or not.
void USART_ClockInit(USART_TypeDef *USARTx, USART_ClockInitTypeDef *USART_ClockInitStruct)
Initializes the USARTx peripheral Clock according to the specified parameters in the USART_ClockInitS...
void USART_Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the specified USART peripheral.
uint16_t USART_HardwareFlowControl
void USART_ClearFlag(USART_TypeDef *USARTx, uint16_t USART_FLAG)
Clears the USARTx's pending flags.
uint16_t USART_ReceiveData(USART_TypeDef *USARTx)
Returns the most recent received data by the USARTx peripheral.
FlagStatus USART_GetFlagStatus(USART_TypeDef *USARTx, uint16_t USART_FLAG)
Checks whether the specified USART flag is set or not.
void USART_DeInit(USART_TypeDef *USARTx)
Deinitializes the USARTx peripheral registers to their default reset values.
void USART_WakeUpConfig(USART_TypeDef *USARTx, uint16_t USART_WakeUp)
Selects the USART WakeUp method.
void USART_SendData(USART_TypeDef *USARTx, uint16_t Data)
Transmits single data through the USARTx peripheral.
This file contains all the functions prototypes for the USART firmware library.
void USART_SetGuardTime(USART_TypeDef *USARTx, uint8_t USART_GuardTime)
Sets the specified USART guard time.
void USART_SendBreak(USART_TypeDef *USARTx)
Transmits break characters.
void USART_StructInit(USART_InitTypeDef *USART_InitStruct)
Fills each USART_InitStruct member with its default value.
void USART_SmartCardCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Smart Card mode.
void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's LIN mode.
USART Init Structure definition.
void USART_IrDAConfig(USART_TypeDef *USARTx, uint16_t USART_IrDAMode)
Configures the USART's IrDA interface.
void USART_OneBitMethodCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's one bit sampling method.
void RCC_APB1PeriphResetCmd(uint32_t RCC_APB1Periph, FunctionalState NewState)
Forces or releases Low Speed APB (APB1) peripheral reset.
void USART_SetAddress(USART_TypeDef *USARTx, uint8_t USART_Address)
Sets the address of the USART node.
void USART_DMACmd(USART_TypeDef *USARTx, uint16_t USART_DMAReq, FunctionalState NewState)
Enables or disables the USART's DMA interface.
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's 8x oversampling mode.
#define CR2_CLOCK_CLEAR_MASK
void RCC_GetClocksFreq(RCC_ClocksTypeDef *RCC_Clocks)
Returns the frequencies of different on chip clocks; SYSCLK, HCLK, PCLK1 and PCLK2.
void RCC_APB2PeriphResetCmd(uint32_t RCC_APB2Periph, FunctionalState NewState)
Forces or releases High Speed APB (APB2) peripheral reset.