Every time I come back to developing for the STM32F4 discovery board, I end up searching for several hours for a basic barebones template and guide for setting everything up. I decided to make this post as a refresher for myself, and I am sure it will help many others out there. I have made a repository on my github page, which contains templates for Mac OSX and Windows (using .bat and Makefiles). The templates incorporate the ST Standard Peripheral Driver library as well as sample assembly code.
I prefer using a barebones setup (no IDE) when developing for the STM32F4. However, it is extremely easy to start development with an IDE. If you want to try out an IDE, I highly recommend CooCox CoIDE. The following steps are provided for those using either a Windows or Mac OSX operating system. If you are using Linux, then I recommend going to EliasElectronics; I have used this on my own system.
0. Install git
I highly recommend that you install git on your machine, regardless if you are using OSX or Windows.
There are tons of great examples on how to install git on Windows and OSX, so just do a google search.
Once you have git installed, clone the repo I have made which contains all of the Barebones templates.
Windows Toolchain Setup:
1. Install arm-none-eabi
We first need to download the GNU Toolchain for ARM embedded systems. Go to the following URL, and download the windows installer (as of now: 4.8 2014q3).
Go to wherever you downloaded the installer and run the executable to start the installation process. When you get to the step to choose a destination location, browse to a path without spaces, as seen below.
Continue with the installation until you reach the final screen. Make sure you click “Add path to environment variable” as seen below.
Now open up the command prompt and type:
You should see the following results if the ARM toolchain was setup correctly.
At this point, you can start developing for the STM32F4. The only caveat is that you must use windows batch files in order to build your projects. This limits the cross compatibility of your code, as you will most likely be using some sort of makefile on OSX and Linux. However, this option is favorable as you do not need to download any other software to build your projects. Therefore, I have created a template for you to use, along with the batch scripts. You can find the template, Barebones_Windows_Batch, on my github.
If you choose to go this route you will still need the ST-Link Utility software in order to flash the .hex file to the ST board. Skip to step 3 for the instructions to install.
2. Install MinGW and MSYS (optional if using .bat files)
We will now install MinGW and MSYS in order to get a nice terminal emulator and many unix capabilites including make.
Download the latest mingw-get-setup.ext
Select mingw32-base, mingw32-gcc-g++, msys-base under ‘Basic Setup’
Select msys-minty and msys-wget under ‘All Packages’
Select Installation/Apply Changes to install the software selected
Add the following to the your PATH variable:
C:\MinGW\msys\1.0\bin\mintty.exe /bin/bash -l
You now have all the command line utilities necessary to build the STM templates using the make command.
3. Install ST-Link Utility
In order to flash the STM32F4 board with our compiled project, we will use the ST-Link Utility.
Go to the link above and download the ST-Link Utility. Follow the steps as it will install all of the necessary drivers for connecting to the STM32 board.
4. Flash The STM32F4
After you build your project, either through make.bat, or the Makefile, you must then flash the .hex file to the ST board.
A. Connect your STM32F4-Discovery board to your PC
B. Open up the ST-Link Utility
C. Select File/Open File/ and navigate to the build/ directory and open the ***.hex file
D. Select Target/Program and Verify/Start to flash the board
Mac OSX Toolchain Setup
1. Install arm-none-eabi
You can either download the toolchain as we did above and then edit your path variables, or we can use the homebrew package manager for osx, which is the way I will describe below.
A. Install Homebrew
Homebrew is a very nice package manager for OSX, much like apt-get on Ubuntu. There is a lot of information on their website, so feel free to take a look.
Otherwise, simply open the terminal, enter the following command, and follow all the steps to install.
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Now that we have homebrew installed, it is very easy to install the ARM toolchain. Simply enter the following commands:
brew tap PX4/homebrew-px4 brew update brew install gcc-arm-none-eabi-48
This will install the latest (as of Oct. 5, 2014) ARM toolchain (4.8 2014q3)
To test that the installation works, enter:
2. Install ST-Link
In order to flash our programs onto the STM32F4 we will use a software called st-link. We will need to get and compile from source, the st-link software. Run the following commands to build st-link. *This assumes you are at your home (~) directory.
mkdir src && cd src git clone git://github.com/texane/stlink.git cd stlink ./autogen.sh ./configure make
Now we will install the st-link tools we will use and make them available via the PATH variable. *Again, this assumes you are in the ~/src/stlink directory from above.
sudo mkdir /usr/local/opt/stlink sudo cp st-flash /usr/local/opt/stlink/. sudo cp st-util /usr/local/opt/stlink/.
Now we must add the st-link to our path (be cautious with this)
sudo bash -c "echo /usr/local/opt/stlink >> /etc/paths" ---> OR, edit the file yourself and append "/usr/local/opt/stlink" sudo emacs /etc/paths
To test the st-link is working, restart the terminal, plug in your STM32F4-Discovery board, and enter st-util into the terminal. You should get the following output.
Have fun developing
Now everything should be setup and you can start developing on either Windows or OSX. I hope this helped some of you and saved many hours hunting. Let me know if you have any questions, and feel free to checkout my youtube page, https://www.youtube.com/user/tdabboud, for tutorials on the STM32F4-Discovery Board. Thanks!!