Category Archives: Projects

libopencm3 Discovery

Hi everyone,

As promised in the previous post. Here is a short write up how to download, compile and upload your first example program using libopencm3 and a STM32F4 discovery board.

Very similar process will apply to any other evaluation boards that employ an STM32 microcontroller and Black Magic Probe JTAG/SWD programmer. Like for example Lisa/M, Lisa/MX, Lisa/S, Apogee and so on.

Step 1

If you did not already do that, download and install GCC ARM Embedded. You might have already done it if you were “fixing” your Discovery board.

You can download the compiler from here:

Unpack it into your home directory:

cd ~
tar xfvj ~/Downloads/gcc-arm-none-eabi-replace this with the version-mac.tar.bz2

You should add the binary directory of the newly unpacked compiler package to your system. Obviously to do this you add the directory to your PATH environment variable. If you don’t know what that is you should learn a bit more about your Unix/Linux basics. 🙂

export PATH=~/gcc-arm-none-eabi-someversion/bin:$PATH

To make this addition persistent you can also add that to your .profile, .bash_profile or .zprofile depending on the shell and setup you use.

Step 2

Download libopencm3-examples. You can find this repository at

git clone

Step 3

Build the libopencm3 examples. The repository contains libopencm3 as a submodule so you will have to initialize and update the submodule before you can compile the library itself as well as all the different examples.

cd libopencm3-examples
git submodule init
git submodule update

This will take a bit as there is a lot of examples included in that repository. In the past the examples were part of the main library itself but there became so many of them that we had to split it off. Otherwise the build and clone process just took too long.

Step 4

Prepare your environment. To make your life easier you should set up your .gdbinit configuration file. This will make the firmware upload and debug process so much easier. Just add the following lines to the file:

set target-async on
set confirm off
set history save
set mem inaccessible-by-default off
tar ext /dev/cu.usbmodemSOMESERIAL1
mon version
mon swdp_scan
#mon jtag_scan
att 1

Note: On linux the cu.usbmodemSOMESERIAL1 becomes ttyACM0.

For reference here is the breakdown of what the commands inside of the .gdbinit file mean:

  • set target-async on: Enable background execution commands.
  • set confirm off: This disables the really annoying “are you sure” questions. 🙂
  • set history save: This forces GDB to save the command history.
  • set mem inaccessible-by-default off: This is one of the most important commands here. Very often when you are trying to debug your code on a microcontroller you have to read the content of memory mapped registers. If you don’t set this option the debugger will prevent you from doing so as it has no idea that this memory is actually accessible. On a PC having the option on makes total sense but on a microcontroller it is mostly a burden.
  • tar ext /dev/cu.usbmodemSOMESERIAL1: tell gdb to connect to Black Magic Probe
  • mon version: Print version of the Black Magic Probe.
  • mon swdp_scan: Scan for devices using SWD protocol.
  • att 1: Attach to the first process. On a microcontroller you will have only one process…

Step 4

Upload fancyblink example. The simplest example for the STM32F4 Discovery board is the fancyblink example. It is also very easy to upload. As long as your Discovery board is “fixed” and uses the BMP firmware.

cd examples/stm32/f4/stm32f4-discovery/fancyblink
arm-none-eabi-gdb fancyblink.elf

Now the LEDs on the Discovery board should be blinking. You can interrupt the execution of the program by pressing <Ctrl>-C. You can continue the execution by running cont.

Here is a short reference of GDB commands that you might find useful when playing around with code:

  •  load -> load the binary from the provided elf file. (Note: it detects if the elf file changed on the hard disk and loads a new one if available. So you don’t have to quit GDB every time when you recompile your code)
  • run -> start the execution of your firmware
  • backtrace -> print the call stack trace of the current line of code being executed
  • make -> runs make command in the directory you started gdb. Very useful if you want to update the binary you are running really quick.
  • break filename:lineno -> you can add a breakpoint inside your code. GDB will stop the execution of the program as soon as the line is hit by the firmware.
  • step -> execute one single line of code and return back to the command line
  • next -> same as step but it does not enter into the functions called and skips them. Useful if you want to step over functions you know take forever and you are not interested in what they are actually doing. 🙂
  • print variablename -> print the content of a variable
  • print/x variablename -> print the content of a variable as HEX
  • list -> prints the context of the line being executed at the very moment
  • kill -> if used in a GDB script it will reset the MCU and exit GDB. Very useful as last command of a GDB script.

