2024-04-25 01:34 AM
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?
2024-04-25 01:42 AM
That seems very slow indeed.
Any interrupts active?
In case you need fast PWM, use a timer.
2024-04-25 01:50 AM
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
2024-04-25 02:10 AM
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?
2024-04-25 02:16 AM
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.
2024-04-25 02:18 AM
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.
2024-04-25 02:28 AM
You did not use a scope to measure timing?
2024-04-25 02:44 AM
I did. time high and time low are exactly the same.
2024-04-25 09:13 PM
As @Tesla DeLorean said above, in 'H7, GPIO access time from processor is dominated by traversal through the many buses and their interfaces.
JW
2024-04-25 10:31 PM
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