drv_usart.h 1.9 KB

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