你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】STM32 DMA相关函数和类型

[复制链接]
STMCU小助手 发布时间:2022-3-28 22:00
01. DMA简介
DMA,全称为:Direct Memory Access,即直接存储器访问。DMA 传输方式无需 CPU 直接控制传输,也没有中断处理方式那样保留现场和恢复现场的过程,通过硬件为 RAM 与 I/O 设备开辟一条直接传送数据的通路,能使 CPU 的效率大为提高。

STM32F4 最多有 2 个 DMA 控制器(DMA1 和 DMA2),共 16 个数据流(每个控制器 8 个),每一个 DMA 控制器都用于管理一个或多个外设的存储器访问请求。每个数据流总共可以有多达 8个通道(或称请求)。每个数据流通道都有一个仲裁器,用于处理 DMA 请求间的优先级。

02. 相关类型
DMA Init structure definition

  1. /**
  2.   * @brief  DMA Init structure definition
  3.   */

  4. typedef struct
  5. {
  6.   uint32_t DMA_Channel;            /*!< Specifies the channel used for the specified stream.
  7.                                         This parameter can be a value of @ref DMA_channel */

  8.   uint32_t DMA_PeripheralBaseAddr; /*!< Specifies the peripheral base address for DMAy Streamx. */

  9.   uint32_t DMA_Memory0BaseAddr;    /*!< Specifies the memory 0 base address for DMAy Streamx.
  10.                                         This memory is the default memory used when double buffer mode is
  11.                                         not enabled. */

  12.   uint32_t DMA_DIR;                /*!< Specifies if the data will be transferred from memory to peripheral,
  13.                                         from memory to memory or from peripheral to memory.
  14.                                         This parameter can be a value of @ref DMA_data_transfer_direction */

  15.   uint32_t DMA_BufferSize;         /*!< Specifies the buffer size, in data unit, of the specified Stream.
  16.                                         The data unit is equal to the configuration set in DMA_PeripheralDataSize
  17.                                         or DMA_MemoryDataSize members depending in the transfer direction. */

  18.   uint32_t DMA_PeripheralInc;      /*!< Specifies whether the Peripheral address register should be incremented or not.
  19.                                         This parameter can be a value of @ref DMA_peripheral_incremented_mode */

  20.   uint32_t DMA_MemoryInc;          /*!< Specifies whether the memory address register should be incremented or not.
  21.                                         This parameter can be a value of @ref DMA_memory_incremented_mode */

  22.   uint32_t DMA_PeripheralDataSize; /*!< Specifies the Peripheral data width.
  23.                                         This parameter can be a value of @ref DMA_peripheral_data_size */

  24.   uint32_t DMA_MemoryDataSize;     /*!< Specifies the Memory data width.
  25.                                         This parameter can be a value of @ref DMA_memory_data_size */

  26.   uint32_t DMA_Mode;               /*!< Specifies the operation mode of the DMAy Streamx.
  27.                                         This parameter can be a value of @ref DMA_circular_normal_mode
  28.                                         @note The circular buffer mode cannot be used if the memory-to-memory
  29.                                               data transfer is configured on the selected Stream */

  30.   uint32_t DMA_Priority;           /*!< Specifies the software priority for the DMAy Streamx.
  31.                                         This parameter can be a value of @ref DMA_priority_level */

  32.   uint32_t DMA_FIFOMode;          /*!< Specifies if the FIFO mode or Direct mode will be used for the specified Stream.
  33.                                         This parameter can be a value of @ref DMA_fifo_direct_mode
  34.                                         @note The Direct mode (FIFO mode disabled) cannot be used if the
  35.                                                memory-to-memory data transfer is configured on the selected Stream */

  36.   uint32_t DMA_FIFOThreshold;      /*!< Specifies the FIFO threshold level.
  37.                                         This parameter can be a value of @ref DMA_fifo_threshold_level */

  38.   uint32_t DMA_MemoryBurst;        /*!< Specifies the Burst transfer configuration for the memory transfers.
  39.                                         It specifies the amount of data to be transferred in a single non interruptable
  40.                                         transaction. This parameter can be a value of @ref DMA_memory_burst
  41.                                         @note The burst mode is possible only if the address Increment mode is enabled. */

  42.   uint32_t DMA_PeripheralBurst;    /*!< Specifies the Burst transfer configuration for the peripheral transfers.
  43.                                         It specifies the amount of data to be transferred in a single non interruptable
  44.                                         transaction. This parameter can be a value of @ref DMA_peripheral_burst
  45.                                         @note The burst mode is possible only if the address Increment mode is enabled. */  
  46. }DMA_InitTypeDef;
