2021-11-12 01:19 AM
My CubeMX Setup:
DMA:
ADC:
ADC NVIC:
After 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:
I 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.
Solved! Go to Solution.
2021-11-16 07:38 AM
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.
2021-11-12 01:26 AM
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
2021-11-12 01:55 AM
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.
2021-11-12 02:27 AM
> 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
2021-11-12 03:40 AM
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.
2021-11-16 07:38 AM
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.
2021-11-16 10:19 PM
Hi @Amel NASRI
Thank you for your help. That was what caused the Problem, the HAL_ADC_Init() was called first. :thumbs_up:
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
2021-11-17 01:09 AM
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.
2021-11-17 01:21 AM
Thank you for all the information, know all is working as expected.