cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX don't generate DMA SW4STM32 code

mh
Associate II
Posted on January 19, 2017 at 01:39

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*
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on January 19, 2017 at 10:48

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-

View solution in original post

6 REPLIES 6
Nesrine M_O
Lead II
Posted on January 19, 2017 at 09:41

Hi

‌,

Using :

  • CUBEMX version 4.18
  • SW4STM32
  • STM32F302RETX
  • ADC1 in continues mode with DMA enabled

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 */ }}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

0690X000006060MQAQ.png 0690X000006062cQAA.png

-Nesrine-

Posted on January 19, 2017 at 09:51

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

0690X000006062hQAA.png0690X000006062mQAA.png
Posted on January 19, 2017 at 10:48

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-

Posted on January 19, 2017 at 12:28

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 ??

0690X000006065BQAQ.png
Posted on January 19, 2017 at 13:13

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.

Posted on January 20, 2017 at 02:12

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.