复制代码

DMA_Exported_Constants

  1. ** @defgroup DMA_Exported_Constants
  2.   * @{
  3.   */

  4. #define IS_DMA_ALL_PERIPH(PERIPH) (((PERIPH) == DMA1_Stream0) || \
  5.                                    ((PERIPH) == DMA1_Stream1) || \
  6.                                    ((PERIPH) == DMA1_Stream2) || \
  7.                                    ((PERIPH) == DMA1_Stream3) || \
  8.                                    ((PERIPH) == DMA1_Stream4) || \
  9.                                    ((PERIPH) == DMA1_Stream5) || \
  10.                                    ((PERIPH) == DMA1_Stream6) || \
  11.                                    ((PERIPH) == DMA1_Stream7) || \
  12.                                    ((PERIPH) == DMA2_Stream0) || \
  13.                                    ((PERIPH) == DMA2_Stream1) || \
  14.                                    ((PERIPH) == DMA2_Stream2) || \
  15.                                    ((PERIPH) == DMA2_Stream3) || \
  16.                                    ((PERIPH) == DMA2_Stream4) || \
  17.                                    ((PERIPH) == DMA2_Stream5) || \
  18.                                    ((PERIPH) == DMA2_Stream6) || \
  19.                                    ((PERIPH) == DMA2_Stream7))

  20. #define IS_DMA_ALL_CONTROLLER(CONTROLLER) (((CONTROLLER) == DMA1) || \
  21.                                            ((CONTROLLER) == DMA2))
复制代码

DMA_channel


  1. /** @defgroup DMA_channel
  2.   * @{
  3.   */
  4. #define DMA_Channel_0                     ((uint32_t)0x00000000)
  5. #define DMA_Channel_1                     ((uint32_t)0x02000000)
  6. #define DMA_Channel_2                     ((uint32_t)0x04000000)
  7. #define DMA_Channel_3                     ((uint32_t)0x06000000)
  8. #define DMA_Channel_4                     ((uint32_t)0x08000000)
  9. #define DMA_Channel_5                     ((uint32_t)0x0A000000)
  10. #define DMA_Channel_6                     ((uint32_t)0x0C000000)
  11. #define DMA_Channel_7                     ((uint32_t)0x0E000000)

  12. #define IS_DMA_CHANNEL(CHANNEL) (((CHANNEL) == DMA_Channel_0) || \
  13.                                  ((CHANNEL) == DMA_Channel_1) || \
  14.                                  ((CHANNEL) == DMA_Channel_2) || \
  15.                                  ((CHANNEL) == DMA_Channel_3) || \
  16.                                  ((CHANNEL) == DMA_Channel_4) || \
  17.                                  ((CHANNEL) == DMA_Channel_5) || \
  18.                                  ((CHANNEL) == DMA_Channel_6) || \
  19.                                  ((CHANNEL) == DMA_Channel_7))
复制代码

DMA_data_transfer_direction

  1. /** @defgroup DMA_data_transfer_direction
  2.   * @{
  3.   */
  4. #define DMA_DIR_PeripheralToMemory        ((uint32_t)0x00000000)
  5. #define DMA_DIR_MemoryToPeripheral        ((uint32_t)0x00000040)
  6. #define DMA_DIR_MemoryToMemory            ((uint32_t)0x00000080)

  7. #define IS_DMA_DIRECTION(DIRECTION) (((DIRECTION) == DMA_DIR_PeripheralToMemory ) || \
  8.                                      ((DIRECTION) == DMA_DIR_MemoryToPeripheral)  || \
  9.                                      ((DIRECTION) == DMA_DIR_MemoryToMemory))
复制代码

DMA_data_buffer_size

  1. /** @defgroup DMA_data_buffer_size
  2.   * @{
  3.   */
  4. #define IS_DMA_BUFFER_SIZE(SIZE) (((SIZE) >= 0x1) && ((SIZE) < 0x10000))
  5. 1
  6. 2
  7. 3
  8. 4
  9. DMA_peripheral_incremented_mode

  10. /** @defgroup DMA_peripheral_incremented_mode
  11.   * @{
  12.   */
  13. #define DMA_PeripheralInc_Enable          ((uint32_t)0x00000200)
  14. #define DMA_PeripheralInc_Disable         ((uint32_t)0x00000000)

  15. #define IS_DMA_PERIPHERAL_INC_STATE(STATE) (((STATE) == DMA_PeripheralInc_Enable) || \
  16.                                             ((STATE) == DMA_PeripheralInc_Disable))
复制代码

