cancel
Showing results for 
Search instead for 
Did you mean: 

Continuous MultiChannell DMA scan through HAL/ cube

estersci2
Associate III
Posted on September 18, 2015 at 23:39

I would be grateful for some advice...

I know how to make a single ADC do a continuous DMA round-robin conversion of a sequence of different channels, using the pre-Cube version of FW.

 Having enables scan mode, you just list them like this...

  ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_41Cycles5);

  ADC_RegularChannelConfig(ADC1, ADC_Channel_17, 2, ADC_SampleTime_239Cycles5);

 ...etc 

However, even after reading the STM32F4 HAL manual UM1725, I can't figure out the syntax for feeding in the sequence of channels, setting priorities etc, to do the above through the modern cube/HAL. 

I would be grateful if some kind soul could provide a known correct example!

I was thinking maybe you just repeat the following over and over, but it can't be right because there is nothing to say which ADC the channel specifications belong to.

   sConfig.Channel = ADC_Channel_11;       //???? but for which adc

  sConfig.Rank = 1;                                       // ??? does this mean position in sequence?

  sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;

  sConfig.Offset = 0;                                  // Whats this for?

 sConfig.Channel = ADC_Channel_17;

  sConfig.Rank = 2;

  sConfig.SamplingTime = ADC_SAMPLETIME_56CYCLES;

  sConfig.Offset = 0;

It occurs to me that under HAL, its the ADC handle that refers to the ADC peripheral.

So if you do your adc1 handle init, then do the above, then do the adc2 handle init, and then repeat code above again - does that somehow make the sconfig code (exact same syntax/values) refer to different channels on different adcs? Surely not- surely you have two distinct ''instances'' of AdcHandle, one called ADC1 and another called ADC2? Then again, this is not C++, maybe the instance is overwritten so that subsequent sConfigs apply to a different ADC? I don't know...

Does rank means position in scan sequence?

What does sconfig offset mean?

  Thanks!
2 REPLIES 2
matic
Associate III
Posted on September 19, 2015 at 10:26

Hi.

I do that initialization using STM32CubeMX software. There you have a graphical interface to select all those things (number of conv., ranks, priorities,...). Then Cube automatically generates C code with all initialization. Then you write your code between ''User code begin'' and ''User code end'' comments. Whenever you want to change anything within your confuguration, you simply go to CubeMX, make a chenge and generate a new code. But anything that was written between mentioned comments will stay as it was - your code will stay untouched.

Now, there are always some bugs with code generated by Cube. Let say, I use on F3 part two ADCs. On each I have 2 differential channels and one (third) single-ended channel. For ADC1 code from Cube is OK, but for ADC2 it configures Channel 1 as differential (which is OK) and both Channel 2 and 3 as single-ended (only 3 should be single-ended). So you have to be careful with a code from a Cube.

I think Cube is OK when you want just to try something, because you have your initialization code done in seconds. But for something serious I think you should write this on your own. But you can always look how Cube make something and you can help your self with that.

Otherwise, ''rank'' means consecutive number of conversions on particular ADC.

estersci2
Associate III
Posted on September 20, 2015 at 10:21

Thanks - I hadn't thought of using cubeMX as ''inspiration'' when hand modifying/writing code, that works well.

I think another reason people can't totally rely on cube is that some of the option boxes in some of the dialogs are a bit cryptic unless you are an expert. That why its a pity you can open up an example project in cubeMX and see how the GUI was configured to generate the init code. The cube as inspiration approach, is the next best thing.