Problem with change to STM32F1 board library STM32ADC

Post Reply
SteveR2018
Posts: 3
Joined: Mon Jun 15, 2020 2:37 am

Problem with change to STM32F1 board library STM32ADC

Post by SteveR2018 »

Hi! This is not my first, first message. I've been watching but not posting for a while. The forum forgot me and I have just re-registered.

My setup:
  • Windows 7,
  • Arduino IDE 1.8.12,
  • Hardware: STM32F103C8T6 Blue Pill board,
  • Upload Method: STM32duino bootloader (USB)
  • Installed Boards: STM32F1xx/GD32F1xx boards, version 2020.6.7,
  • Installed Boards: Arduino SAMD Boards (32-bits Cortex-M0+), for essential arm compiler tools,
  • Selected Board: Generic STM32F103C series, Variant: STM32F103CB (20k RAM 128k Flash)
I had a problem after updating the installed board to STM32F1xx/GD32F1xx boards, version 2020.6.12. Specfically there has been a change in the library STM32ADC, function myADC.setDMA() that prevents my program from compiling. The number of parameters in .setDMA() has changed, and there is also a new function .startDMA(). What I need to know is how to adapt my code to allow it to compile and maintain the same ADC-DMA functionality. I have reverted to using version 2020.6.7 until this is resolved.

The STM32ADC example program 'SingleChannelAtSampleRateCircularBuffer.ino' has served as a model for my ADC-DMA application. The sample program has not been updated (yet) for the STM32F1 board version 2020.6.12. The important code example code, included in the Arduino sketch setup() function, is:

Code: Select all

	...
	Timer3.setPeriod(samplePeriodus);
	Timer3.setMasterModeTrGo(TIMER_CR2_MMS_UPDATE);

	myADC.calibrate();
	myADC.setSampleRate(ADC_SMPR_1_5); // ?
	myADC.setPins(&pins, 1);
 ==>	myADC.setDMA(buffer, maxSamples, (DMA_MINC_MODE | DMA_CIRC_MODE | DMA_HALF_TRNS | DMA_TRNS_CMPLT), DmaIRQ);
	myADC.setTrigger(ADC_EXT_EV_TIM3_TRGO);
	myADC.startConversion();
	...
The associated STM32ADC.h code in board versions up to and including 2020.6.7 is:

Code: Select all

/*    This function is used to setup DMA with the ADC.     
      It will be independent of the mode used. It will either be used in continuous or scan mode    
      or even both... go figure.         

      The reason why this is a uint16 is that I am not ready for dual mode. 
*/    
==>   void setDMA(uint16 * Buf, uint16 BufLen, uint32 dmaFlags, voidFuncPtr func);
The STM32ADC.h code for board version 2020.6.12 is:

Code: Select all

/*    This function is used to setup DMA with the ADC.     
      It will be independent of the mode used. It will either be used in continuous or scan mode    
      or even both... go figure.         

      The reason why this is a uint16 is that I am not ready for dual mode. 
*/
==>   void setDMA(uint16 * Buf, uint32 dmaFlags, voidFuncPtr func);	
==>   void startDMA(uint16 BufLen);
Where in the (old) example code should the new myADC.startDMA() function call be located? Is right after the mayADC.setDMA() call the best location? How can I find alerts and details about changes like this one to the STM32ADC library? The Arduino Boards Manager 'More Info' links to this forum index page, but that isn't specific about changes in the new board release.

I appreciate your time to consider my questions and hope I can receive some advice here.

Steve

stevestrong
Posts: 307
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 7
Location: Munich, Germany
Contact:

Re: Problem with change to STM32F1 board library STM32ADC

Post by stevestrong »

I have changed the API because it was actually not correct for one of the examples which did not run at all.
You are using the other example which I haven't updated yet, but I should.

The setDMA() function now does not need the number of samples. That parameter has to be passed now to startDMA() function.
This is required by the way how DMA works for repetitive SW triggered transactions.
So in your case you have to add startDMA(number_of_samples) each time you "manually" start a (repetitive) transaction, or after setDMA(...) for HW trigger.

Your example is using a timer to trigger the DMA so in this case the old version could remain as it was before.
Maybe I should restore the old version in the lib.

SteveR2018
Posts: 3
Joined: Mon Jun 15, 2020 2:37 am

Re: Problem with change to STM32F1 board library STM32ADC - Resolved

Post by SteveR2018 »

Hi Steve S!

Thanks for your reply.

I get the gist of what you have said. While I was waiting for a reply I just went ahead and took the buffer length parameter out of the .setDMA() call and added a .startDMA() call immediately following that. It works fine. When you issue an update to the STM32ADC example, I will review it.

I admit to knowing little of how to utilize the DMA functionality properly. I have relied so far on the examples that come with STM32duino. I appreciate them and truly wish there were more, as it is far easier to get good results cloning a working example aimed at Arduino users than to wade hip-deep in the weeds of all the relevant STM32 documentation.

As for restoring the old version in the library, use your best judgement about the 'right' way going forward. I was just suddenly caught off balance due to the change, but if the old version is not generally applicable then it will not be as helpful as it might be to learners like me. Best to keep it clear, as simple as possible, no simpler, and effective. So, I would vote for cleaning up the code and examples, announcing the change(s) as you go, so we can stay on top of it.

Many thanks,
Steve R :)

stevestrong
Posts: 307
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 7
Location: Munich, Germany
Contact:

Re: Problem with change to STM32F1 board library STM32ADC

Post by stevestrong »

I think 5236648 fixes the issue without changing all those examples.
Please try it and reopen the issue if it is not the case.

SteveR2018
Posts: 3
Joined: Mon Jun 15, 2020 2:37 am

Re: Problem with change to STM32F1 board library STM32ADC

Post by SteveR2018 »

Hi Steve S!

Roger. No reason it won't work. The second definition is what I implemented 'by hand'.

My coding is basiC and my brain gets overloaded with C++ - :lol:

Thanks,
Steve R

Post Reply

Return to “Let us know a bit about you and your projects”