gr55xx_hal_uart.h
Go to the documentation of this file.
1 
51 /* Define to prevent recursive inclusion -------------------------------------*/
52 #ifndef __GR55xx_HAL_UART_H__
53 #define __GR55xx_HAL_UART_H__
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /* Includes ------------------------------------------------------------------*/
60 #include "gr55xx_ll_uart.h"
61 #include "gr55xx_hal_def.h"
62 
63 /* Exported types ------------------------------------------------------------*/
76 typedef enum
77 {
78  HAL_UART_STATE_RESET = 0x00U,
81  HAL_UART_STATE_READY = 0x10U,
84  HAL_UART_STATE_BUSY = 0x14U,
87  HAL_UART_STATE_BUSY_TX = 0x11U,
90  HAL_UART_STATE_BUSY_RX = 0x12U,
93  HAL_UART_STATE_BUSY_TXRX = 0x13U,
96  HAL_UART_STATE_TIMEOUT = 0x30U,
99  HAL_UART_STATE_ERROR = 0x70U
103 
119 typedef struct _uart_init
120 {
121  uint32_t baud_rate;
123  uint32_t data_bits;
126  uint32_t stop_bits;
129  uint32_t parity;
132  uint32_t hw_flow_ctrl;
135  uint32_t rx_timeout_mode;
152 typedef struct _uart_handle
153 {
154  uart_regs_t *p_instance;
158  uint8_t *p_tx_buffer;
160  uint16_t tx_xfer_size;
162  __IO uint16_t tx_xfer_count;
164  uint8_t *p_rx_buffer;
166  uint16_t rx_xfer_size;
168  __IO uint16_t rx_xfer_count;
174  functional_state_t dma_tx_mode;
176  functional_state_t dma_rx_mode;
186  __IO uint32_t error_code;
188  uint32_t retention[8];
206 typedef struct _hal_uart_callback
207 {
208  void (*uart_msp_init)(uart_handle_t *p_uart);
209  void (*uart_msp_deinit)(uart_handle_t *p_uart);
217 
227 /* Exported constants --------------------------------------------------------*/
235 #define HAL_UART_ERROR_NONE (0x00000000U)
236 #define HAL_UART_ERROR_PE LL_UART_LSR_PE
237 #define HAL_UART_ERROR_FE LL_UART_LSR_FE
238 #define HAL_UART_ERROR_OE LL_UART_LSR_OE
239 #define HAL_UART_ERROR_BI LL_UART_LSR_BI
240 #define HAL_UART_ERROR_DMA (0x00000100U)
241 #define HAL_UART_ERROR_BUSY (0x00000200U)
247 #define UART_DATABITS_5 LL_UART_DATABITS_5B
248 #define UART_DATABITS_6 LL_UART_DATABITS_6B
249 #define UART_DATABITS_7 LL_UART_DATABITS_7B
250 #define UART_DATABITS_8 LL_UART_DATABITS_8B
256 #define UART_STOPBITS_1 LL_UART_STOPBITS_1
257 #define UART_STOPBITS_1_5 LL_UART_STOPBITS_1_5
258 #define UART_STOPBITS_2 LL_UART_STOPBITS_2
264 #define UART_PARITY_NONE LL_UART_PARITY_NONE
265 #define UART_PARITY_ODD LL_UART_PARITY_ODD
266 #define UART_PARITY_EVEN LL_UART_PARITY_EVEN
267 #define UART_PARITY_SP0 LL_UART_PARITY_SP0
268 #define UART_PARITY_SP1 LL_UART_PARITY_SP1
274 #define UART_HWCONTROL_NONE LL_UART_HWCONTROL_NONE
275 #define UART_HWCONTROL_RTS_CTS LL_UART_HWCONTROL_RTS_CTS
281 #define UART_RECEIVER_TIMEOUT_DISABLE (0x00000000U)
282 #define UART_RECEIVER_TIMEOUT_ENABLE (0x00000001U)
288 #define UART_IT_MS LL_UART_IER_MS
289 #define UART_IT_RLS LL_UART_IER_RLS
290 #define UART_IT_THRE LL_UART_IER_THRE
291 #define UART_IT_RDA LL_UART_IER_RDA
297 #define UART_RXDATA_FLUSH_REQUEST UART_SRR_RFR
298 #define UART_TXDATA_FLUSH_REQUEST UART_SRR_XFR
299 #define UART_TXRXDATA_FLUSH_REQUEST (UART_SRR_XFR | UART_SRR_RFR)
305 #define UART_IT_MASK (0x008FU)
311 #define UART_LINE_ERROR_MASK (LL_UART_LSR_PE | LL_UART_LSR_OE | LL_UART_LSR_FE | LL_UART_LSR_BI)
317 #define UART_RETENTION_LENGTH ((uint32_t)8)
323 #define HAL_UART_TIMEOUT_DEFAULT_VALUE ((uint32_t)5000)
328 /* Exported macro ------------------------------------------------------------*/
329 
337 #define __HAL_UART_RESET_HANDLE_STATE(__HANDLE__) \
338  do{ \
339  (__HANDLE__)->g_state = HAL_UART_STATE_RESET; \
340  (__HANDLE__)->rx_state = HAL_UART_STATE_RESET; \
341  } while(0U)
342 
353 #define __HAL_UART_ENABLE_IT(__HANDLE__, __INTERRUPT__) \
354  do { \
355  GLOBAL_EXCEPTION_DISABLE(); \
356  ll_uart_enable_it((__HANDLE__)->p_instance, (__INTERRUPT__)); \
357  GLOBAL_EXCEPTION_ENABLE(); \
358  } while(0U)
359 
370 #define __HAL_UART_DISABLE_IT(__HANDLE__, __INTERRUPT__) \
371  do { \
372  GLOBAL_EXCEPTION_DISABLE(); \
373  ll_uart_disable_it((__HANDLE__)->p_instance, (__INTERRUPT__)); \
374  GLOBAL_EXCEPTION_ENABLE(); \
375  } while(0)
376 
386 #define __HAL_UART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->p_instance->SRR = (__REQ__))
387 
390 /* Private macros ------------------------------------------------------------*/
399 #define IS_UART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 921600U)
400 
406 #define IS_UART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == UART_STOPBITS_1) || \
407  ((__STOPBITS__) == UART_STOPBITS_1_5) || \
408  ((__STOPBITS__) == UART_STOPBITS_2))
409 
415 #define IS_UART_DATABITS(__DATABITS__) (((__DATABITS__) == UART_DATABITS_5) || \
416  ((__DATABITS__) == UART_DATABITS_6) || \
417  ((__DATABITS__) == UART_DATABITS_7) || \
418  ((__DATABITS__) == UART_DATABITS_8))
419 
425 #define IS_UART_PARITY(__PARITY__) (((__PARITY__) == UART_PARITY_NONE) || \
426  ((__PARITY__) == UART_PARITY_EVEN) || \
427  ((__PARITY__) == UART_PARITY_ODD) || \
428  ((__PARITY__) == UART_PARITY_SP0) || \
429  ((__PARITY__) == UART_PARITY_SP1))
430 
436 #define IS_UART_HARDWARE_FLOW_CONTROL(__CONTROL__)\
437  (((__CONTROL__) == UART_HWCONTROL_NONE) || \
438  ((__CONTROL__) == UART_HWCONTROL_RTS_CTS)
439 
444 #define UART_DEFAULT_CONFIG \
445 { \
446  .baud_rate = 9600, \
447  .data_bits = UART_DATABITS_8, \
448  .stop_bits = UART_STOPBITS_1, \
449  .parity = UART_PARITY_NONE, \
450  .hw_flow_ctrl = UART_HWCONTROL_NONE, \
451  .rx_timeout_mode = UART_RECEIVER_TIMEOUT_DISABLE, \
452 }
453 
456 /* Exported functions --------------------------------------------------------*/
496 
509 
520 
531 
625 hal_status_t hal_uart_transmit(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size, uint32_t timeout);
626 
641 hal_status_t hal_uart_receive(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size, uint32_t timeout);
642 
656 hal_status_t hal_uart_transmit_it(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size);
657 
671 hal_status_t hal_uart_receive_it(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size);
672 
689 hal_status_t hal_uart_transmit_dma(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size);
690 
709 hal_status_t hal_uart_receive_dma(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size);
710 
723 
736 
749 
769 
789 
809 
831 
853 
875 
891 
902 
913 
924 
935 
946 
957 
992 
1002 
1015 
1029 
1030 
1035 #ifdef __cplusplus
1036 }
1037 #endif
1038 
1039 #endif /* __GR55xx_HAL_UART_H__ */
1040 
hal_uart_irq_handler
void hal_uart_irq_handler(uart_handle_t *p_uart)
Handle UART interrupt request.
_hal_uart_callback::uart_abort_rx_cplt_callback
void(* uart_abort_rx_cplt_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:215
_hal_uart_callback::uart_msp_deinit
void(* uart_msp_deinit)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:209
_uart_handle::tx_state
__IO hal_uart_state_t tx_state
Definition: gr55xx_hal_uart.h:180
hal_uart_abort_rx_cplt_callback
void hal_uart_abort_rx_cplt_callback(uart_handle_t *p_uart)
UART Abort Receive Complete callback.
_uart_handle::rx_state
__IO hal_uart_state_t rx_state
Definition: gr55xx_hal_uart.h:183
_uart_handle::p_dmatx
dma_handle_t * p_dmatx
Definition: gr55xx_hal_uart.h:170
hal_lock_t
hal_lock_t
HAL Lock structures definition.
Definition: gr55xx_hal_def.h:81
_uart_handle::rx_xfer_size
uint16_t rx_xfer_size
Definition: gr55xx_hal_uart.h:166
hal_uart_get_error
uint32_t hal_uart_get_error(uart_handle_t *p_uart)
Return the UART handle error code.
_uart_init::baud_rate
uint32_t baud_rate
Definition: gr55xx_hal_uart.h:121
_uart_handle::init
uart_init_t init
Definition: gr55xx_hal_uart.h:156
hal_uart_transmit_dma
hal_status_t hal_uart_transmit_dma(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size)
Send an amount of data in DMA mode.
hal_uart_dma_resume
hal_status_t hal_uart_dma_resume(uart_handle_t *p_uart)
Resume the DMA Transfer.
uart_init_t
struct _uart_init uart_init_t
UART init structure definition.
hal_uart_transmit
hal_status_t hal_uart_transmit(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size, uint32_t timeout)
Send an amount of data in blocking mode.
hal_uart_deinit
hal_status_t hal_uart_deinit(uart_handle_t *p_uart)
De-initialize the UART peripheral.
HAL_UART_STATE_BUSY_TX
@ HAL_UART_STATE_BUSY_TX
Definition: gr55xx_hal_uart.h:87
hal_uart_state_t
hal_uart_state_t
HAL UART State enumerations definition.
Definition: gr55xx_hal_uart.h:77
_uart_handle::dma_rx_mode
functional_state_t dma_rx_mode
Definition: gr55xx_hal_uart.h:176
hal_uart_abort_receive
hal_status_t hal_uart_abort_receive(uart_handle_t *p_uart)
Abort ongoing Receive transfer (blocking mode).
hal_uart_abort_receive_it
hal_status_t hal_uart_abort_receive_it(uart_handle_t *p_uart)
Abort ongoing Receive transfer (Interrupt mode).
hal_uart_abort_it
hal_status_t hal_uart_abort_it(uart_handle_t *p_uart)
Abort ongoing transfers (Interrupt mode).
hal_uart_msp_init
void hal_uart_msp_init(uart_handle_t *p_uart)
Initialize the UART MSP.
HAL_UART_STATE_BUSY_RX
@ HAL_UART_STATE_BUSY_RX
Definition: gr55xx_hal_uart.h:90
_uart_handle
UART handle Structure definition.
Definition: gr55xx_hal_uart.h:153
_uart_init::stop_bits
uint32_t stop_bits
Definition: gr55xx_hal_uart.h:126
_uart_handle::p_dmarx
dma_handle_t * p_dmarx
Definition: gr55xx_hal_uart.h:172
_uart_init
UART init structure definition.
Definition: gr55xx_hal_uart.h:120
_uart_handle::lock
hal_lock_t lock
Definition: gr55xx_hal_uart.h:178
_uart_init::rx_timeout_mode
uint32_t rx_timeout_mode
Definition: gr55xx_hal_uart.h:135
hal_uart_error_callback
void hal_uart_error_callback(uart_handle_t *p_uart)
UART error callback.
_hal_uart_callback
HAL_UART Callback function definition.
Definition: gr55xx_hal_uart.h:207
hal_uart_callback_t
struct _hal_uart_callback hal_uart_callback_t
HAL_UART Callback function definition.
_uart_handle::tx_xfer_size
uint16_t tx_xfer_size
Definition: gr55xx_hal_uart.h:160
hal_uart_abort_transmit
hal_status_t hal_uart_abort_transmit(uart_handle_t *p_uart)
Abort ongoing Transmit transfer (blocking mode).
uart_handle_t
struct _uart_handle uart_handle_t
UART handle Structure definition.
_hal_uart_callback::uart_error_callback
void(* uart_error_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:212
HAL_UART_STATE_ERROR
@ HAL_UART_STATE_ERROR
Definition: gr55xx_hal_uart.h:99
HAL_UART_STATE_BUSY
@ HAL_UART_STATE_BUSY
Definition: gr55xx_hal_uart.h:84
_uart_init::parity
uint32_t parity
Definition: gr55xx_hal_uart.h:129
hal_uart_resume_reg
hal_status_t hal_uart_resume_reg(uart_handle_t *p_uart)
Restore some registers related to UART configuration after sleep. This function must be used in conju...
_uart_handle::tx_xfer_count
__IO uint16_t tx_xfer_count
Definition: gr55xx_hal_uart.h:162
_uart_handle::p_rx_buffer
uint8_t * p_rx_buffer
Definition: gr55xx_hal_uart.h:164
hal_uart_suspend_reg
hal_status_t hal_uart_suspend_reg(uart_handle_t *p_uart)
Suspend some registers related to UART configuration before sleep.
HAL_UART_STATE_TIMEOUT
@ HAL_UART_STATE_TIMEOUT
Definition: gr55xx_hal_uart.h:96
hal_uart_init
hal_status_t hal_uart_init(uart_handle_t *p_uart)
Initialize the UART according to the specified parameters in the uart_init_t and initialize the assoc...
HAL_UART_STATE_READY
@ HAL_UART_STATE_READY
Definition: gr55xx_hal_uart.h:81
hal_uart_msp_deinit
void hal_uart_msp_deinit(uart_handle_t *p_uart)
De-initialize the UART MSP.
hal_uart_dma_stop
hal_status_t hal_uart_dma_stop(uart_handle_t *p_uart)
Stop the DMA Transfer.
_hal_uart_callback::uart_abort_cplt_callback
void(* uart_abort_cplt_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:213
gr55xx_ll_uart.h
Header file containing functions prototypes of UART LL library.
hal_uart_tx_cplt_callback
void hal_uart_tx_cplt_callback(uart_handle_t *p_uart)
Tx Transfer completed callback.
_hal_uart_callback::uart_rx_cplt_callback
void(* uart_rx_cplt_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:211
_uart_init::hw_flow_ctrl
uint32_t hw_flow_ctrl
Definition: gr55xx_hal_uart.h:132
HAL_UART_STATE_RESET
@ HAL_UART_STATE_RESET
Definition: gr55xx_hal_uart.h:78
hal_status_t
hal_status_t
HAL Status structures definition.
Definition: gr55xx_hal_def.h:70
hal_uart_transmit_it
hal_status_t hal_uart_transmit_it(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size)
Send an amount of data in interrupt mode.
_uart_handle::retention
uint32_t retention[8]
Definition: gr55xx_hal_uart.h:188
hal_uart_abort
hal_status_t hal_uart_abort(uart_handle_t *p_uart)
Abort ongoing transfers (blocking mode).
HAL_UART_STATE_BUSY_TXRX
@ HAL_UART_STATE_BUSY_TXRX
Definition: gr55xx_hal_uart.h:93
_uart_init::data_bits
uint32_t data_bits
Definition: gr55xx_hal_uart.h:123
hal_uart_abort_transmit_it
hal_status_t hal_uart_abort_transmit_it(uart_handle_t *p_uart)
Abort ongoing Transmit transfer (Interrupt mode).
_hal_uart_callback::uart_abort_tx_cplt_callback
void(* uart_abort_tx_cplt_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:214
_uart_handle::p_tx_buffer
uint8_t * p_tx_buffer
Definition: gr55xx_hal_uart.h:158
hal_uart_abort_cplt_callback
void hal_uart_abort_cplt_callback(uart_handle_t *p_uart)
UART Abort Complete callback.
_uart_handle::p_instance
uart_regs_t * p_instance
Definition: gr55xx_hal_uart.h:154
hal_uart_receive_it
hal_status_t hal_uart_receive_it(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size)
Receive an amount of data in interrupt mode.
_uart_handle::error_code
__IO uint32_t error_code
Definition: gr55xx_hal_uart.h:186
hal_uart_receive
hal_status_t hal_uart_receive(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size, uint32_t timeout)
Receive an amount of data in blocking mode.
_hal_uart_callback::uart_tx_cplt_callback
void(* uart_tx_cplt_callback)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:210
_uart_handle::rx_xfer_count
__IO uint16_t rx_xfer_count
Definition: gr55xx_hal_uart.h:168
_hal_uart_callback::uart_msp_init
void(* uart_msp_init)(uart_handle_t *p_uart)
Definition: gr55xx_hal_uart.h:208
hal_uart_dma_pause
hal_status_t hal_uart_dma_pause(uart_handle_t *p_uart)
Pause the DMA Transfer.
hal_uart_receive_dma
hal_status_t hal_uart_receive_dma(uart_handle_t *p_uart, uint8_t *p_data, uint16_t size)
Receive an amount of data in DMA mode.
_dma_handle
DMA handle Structure definition.
Definition: gr55xx_hal_dma.h:179
gr55xx_hal_def.h
This file contains HAL common definitions, enumeration, macros and structures definitions.
_uart_handle::dma_tx_mode
functional_state_t dma_tx_mode
Definition: gr55xx_hal_uart.h:174
hal_uart_rx_cplt_callback
void hal_uart_rx_cplt_callback(uart_handle_t *p_uart)
Rx Transfer completed callback.
hal_uart_abort_tx_cplt_callback
void hal_uart_abort_tx_cplt_callback(uart_handle_t *p_uart)
UART Abort Tansmit Complete callback.
hal_uart_get_state
hal_uart_state_t hal_uart_get_state(uart_handle_t *p_uart)
Return the UART handle state.