Skip to main content
Visitor II
April 25, 2024
Solved

Fast pin toggling on STMH723

  • April 25, 2024
  • 5 replies
  • 3037 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?

 

    This topic has been closed for replies.
    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

    Graduate II
    April 25, 2024

    That seems very slow indeed.

    Any interrupts active?

    In case you need fast PWM, use a timer.

    Graduate II
    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

    MazzAuthor
    Visitor 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.

    Graduate II
    April 25, 2024

    You did not use a scope to measure timing?

    Graduate II
    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
    Visitor 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.3Answer
    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

     

    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

    Graduate 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