硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5292|回复: 1
收起左侧

[DMA] 注意STM32H7的DMA中断方式启动函数HAL_DMA_Start_IT会开启多个中断,自己实现中断要注意清标志

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106978
QQ
发表于 2019-1-17 15:44:07 | 显示全部楼层 |阅读模式


开启TC发送完成中断,TE传输错误中断,DME直接模式错误中断和FIFO错误中断

#define DMA_IT_TC                         ((uint32_t)DMA_SxCR_TCIE)
#define DMA_IT_HT                         ((uint32_t)DMA_SxCR_HTIE)
#define DMA_IT_TE                         ((uint32_t)DMA_SxCR_TEIE)
#define DMA_IT_DME                        ((uint32_t)DMA_SxCR_DMEIE)
#define DMA_IT_FE                         ((uint32_t)0x00000080U)


最后还有个HT半传输中断,这个根据用户时候注册的半传输回调函数决定。


  1. /**
  2.   * @brief  Start the DMA Transfer with interrupt enabled.
  3.   * @param  hdma:       pointer to a DMA_HandleTypeDef structure that contains
  4.   *                     the configuration information for the specified DMA Stream.
  5.   * @param  SrcAddress: The source memory Buffer address
  6.   * @param  DstAddress: The destination memory Buffer address
  7.   * @param  DataLength: The length of data to be transferred from source to destination
  8.   * @retval HAL status
  9.   */
  10. HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
  11. {
  12.   HAL_StatusTypeDef status = HAL_OK;

  13.   /* Check the parameters */
  14.   assert_param(IS_DMA_BUFFER_SIZE(DataLength));

  15.   /* Check the DMA peripheral handle */
  16.   if(hdma == NULL)
  17.   {
  18.     return HAL_ERROR;
  19.   }

  20.   /* Process locked */
  21.   __HAL_LOCK(hdma);

  22.   if(HAL_DMA_STATE_READY == hdma->State)
  23.   {
  24.     /* Change DMA peripheral state */
  25.     hdma->State = HAL_DMA_STATE_BUSY;

  26.     /* Initialize the error code */
  27.     hdma->ErrorCode = HAL_DMA_ERROR_NONE;

  28.     /* Disable the peripheral */
  29.     __HAL_DMA_DISABLE(hdma);

  30.     /* Configure the source, destination address and the data length */
  31.     DMA_SetConfig(hdma, SrcAddress, DstAddress, DataLength);

  32.     if(IS_D2_DMA_INSTANCE(hdma) != RESET) /* D2 Domain DMA : DMA1 or DMA2 */
  33.     {
  34.       /* Enable Common interrupts*/
  35.       MODIFY_REG(((DMA_Stream_TypeDef   *)hdma->Instance)->CR, (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME | DMA_IT_HT), (DMA_IT_TC | DMA_IT_TE | DMA_IT_DME));
  36.       ((DMA_Stream_TypeDef   *)hdma->Instance)->FCR |= DMA_IT_FE;

  37.       if(hdma->XferHalfCpltCallback != NULL)
  38.       {
  39.         /*Enable Half Transfer IT if corresponding Callback is set*/
  40.         ((DMA_Stream_TypeDef   *)hdma->Instance)->CR  |= DMA_IT_HT;
  41.       }
  42.     }
  43.     else /* D3 Domain BDMA */
  44.     {
  45.       /* Enable Common interrupts*/
  46.       MODIFY_REG(((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR, (BDMA_CCR_TCIE | BDMA_CCR_HTIE | BDMA_CCR_TEIE), (BDMA_CCR_TCIE | BDMA_CCR_TEIE));

  47.       if(hdma->XferHalfCpltCallback != NULL)
  48.       {
  49.         /*Enable Half Transfer IT if corresponding Callback is set*/
  50.         ((BDMA_Channel_TypeDef   *)hdma->Instance)->CCR  |= BDMA_CCR_HTIE;
  51.       }
  52.     }

  53.     /* Check if DMAMUX Synchronization is enabled*/
  54.     if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
  55.     {
  56.       /* Enable DMAMUX sync overrun IT*/
  57.       hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
  58.     }

  59.     if(hdma->DMAmuxRequestGen != 0U)
  60.     {
  61.       /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
  62.       /* enable the request gen overrun IT*/
  63.       hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;

  64.     }

  65.     /* Enable the Peripheral */
  66.     __HAL_DMA_ENABLE(hdma);
  67.   }
  68.   else
  69.   {
  70.     /* Process unlocked */
  71.     __HAL_UNLOCK(hdma);

  72.     /* Set the error code to busy */
  73.     hdma->ErrorCode = HAL_DMA_ERROR_BUSY;

  74.     /* Return error status */
  75.     status = HAL_ERROR;
  76.   }

  77.   return status;
  78. }
复制代码







回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106978
QQ
 楼主| 发表于 2019-1-18 00:41:03 | 显示全部楼层
补充:
同步溢出中断和请求发生器溢出中断也会被使能,如果使用了
  1. /* Check if DMAMUX Synchronization is enabled*/
  2.     if((hdma->DMAmuxChannel->CCR & DMAMUX_CxCR_SE) != 0U)
  3.     {
  4.       /* Enable DMAMUX sync overrun IT*/
  5.       hdma->DMAmuxChannel->CCR |= DMAMUX_CxCR_SOIE;
  6.     }

  7.     if(hdma->DMAmuxRequestGen != 0U)
  8.     {
  9.       /* if using DMAMUX request generator, enable the DMAMUX request generator overrun IT*/
  10.       /* enable the request gen overrun IT*/
  11.       hdma->DMAmuxRequestGen->RGCR |= DMAMUX_RGxCR_OIE;

  12.     }
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-13 00:53 , Processed in 0.154168 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表