STM32 Development Info
MCU Info
- The STM32 board that we are currently evaluating is the Nucleo-F413ZH.
- The target STM32 variant used in our PCBs is the STM32G473CE.
- The STM32G473CE was chosen for its 3 built-in CAN 2.0B controllers and its small pin count package size (48 pins).
- There are many other variants in the STM32 family; if needed, low power or dual core versions of the STM32 such as the STM32H745 could also be considered.
RTOS Info
- A real-time operating system (RTOS) is currently being considered to allow for better modularity and multiple task scheduling.
- The RTOS currently being considered is Mbed OS.
- Open source
- Many built-in libraries (especially for connectivity)
- Developed and backed by ARM
- Many options for toolchains/development environments
- Code written for Mbed can be run on a large number of supported ARM hardware
Development Environment
Software
- PlatformIO Extension for Visual Studio Code (reccommended)
- Extension installation instructions
- This will automatically install the PlatformIO Core and CLI, so skip the next bullet.
- PlatformIO Core/CLI if not using VSCode (NOT recommended)
- Required for base installation. Using the CLI tool by itself is NOT recommended, as it will be installed by the PlatformIO VSCode Extension.
- On MacOS, this can simply be installed using the “platformio” package available in Homebrew.
- On Arch Linux, this can simply be installed using the PlatformIO AUR package.
- For other platforms, please refer to this guide.
Configuration
- Getting started with the IDE
- Or, if you want to go the NOT reccommended route, getting started with the CLI
- The platform for STM32 is
ststm32
. - The evaluation board is
nucleo_f413zh
. - The framework is
mbed
. - If using the RTOS features in the Mbed API, an extra build flag option should be specified in the
platformio.ini
file with a value ofbuild_flags = -D PIO_FRAMEWORK_MBED_RTOS_PRESENT
.
- The default behavior for PlatformIO with Mbed OS is to recompile the entire RTOS every time a project is built with the
PIO_FRAMEWORK_MBED_RTOS_PRESENT
compiler flag. This can lead to extremely long build times.- To prevent PlatformIO from rebuilding the RTOS each time, a build cache directory can be specified to cache the Mbed binaries.
- The first project build will cache the binaries in the specified location, and the binaries will be automatically fetched on subsequent project builds.
Serial Terminal
During development, there will almost certainly be a need to use a serial terminal to view text output or do text input to the device. Several different methods can be used to access the serial terminal, depending on what computer is used:
- On Linux, either GNU Screen or many other terminal emulators can be used.
- The most straightforward one is GNU Screen, which can be installed from almost all repositories. The command to use it to access the terminal is
screen /dev/ttyACM0 9600
, where/dev/ttyACM0
and9600
are the default device and baudrate and can be changed. To exit screen, useCtrl-A \
orCtrl-A
and type:quit
. - Another good option is picocom, which can be installed from most repositories, including Arch and Debian. To access the serial terminal, use
picocom -b 9600 /dev/ttyACM0
. Again, the settings can be changed from the defaults.
- The most straightforward one is GNU Screen, which can be installed from almost all repositories. The command to use it to access the terminal is
- On MacOS,
screen
is also available, and is used similarly to the one in Linux. However, the device path will be different. - On Windows, the most popular option is PuTTY. On Linux and MacOS, the device path can be found using the command
ls /dev/tty*
before and after plugging in the STM32 board. The new device is the STM32. On Windows, the COM port used can be found using Device Manager in a similar manner. It will be listed in the “Ports (COM & LPT)” section.
Alternatively, the PlatformIO extension for VSCode has a built-in Serial Monitor that can be accessed from the blue toolbar on the bottom of the IDE. This link shows the toolbar and what each button does. Click on the 8th button from the left (Serial Monitor, looks like a plug) to open up the built-in Serial Terminal.