This interesting and economical board mounts an
ARM Cortex M4 MCU type STM32F407VET6 produced by ST Microelectronics and is
also called “black board” or “black pill” due to the dark color of the pcb.
There are several versions, the one I used is shown in figure 1.
Figure 1 -The Black Board |
The MCU has 100 pins (LQFP100 package), so it
is suitable for those applications where a lot of I/O and also a remarkable
speed of execution are required. Its main features are: 168MHz clock, 512KB of
Flash memory, 128KB of RAM, 82 GPIO (many of which 5 volt tolerant), 16 12-bit
analog channels, 2 12-bit DAC channels, a USB OTG port and many other things.
Among these, a 32768 Hz crystal RTC and 4kB of RAM rendered non-volatile by the
backup stack.
I bought this interesting and inexpensive card
not only for the reasons mentioned above but also because it had an micro SD card connector. I had already done
several projects with the STM32F103C8T6 board, also called “bluepill”,
compiling with Arduino IDE after loading the package and I wanted to experiment
on bigger systems too.
The SD
card
It is not connected to
the SPI bus but to the SDIO bus and the Arduino libraries use the SPI. To be able to use the more
performing SDIO interface, you need to change the development environment, but
I didn't want to do this.
To overcome this obstacle I connected the SD to an SPI bus with three external wires connected to the pins available on the various connectors. This is easily achieved by connecting the pins with the wires headed with female Dupont connectors the card is equipped with. The original connections do not go into conflict as I initialize them as a pull-up input, therefore, inserting the resistors that were missing.
SPI pin |
J2 |
|
SD pin |
J3 |
name |
PA7 |
30 |
« |
PD2 |
24 |
SPI1 MOSI |
PA6 |
29 |
« |
PC8 |
37 |
SPI1 MISO |
PA5 |
28 |
« |
PC12 |
27 |
SPI1 SCK |
Table 1 – Wiring to do for SPI bus
As you can see in the table, the pins connected
to the SD are all on the J3 connector and the pins of the SPI bus are all on
the J2 connector. Pin 1 of the connectors is always indicated by a square pad,
on the soldered side. Pin PC11, connected to the SD (DAT3 = CS) is fine, just
indicate it in the initialization of the SD.
At the top of the program, among other
instructions, these should be placed:
#include <SD.h>
#define SD_MOSI PA7
#define SD_MISO PA6
#define SD_CLK PA5
#define SD_CS PC11
boolean SDok;
The following instructions must be entered in
the setup () function:
pinMode(PC8, INPUT_PULLUP);// SDIO pin
pinMode(PC12, INPUT_PULLUP);// SDIO pin
SPI.setMOSI(SD_MOSI);
SPI.setSCLK(SD_CLK);
SDok = false;
} else {
SDok = true;
}
The tests gave positive results with the SD.h library and negative with STM32.h.
With this simple trick I could also use the SD
card with Arduino IDE.