DMA_memory_incremented_mode
  1. /** @defgroup DMA_memory_incremented_mode
  2.   * @{
  3.   */
  4. #define DMA_MemoryInc_Enable              ((uint32_t)0x00000400)
  5. #define DMA_MemoryInc_Disable             ((uint32_t)0x00000000)

  6. #define IS_DMA_MEMORY_INC_STATE(STATE) (((STATE) == DMA_MemoryInc_Enable) || \
  7.                                         ((STATE) == DMA_MemoryInc_Disable))
复制代码

DMA_peripheral_data_size
  1. /** @defgroup DMA_peripheral_data_size
  2.   * @{
  3.   */
  4. #define DMA_PeripheralDataSize_Byte       ((uint32_t)0x00000000)
  5. #define DMA_PeripheralDataSize_HalfWord   ((uint32_t)0x00000800)
  6. #define DMA_PeripheralDataSize_Word       ((uint32_t)0x00001000)

  7. #define IS_DMA_PERIPHERAL_DATA_SIZE(SIZE) (((SIZE) == DMA_PeripheralDataSize_Byte)  || \
  8.                                            ((SIZE) == DMA_PeripheralDataSize_HalfWord) || \
  9.                                            ((SIZE) == DMA_PeripheralDataSize_Word))
复制代码

DMA_memory_data_size
  1. /** @defgroup DMA_memory_data_size
  2.   * @{
  3.   */
  4. #define DMA_MemoryDataSize_Byte           ((uint32_t)0x00000000)
  5. #define DMA_MemoryDataSize_HalfWord       ((uint32_t)0x00002000)
  6. #define DMA_MemoryDataSize_Word           ((uint32_t)0x00004000)

  7. #define IS_DMA_MEMORY_DATA_SIZE(SIZE) (((SIZE) == DMA_MemoryDataSize_Byte)  || \
  8.                                        ((SIZE) == DMA_MemoryDataSize_HalfWord) || \
  9.                                        ((SIZE) == DMA_MemoryDataSize_Word ))
复制代码

DMA_circular_normal_mode

  1. /** @defgroup DMA_circular_normal_mode
  2.   * @{
  3.   */
  4. #define DMA_Mode_Normal                   ((uint32_t)0x00000000)
  5. #define DMA_Mode_Circular                 ((uint32_t)0x00000100)

  6. #define IS_DMA_MODE(MODE) (((MODE) == DMA_Mode_Normal ) || \
  7.                            ((MODE) == DMA_Mode_Circular))
复制代码

DMA_priority_level


  1. /** @defgroup DMA_priority_level
  2.   * @{
  3.   */
  4. #define DMA_Priority_Low                  ((uint32_t)0x00000000)
  5. #define DMA_Priority_Medium               ((uint32_t)0x00010000)
  6. #define DMA_Priority_High                 ((uint32_t)0x00020000)
  7. #define DMA_Priority_VeryHigh             ((uint32_t)0x00030000)

  8. #define IS_DMA_PRIORITY(PRIORITY) (((PRIORITY) == DMA_Priority_Low )   || \
  9.                                    ((PRIORITY) == DMA_Priority_Medium) || \
  10.                                    ((PRIORITY) == DMA_Priority_High)   || \
  11.                                    ((PRIORITY) == DMA_Priority_VeryHigh))
复制代码

DMA_fifo_direct_mode
  1. /** @defgroup DMA_fifo_direct_mode
  2.   * @{
  3.   */
  4. #define DMA_FIFOMode_Disable              ((uint32_t)0x00000000)
  5. #define DMA_FIFOMode_Enable               ((uint32_t)0x00000004)

  6. #define IS_DMA_FIFO_MODE_STATE(STATE) (((STATE) == DMA_FIFOMode_Disable ) || \
  7.                                        ((STATE) == DMA_FIFOMode_Enable))
复制代码

DMA_fifo_threshold_level


  1. /** @defgroup DMA_fifo_threshold_level
  2.   * @{
  3.   */
  4. #define DMA_FIFOThreshold_1QuarterFull    ((uint32_t)0x00000000)
  5. #define DMA_FIFOThreshold_HalfFull        ((uint32_t)0x00000001)
  6. #define DMA_FIFOThreshold_3QuartersFull   ((uint32_t)0x00000002)
  7. #define DMA_FIFOThreshold_Full            ((uint32_t)0x00000003)

  8. #define IS_DMA_FIFO_THRESHOLD(THRESHOLD) (((THRESHOLD) == DMA_FIFOThreshold_1QuarterFull ) || \
  9.                                           ((THRESHOLD) == DMA_FIFOThreshold_HalfFull)      || \
  10.                                           ((THRESHOLD) == DMA_FIFOThreshold_3QuartersFull) || \
  11.                                           ((THRESHOLD) == DMA_FIFOThreshold_Full))
