cancel
Showing results for 
Search instead for 
Did you mean: 

DMA to read multiple ADC Channels

APBashara
Associate II

I am trying to read multiple ADCs using DMA on a Nucleo H743ZI2. I currently have code that works, but it only works when my data buffer has a size of 32. This is fine when I was using two channels, but any more than that, it offsets the data, and I cannot know what index is what ADC Channel. If I change the size of the data buffer, then the code stops working the second I try and do anything other than assign variables. I am not sure why this is and have been fighting this issue for about a week; any help is much appreciated.

 

#define ADC_CHANNELS 3 
uint16_t adcResultsDMA[ADC_CHANNELS]; 
int adcConversionComplete = 0; char message[32];
if (HAL_ADC_Start_DMA(&hadc1, (uint16_t*)adcResultsDMA, ADC_CHANNELS) != HAL_OK) { 
Error_Handler(); 
} 
/* Infinite loop */ 
while (1) { 
    if (adcConversionComplete == 1) { 
        sprintf(message, "%d -- %d -- %d\r\n", adcResultsDMA[0], adcResultsDMA[1], 
        adcResultsDMA[2]); 
        HAL_UART_Transmit_IT(&huart3, message, sizeof(message)); HAL_Delay(1); 
        adcConversionComplete = 0; 
}
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc) { 
    adcConversionComplete = 1; 
}

 

1 ACCEPTED SOLUTION

Accepted Solutions
APBashara
Associate II

The issue was too many interrupts being triggered. Found a happy medium between buffer size an adc conversions and it is now working well.

View solution in original post

7 REPLIES 7
MasterT
Lead

AN4891 study. If I'm not mistaken, DMA has no access to AXI memory in the domain D1, ldscript.ld has to be configured to work with D2 & D3 

@brief Linker script for STM32H743ZITx Device from STM32H7 series
* 2048Kbytes FLASH
* 128Kbytes DTCMRAM
* 64Kbytes ITCMRAM
* 512Kbytes RAM_D1
* 288Kbytes RAM_D2
* 64Kbytes RAM_D3
*

I am sorry, but I am not sure that I understand your reply; could you elaborate?

AScha.3
Chief III

32 Bytes is a cache line...

quick test: switch off D-cache (or dont switch on in Cube) - see, if it working better then. :)

If you feel a post has answered your question, please click "Accept as Solution".

O'k. 

"AN4891 study. If I'm not mistaken, DMA has no access to AXI memory in the domain D1, ldscript.ld"

AN4891 is application note, locate it on st.com web site or use google.com as search engine. Read.

ldscript.ld is a config file, installed somewhere within H7 package on your computer, find it and post here.

Also it was disscused a few times on this board, search pattern "DMA stm32H74x", sure it worth to read

D-cache has been disabled the whole time, still having the same issue

APBashara
Associate II

Just to update my further progress, disabling continuous conversion mode allows the code to run fine. This obviously only takes one sample, however, which does not complete my goal. 

I will read through the AN4891. Are there any sections I should focus on @MasterT?

APBashara
Associate II

The issue was too many interrupts being triggered. Found a happy medium between buffer size an adc conversions and it is now working well.