2.main.c修改
需要注意的是,STM32的双缓存机制的设置函数理论上为HAL_DMAEx_MultiBufferStart_IT(),但是使用该函数无法进行缓冲区的切换,可能是官方文档存在一定BUG。为此,我摸索出可以实现相关机制的配置代码如下:
void HAL_ADC_MutiM1ConvCpltCallback(DMA_HandleTypeDef *_hdma);
HAL_DMA_RegisterCallback((&hadc1)>DMA_Handle,HAL_DMA_XFER_M1CPLT_CB_ID,HAL_ADC_MutiM1ConvCpltCallback);
if (HAL_DMAEx_MultiBufferStart((&hadc1)->DMA_Handle,(uint32_t)&hadc1.Instance->DR,(uint32_t)buf0,(uint32_t)buf1,AD_BufferSize)!= HAL_OK){
printf("\r\n HAL_DMAEx_MultiBufferStart failed!");
}
if(HAL_ADC_Start(&hadc3)!=HAL_OK){
Error_Handler();
}
if(HAL_ADC_Start(&hadc2)!=HAL_OK){
Error_Handler();
}
if(HAL_ADCEx_MultiModeStart_DMA(&hadc1,(uint32_t*)buf0,AD_BufferSize)!=HAL_OK){
Error_Handler();
}
__HAL_DMA_ENABLE_IT(&hdma_adc1,DMA_IT_TC);
__HAL_DMA_DISABLE_IT(&hdma_adc1,DMA_IT_HT);
|