复制代码

DMA_memory_burst


  1. /** @defgroup DMA_memory_burst
  2.   * @{
  3.   */
  4. #define DMA_MemoryBurst_Single            ((uint32_t)0x00000000)
  5. #define DMA_MemoryBurst_INC4              ((uint32_t)0x00800000)  
  6. #define DMA_MemoryBurst_INC8              ((uint32_t)0x01000000)
  7. #define DMA_MemoryBurst_INC16             ((uint32_t)0x01800000)

  8. #define IS_DMA_MEMORY_BURST(BURST) (((BURST) == DMA_MemoryBurst_Single) || \
  9.                                     ((BURST) == DMA_MemoryBurst_INC4)  || \
  10.                                     ((BURST) == DMA_MemoryBurst_INC8)  || \
  11.                                     ((BURST) == DMA_MemoryBurst_INC16))
复制代码

DMA_peripheral_burst

  1. /** @defgroup DMA_peripheral_burst
  2.   * @{
  3.   */
  4. #define DMA_PeripheralBurst_Single        ((uint32_t)0x00000000)
  5. #define DMA_PeripheralBurst_INC4          ((uint32_t)0x00200000)  
  6. #define DMA_PeripheralBurst_INC8          ((uint32_t)0x00400000)
  7. #define DMA_PeripheralBurst_INC16         ((uint32_t)0x00600000)

  8. #define IS_DMA_PERIPHERAL_BURST(BURST) (((BURST) == DMA_PeripheralBurst_Single) || \
  9.                                         ((BURST) == DMA_PeripheralBurst_INC4)  || \
  10.                                         ((BURST) == DMA_PeripheralBurst_INC8)  || \
  11.                                         ((BURST) == DMA_PeripheralBurst_INC16))
复制代码

DMA_fifo_status_level

  1. /** @defgroup DMA_fifo_status_level
  2.   * @{
  3.   */
  4. #define DMA_FIFOStatus_Less1QuarterFull   ((uint32_t)0x00000000 << 3)
  5. #define DMA_FIFOStatus_1QuarterFull       ((uint32_t)0x00000001 << 3)
  6. #define DMA_FIFOStatus_HalfFull           ((uint32_t)0x00000002 << 3)
  7. #define DMA_FIFOStatus_3QuartersFull      ((uint32_t)0x00000003 << 3)
  8. #define DMA_FIFOStatus_Empty              ((uint32_t)0x00000004 << 3)
  9. #define DMA_FIFOStatus_Full               ((uint32_t)0x00000005 << 3)

  10. #define IS_DMA_FIFO_STATUS(STATUS) (((STATUS) == DMA_FIFOStatus_Less1QuarterFull ) || \
  11.                                     ((STATUS) == DMA_FIFOStatus_HalfFull)          || \
  12.                                     ((STATUS) == DMA_FIFOStatus_1QuarterFull)      || \
  13.                                     ((STATUS) == DMA_FIFOStatus_3QuartersFull)     || \
  14.                                     ((STATUS) == DMA_FIFOStatus_Full)              || \
  15.                                     ((STATUS) == DMA_FIFOStatus_Empty))
复制代码