I hope this will be helpful for you.


P.S. Big thanks to Jack Ziesing for proofreading and introductory paragraph and sparking the work on this article. It is a great help! 🙂

Black Magic Discovery

Hey everyone!

Today I had to fix another STM32F4 Discovery board. By fixing I mean replacing the STLink firmware with Black Magic Probe firmware. I do that on a semi regular basis but as I have not done it in a long time I did not remember the process anymore. Obviously this calls for a blog post with some step by step instructions on how to do it, so that I have a reference in the future. Also you might find it useful yourself.

First of all let’s explain what we are trying to do. The objective is to replace the STLink SWD (Serial Wire Debug) firmware with Black Magic Probe firmware.  The board is setup by default to use a smaller chip to run the STLink firmware to talk to the main stm32.  We need to change the smaller chips firmware.  The initial adjustments to the board are needed to be able to access the programming pins of the smaller chip and replace it’s contents to Black Magic Probe firmware so that we can use GDB (GNU DeBugger) to program and debug the board instead of the very unstable and unreliable proprietary STLink protocol. The adjustments needed to access the small chips programming pins need to be reversed once the firmware is changed to Black Magic Probe firmware, resulting with an stm32 f4 discovery board with Black Magic Probe firmware ready to use.

For the “Fixing” process I use a genuine Black magic probe, I have one of those very early ones with a 0.1″ header that is very useful in this particular case. You can also use a Black Magic Probe Mini with a PCB adapter, make an adapter cable or you can use another Discovery board that has already been “fixed”.

Step 1

First step is to change the two solder jumpers on the bottom of the discovery board.

Jumper modification for SWD programming.

Jumper modification for SWD programming.

Remove the 0Ohm resistor/jumpers marked with red circles, and close the jumpers marked with blue circles.

Note: The easiest way to do that is to use a soldering tip, add a bunch more solder over the resistor and swipe them of. After that is done use solder wick to make sure there is no short on the “red” jumper. You can discard the 0Ohm resistors. It is much easier to just add a small blob of solder to close the “blue” jumpers, it is easy to remove them later in the process by just using some solder wick.

Step 2

Remove the SWD and slave MCU jumpers as indicated by the red circles in the photo.

STM32F4 Discovery board Jumpers for updating the programmer chip firmware

STM32F4 Discovery board Jumpers for updating the programmer chip firmware

Step 3

Attach jumper wires to the Black Magic Probe header.

Black Magic Probe Serial Wire Debug connections for Discovery board "fixing"

Black Magic Probe Serial Wire Debug connections for Discovery board “fixing”

Standard JTAG/SWD 20Pin 0.1″ header

  • Black wire – Pin 14 (GND)
  • Orange wire – Pin 9 (TCLK/SWCLK)
  • Yellow wire – Pin 8 (TMS/SWDIO)

In case you are trying to figure out which pins these are on a standard ARM Cortex 10Pin 0.05″ header. Here you go:

Standard JTAG/SWD Cortex 10Pin 0.1″ header

  • Black wire – Pin 3, 5 or 9 (GND)
  • Orange wire – Pin 4 (TCLK/SWCLK)
  • Yellow wire – Pin 2 (TMS/SWDIO)

Step 4

Attach the Black Magic Probe to the discovery board.

STM32F4 Discovery board Serial Wire Debug connection for "fixing" the on board programmer firmware

STM32F4 Discovery board Serial Wire Debug connection for “fixing” the on board programmer firmware

  • Black wire (GND) – Pin 3 of the SWD (CN2) header
  • Orange wire (SWCLK) – Pin 2 of the ST-LINK/DISCOVERY (CN3) header
  • Yellow wire (SWDIO) – Pin 4 of the ST-LINK/DISCOVERY (CN3) header

Step 5

Now you can connect the discovery board and the Black Magic probe to your computer via USB. The order should not matter, but usually I tend to connect the usb wires to the laptop before connecting the SWD wires between the two devices, just to make sure we don’t have some strange current loop that powers one or the other via IO pins, which might be problematic.

Step 6

Now we turn our attention to the software. You can obviously do these steps before you wire everything up but this is the order I followed.

