Blue Pill running slow

Post here first, or if you can't find a relevant section!
IanNoob
Posts: 10
Joined: Wed Oct 07, 2020 5:35 pm

Re: Blue Pill running slow

Post by IanNoob »

Thanks fpiSTM, but I have no idea what you mean.

How would HAL, LL or CMSIS look if I used them in the Arduino IDE? Or would they only work in the STMCubeProgrammer?

Ian

GonzoG
Posts: 45
Joined: Wed Jan 15, 2020 11:30 am
Answers: 3

Re: Blue Pill running slow

Post by GonzoG »

IanNoob wrote:
Fri Oct 16, 2020 5:07 pm

I found (using an oscilloscope) that the reaction time to a repeating pulse from a Nano is very 'juddery' and varies between:
1.7uS to 3.8uS using Method A (digitalRead) and
1.0uS to 2.6uS using Method B (digitalReadFast)

Is this what you would expect? Am I doing something fundamentally flawed?
Have you set optimization to "fastest -O3" in Arduino IDE (menu Tools -> optimize) ?? Because this ~1.5x difference I get with standard (-Os) optimization (smallest).

I got up to 20M reads/s using digitalReadFast.

Reading single port using registers (GPIOx->IDR) isn't much faster - about 22M.

User avatar
fpiSTM
Posts: 742
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 27
Location: Le Mans
Contact:

Re: Blue Pill running slow

Post by fpiSTM »


IanNoob
Posts: 10
Joined: Wed Oct 07, 2020 5:35 pm

Re: Blue Pill running slow

Post by IanNoob »

Thanks GonzoG. I just tried that - no change. Well - this time I got:
1.5uS to 4.1uS using Method A (digitalRead) and
1.0uS to 2.7uS using Method B (digitalReadFast)

so a little better than 500k reads/s the same as with optimization on "Smallest -Os (default)"

I jusrt re-tried the digitalWrite version of the same sketch and got pulses of about 60nS, with no difference between optimization settings.

I'm baffled.

Ian

IanNoob
Posts: 10
Joined: Wed Oct 07, 2020 5:35 pm

Re: Blue Pill running slow

Post by IanNoob »

Thanks again fpiSTM. That is a really clear and useful link. As far as I can tell the code given is understood by STM32CubeMX and not by Arduino IDE, is that right?

I have tried some of the code snippets given but they just get rejected by the IDE with error messages.

I am comfortable with register level programming but don't particularly want to move back and forth between programming environments.

Ian

GonzoG
Posts: 45
Joined: Wed Jan 15, 2020 11:30 am
Answers: 3

Re: Blue Pill running slow

Post by GonzoG »

I wrote simple program for testing digital IO speed.
For read tests it's using 2 different pins (PA1 and PB1).
This it what I get (-O3 fastest optimization):

Code: Select all

Port I/O speed test. Arduino digitalRead/Write / digitalReadFast/WriteFast / STM32 register 
********* Write test: *********
 digitalWrite: 1853696us    1op time: 0.93   op/s: 1.08M/s
 digitalWriteFast: 61495us    1op time: 0.03   op/s: 32.52M/s
 GPIOx->ODR: 255674us    1op time: 0.13   op/s: 7.82M/s
********* Read test: *********
 digitalRead: 1838335us    1op time: 0.92 ops/s: 1.09 M/s
 digitalReadFast: 100618us    1op time: 0.05 ops/s: 19.88 M/s
 GPIOx->IDR: 90834us    1op time: 0.05 ops/s: 22.02 M/s
Attachments
IO_speed_test.zip
(1.47 KiB) Downloaded 9 times

IanNoob
Posts: 10
Joined: Wed Oct 07, 2020 5:35 pm

Re: Blue Pill running slow

Post by IanNoob »

That is fantastic GonzoG. It works and I agree with your timings (approximately).

Now I need to do some serious studying to see what is different between yours and mine.

Thanks again.

Ian

IanNoob
Posts: 10
Joined: Wed Oct 07, 2020 5:35 pm

Re: Blue Pill running slow

Post by IanNoob »

Very despondent. I studied GonzoG's code until I understood what was going on, then, using his/her sketch and all the #defines etc I inserted my own code and watched it on a 'scope.

Same problem. digitalWriteFast works a dream producing a pulse train of about 18 pulses in a microsecond, suggesting a clock frequency of 72MHz before loop() and other overheads. Spot on.

digitalReadFast is another issue. Using this code within GonzoG's sketch:

Code: Select all

   if (dRF(PIN3r) == HIGH) {                  // Method A. . Pin 3r is PB3
   dWF(PIN0w,1);
  } else {
      dWF(PIN0w,0);
  }
           
 /* if ( GPIOB->IDR & 0b0000000000001000)  {   // Method B  
      dWF(PIN0w,1);
  } else {
      dWF(PIN0w,0);
  }  
*/
and triggering using a square wave from a Nano, then again using a button, I got VERY erratic and slow responses:
[img]C:\Documents\FTL\Quickest small.jpg[/img]
[img]C:\Documents\FTL\Slowest small.jpg[/img]

The red trace is the trigger pulse, the blue one is the Pill's response. The fastest is about 50uS, the slowest is about 550uS - half a millisecond!

Since the IO is working, what else can be going wrong?

Ian

GonzoG
Posts: 45
Joined: Wed Jan 15, 2020 11:30 am
Answers: 3

Re: Blue Pill running slow

Post by GonzoG »

I don't have oscilloscope, so I used 2 pills (black F411 and blue F103) to do a "ping test" and got about 2-3us response time.

ps. IanNoob, to add images from hdd, you need to add them as attachments.

Post Reply

Return to “General discussion”