drv_usart.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018.10.30 SummerGift change to new framework
  9. */
  10. #ifndef __DRV_USART_H__
  11. #define __DRV_USART_H__
  12. #include <rtthread.h>
  13. #include "rtdevice.h"
  14. #include <rthw.h>
  15. #include <drv_common.h>
  16. #include "drv_dma.h"
  17. int rt_hw_usart_init(void);
  18. #if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4)
  19. #define DMA_INSTANCE_TYPE DMA_Channel_TypeDef
  20. #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  21. #define DMA_INSTANCE_TYPE DMA_Stream_TypeDef
  22. #endif /* defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) */
  23. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
  24. #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_FLAG
  25. #elif defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0)
  26. #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_IT
  27. #endif
  28. /* stm32 config class */
  29. struct stm32_uart_config
  30. {
  31. const char *name;
  32. USART_TypeDef *Instance;
  33. IRQn_Type irq_type;
  34. struct dma_config *dma_rx;
  35. };
  36. /* stm32 uart dirver class */
  37. struct stm32_uart
  38. {
  39. UART_HandleTypeDef handle;
  40. struct stm32_uart_config *config;
  41. #ifdef RT_SERIAL_USING_DMA
  42. struct
  43. {
  44. DMA_HandleTypeDef handle;
  45. rt_size_t last_index;
  46. } dma;
  47. #endif
  48. rt_uint8_t uart_dma_flag;
  49. struct rt_serial_device serial;
  50. };
  51. #endif /* __DRV_USART_H__ */