At the heart of the STM32F401re board is a Cortex-M4 running at 84 MHz. It will be responsible for driving and reading a TCD1304 linear CCD.
The CCD requires some driving signals with the right timing as shown in the timing chart in the chip’s datasheet:The master clock must be between 0.8 MHz and 4 MHz, and the data rate is 1/4 of that. Piece of cake for an 84 MHz MCU you’d think.
In fact, the F401 is only just capable of toggling one of the GPIO’s at around 2.5 MHz when running a simple loop doing only that. This is easily verifiable on the oscilloscope:
Taking care of synchronising the SH and ICG signals with the master clock AND reading the pixel values will be impossible at proper speed.
Luckily the Cortex-M4 has a lot of peripherals that can be put to work, leaving the processor free to do whatever.
The STM32F401re has 8 timers which can be coupled directly to the GPIO’s. The timers work at either 42 or 84 MHz, so it’s no problem to get a 2 MHz signal – you just need to make sure that the MCU’s clock is correctly set.
In the project folder in the SPL library there are examples of how to configure the timers. I’ve modified one to give a 6 MHz signal on PA5, that’s the same pin the LED is connected to. Here’s the source code.
The Nucleo F401re blinking at 6 MHz:
I will need to synchronise two or three timers to drive and read the TCD1304, but more about that in a coming post..