DMA_flags_definition

  1. /** @defgroup DMA_flags_definition
  2.   * @{
  3.   */
  4. #define DMA_FLAG_FEIF0                    ((uint32_t)0x10800001)
  5. #define DMA_FLAG_DMEIF0                   ((uint32_t)0x10800004)
  6. #define DMA_FLAG_TEIF0                    ((uint32_t)0x10000008)
  7. #define DMA_FLAG_HTIF0                    ((uint32_t)0x10000010)
  8. #define DMA_FLAG_TCIF0                    ((uint32_t)0x10000020)
  9. #define DMA_FLAG_FEIF1                    ((uint32_t)0x10000040)
  10. #define DMA_FLAG_DMEIF1                   ((uint32_t)0x10000100)
  11. #define DMA_FLAG_TEIF1                    ((uint32_t)0x10000200)
  12. #define DMA_FLAG_HTIF1                    ((uint32_t)0x10000400)
  13. #define DMA_FLAG_TCIF1                    ((uint32_t)0x10000800)
  14. #define DMA_FLAG_FEIF2                    ((uint32_t)0x10010000)
  15. #define DMA_FLAG_DMEIF2                   ((uint32_t)0x10040000)
  16. #define DMA_FLAG_TEIF2                    ((uint32_t)0x10080000)
  17. #define DMA_FLAG_HTIF2                    ((uint32_t)0x10100000)
  18. #define DMA_FLAG_TCIF2                    ((uint32_t)0x10200000)
  19. #define DMA_FLAG_FEIF3                    ((uint32_t)0x10400000)
  20. #define DMA_FLAG_DMEIF3                   ((uint32_t)0x11000000)
  21. #define DMA_FLAG_TEIF3                    ((uint32_t)0x12000000)
  22. #define DMA_FLAG_HTIF3                    ((uint32_t)0x14000000)
  23. #define DMA_FLAG_TCIF3                    ((uint32_t)0x18000000)
  24. #define DMA_FLAG_FEIF4                    ((uint32_t)0x20000001)
  25. #define DMA_FLAG_DMEIF4                   ((uint32_t)0x20000004)
  26. #define DMA_FLAG_TEIF4                    ((uint32_t)0x20000008)
  27. #define DMA_FLAG_HTIF4                    ((uint32_t)0x20000010)
  28. #define DMA_FLAG_TCIF4                    ((uint32_t)0x20000020)
  29. #define DMA_FLAG_FEIF5                    ((uint32_t)0x20000040)
  30. #define DMA_FLAG_DMEIF5                   ((uint32_t)0x20000100)
  31. #define DMA_FLAG_TEIF5                    ((uint32_t)0x20000200)
  32. #define DMA_FLAG_HTIF5                    ((uint32_t)0x20000400)
  33. #define DMA_FLAG_TCIF5                    ((uint32_t)0x20000800)
  34. #define DMA_FLAG_FEIF6                    ((uint32_t)0x20010000)
  35. #define DMA_FLAG_DMEIF6                   ((uint32_t)0x20040000)
  36. #define DMA_FLAG_TEIF6                    ((uint32_t)0x20080000)
  37. #define DMA_FLAG_HTIF6                    ((uint32_t)0x20100000)
  38. #define DMA_FLAG_TCIF6                    ((uint32_t)0x20200000)
  39. #define DMA_FLAG_FEIF7                    ((uint32_t)0x20400000)
  40. #define DMA_FLAG_DMEIF7                   ((uint32_t)0x21000000)
  41. #define DMA_FLAG_TEIF7                    ((uint32_t)0x22000000)
  42. #define DMA_FLAG_HTIF7                    ((uint32_t)0x24000000)
  43. #define DMA_FLAG_TCIF7                    ((uint32_t)0x28000000)

  44. #define IS_DMA_CLEAR_FLAG(FLAG) ((((FLAG) & 0x30000000) != 0x30000000) && (((FLAG) & 0x30000000) != 0) && \
  45.                                  (((FLAG) & 0xC002F082) == 0x00) && ((FLAG) != 0x00))

  46. #define IS_DMA_GET_FLAG(FLAG) (((FLAG) == DMA_FLAG_TCIF0)  || ((FLAG) == DMA_FLAG_HTIF0)  || \
  47.                                ((FLAG) == DMA_FLAG_TEIF0)  || ((FLAG) == DMA_FLAG_DMEIF0) || \
  48.                                ((FLAG) == DMA_FLAG_FEIF0)  || ((FLAG) == DMA_FLAG_TCIF1)  || \
  49.                                ((FLAG) == DMA_FLAG_HTIF1)  || ((FLAG) == DMA_FLAG_TEIF1)  || \
  50.                                ((FLAG) == DMA_FLAG_DMEIF1) || ((FLAG) == DMA_FLAG_FEIF1)  || \
  51.                                ((FLAG) == DMA_FLAG_TCIF2)  || ((FLAG) == DMA_FLAG_HTIF2)  || \
  52.                                ((FLAG) == DMA_FLAG_TEIF2)  || ((FLAG) == DMA_FLAG_DMEIF2) || \
  53.                                ((FLAG) == DMA_FLAG_FEIF2)  || ((FLAG) == DMA_FLAG_TCIF3)  || \
  54.                                ((FLAG) == DMA_FLAG_HTIF3)  || ((FLAG) == DMA_FLAG_TEIF3)  || \
  55.                                ((FLAG) == DMA_FLAG_DMEIF3) || ((FLAG) == DMA_FLAG_FEIF3)  || \
  56.                                ((FLAG) == DMA_FLAG_TCIF4)  || ((FLAG) == DMA_FLAG_HTIF4)  || \
  57.                                ((FLAG) == DMA_FLAG_TEIF4)  || ((FLAG) == DMA_FLAG_DMEIF4) || \
  58.                                ((FLAG) == DMA_FLAG_FEIF4)  || ((FLAG) == DMA_FLAG_TCIF5)  || \
  59.                                ((FLAG) == DMA_FLAG_HTIF5)  || ((FLAG) == DMA_FLAG_TEIF5)  || \
  60.                                ((FLAG) == DMA_FLAG_DMEIF5) || ((FLAG) == DMA_FLAG_FEIF5)  || \
  61.                                ((FLAG) == DMA_FLAG_TCIF6)  || ((FLAG) == DMA_FLAG_HTIF6)  || \
  62.                                ((FLAG) == DMA_FLAG_TEIF6)  || ((FLAG) == DMA_FLAG_DMEIF6) || \
  63.                                ((FLAG) == DMA_FLAG_FEIF6)  || ((FLAG) == DMA_FLAG_TCIF7)  || \
  64.                                ((FLAG) == DMA_FLAG_HTIF7)  || ((FLAG) == DMA_FLAG_TEIF7)  || \
  65.                                ((FLAG) == DMA_FLAG_DMEIF7) || ((FLAG) == DMA_FLAG_FEIF7))
