drv_usart.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. int rt_hw_usart_init(void);
  17. #if defined(SOC_SERIES_STM32F0) || defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4)
  18. #define DMA_INSTANCE_TYPE DMA_Channel_TypeDef
  19. #elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  20. #define DMA_INSTANCE_TYPE DMA_Stream_TypeDef
  21. #endif /* defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) */
  22. #if defined(SOC_SERIES_STM32F1) || defined(SOC_SERIES_STM32L4) || defined(SOC_SERIES_STM32F4)
  23. #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_FLAG
  24. #elif defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32F0)
  25. #define UART_INSTANCE_CLEAR_FUNCTION __HAL_UART_CLEAR_IT
  26. #endif
  27. /* stm32 config class */
  28. struct stm32_uart_config
  29. {
  30. const char *name;
  31. USART_TypeDef *Instance;
  32. IRQn_Type irq_type;
  33. union {
  34. DMA_INSTANCE_TYPE *Instance;
  35. #if defined(SOC_SERIES_STM32F1)
  36. /* the DMA config has channel only, such as on STM32F1xx */
  37. struct {
  38. DMA_INSTANCE_TYPE *Instance;
  39. } channel;
  40. #endif
  41. #if defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7)
  42. /* the DMA config has stream and channel, such as on STM32F4xx */
  43. struct {
  44. DMA_INSTANCE_TYPE *Instance;
  45. rt_uint32_t channel;
  46. } stream_channel;
  47. #endif
  48. #if defined(SOC_SERIES_STM32L4)
  49. /* the DMA config has channel and request, such as on STM32L4xx */
  50. struct {
  51. DMA_INSTANCE_TYPE *Instance;
  52. rt_uint32_t request;
  53. } channel_request;
  54. #endif
  55. } dma;
  56. rt_uint32_t dma_rcc;
  57. IRQn_Type dma_irq;
  58. };
  59. /* stm32 uart dirver class */
  60. struct stm32_uart
  61. {
  62. UART_HandleTypeDef handle;
  63. const struct stm32_uart_config *config;
  64. #ifdef RT_SERIAL_USING_DMA
  65. struct
  66. {
  67. DMA_HandleTypeDef handle;
  68. rt_size_t last_index;
  69. } dma;
  70. #endif
  71. struct rt_serial_device serial;
  72. };
  73. #endif /* __DRV_USART_H__ */