Electrical – STM32 F4 GPIO clock rate

gpiostm32

I am looking at the STM32 F4 series Discovery board. I have the eval board on my desk currently. I want to use this system to send data from USB to a 3 byte parallel data bus using an external clock source. I am using the STM32407 chip. I need to input data from a PC through the USB bus. My wish list is for the chip to handle a 2 MHz external clock rate and load the 3-byte GPIOs every clock cycle.
That would be 2MHz x 24bits = 48 Mbits/s or 6 MBytes/s if my math is correct. The output from the STM32 GPIO would need to be smooth as the USB would be in packets.
Is the 2 MHz possible? Can I go faster?
Thank you very much.

Best Answer

6 MBytes/s through USB full-speed 12Mbit USB is impossible. So no 2MHz outside clock is not possible through that interface.

A more feasible target through that interface might be about 0.5MB/s over USB. Loading a 3-byte GPIO, would be about 0.5/3, or 167kHz.

The STM32F4 Discovery board (part number STM32F4DISCOVERY) does not have the USB high-speed, 480Mbit, interface implemented, so you'll need to build that (I vaguely remember something about a daughterboard with some more peripheral interfaces, might I might be wrong).

You'll need to check out the library code to drive that peripheral. It runs at 168MHz, which is 28 cycles/byte. ARM load and store instructions are 2 cycles, so 28 cycles isn't many instructions. Worse, GPIO ports are only 16 bits wide, so it's going to be a couple of writes to set up the 24 bits. Depending on the 24-bit bus, it might need a handshake too. Each of those writes is 2 cycles. IIRC DMA runs at about 1/4 CPU frequency (I'd need to dig hard to find that).

It only has 192kB of RAM, so say 180kB for buffers. That is only 3% of your data rate, i.e. 33milliseconds, which isn't very 'luxurious'.

So I guess it might be feasible, but it is likely to be a hard piece of code to write and polish.

I'd have to do some tests to get a better sense for what is reasonable.

I might try something like a BeagleBone Black, i.e. about 4-5x more CPU. It has two RISC CPU's on SoC too, which could offload the low-level I/O, and lots of I/O pins. It might even have 32bit wide ports (maybe someone else can comment).

PS:
I wrote and polished code to toggle one pin on STM32F103, which ran at a CPU clock of 72MHz. IIRC it got 12MHz doing no processing at all. So 2MHz, with two I/O port writes, with USB processing, but just over 2x faster clock (which will suffer program memory wait states), seems impossible.