2019-08-19 05:52 AM
volatile uint32_t dbg_res = 0;
volatile bool isAdcWork = false;
static __attribute__((section(".adc_dma_buf"))) __attribute__((aligned(0x20))) int16_t s_pAlignedAdcBuffer[(1024 + 0x1f) & ~0x1f];
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)
{
if (hadc->Instance == ADC1)
{
//HAL_ADCEx_MultiModeStop_DMA(&hadc1);
dbg_res = HAL_ADC_Stop_DMA(hadc);
isAdcWork = false;
}
}
void HAL_ADC_ErrorCallback(ADC_HandleTypeDef *hadc){
dbg_res = 1;
}
void test_adc(){
uint8_t buf[64];
int len = 1;
volatile float adcf;
memset(&s_pAlignedAdcBuffer[0], 0xff, sizeof(s_pAlignedAdcBuffer));
SCB_CleanDCache_by_Addr((uint32_t*)&s_pAlignedAdcBuffer[0], sizeof(s_pAlignedAdcBuffer));
while(1){
if (!isAdcWork){
isAdcWork = true;
SCB_InvalidateDCache_by_Addr((uint32_t*)&s_pAlignedAdcBuffer[0], sizeof(s_pAlignedAdcBuffer)); // адре�? и размер д.б. выровнены до линии кеша 32хбайт
//HAL_ADCEx_MultiModeStart_DMA(&hadc1, (uint32_t*)&s_pAlignedAdcBuffer[0], 6);
dbg_res = HAL_ADC_Start_DMA(&hadc1,(uint32_t*)&s_pAlignedAdcBuffer[0], 6);
}
adcf = s_pAlignedAdcBuffer[0];
len = snprintf(buf, sizeof(buf), "%d.%03u\r\n", (int32_t)adcf, (uint32_t)(fabs(adcf)*1000)%1000);
HAL_UART_Transmit(&huart3, buf, len, HAL_MAX_DELAY);
HAL_Delay(1000);
}
}
Example project https://github.com/moggiozzi/stm32h7_adc_dma
I tried many combinations of settings, but still could not get it working ADC with DMA. HAL_ADC_ConvCpltCallback() called only once when use HAL_ADC_Start_DMA(). But it work correctly when I use HAL_ADCEx_MultiModeStart_DMA().
Chip: Y STM32H743ZIT6U (NUCLEO-743ZI board)
HAL: STM32Cube FW_H7 V1.5.0
2019-08-20 12:00 PM
HAL_ADC_Stop_DMA() function change cfgr register:
/ Disable ADC DMA (ADC DMA configuration of continous requests is kept) /
MODIFY_REG(hadc->Instance->CFGR, ADC_CFGR_DMNGT_0 |ADC_CFGR_DMNGT_1, 0UL);
This bits initialised in MX_ADC1_Init(), but not restored in HAL_ADC_Start_DMA().