2015-09-21 11:09 AM
2015-09-21 02:17 PM
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.2015-09-21 04:03 PM
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.maticPosted: Monday, September 21, 2015 11:17 PMSubject: 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.2015-09-21 10:24 PM
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.2015-09-22 03:29 AM
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?2015-09-22 03:40 AM
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?
2015-09-22 03:49 AM
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. Hecertainly
knows that.2015-09-22 06:18 AM
> 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?) JW2015-09-22 06:34 AM
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.2015-09-22 10:26 AM
Ah so...arbitration between cpu and dma access...can't get safer then that!
What are the RCC interrupts for, anyone know?Thanks