I have an STM32 that toggles nine GPIO pins repeatedly (one clock pin and eight data pins to load an FPGA image using SelectMap). I am doing this using the standard library function GPIO_WriteBit
that modifies one GPIO bit, and changing one pin at a time.
Unfortunately, this turns out to be quite slow. Is there a way I can make "raw GPIO toggles" very very fast? Is there a clock parameter I should change? Can I use some sort of FIFO, or interrupt-based method?
I have configured the GPIO pins as follows:
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
(Note: The reference manual (see page 133) states that the GPIO is capable of:
Fast toggle capable of changing every two clock cycles
But I cannot see how to activate this fast toggling.)
Best Answer
I answered to your related question why you could only toggle at 4 MHz when you expected 100 MHz:
So, write the functions in assembly. A function like
should take no more than 2 instructions in assembly, while the compiled C code may take 20 times as much. Or more.