97 #define CR1_CLEAR_MASK ((uint32_t)(USART_CR1_M | USART_CR1_PCE | \ 98 USART_CR1_PS | USART_CR1_TE | \ 102 #define CR2_CLOCK_CLEAR_MASK ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | \ 103 USART_CR2_CPHA | USART_CR2_LBCL)) 106 #define CR3_CLEAR_MASK ((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE)) 109 #define IT_MASK ((uint32_t)0x000000FF) 183 else if (USARTx ==
USART2)
188 else if (USARTx ==
USART3)
193 else if (USARTx ==
UART4)
219 uint32_t divider = 0, apbclock = 0, tmpreg = 0;
235 tmpreg = USARTx->
CR2;
244 USARTx->
CR2 = tmpreg;
247 tmpreg = USARTx->
CR1;
259 USARTx->
CR1 = tmpreg;
262 tmpreg = USARTx->
CR3;
271 USARTx->
CR3 = tmpreg;
281 else if (USARTx ==
USART2)
285 else if (USARTx ==
USART3)
289 else if (USARTx ==
UART4)
302 divider = (uint32_t)((2 * apbclock) / (USART_InitStruct->
USART_BaudRate));
303 tmpreg = (uint32_t)((2 * apbclock) % (USART_InitStruct->
USART_BaudRate));
308 divider = (uint32_t)((apbclock) / (USART_InitStruct->
USART_BaudRate));
309 tmpreg = (uint32_t)((apbclock) % (USART_InitStruct->
USART_BaudRate));
322 tmpreg = (divider & (uint16_t)0x000F) >> 1;
325 divider = (divider & (uint16_t)0xFFF0) | tmpreg;
329 USARTx->
BRR = (uint16_t)divider;
369 tmpreg = USARTx->
CR2;
380 USARTx->
CR2 = tmpreg;
447 USARTx->
CR1 |= USART_DirectionMode;
453 USARTx->
CR1 &= (uint32_t)~USART_DirectionMode;
536 USARTx->
CR2 |= USART_CR2_MSBFIRST;
542 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_MSBFIRST);
570 USARTx->
CR2 |= USART_CR2_DATAINV;
576 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_DATAINV);
607 USARTx->
CR2 |= USART_InvPin;
613 USARTx->
CR2 &= (uint32_t)~USART_InvPin;
638 USARTx->
CR2 |= USART_CR2_SWAP;
643 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_SWAP);
665 USARTx->
CR2 |= USART_CR2_RTOEN;
671 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_RTOEN);
690 USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_RTO);
693 USARTx->RTOR |= USART_ReceiverTimeOut;
713 USARTx->
GTPR |= USART_Prescaler;
764 USARTx->
CR1 |= USART_CR1_UESM;
770 USARTx->
CR1 &= (uint32_t)~((uint32_t)USART_CR1_UESM);
793 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_WUS);
794 USARTx->
CR3 |= USART_WakeUpSource;
848 USARTx->
CR2 |= USART_CR2_ABREN;
854 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABREN);
878 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_ABRMODE);
879 USARTx->
CR2 |= USART_AutoBaudRate;
922 USARTx->TDR = (Data & (uint16_t)0x01FF);
937 return (uint16_t)(USARTx->RDR & (uint16_t)0x01FF);
989 USARTx->
CR2 |=((uint32_t)USART_Address << (uint32_t)0x18);
1009 USARTx->
CR1 |= USART_CR1_MME;
1014 USARTx->
CR1 &= (uint32_t)~((uint32_t)USART_CR1_MME);
1035 USARTx->
CR1 |= USART_WakeUp;
1054 USARTx->
CR2 &= (uint32_t)~((uint32_t)USART_CR2_ADDM7);
1055 USARTx->
CR2 |= USART_AddressLength;
1120 USARTx->
CR2 |= USART_LINBreakDetectLength;
1278 USARTx->
GTPR |= (uint16_t)((uint16_t)USART_GuardTime << 0x08);
1344 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_SCARCNT);
1346 USARTx->
CR3 |= (uint32_t)((uint32_t)USART_AutoCount << 0x11);
1362 USARTx->RTOR &= (uint32_t)~((uint32_t)USART_RTOR_BLEN);
1364 USARTx->RTOR |= (uint32_t)((uint32_t)USART_BlockLength << 0x18);
1426 USARTx->
CR3 |= USART_IrDAMode;
1503 USARTx->
CR3 |= USART_CR3_DEM;
1508 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEM);
1528 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_DEP);
1529 USARTx->
CR3 |= USART_DEPolarity;
1547 USARTx->
CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEAT);
1549 USARTx->
CR1 |=((uint32_t)USART_DEAssertionTime << (uint32_t)0x15);
1567 USARTx->
CR1 &= (uint32_t)~((uint32_t)USART_CR1_DEDT);
1569 USARTx->
CR1 |=((uint32_t)USART_DEDeassertionTime << (uint32_t)0x10);
1618 USARTx->
CR3 |= USART_DMAReq;
1624 USARTx->
CR3 &= (uint32_t)~USART_DMAReq;
1647 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_DDRE);
1649 USARTx->
CR3 |= USART_DMAOnError;
1775 uint32_t usartreg = 0, itpos = 0, itmask = 0;
1776 uint32_t usartxbase = 0;
1782 usartxbase = (uint32_t)USARTx;
1785 usartreg = (((uint16_t)USART_IT) >> 0x08);
1789 itmask = (((uint32_t)0x01) << itpos);
1791 if (usartreg == 0x02)
1795 else if (usartreg == 0x03)
1804 *(
__IO uint32_t*)usartxbase |= itmask;
1808 *(
__IO uint32_t*)usartxbase &= ~itmask;
1838 USARTx->RQR |= USART_Request;
1844 USARTx->RQR &= (uint32_t)~USART_Request;
1867 USARTx->
CR3 &= (uint32_t)~((uint32_t)USART_CR3_OVRDIS);
1869 USARTx->
CR3 |= USART_OVRDetection;
1909 if ((USARTx->ISR & USART_FLAG) != (uint16_t)
RESET)
1959 USARTx->ICR = USART_FLAG;
1986 uint32_t bitpos = 0, itmask = 0, usartreg = 0;
1993 usartreg = (((uint16_t)USART_IT) >> 0x08);
1996 itmask = (uint32_t)0x01 << itmask;
1998 if (usartreg == 0x01)
2000 itmask &= USARTx->
CR1;
2002 else if (usartreg == 0x02)
2004 itmask &= USARTx->
CR2;
2008 itmask &= USARTx->
CR3;
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))
2058 uint32_t bitpos = 0, itmask = 0;
2063 bitpos = USART_IT >> 0x10;
2064 itmask = ((uint32_t)0x01 << (uint32_t)bitpos);
2065 USARTx->ICR = (uint32_t)itmask;
#define USART_LastBit_Disable
#define USART_Clock_Disable
#define IS_USART_DATA(DATA)
uint32_t USART3CLK_Frequency
#define IS_USART_CLOCK(CLOCK)
uint16_t USART_HardwareFlowControl
Universal Synchronous Asynchronous Receiver Transmitter.
void USART_SetAutoRetryCount(USART_TypeDef *USARTx, uint8_t USART_AutoCount)
Sets the Smart Card number of retries in transmit and receive.
#define RCC_APB2Periph_USART1
#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)
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)
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's mute mode.
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.
void assert_param(int val)
#define IS_USART_LASTBIT(LASTBIT)
void USART_DECmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's DE functionality.
#define IS_FUNCTIONAL_STATE(STATE)
void USART_DMAReceptionErrorConfig(USART_TypeDef *USARTx, uint32_t USART_DMAOnError)
Enables or disables the USART'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.
void USART_DataInvCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the binary data inversion.
#define IS_USART_1234_PERIPH(PERIPH)
#define RCC_APB1Periph_USART3
#define IS_USART_PARITY(PARITY)
#define USART_HardwareFlowControl_None
void USART_OverSampling8Cmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's 8x oversampling mode.
#define USART_WordLength_8b
uint32_t USART2CLK_Frequency
uint32_t UART4CLK_Frequency
void USART_LINBreakDetectLengthConfig(USART_TypeDef *USARTx, uint32_t USART_LINBreakDetectLength)
Sets the USART LIN Break detection length.
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.
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's one bit sampling method.
#define IS_USART_LIN_BREAK_DETECT_LENGTH(LENGTH)
USART Clock Init Structure definition.
#define IS_USART_BAUDRATE(BAUDRATE)
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'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
#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.
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'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)
#define IS_USART_AUTO_RETRY_COUNTER(COUNTER)
#define IS_USART_FLAG(FLAG)
#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)
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'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)
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 RCC_APB1Periph_UART4
#define IS_USART_REQUEST(REQUEST)
#define IS_USART_123_PERIPH(PERIPH)
void USART_RequestCmd(USART_TypeDef *USARTx, uint32_t USART_Request, FunctionalState NewState)
Enables the specified USART's Request.
void USART_IrDACmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's IrDA interface.
#define RCC_APB1Periph_UART5
#define IS_USART_STOPMODE_WAKEUPSOURCE(SOURCE)
uint32_t UART5CLK_Frequency
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'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's DMA interface.
void USART_ClearFlag(USART_TypeDef *USARTx, uint32_t USART_FLAG)
Clears the USARTx's pending flags.
#define IS_USART_CONFIG_IT(IT)
void USART_IrDAConfig(USART_TypeDef *USARTx, uint32_t USART_IrDAMode)
Configures the USART's IrDA interface.
void USART_AutoBaudRateConfig(USART_TypeDef *USARTx, uint32_t USART_AutoBaudRate)
Selects the USART auto baud rate method.
ITStatus USART_GetITStatus(USART_TypeDef *USARTx, uint32_t USART_IT)
Checks whether the specified USART interrupt has occurred or not.
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's Smart Card mode.
#define IS_USART_GET_IT(IT)
#define IS_USART_DMAONERROR(DMAERROR)
#define IS_USART_IRDA_MODE(MODE)
#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...
void USART_ClearITPendingBit(USART_TypeDef *USARTx, uint32_t USART_IT)
Clears the USARTx's interrupt pending bits.
void USART_LINCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's LIN mode.
#define IS_USART_MUTEMODE_WAKEUP(WAKEUP)
#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.
void USART_HalfDuplexCmd(USART_TypeDef *USARTx, FunctionalState NewState)
Enables or disables the USART's Half Duplex communication.
#define RCC_APB1Periph_USART2
#define IS_USART_CLEAR_IT(IT)