Skip to content

rosvall/cc2531_bootloader

Repository files navigation

Simple USB DFU bootloader for TI CC2531

See this hack for how to flash a stock CC2531USB-RD dongle

Fits in the first flash page (2 kB).

If either

  • watchdog is triggered,
  • clockloss is detected,
  • or a button is held while booting

it enters DFU (USB device firmware upgrade) mode. Otherwise it jumps to code address 0x800 to boot your actual application firmware.

As the bootloader resides in the first 2 kB of the code address space, any firmware used with this bootloader must be compiled with code addresses offset by +0x800.

To compile firmware for use with this bootloader with SDCC, just add --code-loc 0x800 to your CFLAGS.

The interrupt table in the bootloader is filled with jumps to the corresponding offset address, so apart from the extra delay of a ljmp instruction, interrupts will work normally for application firmware.

Note that the bootloader enables the watchdog with a timeout of 250 ms! This means your firmware must periodically feed the watchdog (it can't be disabled), or the device will reboot to DFU mode.

In DFU mode, it presents itself af a USB DFU 1.1 device to the USB host and allows both download (flashing) and upload (reading) for all flash from 0x800 and up. It will not overwrite itself though.

To read or write flash, use a program like dfu-util.

Requirements

How to build

Just run make to build the raw binary image bootloader.bin

Known issues

  • It is not completely conformant to either USB 1.1 or DFU 1.1, and is only tested on Linux using dfu-utils.
  • It's currently using USB vendor id 0x1608 (Inside Out Networks), which is listed as "obsolete" by USB IF. This can be changed in config.inc. I'd like ideas for a better solution.
  • It's written in 8051 assembler. This is on purpose, though. It started out written in C (using SDCC), but i quickly grew tired of trying to get SDCC to generate sensible code.

Feel free to submit a bug or pull request.

References

See also