硬汉嵌入式论坛

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

[DMA] MDMA的应用搞的还挺复杂的,想玩的溜,得花时间研究透才行

[复制链接]

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106989
QQ
发表于 2018-8-8 02:32:09 | 显示全部楼层 |阅读模式
看了下这个例子,整的还挺麻烦,不过MDMA的确是功能强不少,但是用起来不顺手。
QQ截图20180808023104.png

配置:
  1. /**
  2.   * @brief  Initialize the MDMA For repeat block transfer in linked list circular
  3.     with trigger set to DMA2D Transfer complete flag and trigger mode set to
  4.     repeat block transfer.
  5.   * @param  None
  6.   * @retval None
  7.   */
  8. static void MDMA_Config(void)
  9. {
  10.   uint32_t hal_status = HAL_OK;  
  11.   MDMA_LinkNodeConfTypeDef mdmaLinkNodeConfig;   
  12.    
  13.   /*##-1- Enable the MDMA clock ###############################################*/  
  14.   __HAL_RCC_MDMA_CLK_ENABLE();  
  15.   
  16.   /*##-2- Select the MDMA instance to be used : MDMA_Channel0 #################*/
  17.   MDMA_Handle.Instance = MDMA_Channel0;  
  18.   
  19.   /*##-3- Configure the MDMA for block transfer in HW request mode ############*/  
  20.   /*
  21.   Config the MDMA to copy the source image to the LCD frame buffer at the center
  22.   position with 180?rotation and mirror effect.
  23.   Each block corresponds to a line of the source/destination image.
  24.   The number of blocks corresponds to the number of lines of the image.
  25.   
  26.   The MDMA Request is set to DMA2D Transfer complete flag and the MDMA trigger Mode
  27.   is set to Repeat block mode. As consequence each DMA2D transfer complete event
  28.   (DMA2D has end copying an image to the Top-center of the LCD frame buffer ),
  29.   the MDMA will start a repeat block transfer which correspond of copying the DMA2D
  30.   image with 180?and rotation effect to the bottom-center of the LCD frame buffer.
  31.   */
  32.   
  33.   MDMA_Handle.Init.Request              = MDMA_REQUEST_DMA2D_TC;
  34.   MDMA_Handle.Init.TransferTriggerMode  = MDMA_REPEAT_BLOCK_TRANSFER;  
  35.   MDMA_Handle.Init.Priority             = MDMA_PRIORITY_HIGH;
  36.   MDMA_Handle.Init.Endianness           = MDMA_LITTLE_ENDIANNESS_PRESERVE;
  37.   MDMA_Handle.Init.DataAlignment        = MDMA_DATAALIGN_PACKENABLE;                           
  38.   MDMA_Handle.Init.SourceBurst          = MDMA_SOURCE_BURST_SINGLE;
  39.   MDMA_Handle.Init.DestBurst            = MDMA_DEST_BURST_SINGLE;
  40.   MDMA_Handle.Init.BufferTransferLength = 128;
  41.   
  42.   /* Source and Destination data size are word , 4 bytes that correspond to an ARGB8888 pixel 32 bpp */     
  43.   MDMA_Handle.Init.SourceDataSize       = MDMA_SRC_DATASIZE_WORD;
  44.   MDMA_Handle.Init.DestDataSize         = MDMA_DEST_DATASIZE_WORD;
  45.   
  46.   /* Source and Destination  Increment is word , 4 bytes that correspond to an ARGB8888 pixel 32 bpp */      
  47.   MDMA_Handle.Init.SourceInc            = MDMA_SRC_INC_WORD;
  48.   MDMA_Handle.Init.DestinationInc       = MDMA_DEST_INC_WORD;

  49.   /*Source Block address offset is set to LCD Offset as the source image is in the center of the LCD */   
  50.   MDMA_Handle.Init.SourceBlockAddressOffset  = (int32_t)LCD_Offset;
  51.   
  52.   /* Destination Block address offset is set in order to place the image in the center of the LCD frame buffer
  53.   the destination blocks are not contiguous. The LCD_Offset is = to LCD X size - image width
  54.   Knowing that the destination address is set to the first pixel address of the last line
  55.   in the destination image, the destination block offset allows to decrement the destination address
  56.   after each block in order to start the next block at previous line */      
  57.   MDMA_Handle.Init.DestBlockAddressOffset    = ((-2) * ((int32_t)(ARGB8888_BYTES_PER_PIXEL * IMAGE_WIDTH))) - ((int32_t)LCD_Offset);   
  58.   
  59.   /*##-4- Initialize the MDMA channel ##########################################*/  
  60.   hal_status = HAL_MDMA_Init(&MDMA_Handle);
  61.   
  62.   if(hal_status != HAL_OK)  
  63.   {
  64.     /* Initialization Error */
  65.     Error_Handler();
  66.   }

  67.   HAL_MDMA_ConfigPostRequestMask(&MDMA_Handle, 0, 0);
  68.   
  69.   /*##-5- Create Linked list Node ############################################*/
  70.   
  71.   /*
  72.      Create and add a linked list node that have the same parameters as the
  73.      initial transfer.
  74.      The purpose of the linked list node is to create a circular list. the MDMA
  75.      transfer will then loop infinitely. Each DMA2D Transfer complete flag will trig
  76.      a Node transfer ( a repeat block transfer) that correspond to a new image transfer
  77.   */
  78.   mdmaLinkNodeConfig.Init.Request              = MDMA_Handle.Init.Request;
  79.   mdmaLinkNodeConfig.Init.TransferTriggerMode  = MDMA_Handle.Init.TransferTriggerMode;
  80.   mdmaLinkNodeConfig.Init.Priority             = MDMA_Handle.Init.Priority;         
  81.   mdmaLinkNodeConfig.Init.Endianness           = MDMA_Handle.Init.Endianness;         
  82.   
  83.   mdmaLinkNodeConfig.Init.SourceInc            = MDMA_Handle.Init.SourceInc;     
  84.   mdmaLinkNodeConfig.Init.DestinationInc       = MDMA_Handle.Init.DestinationInc;
  85.   
  86.   mdmaLinkNodeConfig.Init.SourceDataSize       = MDMA_Handle.Init.SourceDataSize;      
  87.   mdmaLinkNodeConfig.Init.DestDataSize         = MDMA_Handle.Init.DestDataSize;        
  88.   mdmaLinkNodeConfig.Init.DataAlignment        = MDMA_Handle.Init.DataAlignment;                                 
  89.   mdmaLinkNodeConfig.Init.SourceBurst          = MDMA_Handle.Init.SourceBurst;         
  90.   mdmaLinkNodeConfig.Init.DestBurst            = MDMA_Handle.Init.DestBurst;           
  91.   mdmaLinkNodeConfig.Init.BufferTransferLength = MDMA_Handle.Init.BufferTransferLength;
  92.   
  93.   mdmaLinkNodeConfig.Init.SourceBlockAddressOffset  = MDMA_Handle.Init.SourceBlockAddressOffset;
  94.   mdmaLinkNodeConfig.Init.DestBlockAddressOffset    = MDMA_Handle.Init.DestBlockAddressOffset;
  95.   
  96.   mdmaLinkNodeConfig.PostRequestMaskAddress = 0;
  97.   mdmaLinkNodeConfig.PostRequestMaskData = 0;  
  98.   
  99.   /* Create Node*/  
  100.   mdmaLinkNodeConfig.SrcAddress      = dma2d_destination;
  101.   mdmaLinkNodeConfig.DstAddress      = mdma_destination;
  102.   mdmaLinkNodeConfig.BlockDataLength = IMAGE_WIDTH * ARGB8888_BYTES_PER_PIXEL;
  103.   mdmaLinkNodeConfig.BlockCount      = IMAGE_HEIGHT;

  104.   HAL_MDMA_LinkedList_CreateNode(&Xfer_Node, &mdmaLinkNodeConfig);
  105.   
  106.   /*Add created Node to the linkedlist */
  107.   HAL_MDMA_LinkedList_AddNode(&MDMA_Handle, &Xfer_Node, 0);
  108.   
  109.   /* Make the linked list circular */
  110.   HAL_MDMA_LinkedList_EnableCircularMode(&MDMA_Handle);
  111.   
  112.   /*
  113.     As the MDMA Node descriptor "Xfer_Node" is located in the D1 AXI-SRAM which
  114.     is cacheable, it is necessary to clean the data cache after creating the node
  115.     in order to make sure that the MDMA will load up to date data from the linked list node
  116.   */
  117.   SCB_CleanDCache_by_Addr((uint32_t *)&(Xfer_Node), sizeof(MDMA_LinkNodeTypeDef));
  118.   
  119.   /*##-6- Select Callbacks functions called after MDMA Repeat block Transfer complete and Transfer error */
  120.   HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_REPBLOCKCPLT_CB_ID, MDMA_RepeatBlockTransferCompleteCallback);
  121.   HAL_MDMA_RegisterCallback(&MDMA_Handle, HAL_MDMA_XFER_ERROR_CB_ID, MDMA_TransferErrorCallback);
  122.   
  123.   /*##-7- Configure NVIC for MDMA transfer complete/error interrupts ##########*/
  124.   /* Set Interrupt Group Priority */
  125.   HAL_NVIC_SetPriority(MDMA_IRQn, 0, 0);
  126.   
  127.   /* Enable the MDMA channel global Interrupt */
  128.   HAL_NVIC_EnableIRQ(MDMA_IRQn);  
  129.   

  130. }
复制代码


回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-13 09:48 , Processed in 0.164061 second(s), 28 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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