The process requires a few dependencies that you should install using either apt on Linux or homebrew or macports on OS X:

  • Python
  • pyserial

In my case I use OS X and homebrew so I needed to run the following two commands:

brew install python
pip install pyserial

Step 7

Download and make the an arm gcc compiler “findable”. I recommend using GCC ARM Embedded as it is maintained by the ARM developers themselves and they seem to generally know what they are doing. 🙂

So download it from here:

Then unpack it into your home directory:

cd ~
tar xfvj ~/Downloads/gcc-arm-none-eabi-replace this with the version-mac.tar.bz2

Then you should add the binary directory of the newly unpacked compiler package to your system. Obviously to do this you add the directory to your PATH environment variable. If you don’t know what that is you should learn a bit more about your Unix/Linux basics. 🙂

export PATH=~/gcc-arm-none-eabi-someversion/bin:$PATH

To make this addition persistent you can also add that to your .profile, .bash_profile or .zprofile depending on the shell and setup you use.

Step 8

Download blackmagic firmware source code. You can get it at

The easiest way is to clone the github repository, look for the small window at the center right of the github page for the git repository url. If you have a github account choose the ssh url but if you refuse to do so then you can go with the https one too. 🙂

If you did not learn about GIT and GitHub yet this is the perfect time to take a break from all of this here and come back after you have caught up on your homework. 😀

git clone

Step 9

Now let’s build the firmware. This consists of three steps:

  1. Fetch the libopencm3 submodule
  2. Build from the toplevel so libopencm3 is built
  3. Build the blackmagic firmware for the stlink
cd blacksphere
git submodule init
git submodule update
cd src
make clean
make PROBE_HOST=stlink

Step 10

We can finally connect to the hardware we wired up before and erase the pesky stlink firmware. When the discovery boards ship, the firmware is read and write protected on the STLink chip. So to be able to overwrite the firmware we will have to unlock the chip. Thanks to Gareth there is a small python script that can do that for us. You just have to call the following command inside the src directory of the blackmagic repository and it should be able to remove the write protection:

../scripts/ -s -d /dev/cu.usbmodemSOMESERIAL1 -r blackmagic.bin

In the case you are on Linux you can leave out the -d device parameter. For reference the -s parameter tells hexprog to use Serial Wire Debug instead of JTAG and -r tells it to unlock and erase the target chip.

If you skip any of those two parameters it will not work for you.

Step 11

Flash the bootloader. We are getting very close. To upload the blackmagic bootloader you use arm-none-eabi-gdb.

arm-none-eabi-gdb blackmagic_dfu
target extended_remote /dev/usbmodemSOMESERIAL1
monitor swdp_scan
attach 1

This sequence of commands attaches to the virtual gdb server that is provided by the Black Magic Probe on it’s virtual serial port 1. (The second serial port is the USB to serial interface located on the back of the BMPM) We then tell the monitor (this is the BMP) to scan using Serial Wire Debug as our protocol. Next we attach to the virtual process number 1. (As we are on the embedded systems there usually should only ever be 1 process unless you run an RTOS) We load the firmware from the elf file that we passed on to gdb earlier and exit GDB.

Simple right? 😀 (Believe me that is definitely simpler than setting up and making OpenOCD work with Eclipse)

Tip: To make things easier for the future you can add the following to your .gdbinit file:

set target-async on
set confirm off
set history save
set mem inaccessible-by-default off
tar ext /dev/cu.usbmodemSOMESERIAL1
mon version
mon swdp_scan
#mon jtag_scan
att 1

Note: On Linux the cu.usbmodem device name will be /dev/ttyACM0 instead.

After setting up the .gdbinit file the upload process becomes quite a bit shorter:

arm-none-eabi-gdb blackmagic

Step 12

Upload the black magic firmware itself. Here you have two options. Either you can use the same process as before using GDB or you can use the now uploaded DFU bootloader to upload the Black Magic Probe firmware payload. Using GDB you would run the following:

arm-none-eabi-gdb blackmagic
target extended_remote /dev/cu.usbmodemSOMESERIAL1
monitor swdp_scan
attach 1

Alternatively you can upload the firmware using a DFU script. Before you do that though you should disconnect the genuine Black Magic Probe from your computer as you want to make sure the script flashes the Discovery board and not your BMP. To do that you will need to install python libusb as an additional dependency. But having done that you can then run the following to upload the firmware:

./scripts/ blackmagic.bin

Step 13

Put everything back together. Now you just have to do four things:

  1. Disconnect your Black Magic Probe and Discovery board from your computer as well as each other.
  2. Remove the solder blobs you have added on the back of the board.
  3. Add solder blobs to where you removed the resistors at the very beginning.
  4. Put the jumpers back to where they were on the front of the Discovery board.

You are pretty much done now. If everything went well you should have your “fixed” discovery board. Follow to the one additional step below to test that.

Step 14

Plug in your Discovery board into your computer. The dual color led next to the USB connector should be solid Green. If it is blinking Green it means the bootloader is running and the board is expecting to be flashed with the firmware. This can happen if you still have the power jumper disconnected that provides power to the “slave” STM32F4 chip. This is actually very useful if you want to upgrade the Black Magic Probe firmware on your discovery board. 😀

Additionally if everything went well if you are on Mac OS X a /dev/cu.usbmodemSOMESERIAL1 and /dev/cu.usbmodemSOMESERIAL3 should appear. If you are on linux you should be able to find ttyACM0 and ttyACM1 in the /dev directory.

I hope this write up is useful for you and the future me. 🙂 I am planning to write another blog post on how to build and upload an example firmware onto the slave processor. So hold on to your hats! 🙂


P.S. Big thanks to Jack Ziesing for proofreading and introductory paragraph and sparking the work on this article. It is a great help! 🙂

Lisa/S, SuperbitRF, 1 BIT SQUARED

Hi everyone,

Again it was a while since I posted something here. I just wanted to write a quick update on what I’ve been up to lately.

I am working very hard on Lisa/S and SuperbitRF. The goal of the project is to develop the smallest and lightest possible UAV controller system without compromising functionality.


The Lisa/S board is only 20mm x 20mm and weighs about 3g with a lot of integrated sensors.

  • 3 Axis Gyroscope
  • 3 Axis Accelerometer
  • 3 Axis Magnetometer (Compass)
  • Barometer (Altimeter)
  • GPS Receiver

Just like Lisa/M it’s bigger sister. Lisa/S is powered by the STM32F103 ARM 32bit microcontroller. Providing quite a lot of processing power for your UAV needs. On top of it all the board has 4 MOSFET solid state switches. They make it possible to use the board directly on the tiny brushed motor quadcopters, nano helicopters and fixed wing airplanes. I am quite excited how much I managed to put onto that tiny footprint. Usually much bigger boards don’t even include a GPS receiver on the board.

Another feature of Lisa/S that I think is worth mentioning is that it has a CYRF footprint.

CYRF is a module that I developed as part of the system. It contains the CYRF6936 2.5GHz transceiver chip. It is connected to the MCU on Lisa/S through SPI. The particular transceiver is the one at the heart of all the Spektrum transmitter and receiver systems and many others like Walkera Devo. It is very exciting because we have direct access to that chip from the autopilot and can implement compatibility to a lot of 2.4GHz RC gear available out there.

Our current software implements support for some Spektrum RC transmitters and as a bonus we can simultaneously connect to a laptop using the USBRF dongle. This removes the need for having two radios on your vehicle thus saving weight.

All of these items are currently available for pre-order in the 1 BIT SQUARED shop. We are working on finalizing the production process of the first batch of Lisa/S, CYRF and USBRF. We are projecting they will be available in the shop by the end of May. We have put a lot of effort into making these boards, if you are interested you can read more about it in the 1 BIT SQUARED blog.

Last but not least 1 BIT SQUARED is my own company that I founded early last year. I want to develop and produce hardware and software that I am excited about and would like to share with others that are interested in the field of airborne robotics. If you like open hardware and software and want to support me directly the shop is the most direct and easiest way to do so.


Quadshot – an aerobatic blend of RC quadrocopters and airplanes

Hi everyone,

As you probably notice I am very busy lately. Together with some friends we were working on the Quadshot an aerobatic blend between a quadrocopter and an airplane.

It takes off and lands vertically like a quadrocopter as well as it can fly forward like an airplane using its wing to add additional lift extending flight time.

