Developing STM32F4-Discovery firmware on Linux (Part 1)

In a world where all the developers are fogged under IDEs this post might sound a bit obsolete. But when it comes to highly demanding embedded applications the Electronics Engineers need unlimited access to hardware. Then we will have to rethink whether the flexibility we required is provided by the “Expensive” IDEs.

This blog post is an aggregation of information I found through following sites. I took time to repost them here to give them wider audience. They are wonderful references.

indexstm32f4_discovery_small

Links:

http://www.wolinlabs.com/blog/linux.stm32.discovery.gcc.html

https://github.com/texane/stlink

http://hackaday.com/2011/10/17/how-to-develop-for-stm32-discovery-boards-using-linux/

I tested the whole system under Ubuntu 14.04 LTS x64 OS. It worked perfectly. Mostly I followed the steps provided by the link 1. But some parts were carried out in a different way. I still did not try any debugging. In this post it will be about compiling and flashing a simple sample firmware.

Let me briefly post the steps here,

  • Download the GNU ARM tool-chain.

Download link: https://launchpad.net/gcc-arm-embedded

  • Extract and export the path to the tool-chain.

Extract: tar -xvjf gcc-arm-none-eabi-4_8-2014q1-20140314-linux.tar.bz2

Export: Add the following line to ~/.bashrc file. Please replace the path as necessary.

PATH=$PATH:/home/pradeepas/toolchains/gcc-arm-none-eabi-4_8-2014q1/bin
export PATH

  • Run the following command and install the packages needed to install ST-Link. Some of these packages may already available in your PC.

sudo apt-get install autoconf pkg-config libusb-1.0 git

  • Clone the st-link from the git repository using the following command. 

Please navigate to the place where you want to clone the repo and run the command.

git clone https://github.com/texane/stlink.git

  • Build the st-link package

cd stlink
./autogen.sh
./configure
make

It should create the executable file st-flash within ‘stlink’ directory.

  • Download the sample code.

git clone https://github.com/rowol/stm32_discovery_arm_gcc

  • Edit the makefile of the cloned blinky sample to point to the correct stlink folder and correct st-library folder

You will have to modify ‘STLINK’ path in the makefile.

  • Copy the udev rules to /etc/udev/rules.d directory.

Goto the stlink repository. (The place where you cloned stlink)

Run the following commands:
sudo cp 49-stlinkv* /etc/udev/rules.d/
sudo udevadm control –reload-rules

  • Now connect the device and check in /dev to see whether st-link is listed.

If not please refer stlink/Readme file for possible issues. I did not run into any issue. In my PC it is displayed as “stlinkv2_4”.

  • Compile and burn the firmware

Goto blinky folder.
Run ‘make’ to build the blinky project.
Run ‘make burn’ to burn the ‘.bin’ to the device.

PS: I tried to be as abstract as possible. If you came across any issue, put a comment or refer the links.

Enjoy!!!
Happy coding!!!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s