cancel
Showing results for 
Search instead for 
Did you mean: 

Understanding low level finer points of CubeMX

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

I am trying to set up my first project with CubeMX and would appreciate help

understanding some of the finer details...

1.

ADC configuration:

    A. Under adc NVIC tab, there in an option to enable nvic global interrupts. 

    B. Then if I enable DMA, there is the additional DMA stream2 global interrupt. 

    I am not sure what these are. If using DMA, do I need NVIC globals, are they mutually  

  exclusive? IS Nvic just needed for interrupt driven examples? Can I enable both and then not use some of them in my code with risk?

  

    C. Analog watchdog. I know what WWDG and IWDG is, but what is analog watchdog under adc config?

2.

RCC Global Interrupts...how do I know if I need this? Should I always turn on (default is off)

3.Weird Timer issues.

In the configuration tree on the left hand side of the application, it presents 

all the timers. 

Most timers give the full subtree of options.

However, some just present little more than the option to ''enable''.

Is this change of presentation a way of saying that the timers are required by other items in my configuration, and should be enabled? For example, I know Timer 6 is needed, and it just presents enabled option. However, other timers also present this way - not sure why, so does this mean they are needed and its just that I don't understand why?

4. Clock config - having spec the HSE correctly, typically can i expect to just run with the clock config that it gives me, or do i need to edit it?

Thanks,
10 REPLIES 10
matic
Associate III
Posted on September 21, 2015 at 23:17

Hi.

1. When I work with several ADC channels, I never use ADC interrupts. Actually, I always prefer to use DMA. In this case, you don't have to check ADC global interrupts. DMA will interrupt on Half Transfer (if enabled, by default from Cube I think it is), Complete Transfer and Error Transfer. TC (transfer complete) is the most important - then you know that everything is in buffer.

There is another bug in Cube about that, I suppose. If you enable DMA for ADC, you are not able to unchecked DMA interrupt at all. Cube will generate that interrupt routine (with whole bunch of stuff inside) if you want or not. (The same is with Systick - you can't enable it in Cube). And because I like to write interrupt routine short and fast, I simply comment that part of code and write it on my own. Same if you don't use interrupt al all. If just want to loop in while and wait for TCIF (transfer complete flag) and then go further.

For analog watchdog I'm not sure. I know there is possibility to set lower and upper threshold for ADC. If conversion is not in between those values, it reminds you. Maybe this is it. Look in ref. manual.

2. I've never touched RCC interrupts till now.

3. These Timers are so called ''Basic'' timers. They have limited features, compared to other timers. For details look in ref. manual.

They are independent from other timers.

4. You must always edit it. By default, external cristal is set to 8 MHz I think. But you can put 16 MHz on PCB, why not. 

estersci2
Associate III
Posted on September 22, 2015 at 01:03

Thanks - I am a bit wary of the safety in relation to reading data at the endpoint of a continuous DMA stream from an ADC. For example, if you consider the ADC_RegularConversion DMA stream where data is transferred to a point in memory. How does your user program access (read) that location safely, considering that it is being constantly updated? 

The fact that ST FW lib includes that example implies that it must somehow be safe to read from a location that is being constantly updated by DMA - else what use is that type of DMA configuration, yet other say there is no atomic lock.  

In your experience, can a situation arise where your code read from that element DMA endpoint location clashes with a DMA write to that element, resulting in corrupted data?    

Or is it somehow safe?

 

 

From: obid.matic

Posted: Monday, September 21, 2015 11:17 PM

Subject: Understanding low level finer points of CubeMX

Hi.

1. When I work with several ADC channels, I never use ADC interrupts. Actually, I always prefer to use DMA. In this case, you don't have to check ADC global interrupts. DMA will interrupt on Half Transfer (if enabled, by default from Cube I think it is), Complete Transfer and Error Transfer. TC (transfer complete) is the most important - then you know that everything is in buffer.

There is another bug in Cube about that, I suppose. If you enable DMA for ADC, you are not able to unchecked DMA interrupt at all. Cube will generate that interrupt routine (with whole bunch of stuff inside) if you want or not. (The same is with Systick - you can't enable it in Cube). And because I like to write interrupt routine short and fast, I simply comment that part of code and write it on my own. Same if you don't use interrupt al all. If just want to loop in while and wait for TCIF (transfer complete flag) and then go further.

For analog watchdog I'm not sure. I know there is possibility to set lower and upper threshold for ADC. If conversion is not in between those values, it reminds you. Maybe this is it. Look in ref. manual.

2. I've never touched RCC interrupts till now.

3. These Timers are so called ''Basic'' timers. They have limited features, compared to other timers. For details look in ref. manual.

They are independent from other timers.

4. You must always edit it. By default, external cristal is set to 8 MHz I think. But you can put 16 MHz on PCB, why not. 

matic
Associate III
Posted on September 22, 2015 at 07:24

I'm not sure if I understand you, but...

I suppose you are converting more than one channel with a single ADC. Let sey 4 channels. Thus you have to initialize a buffer (array) of 4 16-bit elements. To convert all 4 channels in a sequence you have to enable SCAN mode (in ADC conf.). If you want to execute that sequence repeatedly (one ofter another with any kind of ADC triggering) you have to enable CONTINUOUS mode.

Now, on the DMA side. If you want to read exactly one (and only one sequence - 4 channels) you have to set DMA to NORMAL mode (not CIRCULAR). Thus, after TCIF flag you are 100% sure that you have 4 results in your buffer, which are the first 4 after ADC was triggered. Even if ADC is in CONTINUOUS mode - in that case it is converting repeatedly, but DMA is not requesting anything more CNDTR register od DMA is 0. At the beginning it was 4 (for 4 transfers). It decreases for every executed transfer. And then it stays at 0.

If you want to receive every sequence to your buffer, then I suggest that you manually reset CNDTR to 4 and start ADC again. You could use CIRCULAR mode for DMA, but then, it can happen that you will read some data from old sequence and some from new. I found CIRCULAR mode more useful when I haven't enabled CONTINUOUS mode on ADC (I was starting it every time or with external trigger). In that case DMA was re-initialize (CNDTR register) automatically by its own.

estersci2
Associate III
Posted on September 22, 2015 at 12:29

Lets take a simple case of just one value being continuously updated in memory, over and over and over again. 

I am ok with the possibility of getting on old value or the latest vale. 

What I am asking is, is there a risk that when I read from that location, I could read in the same instant that the location is being updated by the dma, and therefore receive corrupted data (which is a different question to old versus current data). Could I read the value and get mangled garbage back, by reading at the wrong instant?

estersci2
Associate III
Posted on September 22, 2015 at 12:40

i.e. how can I use the data in a way that is safe from a dma write/user-read clash in the same cpu tick. Is this even an issue?

matic
Associate III
Posted on September 22, 2015 at 12:49

For one channel that is continuously converted use ADC in CONTINUOUS mode. SCAN mode has to be disabled (because of only one channel). DMA should be in CIRCULAR mode.

Unfortunatelly, I don't know the answer to your question what could happen if reading on the same time as DMA is writing to that address. Hopefully Clive will see this and answer you. He

certainly

knows that.

Posted on September 22, 2015 at 15:18

> i.e. how can I use the data in a way that is safe from a dma write/user-read clash in the same cpu tick. Is this even an issue?

DMA and CPU accesses are multiplexed. You may want to read AN4031 for 'F2/'F4.

This has nothing to do with Cube nor CubeMX (are you aware of the difference between these two?)

JW

matic
Associate III
Posted on September 22, 2015 at 15:34

I know that CubeMX is a software, but I am not sure what did you mean with Cube only. Probably you thought CubeF1, CubeF2, etc. as a firmware package.

Thanks for answering OP question.

estersci2
Associate III
Posted on September 22, 2015 at 19:26

Ah so...arbitration between cpu and dma access...can't get safer then that!

What are the RCC interrupts for, anyone know?

Thanks