33#if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
64 #ifdef __STM32F030x6_H
65 return (uint8_t)(READ_BIT(
Wrapper->USART->RDR, USART_RDR_RDR));
68 return (uint8_t)(READ_BIT(
Wrapper->USART->DR, USART_DR_DR));
90 uint16_t RX_BufferSize,
91 void (*RX_Handler)(uint8_t)
101 uint32_t USART_Address = (uint32_t)USART;
103 switch(USART_Address)
105 case ( (uint32_t)USART1 ):
109 #if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
110 case ( (uint32_t)USART2 ):
115 #ifdef __STM32F103xB_H
116 case ( (uint32_t)USART3 ):
121 #ifdef __STM32F401xC_H
122 case ( (uint32_t)USART6 ):
134 (*Wrapper)->USART = USART;
137 (*Wrapper)->RX_New = 0;
139 (*Wrapper)->RX_BufferSize = RX_BufferSize;
140 (*Wrapper)->RX_Buffer = (uint8_t*)malloc( ((*Wrapper)->RX_BufferSize) *
sizeof(uint8_t));
141 for( uint16_t _rxb_init = 0 ; _rxb_init < (*Wrapper)->RX_BufferSize ; _rxb_init++ )
143 ((*Wrapper)->RX_Buffer)[_rxb_init] =
'\0';
145 (*Wrapper)->RX_Handler = RX_Handler;
147 CLEAR_BIT((*Wrapper)->USART->CR1, USART_CR1_RE);
150 #ifdef __STM32F030x6_H
151 CLEAR_BIT((*Wrapper)->USART->ISR, USART_ISR_RXNE);
154 CLEAR_BIT((*Wrapper)->USART->SR, USART_SR_RXNE);
167 CLEAR_BIT(
Wrapper->USART->CR1, USART_CR1_RE);
170 #ifdef __STM32F030x6_H
171 CLEAR_BIT(
Wrapper->USART->ISR, USART_ISR_RXNE);
174 CLEAR_BIT(
Wrapper->USART->SR, USART_SR_RXNE);
189 SET_BIT(
Wrapper->USART->CR1, USART_CR1_RXNEIE);
190 SET_BIT(
Wrapper->USART->CR1, USART_CR1_RE);
197 CLEAR_BIT(
Wrapper->USART->CR1, USART_CR1_RXNEIE);
198 CLEAR_BIT(
Wrapper->USART->CR1, USART_CR1_RE);
206 #ifdef __STM32F030x6_H
207 return (READ_BIT(
Wrapper->USART->ISR, USART_ISR_RXNE) == (USART_ISR_RXNE));
210 return (READ_BIT(
Wrapper->USART->SR, USART_SR_RXNE) == (USART_SR_RXNE));
220 #ifdef __STM32F030x6_H
221 return (READ_BIT(
Wrapper->USART->ISR, USART_ISR_TXE) == (USART_ISR_TXE));
224 return (READ_BIT(
Wrapper->USART->SR, USART_SR_TXE) == (USART_SR_TXE));
265 #ifdef __STM32F030x6_H
281 volatile uint32_t _ctr = 0;
284 if( String[_ctr] ==
'\0' )
328 if(
Wrapper->RX_Handler != NULL)
356#if ( (defined __STM32F103xB_H) || (defined __STM32F401xC_H) )
369#ifdef __STM32F103xB_H
382#ifdef __STM32F401xC_H
static HIERODULE_USART_Wrapper * USART1_Wrapper
USART wrapper pointer meant for USART1.
void USART_IRQHandler(HIERODULE_USART_Wrapper *Wrapper)
The base IRQ body to be used for all USART IRQs.
static HIERODULE_USART_Wrapper * USART6_Wrapper
USART wrapper pointer meant for USART6. Requires the device specific macro __STM32F401xC_H to be defi...
static HIERODULE_USART_Wrapper * USART3_Wrapper
USART wrapper pointer meant for USART3. Requires the device specific macro __STM32F103xB_H to be defi...
static HIERODULE_USART_Wrapper * USART2_Wrapper
USART wrapper pointer meant for USART2. Requires the device specific macro __STM32F103xB_H or __STM32...
uint8_t ReceiveByte(HIERODULE_USART_Wrapper *Wrapper)
Reads and returns a single byte received by the USART peripheral.
void USART2_IRQHandler(void)
USART2 IRQ implementation. Requires the device specific macro __STM32F103xB_H or __STM32F401xC_H to b...
void USART3_IRQHandler(void)
USART3 IRQ implementation. Requires the device specific macro __STM32F103xB_H to be defined.
void USART6_IRQHandler(void)
USART6 IRQ implementation. Requires the device specific macro __STM32F401xC_H to be defined.
uint32_t HIERODULE_USART_IsActiveFlag_TXE(HIERODULE_USART_Wrapper *Wrapper)
Checks the TX is empty interrupt flag of the USART peripheral.
uint32_t HIERODULE_USART_IsActiveFlag_RXNE(HIERODULE_USART_Wrapper *Wrapper)
Checks the RX not empty interrupt flag of the USART peripheral.
void HIERODULE_USART_TransmitByte(HIERODULE_USART_Wrapper *Wrapper, uint8_t Byte)
Transmits a single byte.
void USART1_IRQHandler(void)
USART1 IRQ implementation.
void HIERODULE_USART_ReleaseWrapper(HIERODULE_USART_Wrapper *Wrapper)
Frees the memory allocated to a USART wrapper and clears USART status flags and control bits.
uint8_t HIERODULE_USART_GetNextByte(HIERODULE_USART_Wrapper *Wrapper)
Fetches the next byte in the ring buffer.
void HIERODULE_USART_TransmitString(HIERODULE_USART_Wrapper *Wrapper, char *String)
Transmits a string.
void HIERODULE_USART_Disable_IT_RXNE(HIERODULE_USART_Wrapper *Wrapper)
Disables the RX not empty interrupt of the USART peripheral , also disables the RE bit of the control...
void HIERODULE_USART_Enable_IT_RXNE(HIERODULE_USART_Wrapper *Wrapper)
Enables the RX not empty interrupt of the USART peripheral , also enables the RE bit of the control r...
HIERODULE_USART_Wrapper ** HIERODULE_USART_InitWrapper(USART_TypeDef *USART, uint16_t RX_BufferSize, void(*RX_Handler)(uint8_t))
Initializes a wrapper for the specified USART peripheral.
HIERODULE_USB_Wrapper Wrapper
Extern declaration for the wrapper instance in the source file.
: Header file for the USART module.
Struct that keeps variables for the ring buffer, a pointer to the USART peripheral and a pointer to t...
uint8_t * RX_Buffer
The ring buffer where the data received is appended.
uint32_t RX_New
Number of new bytes in the ring buffer.
uint16_t RX_BufferSize
Number of elements in the ring buffer.
uint32_t RX_Index
Index of next-byte-to-be-received in the ring buffer.