The STMicros Discovery boards, such as
the STM32F4 Discovery (S4D), offer excellent value for their
price. For example, the S4D sports 1 MB of flash, 192 KB of RAM,
six UARTs, and an assortment of other goodies such as DACs, ADCs, I2C,
SPI, and CAN. But the best part is the price of the board; just
US$15 each in singles.
Unfortunately, the Discovery boards are some of the most
hobbyist-unfriendly boards I've dealt with. The PCBs are large
and contain 100 header pins, arranged as two 2x25 connectors. The
boards are so large, in fact, that they don't fit on most experimenter
plug boards, even assuming you could find the proper 2x25 female
connectors to isolate the signals when you plug it into your board.
And having all pins from the MCU available might be great for
developers, but it can make life tough for the hobbyist. If you
want to test out an idea that only requires a few I/O lines, good luck
making a few quick connections easily.
I also wanted to install a minimal set of peripherals on my Discovery
boards, using as little external circuitry and connectors as
possible. Finally, the resulting board needed to support my
experiments with the eLua programming language.
This page describes my efforts in creating a basic hobbyist
configuration for the S4D board.
Step 1: The SD card
It's always nice to have some non-volatile data storage, and adding an
SD card through SPI has become pretty standard on large embedded
systems. For this mod, I chose to use a micro-SD adapter as my SD
connector. I soldered wirewrap wires to the relevant pins on the
adapter and ran them to the proper pins on the S4D board. I then
double-sided foam tape to fasten the adapter to the underside of the
If you use a microSD adapter this way, be sure your soldering iron is
set to a fairly low termperature, say 700 degF, and don't overheat the
connections. It's easy to leave the iron on the connection point
long and melt the terminal into the adapter's body, ruining the adapter.
My eLua image has support for an SD card already built in. I just
chucked the microSD card into my laptop, formatted it, then moved the
card into the microSD adapter on the S4D. Now I can store
data on an 8 GB microSD card.
To support eLua's connections to the SD card, I used:
Step 2: The UART
|Data in to
|3 VDC (do
NOT use 5 VDC!)
eLua wants to use a serial console, either through one of the
six available UARTs or through the USB CDC connection. On the
S4D, this CDC connection appears on a USB microB connector, and the
default configuration for eLua is CDC.
Unfortunately, my efforts to use USB CDC as a serial console were
totally frustrating. Even finding the STMicros driver for this
connection took hours of hunting on the web. When I finally found
what looked like a suitable driver (not on the STMicros site), the
installation didn't work on one of my laptops (WinXP, SP3). I had
instead to install the driver on a second laptop (also WinXP, SP3),
then copy the installed folder over to the first laptop.
Although I could now use the CDC connection for my console, some
combination of the eLua CDC code, the STMicros driver, and my laptop
installation made the experience too painful. Every time I reset
my S4D board, TeraTerm would lose contact with the serial device and
could not reconnect; the CDC serial port would no longer appear in the
TeraTerm drop-down list. The only way to reconnect with TeraTerm
was to exit TeraTerm, reset the board, wait for the OS to discover the
serial port, restart TeraTerm, and reconnect to the CDC serial port.
I don't know exactly where the problem lies and I don't care. I
simply wired a serial port connection to the S4D's UART3, recoded eLua
to use that serial port rather than CDC, and called it good.
Making the connection to UART3 involved adding a four-pin quick-connect
header to the underside of the S4D board. This connector is wired
to GND, 3 VDC, PD8 (Tx), and PD9 (Rx). I have a cable I made that
includes RS-232 level shifters and a matching connector, so I simply
plug this cable into my new four-pin header and I have RS-232 comm with
Here you can see the UART connectpr (white header) immediately below
the microSD adapter on the underside of the S4D board. I've
fastened the UART connector down with hot glue.
Step 3: I/O expansion
The biggest headache with the S4D is accessing the I/O pins easily when
you want to try out an idea. I chose to add five four-pin mini
screw-terminal blocks to a piece of perfboard, along with one 2x25
female header. Plugging this header into the S4D's P1 I/O
connector gives me access to 12 selected I/O lines plus several power
and ground connections. The perfboard I used is big enough to
take more terminal blocks, but that's all I had in my junkbox at the
I chose a group of I/O pins from the SD4 board. The pins I
selected give me a good mix of A/D inputs, digital I/O, one SPI
channel, and one I2C channel, plus an assortment of timer
channels. Feel free to change this list for your needs.
I added labeling to this perfboard so I could quickly determine which
connector terminal maps to which I/O pin on the S4D board. I
created a small document in Word and used 6-point Courier bold to label
the pins, then cut up the printed page and glued the labels to the
perfboard with white glue.
Here's a picture of my S4D board with the attached expansion
board. As mentioned above, I have plans to add more terminal
blocks for extra I/O, but this is a good start.
The first test
I already had some eLua code for playing with the G35 RGB LED Christmas
lights. I edited that program to use PB2 as the G35 network data
line. Using a small screwdriver, I connected my G35 network wire
to a GND terminal and the PB2 terminal on my expansion board, then
powered up the G35 string. When I executed the G35 test program
in eLua, the string of lights lit right up. Total time to make
the I/O connections: about ten seconds.
As you can see in the photos, I made my connections to the S4D I/O pins
using 30 AWG wirewrap wire. Note that the pins on the S4D
connectors do NOT have square corners and will NOT make a gas-tight
connection if you wrap to them! To be safe, add a bit of solder
on each wrap after you are sure you have the right connection.
My expansion board connects to the 3 VDC output on the S4D board, which
means that all of the peripherals I connect to my board are limited to
3 VDC. If you need to use 5 VDC peripherals, you can tie into the
5 VDC output on the S4D board, but make sure any I/O line you connect
to is 5V-tolerant.
Other pages on my site that describe using eLua on a Discovery board
expect the serial console on UART2. The above descriptions that
mention UART3 are not an error; I am using (yet another) custom eLua
image for my STM32F4 Discovery board. The only reason I changed
UARTs was to leave access to the UART2 Rx and Tx pins empty, should I
want to use them later. If you are using the other eLua image,
you won't have any problems. Just select whatever I/O pins you
want to use and wire up your expansion board accordingly.