复制代码

DMA_interrupt_enable_definitions

  1. /** @defgroup DMA_interrupt_enable_definitions
  2.   * @{
  3.   */
  4. #define DMA_IT_TC                         ((uint32_t)0x00000010)
  5. #define DMA_IT_HT                         ((uint32_t)0x00000008)
  6. #define DMA_IT_TE                         ((uint32_t)0x00000004)
  7. #define DMA_IT_DME                        ((uint32_t)0x00000002)
  8. #define DMA_IT_FE                         ((uint32_t)0x00000080)

  9. #define IS_DMA_CONFIG_IT(IT) ((((IT) & 0xFFFFFF61) == 0x00) && ((IT) != 0x00))
复制代码

DMA_interrupts_definitions

  1. /** @defgroup DMA_interrupts_definitions
  2.   * @{
  3.   */
  4. #define DMA_IT_FEIF0                      ((uint32_t)0x90000001)
  5. #define DMA_IT_DMEIF0                     ((uint32_t)0x10001004)
  6. #define DMA_IT_TEIF0                      ((uint32_t)0x10002008)
  7. #define DMA_IT_HTIF0                      ((uint32_t)0x10004010)
  8. #define DMA_IT_TCIF0                      ((uint32_t)0x10008020)
  9. #define DMA_IT_FEIF1                      ((uint32_t)0x90000040)
  10. #define DMA_IT_DMEIF1                     ((uint32_t)0x10001100)
  11. #define DMA_IT_TEIF1                      ((uint32_t)0x10002200)
  12. #define DMA_IT_HTIF1                      ((uint32_t)0x10004400)
  13. #define DMA_IT_TCIF1                      ((uint32_t)0x10008800)
  14. #define DMA_IT_FEIF2                      ((uint32_t)0x90010000)
  15. #define DMA_IT_DMEIF2                     ((uint32_t)0x10041000)
  16. #define DMA_IT_TEIF2                      ((uint32_t)0x10082000)
  17. #define DMA_IT_HTIF2                      ((uint32_t)0x10104000)
  18. #define DMA_IT_TCIF2                      ((uint32_t)0x10208000)
  19. #define DMA_IT_FEIF3                      ((uint32_t)0x90400000)
  20. #define DMA_IT_DMEIF3                     ((uint32_t)0x11001000)
  21. #define DMA_IT_TEIF3                      ((uint32_t)0x12002000)
  22. #define DMA_IT_HTIF3                      ((uint32_t)0x14004000)
  23. #define DMA_IT_TCIF3                      ((uint32_t)0x18008000)
  24. #define DMA_IT_FEIF4                      ((uint32_t)0xA0000001)
  25. #define DMA_IT_DMEIF4                     ((uint32_t)0x20001004)
  26. #define DMA_IT_TEIF4                      ((uint32_t)0x20002008)
  27. #define DMA_IT_HTIF4                      ((uint32_t)0x20004010)
  28. #define DMA_IT_TCIF4                      ((uint32_t)0x20008020)
  29. #define DMA_IT_FEIF5                      ((uint32_t)0xA0000040)
  30. #define DMA_IT_DMEIF5                     ((uint32_t)0x20001100)
  31. #define DMA_IT_TEIF5                      ((uint32_t)0x20002200)
  32. #define DMA_IT_HTIF5                      ((uint32_t)0x20004400)
  33. #define DMA_IT_TCIF5                      ((uint32_t)0x20008800)
  34. #define DMA_IT_FEIF6                      ((uint32_t)0xA0010000)
  35. #define DMA_IT_DMEIF6                     ((uint32_t)0x20041000)
  36. #define DMA_IT_TEIF6                      ((uint32_t)0x20082000)
  37. #define DMA_IT_HTIF6                      ((uint32_t)0x20104000)
  38. #define DMA_IT_TCIF6                      ((uint32_t)0x20208000)
  39. #define DMA_IT_FEIF7                      ((uint32_t)0xA0400000)
  40. #define DMA_IT_DMEIF7                     ((uint32_t)0x21001000)
  41. #define DMA_IT_TEIF7                      ((uint32_t)0x22002000)
  42. #define DMA_IT_HTIF7                      ((uint32_t)0x24004000)
  43. #define DMA_IT_TCIF7                      ((uint32_t)0x28008000)

  44. #define IS_DMA_CLEAR_IT(IT) ((((IT) & 0x30000000) != 0x30000000) && \
  45.                              (((IT) & 0x30000000) != 0) && ((IT) != 0x00) && \
  46.                              (((IT) & 0x40820082) == 0x00))

  47. #define IS_DMA_GET_IT(IT) (((IT) == DMA_IT_TCIF0) || ((IT) == DMA_IT_HTIF0)  || \
  48.                            ((IT) == DMA_IT_TEIF0) || ((IT) == DMA_IT_DMEIF0) || \
  49.                            ((IT) == DMA_IT_FEIF0) || ((IT) == DMA_IT_TCIF1)  || \
  50.                            ((IT) == DMA_IT_HTIF1) || ((IT) == DMA_IT_TEIF1)  || \
  51.                            ((IT) == DMA_IT_DMEIF1)|| ((IT) == DMA_IT_FEIF1)  || \
  52.                            ((IT) == DMA_IT_TCIF2) || ((IT) == DMA_IT_HTIF2)  || \
  53.                            ((IT) == DMA_IT_TEIF2) || ((IT) == DMA_IT_DMEIF2) || \
  54.                            ((IT) == DMA_IT_FEIF2) || ((IT) == DMA_IT_TCIF3)  || \
  55.                            ((IT) == DMA_IT_HTIF3) || ((IT) == DMA_IT_TEIF3)  || \
  56.                            ((IT) == DMA_IT_DMEIF3)|| ((IT) == DMA_IT_FEIF3)  || \
  57.                            ((IT) == DMA_IT_TCIF4) || ((IT) == DMA_IT_HTIF4)  || \
  58.                            ((IT) == DMA_IT_TEIF4) || ((IT) == DMA_IT_DMEIF4) || \
  59.                            ((IT) == DMA_IT_FEIF4) || ((IT) == DMA_IT_TCIF5)  || \
  60.                            ((IT) == DMA_IT_HTIF5) || ((IT) == DMA_IT_TEIF5)  || \
  61.                            ((IT) == DMA_IT_DMEIF5)|| ((IT) == DMA_IT_FEIF5)  || \
  62.                            ((IT) == DMA_IT_TCIF6) || ((IT) == DMA_IT_HTIF6)  || \
  63.                            ((IT) == DMA_IT_TEIF6) || ((IT) == DMA_IT_DMEIF6) || \
  64.                            ((IT) == DMA_IT_FEIF6) || ((IT) == DMA_IT_TCIF7)  || \
  65.                            ((IT) == DMA_IT_HTIF7) || ((IT) == DMA_IT_TEIF7)  || \
  66.                            ((IT) == DMA_IT_DMEIF7)|| ((IT) == DMA_IT_FEIF7))
