2017-03-25 110 views
0

我有一個STM32F769I-EVAL配置爲接收基於ST的AN4666代碼的8位並行數據。我期望發生的情況是:來自輸入設備的時鐘觸發輸入捕捉DMA並將數據寫入SDRAM,直到OC定時器中斷禁止傳輸。此時,我可以操縱SDRAM中的數據並將其傳輸到其他地方。但是,硬件配置完成並且啓用輸入捕捉後,會出現DMA傳輸錯誤。 HAL_DMA_IRQHandler函數中errorcode(6)的值表示設置了FIFO和傳輸錯誤標誌。根據我對datasheet(請參閱第261頁)的理解,這應該是不可能的,我認爲我錯誤地配置了某個設置,但是我仍然無法完成設置。我可以採取哪些措施來解決這個問題?STM32 DMA傳輸錯誤,同時設置FIFO和傳輸錯誤標誌

DMA配置:

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef *htim) 
{ 
    GPIO_InitTypeDef GPIO_InitStruct; 
    static DMA_HandleTypeDef hdma_tim; 

    /* TIMx clock enable */ 
    TIMx_CLK_ENABLE(); 

    /* Enable DMA clock */ 
    DMAx_CLK_ENABLE(); 

    /* Enable TIM input GPIO clock */ 
    TIMx_CHy_GPIOCLK_ENABLE(); 

    /* Configure input of TIMx_CHy on AF */ 
    GPIO_InitStruct.Pin = TIMx_CHy_PIN; 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 
    GPIO_InitStruct.Pull = GPIO_NOPULL; 
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; 
    GPIO_InitStruct.Alternate = GPIO_AF_TIMx; 
    HAL_GPIO_Init(TIMx_CHy_PORT, &GPIO_InitStruct); 

    /* Set the parameters to be configured */ 
    hdma_tim.Init.Channel = DMA_CHANNEL; 
    hdma_tim.Init.Direction = DMA_PERIPH_TO_MEMORY; 
    hdma_tim.Init.PeriphInc = DMA_PINC_DISABLE; 
    hdma_tim.Init.MemInc = DMA_MINC_ENABLE; 
    hdma_tim.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE ; /* Reading in GPIO PC[7:0]*/ 
    hdma_tim.Init.MemDataAlignment = DMA_MDATAALIGN_WORD ; 
    hdma_tim.Init.Mode = DMA_NORMAL; /* double memory buffer used */ 
    hdma_tim.Init.Priority = DMA_PRIORITY_HIGH; 
    hdma_tim.Init.FIFOMode = DMA_FIFOMODE_ENABLE; /* using FIFO mode since memory datasize=32bit and GPIO=8bits in our case */ 
    hdma_tim.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_1QUARTERFULL; /* flushing FIFO at each 32bit reception (4 data) */ 
    hdma_tim.Init.MemBurst = DMA_MBURST_SINGLE; 
    hdma_tim.Init.PeriphBurst = DMA_PBURST_SINGLE; 

    /* Set hdma_tim instance */ 
    hdma_tim.Instance = DMA_STREAM; 

    /* Link hdma_tim to hdma[CC1] */ 
    __HAL_LINKDMA(htim, hdma[TIMx_DMA_ID], hdma_tim); 

    /* Initialize TIMx DMA handle */ 
    HAL_DMA_Init(htim->hdma[TIMx_DMA_ID]); 

    /* NVIC configuration for TIMx output compare interrupt */ 
    HAL_NVIC_SetPriority(TIMx_IRQn, 0, 2); 
    HAL_NVIC_EnableIRQ(TIMx_IRQn); 

    /* Configure the NVIC for DMA        */ 
    /* NVIC configuration for DMA transfer complete interrupt */ 
    HAL_NVIC_SetPriority(TIMx_DMA_IRQn, 0, 0); 
    HAL_NVIC_EnableIRQ(TIMx_DMA_IRQn); 

} 

從主代碼:

/* Initialize SDRAM */ 
BSP_SDRAM_Init(); 

/* Configure the Data GPIO in input mode */ 
Data_GPIO_Config(); 

/* Set Timers instance */ 
TimHandle.Instance = TIMx; 

/* Initialize global Timer parameters */ 
TimHandle.Init.Period   = MAX_COUNTER; 
TimHandle.Init.Prescaler   = TIMx_PRESCALER - 1; 
TimHandle.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1; 
TimHandle.Init.CounterMode  = TIM_COUNTERMODE_UP; 
TimHandle.Init.RepetitionCounter = 0; 
if (HAL_TIM_Base_Init(&TimHandle) != HAL_OK) 
{ 
    /* Initialization Error */ 
    Error_Handler(); 
} 

