Blinking LED on STM32F103 with only Linux tools

I decided to do some experiments with STM32. So I bought cheapest STM32F103C8T6 board for about $5 (ebay). The chip has some nice features, e.g. dozens of GPIOs, AD converter, timers, USB full-speed interface etc., full specs here.

The board has JTAG programming/debug interface header so I also needed some JTAG interface. I decided to buy some Chinese j-link clone for about $12 (ebay).

When I had the hardware at home, I started to find some know-how on the internet. My requirement was, that the software has to work under Linux.

On the beginning, I’ve found this article, which talks about running STM32F4 discovery under Linux. It gave me some ideas where to start and what should I look for, so I knew I need some example code with makefile, compiler and debug/flash tool.

Installing compiler was the easiest part, the article suggested downloading a package and uncompressing it, but I used another way, simple package installation:

I didn’t give up and googled how to unbrick it. Fortunately, chip used in j-link is atmel AT91SAM7S64 which supports uploading firmware via USB when put into recovery mode. Full manual is available here. Atmel SAM-BA utility can be also found here. Using this, I successfully bring my debugger back to life.

So I had to find another utilty for programming. OpenOCD is what I’ve found. Some pages mentioned it as working option so I installed it from repository:

sudo apt-get install openocd

OpenOCD needs a config to know which chip and debugger is used. I easilly found an example here. It mentions ft2232 device as debugger but only a simple change was enough to make it work: