MIOS32 Bootloader Installation
This page describes how to install the MIOS32 bootloader on a STM32 and LPC17 microcontroller, so that applications can be uploaded via MIDI without opening the MIDIbox case.
Following informations are not for interest if you got a preburned STM32F103RE resp. LPC1769 device -> please continue at this page.
COM or JTAG?
Unfortunately STM and NXP missed to integrate an USB based bootloader into the ROM memory, so that additional hardware is required to program a "virgin" internal flash memory. Using the ROM based UART Bootloader is probably the cheapest method, as it only requires a RS232 level shifter (e.g. available on the MBHP_LTC module) and a COM port on your PC (virtual USB based COM devices are working as well).
The preferred method for experts is the usage of a JTAG wiggler, as it gives access to debugging features of the ARM Cortex M3, like halting the CPU, setting breakpoints, reading/writing memories during the application is running.
Here an oversight about the advantages/disadvantages in conjunction with code upload via MIOS32 bootloader:
- MIOS32 MIDI/USB Bootloader
- - has to be programmed into a virgin flash via JTAG or UART - or has to be provided in "preprogrammed chips"
- - can be destroyed by the application on gross program errors (e.g. erasing the wrong flash sector), therefore JTAG or UART BSL has to be used as fallback solution
- - no access to debug features of STM32/LPC17
- - UART based MIDI is much slower than JTAG or UART BSL (ca. 2.5 kb/s)
- + however, USB MIDI (STM32: 13..17 kb/s, LPC17: 20..40 kb/s) is even faster than JTAG (12 kb/s)
- + USB interface won't be reset after code upload (means: no need to re-open a running MIDI program on your Windows PC)
- + a solution to program STM32 Primer under Linux/MacOS
- + proven concept for end-users
- + doesn't require to open the MIDIbox case when updating an application
- JTAG
- - requires JTAG wiggler (USB based: ca. 30-40 EUR, DIY Parallel Port based: ca. 5 EUR)
- - Parallel Port based: no precompiled openocd version for Windows available
- - Parallel Port based: requires "true LPT" port, USB Printer adapters won't work. Therefore especially no solution for modern Laptops
- + FT2232 based USB JTAG wiggler is expensive, but works fast & flawless under Windows/Linux/MacOS
- + allows to debug application during runtime (e.g. display and modify memory locations, halt the CPU, setting breakpoints)
- - MIDIbox case has to be opened to connect the JTAG wiggler
- + LPC17 only: the LPCXPRESSO board includes a LPC-Link, which is a proprotary JTAG interface which runs with a commercial software. A demo version allows to debug applications of up to 128k for free. But the best: it allows to program the MIOS32 BSL! :-)
- UART BSL
- + requires COM port (USB based COM adapters will work as well) + a RS232 level shifter like available on the MBHP_LTC module
- + code upload slower than JTAG, but acceptible for less frequent updates
- + COM/LTC combination not only useful for flash programming, but also for debugging (-> printf to a console)
- - case has to be opened
- - before using the BSL, jumpers have to be stuffed on the core module
- - no access to ARM debugging functions
- + anyhow, perfect fallback solution for end-users, if the MIOS32 BSL has been destroyed, and useful for textual output as well
LPCXPRESSO: using LPC-Link to upload the MIOS32 Bootloader
 |
The original LPCXpresso board consists of a debug interface (left side) and the so called target (right side), which we will mount on the MBHP_CORE_LPC17 module later.
Before a MIOS32 application can be uploaded via USB-MIDI, it's required to install the MIOS32 Bootloader. This can be done with the freely available LPCXpresso IDE which can be downloaded from the Code Red Technologies webpage.
|
 |
Note that a registration is required to get access to the IDE installation package. A version for Windows and Linux is available. Mac Users can run the Linux version on a virtual machine like VirtualBox (this is what I did). Once the IDE has been installed, another registration has to be done to enable the LPC-Link interface - ready!
|
 |
After the LPCxpresso IDE has been opened, click on the small "Program Flash" icon
|
 |
Thereafter select the LPC1769 target.
You will be informed that the freeware version of the IDE only allows to program 128k of the flash memory, but since the MIOS32 bootloader is smaller (ca. 16k), this limitation isn't an issue for us. Later we will upload applications from MIOS Studio which is much faster anyhow (up to 40 kb/s!).
|
 |
Select a suitable project.bin file - in fact any project.bin of a LPC17 based MIOS32 application can be used which is smaller than 128k, because the bootloader is always included. If you are unsure about the best application, just upload the MIOS32 Bootloader application - it contains the bootloader, and a checking routine which verifies that the flash has been programmed correctly.
|
 |
