RTEMS 6.1-rc5
Loading...
Searching...
No Matches
stm32h7xx_hal_usart.h
Go to the documentation of this file.
1
19/* Define to prevent recursive inclusion -------------------------------------*/
20#ifndef STM32H7xx_HAL_USART_H
21#define STM32H7xx_HAL_USART_H
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27/* Includes ------------------------------------------------------------------*/
28#include "stm32h7xx_hal_def.h"
29
38/* Exported types ------------------------------------------------------------*/
47typedef struct
48{
49 uint32_t BaudRate;
61 uint32_t WordLength;
64 uint32_t StopBits;
67 uint32_t Parity;
74 uint32_t Mode;
77 uint32_t CLKPolarity;
80 uint32_t CLKPhase;
83 uint32_t CLKLastBit;
87 uint32_t ClockPrescaler;
90
94typedef enum
95{
103 HAL_USART_STATE_ERROR = 0x04U
105
109typedef enum
110{
120
125{
130 const uint8_t *pTxBuffPtr;
132 uint16_t TxXferSize;
134 __IO uint16_t TxXferCount;
136 uint8_t *pRxBuffPtr;
138 uint16_t RxXferSize;
140 __IO uint16_t RxXferCount;
142 uint16_t Mask;
148 uint32_t SlaveMode;
151 uint32_t FifoMode;
154 void (*RxISR)(struct __USART_HandleTypeDef *husart);
156 void (*TxISR)(struct __USART_HandleTypeDef *husart);
166 __IO uint32_t ErrorCode;
168#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
169 void (* TxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);
170 void (* TxCpltCallback)(struct __USART_HandleTypeDef *husart);
171 void (* RxHalfCpltCallback)(struct __USART_HandleTypeDef *husart);
172 void (* RxCpltCallback)(struct __USART_HandleTypeDef *husart);
173 void (* TxRxCpltCallback)(struct __USART_HandleTypeDef *husart);
174 void (* ErrorCallback)(struct __USART_HandleTypeDef *husart);
175 void (* AbortCpltCallback)(struct __USART_HandleTypeDef *husart);
176 void (* RxFifoFullCallback)(struct __USART_HandleTypeDef *husart);
177 void (* TxFifoEmptyCallback)(struct __USART_HandleTypeDef *husart);
179 void (* MspInitCallback)(struct __USART_HandleTypeDef *husart);
180 void (* MspDeInitCallback)(struct __USART_HandleTypeDef *husart);
181#endif /* USE_HAL_USART_REGISTER_CALLBACKS */
182
184
185#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
189typedef enum
190{
191 HAL_USART_TX_HALFCOMPLETE_CB_ID = 0x00U,
192 HAL_USART_TX_COMPLETE_CB_ID = 0x01U,
193 HAL_USART_RX_HALFCOMPLETE_CB_ID = 0x02U,
194 HAL_USART_RX_COMPLETE_CB_ID = 0x03U,
195 HAL_USART_TX_RX_COMPLETE_CB_ID = 0x04U,
196 HAL_USART_ERROR_CB_ID = 0x05U,
197 HAL_USART_ABORT_COMPLETE_CB_ID = 0x06U,
198 HAL_USART_RX_FIFO_FULL_CB_ID = 0x07U,
199 HAL_USART_TX_FIFO_EMPTY_CB_ID = 0x08U,
201 HAL_USART_MSPINIT_CB_ID = 0x09U,
202 HAL_USART_MSPDEINIT_CB_ID = 0x0AU
204} HAL_USART_CallbackIDTypeDef;
205
209typedef void (*pUSART_CallbackTypeDef)(USART_HandleTypeDef *husart);
211#endif /* USE_HAL_USART_REGISTER_CALLBACKS */
212
217/* Exported constants --------------------------------------------------------*/
227#define HAL_USART_ERROR_NONE (0x00000000U)
228#define HAL_USART_ERROR_PE (0x00000001U)
229#define HAL_USART_ERROR_NE (0x00000002U)
230#define HAL_USART_ERROR_FE (0x00000004U)
231#define HAL_USART_ERROR_ORE (0x00000008U)
232#define HAL_USART_ERROR_DMA (0x00000010U)
233#define HAL_USART_ERROR_UDR (0x00000020U)
234#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
235#define HAL_USART_ERROR_INVALID_CALLBACK (0x00000040U)
236#endif /* USE_HAL_USART_REGISTER_CALLBACKS */
237#define HAL_USART_ERROR_RTO (0x00000080U)
246#define USART_STOPBITS_0_5 USART_CR2_STOP_0
247#define USART_STOPBITS_1 0x00000000U
248#define USART_STOPBITS_1_5 (USART_CR2_STOP_0 | USART_CR2_STOP_1)
249#define USART_STOPBITS_2 USART_CR2_STOP_1
258#define USART_PARITY_NONE 0x00000000U
259#define USART_PARITY_EVEN USART_CR1_PCE
260#define USART_PARITY_ODD (USART_CR1_PCE | USART_CR1_PS)
269#define USART_MODE_RX USART_CR1_RE
270#define USART_MODE_TX USART_CR1_TE
271#define USART_MODE_TX_RX (USART_CR1_TE |USART_CR1_RE)
280#define USART_CLOCK_DISABLE 0x00000000U
281#define USART_CLOCK_ENABLE USART_CR2_CLKEN
290#define USART_POLARITY_LOW 0x00000000U
291#define USART_POLARITY_HIGH USART_CR2_CPOL
300#define USART_PHASE_1EDGE 0x00000000U
301#define USART_PHASE_2EDGE USART_CR2_CPHA
310#define USART_LASTBIT_DISABLE 0x00000000U
311#define USART_LASTBIT_ENABLE USART_CR2_LBCL
320#define USART_PRESCALER_DIV1 0x00000000U
321#define USART_PRESCALER_DIV2 0x00000001U
322#define USART_PRESCALER_DIV4 0x00000002U
323#define USART_PRESCALER_DIV6 0x00000003U
324#define USART_PRESCALER_DIV8 0x00000004U
325#define USART_PRESCALER_DIV10 0x00000005U
326#define USART_PRESCALER_DIV12 0x00000006U
327#define USART_PRESCALER_DIV16 0x00000007U
328#define USART_PRESCALER_DIV32 0x00000008U
329#define USART_PRESCALER_DIV64 0x00000009U
330#define USART_PRESCALER_DIV128 0x0000000AU
331#define USART_PRESCALER_DIV256 0x0000000BU
341#define USART_RXDATA_FLUSH_REQUEST USART_RQR_RXFRQ
342#define USART_TXDATA_FLUSH_REQUEST USART_RQR_TXFRQ
353#define USART_FLAG_TXFT USART_ISR_TXFT
354#define USART_FLAG_RXFT USART_ISR_RXFT
355#define USART_FLAG_RXFF USART_ISR_RXFF
356#define USART_FLAG_TXFE USART_ISR_TXFE
357#define USART_FLAG_REACK USART_ISR_REACK
358#define USART_FLAG_TEACK USART_ISR_TEACK
359#define USART_FLAG_BUSY USART_ISR_BUSY
360#define USART_FLAG_UDR USART_ISR_UDR
361#define USART_FLAG_TXE USART_ISR_TXE_TXFNF
362#define USART_FLAG_TXFNF USART_ISR_TXE_TXFNF
363#define USART_FLAG_RTOF USART_ISR_RTOF
364#define USART_FLAG_TC USART_ISR_TC
365#define USART_FLAG_RXNE USART_ISR_RXNE_RXFNE
366#define USART_FLAG_RXFNE USART_ISR_RXNE_RXFNE
367#define USART_FLAG_IDLE USART_ISR_IDLE
368#define USART_FLAG_ORE USART_ISR_ORE
369#define USART_FLAG_NE USART_ISR_NE
370#define USART_FLAG_FE USART_ISR_FE
371#define USART_FLAG_PE USART_ISR_PE
388#define USART_IT_PE 0x0028U
389#define USART_IT_TXE 0x0727U
390#define USART_IT_TXFNF 0x0727U
391#define USART_IT_TC 0x0626U
392#define USART_IT_RXNE 0x0525U
393#define USART_IT_RXFNE 0x0525U
394#define USART_IT_IDLE 0x0424U
395#define USART_IT_ERR 0x0060U
396#define USART_IT_ORE 0x0300U
397#define USART_IT_NE 0x0200U
398#define USART_IT_FE 0x0100U
399#define USART_IT_RXFF 0x183FU
400#define USART_IT_TXFE 0x173EU
401#define USART_IT_RXFT 0x1A7CU
402#define USART_IT_TXFT 0x1B77U
412#define USART_CLEAR_PEF USART_ICR_PECF
413#define USART_CLEAR_FEF USART_ICR_FECF
414#define USART_CLEAR_NEF USART_ICR_NECF
415#define USART_CLEAR_OREF USART_ICR_ORECF
416#define USART_CLEAR_IDLEF USART_ICR_IDLECF
417#define USART_CLEAR_TCF USART_ICR_TCCF
418#define USART_CLEAR_UDRF USART_ICR_UDRCF
419#define USART_CLEAR_TXFECF USART_ICR_TXFECF
420#define USART_CLEAR_RTOF USART_ICR_RTOCF
429#define USART_IT_MASK 0x001FU
430#define USART_CR_MASK 0x00E0U
431#define USART_CR_POS 5U
432#define USART_ISR_MASK 0x1F00U
433#define USART_ISR_POS 8U
442/* Exported macros -----------------------------------------------------------*/
452#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
453#define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) do{ \
454 (__HANDLE__)->State = HAL_USART_STATE_RESET; \
455 (__HANDLE__)->MspInitCallback = NULL; \
456 (__HANDLE__)->MspDeInitCallback = NULL; \
457 } while(0U)
458#else
459#define __HAL_USART_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_USART_STATE_RESET)
460#endif /* USE_HAL_USART_REGISTER_CALLBACKS */
461
487#define __HAL_USART_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
488
504#define __HAL_USART_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
505
510#define __HAL_USART_CLEAR_PEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_PEF)
511
516#define __HAL_USART_CLEAR_FEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_FEF)
517
522#define __HAL_USART_CLEAR_NEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_NEF)
523
528#define __HAL_USART_CLEAR_OREFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_OREF)
529
534#define __HAL_USART_CLEAR_IDLEFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_IDLEF)
535
540#define __HAL_USART_CLEAR_TXFECF(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_TXFECF)
541
546#define __HAL_USART_CLEAR_UDRFLAG(__HANDLE__) __HAL_USART_CLEAR_FLAG((__HANDLE__), USART_CLEAR_UDRF)
547
566#define __HAL_USART_ENABLE_IT(__HANDLE__, __INTERRUPT__)\
567 (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)?\
568 ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
569 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)?\
570 ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
571 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & USART_IT_MASK))))
572
591#define __HAL_USART_DISABLE_IT(__HANDLE__, __INTERRUPT__)\
592 (((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 1U)?\
593 ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
594 ((((__INTERRUPT__) & USART_CR_MASK) >> USART_CR_POS) == 2U)?\
595 ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))): \
596 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & USART_IT_MASK))))
597
618#define __HAL_USART_GET_IT(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->ISR\
619 & (0x01U << (((__INTERRUPT__) & USART_ISR_MASK)>>\
620 USART_ISR_POS))) != 0U) ? SET : RESET)
621
642#define __HAL_USART_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x01U) ?\
643 (__HANDLE__)->Instance->CR1 : \
644 (((((uint8_t)(__INTERRUPT__)) >> 0x05U) == 0x02U) ?\
645 (__HANDLE__)->Instance->CR2 : \
646 (__HANDLE__)->Instance->CR3)) & (0x01U <<\
647 (((uint16_t)(__INTERRUPT__)) &\
648 USART_IT_MASK))) != 0U) ? SET : RESET)
649
665#define __HAL_USART_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
666
676#define __HAL_USART_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
677
682#define __HAL_USART_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
683
688#define __HAL_USART_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= ~USART_CR3_ONEBIT)
689
694#define __HAL_USART_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
695
700#define __HAL_USART_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
701
706/* Private macros --------------------------------------------------------*/
716#define USART_GET_DIV_FACTOR(__CLOCKPRESCALER__) \
717 (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) ? 1U : \
718 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) ? 2U : \
719 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) ? 4U : \
720 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) ? 6U : \
721 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) ? 8U : \
722 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) ? 10U : \
723 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) ? 12U : \
724 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) ? 16U : \
725 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) ? 32U : \
726 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) ? 64U : \
727 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) ? 128U : \
728 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256) ? 256U : 1U)
729
736#define USART_DIV_SAMPLING8(__PCLK__, __BAUD__, __CLOCKPRESCALER__)\
737 (((((__PCLK__)/USART_GET_DIV_FACTOR(__CLOCKPRESCALER__))*2U)\
738 + ((__BAUD__)/2U)) / (__BAUD__))
739
745#if defined(UART9) && defined(USART10)
746#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
747 do { \
748 if((__HANDLE__)->Instance == USART1) \
749 { \
750 switch(__HAL_RCC_GET_USART1_SOURCE()) \
751 { \
752 case RCC_USART1CLKSOURCE_D2PCLK2: \
753 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK2; \
754 break; \
755 case RCC_USART1CLKSOURCE_PLL2: \
756 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
757 break; \
758 case RCC_USART1CLKSOURCE_PLL3: \
759 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
760 break; \
761 case RCC_USART1CLKSOURCE_HSI: \
762 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
763 break; \
764 case RCC_USART1CLKSOURCE_CSI: \
765 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
766 break; \
767 case RCC_USART1CLKSOURCE_LSE: \
768 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
769 break; \
770 default: \
771 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
772 break; \
773 } \
774 } \
775 else if((__HANDLE__)->Instance == USART2) \
776 { \
777 switch(__HAL_RCC_GET_USART2_SOURCE()) \
778 { \
779 case RCC_USART2CLKSOURCE_D2PCLK1: \
780 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK1; \
781 break; \
782 case RCC_USART2CLKSOURCE_PLL2: \
783 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
784 break; \
785 case RCC_USART2CLKSOURCE_PLL3: \
786 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
787 break; \
788 case RCC_USART2CLKSOURCE_HSI: \
789 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
790 break; \
791 case RCC_USART2CLKSOURCE_CSI: \
792 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
793 break; \
794 case RCC_USART2CLKSOURCE_LSE: \
795 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
796 break; \
797 default: \
798 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
799 break; \
800 } \
801 } \
802 else if((__HANDLE__)->Instance == USART3) \
803 { \
804 switch(__HAL_RCC_GET_USART3_SOURCE()) \
805 { \
806 case RCC_USART3CLKSOURCE_D2PCLK1: \
807 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK1; \
808 break; \
809 case RCC_USART3CLKSOURCE_PLL2: \
810 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
811 break; \
812 case RCC_USART3CLKSOURCE_PLL3: \
813 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
814 break; \
815 case RCC_USART3CLKSOURCE_HSI: \
816 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
817 break; \
818 case RCC_USART3CLKSOURCE_CSI: \
819 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
820 break; \
821 case RCC_USART3CLKSOURCE_LSE: \
822 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
823 break; \
824 default: \
825 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
826 break; \
827 } \
828 } \
829 else if((__HANDLE__)->Instance == USART6) \
830 { \
831 switch(__HAL_RCC_GET_USART6_SOURCE()) \
832 { \
833 case RCC_USART6CLKSOURCE_D2PCLK2: \
834 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK2; \
835 break; \
836 case RCC_USART6CLKSOURCE_PLL2: \
837 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
838 break; \
839 case RCC_USART6CLKSOURCE_PLL3: \
840 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
841 break; \
842 case RCC_USART6CLKSOURCE_HSI: \
843 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
844 break; \
845 case RCC_USART6CLKSOURCE_CSI: \
846 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
847 break; \
848 case RCC_USART6CLKSOURCE_LSE: \
849 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
850 break; \
851 default: \
852 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
853 break; \
854 } \
855 } \
856 else if((__HANDLE__)->Instance == USART10) \
857 { \
858 switch(__HAL_RCC_GET_USART10_SOURCE()) \
859 { \
860 case RCC_USART10CLKSOURCE_D2PCLK2: \
861 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK2; \
862 break; \
863 case RCC_USART10CLKSOURCE_PLL2: \
864 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
865 break; \
866 case RCC_USART10CLKSOURCE_PLL3: \
867 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
868 break; \
869 case RCC_USART10CLKSOURCE_HSI: \
870 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
871 break; \
872 case RCC_USART10CLKSOURCE_CSI: \
873 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
874 break; \
875 case RCC_USART10CLKSOURCE_LSE: \
876 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
877 break; \
878 default: \
879 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
880 break; \
881 } \
882 } \
883 else \
884 { \
885 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
886 } \
887 } while(0U)
888#else
889#define USART_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__) \
890 do { \
891 if((__HANDLE__)->Instance == USART1) \
892 { \
893 switch(__HAL_RCC_GET_USART1_SOURCE()) \
894 { \
895 case RCC_USART1CLKSOURCE_D2PCLK2: \
896 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK2; \
897 break; \
898 case RCC_USART1CLKSOURCE_PLL2: \
899 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
900 break; \
901 case RCC_USART1CLKSOURCE_PLL3: \
902 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
903 break; \
904 case RCC_USART1CLKSOURCE_HSI: \
905 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
906 break; \
907 case RCC_USART1CLKSOURCE_CSI: \
908 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
909 break; \
910 case RCC_USART1CLKSOURCE_LSE: \
911 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
912 break; \
913 default: \
914 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
915 break; \
916 } \
917 } \
918 else if((__HANDLE__)->Instance == USART2) \
919 { \
920 switch(__HAL_RCC_GET_USART2_SOURCE()) \
921 { \
922 case RCC_USART2CLKSOURCE_D2PCLK1: \
923 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK1; \
924 break; \
925 case RCC_USART2CLKSOURCE_PLL2: \
926 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
927 break; \
928 case RCC_USART2CLKSOURCE_PLL3: \
929 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
930 break; \
931 case RCC_USART2CLKSOURCE_HSI: \
932 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
933 break; \
934 case RCC_USART2CLKSOURCE_CSI: \
935 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
936 break; \
937 case RCC_USART2CLKSOURCE_LSE: \
938 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
939 break; \
940 default: \
941 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
942 break; \
943 } \
944 } \
945 else if((__HANDLE__)->Instance == USART3) \
946 { \
947 switch(__HAL_RCC_GET_USART3_SOURCE()) \
948 { \
949 case RCC_USART3CLKSOURCE_D2PCLK1: \
950 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK1; \
951 break; \
952 case RCC_USART3CLKSOURCE_PLL2: \
953 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
954 break; \
955 case RCC_USART3CLKSOURCE_PLL3: \
956 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
957 break; \
958 case RCC_USART3CLKSOURCE_HSI: \
959 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
960 break; \
961 case RCC_USART3CLKSOURCE_CSI: \
962 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
963 break; \
964 case RCC_USART3CLKSOURCE_LSE: \
965 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
966 break; \
967 default: \
968 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
969 break; \
970 } \
971 } \
972 else if((__HANDLE__)->Instance == USART6) \
973 { \
974 switch(__HAL_RCC_GET_USART6_SOURCE()) \
975 { \
976 case RCC_USART6CLKSOURCE_D2PCLK2: \
977 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_D2PCLK2; \
978 break; \
979 case RCC_USART6CLKSOURCE_PLL2: \
980 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL2; \
981 break; \
982 case RCC_USART6CLKSOURCE_PLL3: \
983 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_PLL3; \
984 break; \
985 case RCC_USART6CLKSOURCE_HSI: \
986 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_HSI; \
987 break; \
988 case RCC_USART6CLKSOURCE_CSI: \
989 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_CSI; \
990 break; \
991 case RCC_USART6CLKSOURCE_LSE: \
992 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_LSE; \
993 break; \
994 default: \
995 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
996 break; \
997 } \
998 } \
999 else \
1000 { \
1001 (__CLOCKSOURCE__) = USART_CLOCKSOURCE_UNDEFINED; \
1002 } \
1003 } while(0U)
1004#endif /* UART9 && USART10 */
1005
1011#define IS_USART_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) <= 12500000U)
1012
1018#define IS_USART_STOPBITS(__STOPBITS__) (((__STOPBITS__) == USART_STOPBITS_0_5) || \
1019 ((__STOPBITS__) == USART_STOPBITS_1) || \
1020 ((__STOPBITS__) == USART_STOPBITS_1_5) || \
1021 ((__STOPBITS__) == USART_STOPBITS_2))
1022
1028#define IS_USART_PARITY(__PARITY__) (((__PARITY__) == USART_PARITY_NONE) || \
1029 ((__PARITY__) == USART_PARITY_EVEN) || \
1030 ((__PARITY__) == USART_PARITY_ODD))
1031
1037#define IS_USART_MODE(__MODE__) ((((__MODE__) & 0xFFFFFFF3U) == 0x00U) && ((__MODE__) != 0x00U))
1038
1044#define IS_USART_CLOCK(__CLOCK__) (((__CLOCK__) == USART_CLOCK_DISABLE) || \
1045 ((__CLOCK__) == USART_CLOCK_ENABLE))
1046
1052#define IS_USART_POLARITY(__CPOL__) (((__CPOL__) == USART_POLARITY_LOW) || ((__CPOL__) == USART_POLARITY_HIGH))
1053
1059#define IS_USART_PHASE(__CPHA__) (((__CPHA__) == USART_PHASE_1EDGE) || ((__CPHA__) == USART_PHASE_2EDGE))
1060
1066#define IS_USART_LASTBIT(__LASTBIT__) (((__LASTBIT__) == USART_LASTBIT_DISABLE) || \
1067 ((__LASTBIT__) == USART_LASTBIT_ENABLE))
1068
1074#define IS_USART_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == USART_RXDATA_FLUSH_REQUEST) || \
1075 ((__PARAM__) == USART_TXDATA_FLUSH_REQUEST))
1076
1082#define IS_USART_PRESCALER(__CLOCKPRESCALER__) (((__CLOCKPRESCALER__) == USART_PRESCALER_DIV1) || \
1083 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV2) || \
1084 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV4) || \
1085 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV6) || \
1086 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV8) || \
1087 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV10) || \
1088 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV12) || \
1089 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV16) || \
1090 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV32) || \
1091 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV64) || \
1092 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV128) || \
1093 ((__CLOCKPRESCALER__) == USART_PRESCALER_DIV256))
1094
1099/* Include USART HAL Extended module */
1100#include "stm32h7xx_hal_usart_ex.h"
1101
1102/* Exported functions --------------------------------------------------------*/
1111/* Initialization and de-initialization functions ****************************/
1112HAL_StatusTypeDef HAL_USART_Init(USART_HandleTypeDef *husart);
1113HAL_StatusTypeDef HAL_USART_DeInit(USART_HandleTypeDef *husart);
1114void HAL_USART_MspInit(USART_HandleTypeDef *husart);
1115void HAL_USART_MspDeInit(USART_HandleTypeDef *husart);
1116
1117/* Callbacks Register/UnRegister functions ***********************************/
1118#if (USE_HAL_USART_REGISTER_CALLBACKS == 1)
1119HAL_StatusTypeDef HAL_USART_RegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID,
1120 pUSART_CallbackTypeDef pCallback);
1121HAL_StatusTypeDef HAL_USART_UnRegisterCallback(USART_HandleTypeDef *husart, HAL_USART_CallbackIDTypeDef CallbackID);
1122#endif /* USE_HAL_USART_REGISTER_CALLBACKS */
1123
1132/* IO operation functions *****************************************************/
1133HAL_StatusTypeDef HAL_USART_Transmit(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size,
1134 uint32_t Timeout);
1135HAL_StatusTypeDef HAL_USART_Receive(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size, uint32_t Timeout);
1136HAL_StatusTypeDef HAL_USART_TransmitReceive(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
1137 uint16_t Size, uint32_t Timeout);
1138HAL_StatusTypeDef HAL_USART_Transmit_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size);
1139HAL_StatusTypeDef HAL_USART_Receive_IT(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
1140HAL_StatusTypeDef HAL_USART_TransmitReceive_IT(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
1141 uint16_t Size);
1142HAL_StatusTypeDef HAL_USART_Transmit_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint16_t Size);
1143HAL_StatusTypeDef HAL_USART_Receive_DMA(USART_HandleTypeDef *husart, uint8_t *pRxData, uint16_t Size);
1144HAL_StatusTypeDef HAL_USART_TransmitReceive_DMA(USART_HandleTypeDef *husart, const uint8_t *pTxData, uint8_t *pRxData,
1145 uint16_t Size);
1146HAL_StatusTypeDef HAL_USART_DMAPause(USART_HandleTypeDef *husart);
1147HAL_StatusTypeDef HAL_USART_DMAResume(USART_HandleTypeDef *husart);
1148HAL_StatusTypeDef HAL_USART_DMAStop(USART_HandleTypeDef *husart);
1149/* Transfer Abort functions */
1150HAL_StatusTypeDef HAL_USART_Abort(USART_HandleTypeDef *husart);
1151HAL_StatusTypeDef HAL_USART_Abort_IT(USART_HandleTypeDef *husart);
1152
1153void HAL_USART_IRQHandler(USART_HandleTypeDef *husart);
1154void HAL_USART_TxHalfCpltCallback(USART_HandleTypeDef *husart);
1155void HAL_USART_TxCpltCallback(USART_HandleTypeDef *husart);
1156void HAL_USART_RxCpltCallback(USART_HandleTypeDef *husart);
1157void HAL_USART_RxHalfCpltCallback(USART_HandleTypeDef *husart);
1158void HAL_USART_TxRxCpltCallback(USART_HandleTypeDef *husart);
1159void HAL_USART_ErrorCallback(USART_HandleTypeDef *husart);
1160void HAL_USART_AbortCpltCallback(USART_HandleTypeDef *husart);
1161
1170/* Peripheral State and Error functions ***************************************/
1171HAL_USART_StateTypeDef HAL_USART_GetState(const USART_HandleTypeDef *husart);
1172uint32_t HAL_USART_GetError(const USART_HandleTypeDef *husart);
1173
1190#ifdef __cplusplus
1191}
1192#endif
1193
1194#endif /* STM32H7xx_HAL_USART_H */
1195
#define __IO
Definition: core_cm4.h:239
USART_ClockSourceTypeDef
USART clock sources definitions.
Definition: stm32h7xx_hal_usart.h:110
HAL_USART_StateTypeDef
HAL USART State structures definition.
Definition: stm32h7xx_hal_usart.h:95
struct __USART_HandleTypeDef USART_HandleTypeDef
USART handle Structure definition.
@ USART_CLOCKSOURCE_LSE
Definition: stm32h7xx_hal_usart.h:117
@ USART_CLOCKSOURCE_D2PCLK2
Definition: stm32h7xx_hal_usart.h:112
@ USART_CLOCKSOURCE_CSI
Definition: stm32h7xx_hal_usart.h:116
@ USART_CLOCKSOURCE_UNDEFINED
Definition: stm32h7xx_hal_usart.h:118
@ USART_CLOCKSOURCE_HSI
Definition: stm32h7xx_hal_usart.h:115
@ USART_CLOCKSOURCE_D2PCLK1
Definition: stm32h7xx_hal_usart.h:111
@ USART_CLOCKSOURCE_PLL3
Definition: stm32h7xx_hal_usart.h:114
@ USART_CLOCKSOURCE_PLL2
Definition: stm32h7xx_hal_usart.h:113
@ HAL_USART_STATE_BUSY_TX
Definition: stm32h7xx_hal_usart.h:99
@ HAL_USART_STATE_ERROR
Definition: stm32h7xx_hal_usart.h:103
@ HAL_USART_STATE_BUSY_RX
Definition: stm32h7xx_hal_usart.h:100
@ HAL_USART_STATE_TIMEOUT
Definition: stm32h7xx_hal_usart.h:102
@ HAL_USART_STATE_BUSY_TX_RX
Definition: stm32h7xx_hal_usart.h:101
@ HAL_USART_STATE_RESET
Definition: stm32h7xx_hal_usart.h:96
@ HAL_USART_STATE_READY
Definition: stm32h7xx_hal_usart.h:97
@ HAL_USART_STATE_BUSY
Definition: stm32h7xx_hal_usart.h:98
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef
HAL Status structures definition.
Definition: stm32h7xx_hal_def.h:47
HAL_LockTypeDef
HAL Lock structures definition.
Definition: stm32h7xx_hal_def.h:58
Header file of USART HAL Extended module.
USART Init Structure definition.
Definition: stm32h7xx_hal_usart.h:48
uint32_t StopBits
Definition: stm32h7xx_hal_usart.h:64
uint32_t ClockPrescaler
Definition: stm32h7xx_hal_usart.h:87
uint32_t CLKLastBit
Definition: stm32h7xx_hal_usart.h:83
uint32_t Parity
Definition: stm32h7xx_hal_usart.h:67
uint32_t Mode
Definition: stm32h7xx_hal_usart.h:74
uint32_t WordLength
Definition: stm32h7xx_hal_usart.h:61
uint32_t CLKPhase
Definition: stm32h7xx_hal_usart.h:80
uint32_t BaudRate
Definition: stm32h7xx_hal_usart.h:49
uint32_t CLKPolarity
Definition: stm32h7xx_hal_usart.h:77
Universal Synchronous Asynchronous Receiver Transmitter.
Definition: stm32h723xx.h:1596
DMA handle Structure definition.
Definition: stm32h7xx_hal_dma.h:138
USART handle Structure definition.
Definition: stm32h7xx_hal_usart.h:125
DMA_HandleTypeDef * hdmatx
Definition: stm32h7xx_hal_usart.h:158
__IO uint16_t RxXferCount
Definition: stm32h7xx_hal_usart.h:140
USART_InitTypeDef Init
Definition: stm32h7xx_hal_usart.h:128
__IO uint16_t TxXferCount
Definition: stm32h7xx_hal_usart.h:134
uint16_t NbTxDataToProcess
Definition: stm32h7xx_hal_usart.h:146
uint16_t RxXferSize
Definition: stm32h7xx_hal_usart.h:138
uint16_t NbRxDataToProcess
Definition: stm32h7xx_hal_usart.h:144
const uint8_t * pTxBuffPtr
Definition: stm32h7xx_hal_usart.h:130
uint16_t Mask
Definition: stm32h7xx_hal_usart.h:142
uint32_t SlaveMode
Definition: stm32h7xx_hal_usart.h:148
DMA_HandleTypeDef * hdmarx
Definition: stm32h7xx_hal_usart.h:160
void(* RxISR)(struct __USART_HandleTypeDef *husart)
Definition: stm32h7xx_hal_usart.h:154
void(* TxISR)(struct __USART_HandleTypeDef *husart)
Definition: stm32h7xx_hal_usart.h:156
uint16_t TxXferSize
Definition: stm32h7xx_hal_usart.h:132
uint8_t * pRxBuffPtr
Definition: stm32h7xx_hal_usart.h:136
__IO HAL_USART_StateTypeDef State
Definition: stm32h7xx_hal_usart.h:164
__IO uint32_t ErrorCode
Definition: stm32h7xx_hal_usart.h:166
HAL_LockTypeDef Lock
Definition: stm32h7xx_hal_usart.h:162
uint32_t FifoMode
Definition: stm32h7xx_hal_usart.h:151
USART_TypeDef * Instance
Definition: stm32h7xx_hal_usart.h:126