2021-03-17 03:07 PM
Hi! I have STM32H745 Nucleo and i want to transfer data from ADC via DMA.
1. At first i write code for ADC with out DMA (ADC3, PF10 in) and it work excellent. I get positive knovlege.
2. At second step i tried to use DMA (DMA1 stream 1), but code don't work.
It is code with DMA:
2021-03-17 03:10 PM
void ADC3_DMA_Config(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
static DMA_HandleTypeDef DmaHandle;
/* ADC handler declaration */
ADC_HandleTypeDef AdcHandle_singl;
ADC_ChannelConfTypeDef sConfig;
__HAL_RCC_GPIOF_CLK_ENABLE() ;
__HAL_RCC_ADC3_CLK_ENABLE() ;
__HAL_RCC_ADC_CONFIG(RCC_ADCCLKSOURCE_CLKP);
__HAL_RCC_DMA1_CLK_ENABLE();
GPIO_InitStruct.Pin = GPIO_PIN_10 ;
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);
DmaHandle.Instance = DMA1_Stream1;
DmaHandle.Init.Request = DMA_REQUEST_ADC3;
DmaHandle.Init.Direction = DMA_PERIPH_TO_MEMORY;
DmaHandle.Init.PeriphInc = DMA_PINC_DISABLE;
// DMA1_Stream1->PAR = (uint32_t)&ADC3->DR;
// DMA1_Stream1->M0AR = (uint32_t)&ADC1ConvertedValue;
DmaHandle.Init.MemInc = DMA_MINC_ENABLE;
DmaHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD;
DmaHandle.Init.MemDataAlignment = DMA_MDATAALIGN_WORD;
DmaHandle.Init.Mode = DMA_CIRCULAR;
DmaHandle.Init.Priority = DMA_PRIORITY_HIGH;
HAL_DMA_DeInit(&DmaHandle);
HAL_DMA_Init(&DmaHandle);
DMAMUX1_Channel1->CCR|= 115U;; //stream 1 29 ????
//DMAMUX1_Channel1->CCR = (115u << DMAMUX_CxCR_DMAREQ_ID_Pos);
DMA1_Stream1->CR |= DMA_SxCR_EN;
AdcHandle_singl.Instance = ADC3;
AdcHandle_singl.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV2;
AdcHandle_singl.Init.Resolution = ADC_RESOLUTION_16B;
AdcHandle_singl.Init.ScanConvMode = DISABLE;
AdcHandle_singl.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
AdcHandle_singl.Init.LowPowerAutoWait = DISABLE;
AdcHandle_singl.Init.ContinuousConvMode = ENABLE ;
AdcHandle_singl.Init.NbrOfConversion = 1;
AdcHandle_singl.Init.DiscontinuousConvMode = DISABLE;
AdcHandle_singl.Init.NbrOfDiscConversion = 1;
AdcHandle_singl.Init.ExternalTrigConv = ADC_SOFTWARE_START; ;
AdcHandle_singl.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
AdcHandle_singl.Init.ConversionDataManagement = ADC_CONVERSIONDATA_DMA_CIRCULAR;
AdcHandle_singl.Init.Overrun = ADC_OVR_DATA_OVERWRITTEN;
AdcHandle_singl.Init.OversamplingMode = DISABLE;
if (HAL_ADC_Init(&AdcHandle_singl) != HAL_OK)
{
; //Error_Handler();
}
/* ### - 2 - Start calibration ############################################ */
if (HAL_ADCEx_Calibration_Start(&AdcHandle_singl, ADC_CALIB_OFFSET, ADC_SINGLE_ENDED) != HAL_OK)
{
; //Error_Handler();
}
sConfig.Channel = ADC_CHANNEL_6; //ADC3_CHANNELa; /* Sampled channel number */
sConfig.Rank = ADC_REGULAR_RANK_1; /* Rank of sampled channel number ADCx_CHANNEL */
sConfig.SamplingTime = ADC_SAMPLETIME_8CYCLES_5; /* Minimum sampling time */
sConfig.SingleDiff = ADC_SINGLE_ENDED; /* Single-ended input channel */
sConfig.OffsetNumber = ADC_OFFSET_NONE; /* No offset subtraction */
sConfig.Offset = 0; /* Parameter discarded because offset correction is disabled */
if (HAL_ADC_ConfigChannel(&AdcHandle_singl, &sConfig) != HAL_OK)
{
; //Error_Handler();
}
/* ### - 4 - Start conversion in DMA mode ################################# */
if (HAL_ADC_Start_DMA(&AdcHandle_singl,
(uint32_t *)aADCxConvertedData,
ADC_CONVERTED_DATA_BUFFER_SIZE
) != HAL_OK)
{
; //Error_Handler();
}
}
2021-04-09 03:41 AM
I've been trying to get this to work on STMCube IDE but I have not had any luck as of yet when I have created my own project.
However if you go into the IDE, create a new project and go to examples you'll find an example of how it should work. I did this and it worked perfectly for me, I just could not get it to work when I write it myself when the values are set by me .ioc file.
2021-04-09 04:30 AM
Dear @KSOdin2 this (upper ) code was written by using examples from stm site.
Code with simple adc conversion work perfectly (i wrote about this) and changed code to transfer data via DMA DON'T WORK (i wrote thise too)
In another topics i found that DMA don't work DTCM RAM, only with AXI RAM, but i need to use DTCM RAM too for faster signal processing.
On another topics are some steps for readressing place of varribles based, but their ideas don't work (idea with scatcher file don't help me). "Keil scatter file (*.sct file)" https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
2021-04-09 05:06 AM
Hi @AAnt.1 I'm having the same issues as you. I could get ADC to work but once I used the DMA the buffer is just constantly 0. I have tried changing settings and re-doing it but no look. I am looking into increasing the clock config speeds in case the clock is to slow?
If I get mine to work I'll be sure to let you know!