MIOS32 Bootloader Installation
This page describes how to install the MIOS32 bootloader on a STM32F1, STM32F4 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 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 attach 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 Windows or Linux version on a virtual machine like VirtualBox (this is what I did - both variants are working fine!). 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, create a new "FreeRTOS project" for LPC1700 controllers. This project is only used as a dummy to enable the flash programmer - you don't need to change something in the code template, it won't run under MIOS32 anyhow! (You will transfer a precompiled binary into the flash)
|
|
Select the LPC1769 target. It's red marked because it isn't fully supported by the evaluation version of this IDE - but again: for application development you wouldn't use this IDE anyhow!
|
|
Click on the small "Program Flash" icon
|
|
Click on the "Browse" button and search for the project.bin binary of the MBHP_CORE_LPC1769 directory which comes with the MIOS32 Bootloader application. Note that you've to explicitely change the file search mask to "*.bin", since this isn't done by default (-> project.bin file not displayed)
|
|
Click on the "OK" button to program the bootloader into the flash.
|
|
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. But before we can use it, some additional preparations are required as explained in the next sections.
|
STM32F4: using ST-Link to upload the MIOS32 Bootloader
|
The STM32F4DISCOVERY board is equipped with an on-board debugger (right side) which is called ST-LINK/V2. It has to be connected via a Mini-USB cable to your PC, and allows to program the flash of the target device (the STM32F407VE chip).
We use ST-LINK to install the MIOS32 Bootloader, so that a MIOS32 application can be flashed via USB-MIDI later with the Micro-USB connector at the left side. This approach will allow you to update an application on-the-fly without the need for a second USB port on your MIDIbox, it's even faster than via ST-LINK, and it will work under MacOS and Linux as well by using MIOS Studio instead of the Windows propritary ST-LINK utility.! :-)
|
|
STM provides a Windows tool for ST-LINK/V2 which can be downloaded from this webpage. You should also download the Windows driver, and install it before starting the ST-Link utility.
Linux and Mac Users could run the ST-LINK utility on a virtual machine like VirtualBox (this is what I did). Alternatively, they could try alternative debugging tools like OpenOCD or qstlink2. However, using the "official" utility is the most simple solution, especially because it's ready-to-go (no compile orgies, no hunting for missing libraries, etc...).
You only need to install the MIOS32 bootloader once, thereafter you can continue with the platform independent MIOS Studio!
|
|
After the STM32F4DISCOVERY board has been connected to your PC, the driver has been installed, and the ST-LINK utility has been opened, try to connect to the ST-LINK by pushing the appr. button.
|
|
The target device should be displayed.
|
|
Click on the small "Program and Verify" icon
|
|
Click on the "Browse" button and search for the project.hex binary of the STM32F4DISCOVERY directory which comes with the MIOS32 Bootloader application.
|
|
Click on the "START" button to program the bootloader into the flash. The "Verification...OK" message should be displayed -> success! :-)
|
|
Finally press the (black) Reset button on the STM32F4DISCOVERY board. The green status LED should flash two times (effect via PWM modulation) - the MIOS32 bootloader is up and running!
|
|
The bootloader doesn't work through the USB port of ST-LINK. Instead, a second USB cable has to be connected to the Micro-USB socket at the left side of the board!
After the cable has been plugged in, wait until your operating system has found the interface and installed the legacy USB MIDI driver (typically works immediately under MacOS and Linux, but could take several seconds under Windows).
More informations about the bootloader can be found here.
|
|
Now start MIOS Studio, select the correct MIDI IN and OUT ports (called "MIOS32" or "MIOS32 Bootloader"). MIOS Studio should be able to query the device parameters as shown at the left picture.
|
STM32F1: 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.
STM32F1: 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: 2024-05-08
Copyright © 1998-2023, Thorsten Klose. All rights reserved.
|