We submitted the project to Kickstarter and we are very happy to see that we got such a great response. The Kickstarter funding runs for another three days and if you pledge you can get a Quadshot at a discounted price as a reward.

At it’s heart Quadshot is using the avionics and software framework of Paparazzi. We developed the additional necessary controls for Quadshot and released them. So Quadshot has Open-Hardware electronics and Open-Source firmware making it a great platform for research and hacking.

Having an autopilot makes it also very easy to fly for a beginner RC pilot.

I hope to find some more time in the future to get into more details about Quadshot. But till then check out the following links:

Cheers Esden

Open-BLDC and the CLogic story

Castle ICE HV to Open-BLDC Mod Tutorial Step 10Hi,

It was again a while since my last post, but as always I was quite busy. 🙂

The last news about Open-BLDC was about its V0.3 iteration. A lot has changed and happened since then. I was realizing that I am getting more and more inquires where people were asking about obldc being able to control very different sizes of motors, ranging from 12V and 10A up to 48V and 200A.

This requirement does not really ask for different logic and controls but it definitely asks for many different power stages. Open-BLDC was designed to be modular from the beginning but still to accomodate that kind of a power range it would be necessary to design and create quite a big lineup of hardware.

Around that time I had the opportunity to take a look inside a dead motor controller from Castle Creations just to realize that these guys seem to know what they are doing and that they went with a modular design too. To make a long story short I decided that it will be better to buy one of their of the shelf motor controllers and retrofit them with my logic. That is how CLogic was born.

As it seems other manufacturers are selling ESCs that have the same interface between the logic and the power stage too. Tekin for example. But my guess is that they are just OEM of castle themselves. But who knows. 🙂

Turingy also came out with an ESC that seems to have the same interface, the Turingy dlux. I ordered a few of them to take a look for myself and see if CLogic will fit in there. That would be a great source of cheep power stages. 🙂

CLogic has most of the functionality the Open-BLDC v0.3 had. Because of the size constrains I had to get rid of the dedicated i2c and PPM connectors, but I added isolation on the CAN interface that should provide additional safety when used on a 50V and bigger systems. The i2c and PPM interfaces are still available either over the new AUX connector or through the UART interface connector.

The new AUX connector gives the possibility of easily connecting encoders or hal sensors for sensored operation. So the interfaces stay very flexible with added flexibility due to the big variety of power stages you can use, while being very very compact.

Sure some people complained “The power stages are not Open-Source!!!”, yes that is true. Also these systems start at a higher power and weight class than some of you would want to operate them. That is why there is CPico Power. It is a very small, low power and a hopefully cheep power stage that we are putting together for those who want it all fully open! So no worries. 🙂

I think that wraps up the news about the new direction Open-BLDC is going. I hope you like it. I am looking forward to your comments.

Cheers Esden

FLOSS-JTAG V1.0 Released and Available

Hey everyone,

As you might know some time ago I have developed a small JTAG adapter based on the FT2232H chip. I gave it the name FLOSS-JTAG as the idea was that it should be absolutely OpenSource and OpenHardware.

You can find the project at GitHub and some more info at it’s random projects wiki page.

FLOSS-JTAG not only has the high speed 24MHz FT2232H chip (there are some designs based on my idea that are using a low speed version of the same chip). It provides the new standard 0.05″ pitch 10 pin Cortex JTAG header as well as a TTL level serial interface on it’s second interface.

I am glad to announce that I have reached the V1.0 with it. All necessary files to make your own are in the GitHub repository. But if you don’t want to go through the pains of ordering PCB, sourcing parts, assembling QFN SMD packages you can also purchase it in the Joby Robotics online shop.

At Joby Robotics you get a cable assembly to connect the FLOSS-JTAG to a target. This allows you to debug and connect to targets that are difficult to reach otherwise. You also will get a cortex connector to old standard 20pin 0.1″ pitch connector adapter.

The adapter is small and will make it also easier to debug targets that are difficult to reach.

You can get precrimped Molex Picoblade wires in 10 different colors at Joby Robotics too. This way you can easily build a UART cable that connects FLOSS-JTAG to a device.

I am very happy that FLOSS-JTAG is finally easily accessible to anyone who needs it.

FLOSS-JTAG works perfectly together with Openocd and Summon-ARM-Toolchain.

Cheers Esden

