STM32 Starter Guide

From Eleccelerator Wiki
Revision as of 17:04, 31 October 2013 by Admin (Talk | contribs)

Jump to: navigation, search

I use a lot of the STM32 family microcontrollers. This page will have some info on how to start using them.

Contents

IDE

I use Eclipse with the CDT (these help with C and C++ code). Some plugins can be installed from within Eclipse itself, some must be manually installed. Here are the list of plugins I have installed:

  • C/C++ Remote Debug Launcher
  • CDT GCC Cross Compiler Support
  • Eclipse C/C++ Development Tools
  • Eclipse GDB Hardware Debugging Plug-in
  • GDB Common
  • GNU ARM C/C++ Development Support

Using the GNU ARM Plugin

Once you start a project, the plugin gives your projects a ton of additional settings. Access them through "Properties for ProjectName" -> "C/C++ Build" -> "Settings". This gives you a GUI for the various settings available for the GNU GCC toolchain, plus the additional settings for ARM. Make sure you select the correct target processor (and whether or not you are using the THUMB instruction set). Make sure you have at least checked off "Create Flash Image".

Under the general settings for the linker, make sure you specify the linker script file (it's a *.ld file, you can find one in the ST libraries and examples). Check off "-nostartfiles".

For optimization, make sure all of the optimization options are enabled in the compiler optimization page. Use "-Os" if possible. Tell the linker general options to "remove unused sections".

Play around with the other settings.

Compiler Toolchain

I use GCC ARM Embedded, because "ARM employees are maintaining this project", it is very up-to-date right now.

The GNU ARM plugin for Eclipse does support it.

Tools and Documents from ST

Remember to read the following documents for your specific chip

  • Datasheet, tells you about most of the electrical specifications, pin mappings, package details, etc
  • Reference Manual, tells you how to use the internal peripherals, etc
  • Programming Manual, not required to read but it is useful to understand how the flash memory is organized and written

Bootloader

Almost all STM32 chips can enter a factory stock bootloader that is stored in ROM (meaning it cannot be overwritten or deleted accidentally), and activated by a pin called BOOT0. To learn how to activate this bootloader mode, look for a document named STM32 microcontroller system memory boot mode. The bootloader uses UART (aka serial port) for communication, and it can also use USB if the chip has USB abilities.

This ROM bootloader usually works with a tool called "Flash Loader Demo", also known as STSW-MCU005. The protocol is also documented so that you can write your own application, but this is not required.

If you want to use the USB version of the bootloader, look for a tool called "DfuSe", also known as STSW-STM32080. The protocol is also documented, and the source code for the DfuSe tool is available as well.

If you want to implement a custom version of the USB bootloader, ST does provide source code for the bootloader firmware (provided with their USB library), and it is compatible with DfuSe.

Clock Configuration Tool

For different STM32 chips, ST provides an Excel spreadsheet with macros. You have to enter your parameters such as input crystal frequency and desired output frequency. The spreadsheet macro will use your info to generate a file that you can compile into your project. This file will setup the clock sources and PLLs for you. To find these files, you need to search for "Clock configuration tool for" on the ST website, there is a different tool for each chip.

Standard Peripheral Libraries

ST provides libraries that help you use the features of their microcontrollers. You need to find the specific library for your specific chip by searching for "Standard Peripheral Library" on the ST website.

Inside the library download, you will also find CMSIS support files, a startup file written in assembly, and linker scripts for GCC's linker. You need these files to build any project.

You may also find a clock configuration file inside the examples, but keep in mind that it might be designed for a frequency that is different from the frequency you need.

The library also comes with a ton of examples that compiles under many toolchains. If you get lost, start with an example.

ST supports Atollic TrueSTUDIO, which is an expensive IDE that is based on Eclipse and GNU GCC, so any files that works for TrueSTUDIO will also work using our GNU GCC build process.

USB Device and Host Library

ST provides a half decent USB library. It's not perfect but it gets the job done. Also known as STSW-STM32046.

Debugger

Discovery Boards

ST has a family of Discovery boards, which are dirt cheap ($8 is the cheapest). Each Discovery board has a ST Link V2 built into it, which can do SWD debugging. You can disconnect the ST Link and use it for other projects. This is a great backup tool as well.

The schematics for the Discovery boards are always available. They are a great starting point for when you need to design your own circuit with STM32 chips. There are also example code from ST written specifically for Discovery boards.

CoLink

CoLinkEx is also very cheap but it does not support all of the STM32 family. I support CooCox's open source efforts but I cannot recommend this debugger because some of my favorite STM32 chips are not supported yet. Once the support has been added, then I can recommend it.

J-Link

I own a J-Link EDU, which is reasonably priced at around $70. This is what I use. J-Link has a GDB server application that works with the GDB plugins in Eclipse.

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox