Skip to main content
Associate II
April 25, 2024
Solved

Fast pin toggling on STMH723

  • April 25, 2024
  • 5 replies
  • 3038 views

I have been trying to see how fast can I toggle the pins on STM32H7 MCU. I'm using a nucleo-H723zg board. 

the clock configs are at the highest (550Mhz for CPU, 275 for APB and AHB), the pins are configured as very high speed. 
But still with a simple while loop such as 

 

while (1) {

GPIOE->BSRR = (uint32_t) GPIO_PIN_2;

GPIOE->BSRR = (uint32_t) GPIO_PIN_2 << 16U;

}

the frequency of the PWM I see on the oscilloscope is 7.3 MHz max. Ofcourse the PWM is not the final goal
but I wanted to see how fast this mcu can implemnet the bit toggling.
Am I doing something wrong here?

 

Best answer by AScha.3

From my tests :

AScha3_0-1714113705274.png

20 MHz can get from H743 , at 480MHz , -O2, : 25ns hi or lo time ;

compared to cpu with "better" = direct access to port/bus : H563 , at 250MHz :

 4ns pin access, 16ns with while-loop : 82MHz output by pin toggling - not bad , i would say...

see:

https://community.st.com/t5/stm32-mcus-products/which-is-best-stm32-mcu-for-fast-driving-of-gpio/m-p/632729#M233727

 

5 replies

LCE
Principal II
April 25, 2024

That seems very slow indeed.

Any interrupts active?

In case you need fast PWM, use a timer.

Tesla DeLorean
Guru
April 25, 2024

Not really a great test, way the bus is constructed apt to be slow.

Use a TIM, they have an actual mode for this..

Perhaps use an address bit of an FMC bus? And use M2M mode DMA

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MazzAuthor
Associate II
April 25, 2024

I don't just need a pwm. it was more of a test because I suspected that every instruction is taking longer than I expected. 

originally I realized this while trying to implement a custom protocol and realized every instruction seem to add a considerable amount of overhead. 

for example a simple

 GPIOE->BSRR = (uint32_t) GPIO_PIN_2;

adding 60ns. Also not getting accurate delay because 

CYCCNT_reg = DWT->CYCCNT; 

adding extra 20 or 30ns.

Uwe Bonnes
Chief
April 25, 2024

You did not use a scope to measure timing?

Uwe Bonnes
Chief
April 25, 2024

What is GPIO High time, what is low time? Low time include the loop. Run many such sequences in a loop! Is Icache Otherwise the loop will include wait state. And what is optimization setting?

MazzAuthor
Associate II
April 25, 2024

The high and low time were almost the same. maybe 45% high 55% low. changed the optimization from none (-O0) to optimize for speed (-Ofast) and no change. 

AScha.3
AScha.3Best answer
Super User
April 26, 2024

From my tests :

AScha3_0-1714113705274.png

20 MHz can get from H743 , at 480MHz , -O2, : 25ns hi or lo time ;

compared to cpu with "better" = direct access to port/bus : H563 , at 250MHz :

 4ns pin access, 16ns with while-loop : 82MHz output by pin toggling - not bad , i would say...

see:

https://community.st.com/t5/stm32-mcus-products/which-is-best-stm32-mcu-for-fast-driving-of-gpio/m-p/632729#M233727

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
April 26, 2024

As @Tesla DeLorean said above, in 'H7, GPIO access time from processor is dominated by traversal through the many buses and their interfaces

JW

PGump.1
Senior II
April 26, 2024

Hi,

Try removing the unnecessary casting, from

GPIOE->BSRR = (uint32_t) GPIO_PIN_2 << 16U;

to

GPIOE->BSRR = GPIO_PIN_2 << 16;

I hope this helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.