2017-01-18 04:39 PM
I have setup the STM32CubeMX project.. (STM32F302RExx)
I use the ADC in continues / scan mode.
I have DMAContReq = true..
I then setup DMA on ADC1-CH1 with HIGH prio..
but when i generate my Cube-code... i don't see ANY code for the DMA setup ??
The ADC's works fine if i poll them.
This : 'DMA_HandleTypeDef hdma_adc1;' I see..
but thats IT .. no more references.. i have all in my MainFile..
Any clues ?
/M.H.
p.s..
I'm guessing i am missing something like THIS (THIS IS NOT TO FIND IN CUBE-GENERATED CODE):
hdma_adc1.Instance = DMA1_Channel1;
hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_WORD; hdma_adc1.Init.Mode = DMA_CIRCULAR; hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH; if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) { Error_Handler(); }__HAL_LINKDMA(&hadc1,DMA_Handle,hdma_adc1);
#stm32cubemx*Solved! Go to Solution.
2017-01-19 02:48 AM
Hi
Holch.Mikkel
,I'm using the 4.19 version,
the ADC
MSP Initialization with DMA configuration isavailableon
stm32f3xx_hal_msp.c file.
The MSP file ( located in your project Src folder) is generated automatically.
-Nesrine-
2017-01-19 12:41 AM
Hi
,Using :
all work as expected and theHAL_ADC_MspInit is generated correctly :
void HAL_ADC_MspInit(ADC_HandleTypeDef* hadc){ GPIO_InitTypeDef GPIO_InitStruct; if(hadc->Instance==ADC1) { /* USER CODE BEGIN ADC1_MspInit 0 */ /* USER CODE END ADC1_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_ADC12_CLK_ENABLE(); /**ADC1 GPIO Configuration PA0 ------> ADC1_IN1 PA1 ------> ADC1_IN2 */ GPIO_InitStruct.Pin = GPIO_PIN_0|GPIO_PIN_1; GPIO_InitStruct.Mode = GPIO_MODE_ANALOG; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Peripheral DMA init*/ hdma_adc1.Instance = DMA1_Channel1; hdma_adc1.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_adc1.Init.PeriphInc = DMA_PINC_DISABLE; hdma_adc1.Init.MemInc = DMA_MINC_ENABLE; hdma_adc1.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_adc1.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_adc1.Init.Mode = DMA_NORMAL; hdma_adc1.Init.Priority = DMA_PRIORITY_HIGH; if (HAL_DMA_Init(&hdma_adc1) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(hadc,DMA_Handle,hdma_adc1); /* USER CODE BEGIN ADC1_MspInit 1 */ /* USER CODE END ADC1_MspInit 1 */ }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
-Nesrine-
2017-01-19 01:51 AM
hmm... now thats looks funny...
try CubeMx 4.19
and I DON't generate code in seperate C/H files..
but have it all in 1 Main.c
I'm Generating Code UPDATE the code, because i have added own code..
/M
2017-01-19 02:48 AM
Hi
Holch.Mikkel
,I'm using the 4.19 version,
the ADC
MSP Initialization with DMA configuration isavailableon
stm32f3xx_hal_msp.c file.
The MSP file ( located in your project Src folder) is generated automatically.
-Nesrine-
2017-01-19 04:28 AM
Ahh... Thanks..
Found the File. and now it makes more sense (also GPIO alternative function setup)
That is the CodeGeneration Part.
I can debug that the Code is being run, and the DMA is setup according to CubeMX Spec.
but then I don't know why it is not working.
Do you have to manual start DMA initially ?
HAL_ADC_Start(&hadc1);
uint32_t g_ADCBuffer1[16];
HAL_ADC_Start_DMA(&hadc1, g_ADCBuffer1, 16);
�?�?�?�?�?�?�?�?�?
If I do a Poll on the ADC i Read what i expect..
Does this look correct setup ? EN = 0 ??
2017-01-19 05:13 AM
Hi
Holch.Mikkel
,I recommend you to have a look to ADC example under the STM32F3 cube package it may be helpful :
STM32Cube_FW_F3_V1.7.0\Projects\STM32F303K8-Nucleo\Examples\ADC\ADC_DMA_Transfer
This example describes how to configure and use the ADC to convert an externalanalog input and get the result using a DMA transfer through the HAL API.
-Nesrine-
Ifmy suggestanswers your question, please mark it as correct.
2017-01-19 06:12 PM
Okey, I found the cause of my problem...
And yes... My Mistake..
I started my project by doing a POLLED test... (made it work)
Then going to a DMA setup... BUT..
I NEVER removed the line at top of my code: ( I was not aware the importance)
HAL_ADC_Start(&hadc1);�?�?�?�?
So when then reading about DMA.. I Added the DMA setup:
HAL_ADC_Start_DMA(&hadc1, g_ADCBuffer1, 6);�?
but what,, what does this mean... well..... HAL_ADC_Start_DMA, NEVER RUNS..
because the ADC is busy from old ADC START..
REMEMBER !!! ONLY ONE START
at least on STM32F302RETx
But thanks for leading med to where to find the code, that led me to find the problem... (and the importance of reading return status) :)
M.