复制代码

DMA_peripheral_increment_offset

  1. /** @defgroup DMA_peripheral_increment_offset
  2.   * @{
  3.   */
  4. #define DMA_PINCOS_Psize                  ((uint32_t)0x00000000)
  5. #define DMA_PINCOS_WordAligned            ((uint32_t)0x00008000)

  6. #define IS_DMA_PINCOS_SIZE(SIZE) (((SIZE) == DMA_PINCOS_Psize) || \
  7.                                   ((SIZE) == DMA_PINCOS_WordAligned))
复制代码

controller_definitions
  1. /** @defgroup DMA_flow_controller_definitions
  2.   * @{
  3.   */
  4. #define DMA_FlowCtrl_Memory               ((uint32_t)0x00000000)
  5. #define DMA_FlowCtrl_Peripheral           ((uint32_t)0x00000020)

  6. #define IS_DMA_FLOW_CTRL(CTRL) (((CTRL) == DMA_FlowCtrl_Memory) || \
  7.                                 ((CTRL) == DMA_FlowCtrl_Peripheral))
复制代码

DMA_memory_targets_definitions

  1. /** @defgroup DMA_memory_targets_definitions
  2.   * @{
  3.   */
  4. #define DMA_Memory_0                      ((uint32_t)0x00000000)
  5. #define DMA_Memory_1                      ((uint32_t)0x00080000)

  6. #define IS_DMA_CURRENT_MEM(MEM) (((MEM) == DMA_Memory_0) || ((MEM) == DMA_Memory_1))
