cancel
Showing results for 
Search instead for 
Did you mean: 

DMA registers are not set correctly on STM32L052K8T6 Hello, I want to use the DMA to shift data from 9 ADC Channels into an Array. The problem is that I set up the ADC and the DMA in CubeMX. But the Registers of the DMA are not set correctly.

MMüll.5
Associate II

My CubeMX Setup:

DMA:

0693W00000GXM5cQAH.pngADC:

0693W00000GXM5wQAH.pngADC NVIC:

0693W00000GXM6QQAX.pngAfter I had done this, I generated the

Code and Started the ADC and the DMA with the HAL_ADC_Start_DMA function. The

function Started the ADC as I wanted, but the Registers of the DMA are not set

Correctly.

The DMA register, which is not set correctly:

0693W00000GXM4aQAH.pngI assumed that the CIRC and the MINC bit should be set, and also the PSIZE should be 0x01 and MSIZE 0x02. Have I done something wrong or what is happening?

If you need some more Information, just say it and I will upload it as fast as possible.

1 ACCEPTED SOLUTION

Accepted Solutions
Amel NASRI
ST Employee

Hi @Mathias Müller​ ,

Please check the order of the calls for HAL_ADC_Init() and HAL_DMA_Init().

In the generated code, make sure that HAL_DMA_Init() is called first, then HAL_ADC_Init().

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

8 REPLIES 8

Cube is open source so you can step through the functions which set the DMA and observe variables and registers to find out where is the problem.

JW

MMüll.5
Associate II

Hi,

I tried to do that, but I could not find where they should get set. I think that could be because they are just left in their standard setting, but the problem is I don't want them to be in that setting.

I think it could be useful to know that when i try to set the Registers to the right value in the debugger, they change back to the value I have shown in the snapshot. Except for the CIRC bit, this stays at the value I set it to.

> I tried to do that, but I could not find where they should get set.

In the Cube function which sets DMA. Don't "step over" it, "step into". I don't use Cube.

> [...] they change back [...]

Sounds like you are trying to modify registers while the program is running.

JW

MMüll.5
Associate II

I looked in an older project where I used the DMA for something similar. And I compared both of them and found out that the registers I want to set are set in the ADC init, so I looked into that and found some differences. I will try to fix that and tell you later if it worked and what exactly was wrong.

Amel NASRI
ST Employee

Hi @Mathias Müller​ ,

Please check the order of the calls for HAL_ADC_Init() and HAL_DMA_Init().

In the generated code, make sure that HAL_DMA_Init() is called first, then HAL_ADC_Init().

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

MMüll.5
Associate II

Hi @Amel NASRI​ 

Thank you for your help. That was what caused the Problem, the HAL_ADC_Init() was called first. 👍

Can you explain to me why the HAL_DMA_Init must be called first and why the Cube MX does not do it like it is supposed to be?

It also would be useful to know how I can generate code from Cube MX and force it to initialize the DMA first because every time I generate code I need to switch the MX_DMA_Init and the MX_ADC_Init in which the HAL functions are called.

Thank you in advance.

Mathias

Hi @Mathias Müller​ ,

The peripheral initialization (HAL_ADC_Init() in your case) modifies a DMA register, which needs the DMA clock to be active. The clock is activated in the DMA initialization. That is why it is required to call HAL_DMA_Init then HAL_ADC_Init.

Unfortunately this was a regression introduced in STM32CubeMX 6.3.0. A fix is expected in next tool release.

A possible workaround is to force the order of functions calls. Please refer to the paragraph Ordering initialization function calls in the user manual UM1718 STM32CubeMX for STM32 configuration and initialization C code generation.

-Amel

PS: Once your question is answered, please select the relevant comment to be marked as a Best Answer.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

MMüll.5
Associate II

Thank you for all the information, know all is working as expected.