Programming an ARM-processor (II)

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:TCD1304-timingThe 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:


For more information about programming STM32F4 boards, I found this tutorial very helpful in understanding timers, and this one very inspiring once I understood the basics.

I will need to synchronise two or three timers to drive and read the TCD1304, but more about that in a coming post..

Links explicated:

One thought on “Programming an ARM-processor (II)

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.