【iCore4 雙核心板_ARM】例程十一:DMA實驗——儲存器到儲存器的傳輸

XiaomaGee發表於2017-08-22

實驗原理:

  DAM(直接儲存器訪問)傳輸不需要佔用CPU,可以在儲存器至儲存器實現高速的資料

傳輸。本實驗採用DAM2控制器的資料流0,選用通道0進行資料傳輸。通過LED的顏色來

判斷傳輸是否成功。

實驗現象:

  實驗成功藍色LED燈閃爍,實驗失敗紅色LED燈閃爍。

核心程式碼:

int main(void)
{

  /* USER CODE BEGIN 1 */
    int i;

  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();

  /* USER CODE BEGIN 2 */
    dma.initialize();

    //²âÊÔDMA£¬²âÊԳɹ¦À¶µÆÉÁ˸£¬²âÊÔʧ°Ü£¬ºìµÆÉÁ˸
  /* Configure DMA request hdma_memtomem_dma2_stream0 on DMA2_Stream0 */
  hdma_memtomem_dma2_stream0.Instance = DMA2_Stream0;
  hdma_memtomem_dma2_stream0.Init.Channel = DMA_CHANNEL_0;
  hdma_memtomem_dma2_stream0.Init.Direction = DMA_MEMORY_TO_MEMORY;
  hdma_memtomem_dma2_stream0.Init.PeriphInc = DMA_PINC_ENABLE;
  hdma_memtomem_dma2_stream0.Init.MemInc = DMA_MINC_ENABLE;
  hdma_memtomem_dma2_stream0.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
  hdma_memtomem_dma2_stream0.Init.MemDataAlignment = DMA_PDATAALIGN_WORD;
  hdma_memtomem_dma2_stream0.Init.Mode = DMA_NORMAL;
  hdma_memtomem_dma2_stream0.Init.Priority = DMA_PRIORITY_HIGH;
  hdma_memtomem_dma2_stream0.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
  hdma_memtomem_dma2_stream0.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
  hdma_memtomem_dma2_stream0.Init.MemBurst = DMA_MBURST_SINGLE;
  hdma_memtomem_dma2_stream0.Init.PeriphBurst = DMA_PBURST_SINGLE;
  if(HAL_DMA_Init(&hdma_memtomem_dma2_stream0) != HAL_OK)
  {
    while(1);
  }
    
    HAL_DMA_Start(&hdma_memtomem_dma2_stream0,(unsigned long int)src_buffer,(unsigned long int)dst_buffer,(unsigned long int)BUFFER_SIZE);
    
    while(__HAL_DMA_GET_FLAG(&hdma_memtomem_dma2_stream0,DMA_FLAG_TCIF0_4) == SET);

    for(i = 0;i < BUFFER_SIZE;i++){
        if(dst_buffer[i] != src_buffer[i]){
            //²âÊÔʧ°Ü
            while(1){
                    HAL_Delay(500);
                    LED_RED_ON;
                    HAL_Delay(500);
                    LED_RED_OFF;
            }
        }
    }
  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
    //²âÊԳɹ¦
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */
        HAL_Delay(500);
        LED_BLUE_ON;
        HAL_Delay(500);
        LED_BLUE_OFF;    
  }
  /* USER CODE END 3 */

}

原始碼下載連結:

連結:http://pan.baidu.com/s/1cxtwaq 密碼:yvxw

iCore4連結:

 

相關文章