Open-BLDC V0.3 Hardware Based Closed Loop Control


Good news everyone!

After again a way too long time some new news! I finally implemented hardware based commutation detection and the associated closed loop controller.

That was quite a run because of a cascade of timing and timer problems. And a very nasty compiler bug. But now it works and very well on top of that. Woohoo o/ But see for yourself in the video.

The video also shows the new implementation of the startup routine. It uses now a separate software timer. It was made possible by using SysTick as timer base and implementing the timer in software. This way it is easy to add new timers that don’t need to be very time precise, as it is the case in startup, or ignite as I like to call it. 🙂 The old implementation was using timer overflows of the commutation timer that led to nasty speed jumps while starting up and made the startup unreliable.

Next step, put Open-BLDC on a plane! 🙂

As always you are welcome to drop by in #open-bldc channel on freenode if you have questions or just want to hang around to follow the cutting edge development. 🙂

Open-BLDC Documentation

Today was a big documentation day for Open-BLDC.

As Tobi is learning about Open-BLDC to be able to help me with development I really felt the lack of documentation. So together with him we wrote down how the ignition system currently works. Also I added a getting started page describing how to build the firmware.

Last but not least (that took me most of yesterday) I finally managed to add doxygen generation to the firmware code. It is even being automatically generated out of the git repository and making it available on

There is still a lot that can be told about the system, but I think we are on the right path. The documentation should grow now significantly when I am not the only person working on the code. 🙂

Open-BLDC v0.3

Open-BLDC V0.3 Full Front
Hey everyone!

Just a short update so that you don’t think that I have disappeared completely. 🙂

Lately I am really busy so that is why my updates here are very rare. I have moved to California few months ago to work full time on Open-BLDC and Paparazzi. Although Open-BLDC got quite a bunch of attention there is still a lot to do, and this project is still not in a state where it is possible to put the controller on a vehicle and fly with it. 🙁

There is some good and bad news. I got the sampling based commutation detection running pretty good. There is an issue with it. Because you can sample the BEMF only once a PWM cycle the resolution prevents turning the motor very fast without adding some kind of an estimator or at least a PLL. So currently only 4000RPM with a 7pole pare motor are possible. 🙁

That is why I started working on Open-BLDC v0.3 hardware. It is assembled now and you can look at some pictures here. It has a comparator integrated into the power driver board to make commutation detection really easy and have something usable _NOW_. I also found out that using many small mosfet’s is much more efficient then using single big ones. The gate capacitance is lower, the heat dissipation is easier, the on resistance is tiny. The only question is if they will distribute the power evenly between the switches. That is still something that has to be tested. But the power stage board looks really pretty with all those tiny fets on it. There are many more other smaller and bigger improvements that would be too much for such a small post.

I am currently bringing up one subsystem after another. I had to change some of the connections to the STM32 which means that I have to change the low level drivers and it is always a pain to do.

Anyways, there is progress and Open-BLDC is not dead! I am working on it. And I am sorry for not keeping you guys more up to date. As always I will try to be better about that. 😉

Floss-JTAG V0.1 Assembly and V0.2 boards.

Because I wanted to have a small JTAG adapter with additional UART port and a different (smaller) connector then what is available out there, I have decided to make a JTAG adapter. I chose the FT2232 USB adapter chip. This guy is pretty nice because it has a special engine inside that is supporting many different protocols. One of them is JTAG. I have released what I made as always on GitHub under the CC-BY-SA 3.0 license. There is no software needed on the adapter side so no software included. All you need is OpenOCD. It now even has a config file dedicated for Floss-JTAG. Calling for example:

#> openocd -f interface/flossjtag.cfg -f board/open-bldc.cfg

will connect to Open-BLDC using the Floss-JTAG adapter.

Building Floss-JTAG I learned a nice lesson. Always check your footprints 10x before you send the gerber files to the manufacturer!!! I had to customize the footprint for the FT2232 chip and made a mistake. The pads were not long enough so the pins had only 0.1mm overlap area. It was a real pain to solder that. I assembled 3 of Floss-JTAG using this design. Sadly only two are working.

Because of that mistake I immediately corrected the board layout and sent it out. I got the boards today. I hope that there is no other mistake hidden somewhere. 🙂 Attached are the images of V0.1 assembly and of the V0.2 boards.