Finally disconnect the USB plug, connect it again.
The red status LED should slowly fade three times (effect via PWM modulation) - the MIOS32 bootloader is up and running!
|
|
Please note that the bootloader doesn't work through the USB port of LPC-Link! Instead, a second USB socket will be required, which is directly connected to the LPC1769 target, and which is part of the MBHP_CORE_LPC17 module. The next steps are explained at the MBHP_CORE_LPC17 page.
|
STM32: Accessing the core via JTAG
JTAG is a standardized serial interface (IEEE 1149.1) made especially for debugging and testing purposes, and supported by many hardware devices today, especially by microcontrollers.
A premade wiggler typically costs around 30..40 EUR, such as the OpenOCD USB Adapter (40 EUR) or the JTAGkey-Tiny (30 EUR). I for myself own the OpenOCD USB Adapter and really like the additional COM port, which allows me to send printf based debug messages to a COM terminal on my Mac by connecting it to a UART output (typically MBHP_CORE_STM32::J11:MO2, configured at 115200 baud). It also works flawless under Windows and Linux, however this can be expected for all FT2232 based JTAG interfaces, such as JTAGkey-Tiny.
There are also cheaper, LPT (parallel port) based JTAG interfaces on the market (especially on EBay), but LPT ports are normaly not available on modern computers anymore, and USB Printer adapters won't allow you to access the wiggler.
The 20 pin JTAG cable has to be connected to J3 of the MBHP_CORE_STM32 module. This can even be done while an application is running (hot-attach).
With OpenOCD a platform independent open source tool is available to access the STM32. The scripts in the MIOS32 programming platform are prepared for v0.1.0 and not probably compatible to newer versions, therefore it is recommended to try v0.1.0 first before using a newer version.
Installation:
- You can download an installation package of OpenOCD v0.1.0 (.msi file for Windows, .rpm for Linux, source code for MacOS) here
If you prefer to compile the source code by yourself, you might need to install usblib before, which gives OpenOCD access to the USB interface.
Quickstart: While starting OpenOCD, you need to specify two configuration scripts - one which specifies the JTAG interface, another which specifies the STM32 target. Prepared scripts are located in the MIOS32 repository under $MIOS32_PATH/etc/openocd.
- Quickstart DOS:
We assume, that the MIOS32 repository is available under D:\mios32, and that MIOS32_PATH has been set accordingly:
- set MIOS32_PATH=D:\mios32\trunk
Open a new DOS shell, go into the directory where you built the code, and start the OpenOCD server with:
- openocd-ftd2xx -f %MIOS32_PATH%\etc\openocd\interface\in-circuit-openocd-dos.cfg -f %MIOS32_PATH%\etc\openocd\target\STM32F10x.cfg
Note that you probably need to adapt the interface setup file!
You can left this DOS window open while rebuilding your application - it can run permanently to talk with your STM32
If you are using a different JTAG interface, create a new .cfg file for it and
adapt the USB search string (thereafter commit your new file to the repository,
so that others can use it as well!)
Open another DOS shell, and type: telnet localhost 4444
This will connect you with the server
"help" gives you a list of available commands.
My favourites:
script <filename> # to execute a batch file
reset run # to reset the chip
halt # to stop CPU execution
resume # to continue CPU execution
reg # to get CPU registers, e.g. the program counter (only works in halt mode)
mdw # to display memory regions, e.g. flash, SRAM and peripheral registers
Inside the telnet session, type:
- script D:\mios32\trunk\etc\openocd\scripts\STM32F10x_upload.script
to download and execute the project.bin file of the directory location from
where you started the OpenOCD server (and not the telnet session!)
Note that "telnet" also allows to connect you to a remote computer. Means: you are able to debug a MBHP_CORE_STM32 module via intra- or internet!
- Quickstart MacOS/Linux:
We assume, that the MIOS32 repository is available under /Users/TK/svn/mios32, and that MIOS32_PATH has been set accordingly:
- export MIOS32_PATH = /Users/TK/svn/mios32/trunk
Open a new shell, go into the directory where you built the code, and start the OpenOCD server with:
- openocd -f $MIOS32_PATH/etc/openocd/interface/in-circuit-openocd.cfg -f target/stm32.cfg -f chip/st/stm32/stm32.tcl
Note that you probably need to adapt the interface setup file!
You can left this shell window open while rebuilding your application - it can run permanently to talk with your STM32
If you are using a different JTAG interface, create a new .cfg file for it and
adapt the USB search string (thereafter commit your new file to the repository,
so that others can use it as well!)
Open another shell, and type: telnet localhost 4444
This will connect you with the server
"help" gives you a list of available commands.
My favourites:
script <filename> # to execute a batch file
reset run # to reset the chip
halt # to stop CPU execution
resume # to continue CPU execution
reg # to get CPU registers, e.g. the program counter (only works in halt mode)
mdw # to display memory regions, e.g. flash, SRAM and peripheral registers
Inside the telnet session, type:
- script /Users/TK/svn/mios32/trunk/etc/openocd/scripts/STM32F10x_upload.script
to download and execute the project.bin file of the directory location from
where you started the OpenOCD server (and not the telnet session!)
Note that "telnet" also allows to connect you to a remote computer. Means: you are able to debug a MBHP_CORE_STM32 module via intra- or internet!
Not part of this quickstart guide: OpenOCD has a gdb interface which allows you to debug code from a IDE like Eclipse, Code Blocks (all operating systems) and XCode (MacOS)
Personally I prefer to edit source code with xemacs, run "make" in the shell to build a new binary, and debugging my code with printf messages or by sending MIDI events. Under special circumstances, I'm using Insight to debug the application for interactive debugging via gdb. A short installation guide can be found in the MIOS32 MEMO.
STM32: Uploading code via ROM based UART Bootloader
This is probably the cheapest solution to download code into a "virgin" device. STM provides a comfortable windows application which connects to the bootloader and allows to upload a .bin file.
References: Flash Loader, Documentation.
The transfer protocol is documented as well (here), so creating a similar program for Linux and MacOS is feasible.
Here an interconnection diagram for the LTC module.
Picture of my test setup:

Note that you need to remove the bootmode jumpers on J27 and J23, and power-cycle the core after code upload.

Last update: 2011-04-25
Copyright © 1998-2010, Thorsten Klose. All rights reserved.
|