MIOS Bootstrap Loader

The MIOS bootstrap loader allows you to install applications, but also the operating system itself in the flash memory of a PIC over the MIDI interface without the use of a special programming device. It is possible to exchange application code on-the-fly, which makes the development of applications very efficient.

Installation of the Primary Bootstrap Loader

The MIDIbox project started around 1998. In these years it was quite common that PCs were equipped with a RS232 and SSP ("printer") port, so that PICs could be programmed with cheap DIY programmers such as MBHP_JDM or MBHP_BURNER.

Today (more than 10 years later), these interfaces have been completely replaced by USB. If you don't own an old PC, USB will be the only choice. Some DIY USB programmers exist, such as Brenner8, but fortunately Microchip noticed the need for a hobbyist solution as well, and published the PICkit2 (and later also the PICkit3), which are available for around 50 EUR.

Since Microchip published the schematics as open source, some clones exist which are even cheaper. And these clones are actually my proposed solution for people who want to program PICs for the MBHP platform, because they are sufficient for our purposes. Clones are only available for PICkit2. They will also work under Linux and MacOS with command line tools which are provided by Microchip at the PICkit2 page!

I tried a PICkit2 clone from Diamex, which is available in their shop, but also at Reichelt for 30 EUR. Similar clones can be found at ebay.

MBHP_CORE isn't designed for "In Circuit Serial Programming" (ICSB), therefore you have to build a special programming board which consists of a DIP socket and a 6-pin header, which connects to the PICkit2 (clone):

Here the schematic

Programming the bootloader under Windows is easy: just use the PICkit GUI, import the bootloader_*.hex which matches with your PIC (can be found in the MIOS installation package), and press the "Write" button.

Under MacOS and Linux, you can use pk2cmd, which can be downloaded from the PICkit2 page as well. After the download, copy the bootloader_*.hex file into the same directory where pk2cmd resists - here a typical command log while programming the bootloader for a PIC18F4685 device under MacOS:

macmini2:PK2CMDv1-20MacOSX TK$ cd ~/Downloads/PK2CMDv1-20MacOSX
macmini2:PK2CMDv1-20MacOSX TK$ cp ~/Downloads/mios_v1_9g/pic18f4685/burner/bootloader_v1_2b_pic18f4685.hex .
macmini2:PK2CMDv1-20MacOSX TK$ ./pk2cmd -P
Auto-Detect: Found part PIC18F4685.
Operation Succeeded
macmini2:PK2CMDv1-20MacOSX TK$ ./pk2cmd -P -F bootloader_v1_2b_pic18f4685.hex -J0 -M
Auto-Detect: Found part PIC18F4685.
PICkit 2 Program Report       
12-10-2013, 9:14:03
Device Type: PIC18F4685
Program Succeeded.
Operation Succeeded

You don't want to buy a PIC programmer to save money?

You could buy preprogrammed PICs from SmashTV or Mike, or you can ask a friend or a member of the MIDIbox Forum who already owns a PIC programmer for burning the bootstrap loader into the chip

MIOS and Application Upload via MIDI

After the primary bootloader has been flashed, it's strongly recommended to use MIOS Studio to download MIOS and the applicatio via MIDI. Don't flash the appr. .hex files with your programmer, because this will overwrite previous installations of the primary bootloader (and MIOS if application .hex is flashed).

See also the Newbies page, and in case of troubles, the MIOS Studio Troubleshooting Page.

Boot options

The bootstrap loader has to know about two important parameters: the MIDI device ID, which should be unique number in a chain of multiple MIDIboxes, and the baudrate. It can be chosen between the common MIDI baudrate (31250) and the rate used by the MIDIbox-to-COM interface (38400).
A third parameter allows to define the connected LCD type, so that MIOS is able to select the appropriate driver before printing a message on screen. Currently character displays (1x8, 1x16, 2x16, 2x20, 2x40, 4x16, 4x40) and KS0108-based graphical LCDs are supported, other GLCD types require a special driver which is embedded into the application.

The boot options are located in the PIC ID header. The SysEx device ID is located in bitfield ID[57-63], the UART mode in ID[55], the LCD type in ID[48..51], the MBHP_IIC_MIDI address for MIDI Out redirection in ID[40..47]. Here are some setup examples:

  • ID = 0000000000000000: common MIDI interface, character LCD, Device ID 0x00
  • ID = 0000000000000001: common MIDI interface, character LCD, Device ID 0x01 (e.g. for a MBSID Slave #1")
  • ID = 0000000000000002: common MIDI interface, character LCD, Device ID 0x01 (e.g. for a MBSID Slave #2")
  • ID = 0000000000000003: common MIDI interface, character LCD, Device ID 0x01 (e.g. for a MBSID Slave #3")
  • ID = 0000000000000142: MIDIbox-to-COM interface, character LCD
  • ID = 0000000000001000: common MIDI interface, graphical LCD (KS0108)
  • ID = 0000000000007000: common MIDI interface, custom LCD driver (see also these examples)
  • ID = 0000000000120000: common MIDI interface, redirect MIDI Out stream to MBHP_IIC_MIDI with address 0x12

SmashTV wrote a nice online user interface to select the PIC ID values!

Unfortunately, "modern" PIC programmers (like for PICKIT2) don't allow to change the ID from the GUI anymore. :-(
Therefore the proposed solution (aside from .hex file hacking) is the usage of the change_id application, which allows to change these parameters via MIDI.

SysEx protocol specifics

If it should be for interest, the SysEx commands and error codes are described in this document.

Performance

  • upload of MIOS (12k): 9 seconds
  • upload of a typical application (4k): 3 seconds

Download

The bootloader image file is part of the MIOS release package.



Last update: 2017-04-09

Copyright 1998-2017, Thorsten Klose. All rights reserved.