复制代码


03. 相关函数

  1. /* Exported macro ------------------------------------------------------------*/
  2. /* Exported functions --------------------------------------------------------*/

  3. /*  Function used to set the DMA configuration to the default reset state *****/
  4. void DMA_DeInit(DMA_Stream_TypeDef* DMAy_Streamx);

  5. /* Initialization and Configuration functions *********************************/
  6. void DMA_Init(DMA_Stream_TypeDef* DMAy_Streamx, DMA_InitTypeDef* DMA_InitStruct);
  7. void DMA_StructInit(DMA_InitTypeDef* DMA_InitStruct);
  8. void DMA_Cmd(DMA_Stream_TypeDef* DMAy_Streamx, FunctionalState NewState);

  9. /* Optional Configuration functions *******************************************/
  10. void DMA_PeriphIncOffsetSizeConfig(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_Pincos);
  11. void DMA_FlowControllerConfig(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_FlowCtrl);

  12. /* Data Counter functions *****************************************************/
  13. void DMA_SetCurrDataCounter(DMA_Stream_TypeDef* DMAy_Streamx, uint16_t Counter);
  14. uint16_t DMA_GetCurrDataCounter(DMA_Stream_TypeDef* DMAy_Streamx);

  15. /* Double Buffer mode functions ***********************************************/
  16. void DMA_DoubleBufferModeConfig(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t Memory1BaseAddr,
  17.                                 uint32_t DMA_CurrentMemory);
  18. void DMA_DoubleBufferModeCmd(DMA_Stream_TypeDef* DMAy_Streamx, FunctionalState NewState);
  19. void DMA_MemoryTargetConfig(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t MemoryBaseAddr,
  20.                             uint32_t DMA_MemoryTarget);
  21. uint32_t DMA_GetCurrentMemoryTarget(DMA_Stream_TypeDef* DMAy_Streamx);

  22. /* Interrupts and flags management functions **********************************/
  23. FunctionalState DMA_GetCmdStatus(DMA_Stream_TypeDef* DMAy_Streamx);
  24. uint32_t DMA_GetFIFOStatus(DMA_Stream_TypeDef* DMAy_Streamx);
  25. FlagStatus DMA_GetFlagStatus(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_FLAG);
  26. void DMA_ClearFlag(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_FLAG);
  27. void DMA_ITConfig(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_IT, FunctionalState NewState);
  28. ITStatus DMA_GetITStatus(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_IT);
  29. void DMA_ClearITPendingBit(DMA_Stream_TypeDef* DMAy_Streamx, uint32_t DMA_IT);

复制代码

04. 结构体封装

  1. /**
  2.   * @brief DMA Controller
  3.   */

  4. typedef struct
  5. {
  6.   __IO uint32_t CR;     /*!< DMA stream x configuration register      */
  7.   __IO uint32_t NDTR;   /*!< DMA stream x number of data register     */
  8.   __IO uint32_t PAR;    /*!< DMA stream x peripheral address register */
  9.   __IO uint32_t M0AR;   /*!< DMA stream x memory 0 address register   */
  10.   __IO uint32_t M1AR;   /*!< DMA stream x memory 1 address register   */
  11.   __IO uint32_t FCR;    /*!< DMA stream x FIFO control register       */
  12. } DMA_Stream_TypeDef;

  13. typedef struct
  14. {
  15.   __IO uint32_t LISR;   /*!< DMA low interrupt status register,      Address offset: 0x00 */
  16.   __IO uint32_t HISR;   /*!< DMA high interrupt status register,     Address offset: 0x04 */
  17.   __IO uint32_t LIFCR;  /*!< DMA low interrupt flag clear register,  Address offset: 0x08 */
  18.   __IO uint32_t HIFCR;  /*!< DMA high interrupt flag clear register, Address offset: 0x0C */
  19. } DMA_TypeDef;
复制代码




收藏 评论0 发布时间:2022-3-28 22:00

举报

0个回答

所属标签

相似分享

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版