//Initialize Timer "OC" channel for OC mode 
sOConfig.OCMode  = TIM_OCMODE_TIMING/*TIM_OCMODE_TOGGLE*/; 
sOConfig.OCPolarity = TIM_OCPOLARITY_HIGH; 
sOConfig.Pulse  = NB_COUNTER_CYCLE; 
sOConfig.OCNPolarity = TIM_OCPOLARITY_HIGH; 
sOConfig.OCFastMode = TIM_OCFAST_DISABLE; 
sOConfig.OCNIdleState = TIM_OCNIDLESTATE_RESET; 
sOConfig.OCIdleState = TIM_OCIDLESTATE_RESET; 
if (HAL_TIM_OC_ConfigChannel(&TimHandle, &sOConfig, TIMx_CHANNEL_OC) != HAL_OK) 
{ 
    //Configuration Error 
Error_Handler(); 
} 

/* Initialize Timer "IC" channel for IC mode  */ 
sICConfig.ICPolarity = CLK_LATCHING_DATA_EDGE; 
sICConfig.ICSelection = TIM_ICSELECTION_DIRECTTI; 
sICConfig.ICPrescaler = TIM_ICPSC_DIV1; 
sICConfig.ICFilter = TIM_IC_FILTER; /* filter the clock signal over/undershoot */ 
if (HAL_TIM_IC_ConfigChannel(&TimHandle, &sICConfig, TIMx_CHANNEL_IC) != HAL_OK) 
{ 
    /* Configuration Error */ 
    Error_Handler(); 
} 

/* Set the DMA memory0 conversion complete callback */ 
TimHandle.hdma[TIMx_DMA_ID]->XferCpltCallback = TransferComplete; 
/* Set the DMA memory1 conversion complete callback */ 
TimHandle.hdma[TIMx_DMA_ID]->XferM1CpltCallback = TransferComplete; 
/* Set the DMA error callback */ 
TimHandle.hdma[TIMx_DMA_ID]->XferErrorCallback = TransferError ; 

/* Update second memory address */ 
second_mem_address = (uint32_t)((SDRAM_BANK_ADDR + WRITE_READ_ADDR) + (DMA_MEM_BUFF_SIZE)); 

/* Start DMA multi buffer transfer */ 
if (HAL_DMAEx_MultiBufferStart_IT(TimHandle.hdma[TIMx_DMA_ID], GPIOx_IDR, (SDRAM_BANK_ADDR + WRITE_READ_ADDR), second_mem_address, DMA_MEM_BUFF_SIZE) != HAL_OK) 
{ 
    /* Transfer Error */ 
    Error_Handler(); 
} 

__HAL_TIM_ENABLE_DMA(&TimHandle, TIMx_DMA_CC); 

/* Enable the TIMx OC channel interrupt */ 
__HAL_TIM_ENABLE_IT(&TimHandle, TIMx_IT_OC); 
/* Enable the TIMX OC channel */ 
TIM_CCxChannelCmd(TimHandle.Instance, TIMx_CHANNEL_OC, TIM_CCx_ENABLE); 

/* Enable the TIMx IC channel */ 
TIM_CCxChannelCmd(TimHandle.Instance, TIMx_CHANNEL_IC, TIM_CCx_ENABLE); 

HAL_TIM_OC_Start(&TimHandle, TIMx_CHANNEL_OC); // enable counter 

/* processing while Timeout not reached */ 
while (timeout_flag == 0); 
+1

STlib HAL只是英國媒體報道,沒有任何好處。使用直接註冊編程。這樣你可以直接檢查狀態寄存器並檢查標誌的含義。使用調試器進行仔細檢查。 – Olaf

+0

如果我編寫自己的驅動程序,ST的HAL是否會改變狀態寄存器中的值?我可以在調試器中看到狀態寄存器,並且上述錯誤標誌在DMA_HISR中斷狀態寄存器中設置,但我不知道我應該尋找什麼來解決我所看到的問題。 – anOkCoder

+0

自從我第一次看到那個爛攤子以來,我並沒有和HAL一起工作。由於它聲稱是「硬件**抽象**層」,我會假設它。但是,它使調試和代碼複雜化。相反,將語音驅動程序中的硬件訪問封裝起來(無論如何,HAL與否都是最佳實踐)。 – Olaf

回答

1

該錯誤是由FIFO溢出條件而接收數據引起的。將FIFO閾值從1/4增加到完全停止發生傳輸錯誤。

cortex-M7引入了一個數據和指令緩存,可能會導致DMA傳輸問題,但我可以確認情況並非如此,更多信息請參考here