ChibiOS based STM32 bootloader example

Hi there,

since I’ve finally but my last oral exam for this semester behind me there is more time for me to hack on various stuff again.

Some of you might now that I’m a big fan of of the ChibiOS paired with the awesome STMicrolectronics STM32F series of Cortex-M3 microprocessors. These days I’m more and more into developing products which will run and work i.e. in Belgium. So there is no easy way to just pop by and deliver a firmware update over JTAG or there must be at least one remote controllable computer with a JTAG probe – not an elegant solution.

But there is hope, the STM32 chips do include the possibility to update the Flash ROM from inside a boot loader. Now, there are examples for boot loaders but I found most of them to be too “hackish”. So I set out to write my own boot loader based on ChibiOS. The example is targeting the Olimex STM32P107 development board but should be easy to adapt to other boards. You can find the final result on my github page:

https://github.com/mabl/ARMCM3-STM32F107-BOOTLOADER

The example includes helper function abstracting the flashing process. The example implementation demos reading the firmware in Intel Hex format from a SD card.

 

 

12 thoughts on “ChibiOS based STM32 bootloader example

    1. Hi Giovanni,

      the bootloader start address is defined in flashconfig.h. The user code is flashconfig.h, currently it is. 0x08005000. The loaded code is responsible to reallocate the interrupts, maybe this is not optimal. Probably the code also has to be updated to work with more recent ChibiOS version.

      Best,
      Matthias

          1. Hi Matthias,

            actually no, I am not having problems with the bootloader.

            I am just asking, before starting my project: it is based on chibios application and so, I liked to know if bootloader is able to handle chibios application.

            I will let inform you about any progress I will do.

            Thanks.
            -g

  1. Hi Matthias, I think there is a major problem with FATFS: a required file, diskio.h, is not present… I am using 2.4.2, and backported fatfs bindings from git snapshot.

    Bye

    1. Hi Giovanni,
      this file is included in ChibiOS/ext/fatfs-0.9-patched.zip. Also have a look at ext/readme.txt.

      There have been many changes to the MMC/SDIO interface in chibios. You best have a look at the FAT examples of ChibiOS. I don’t think there is too much need for backporting.

      The bootloader itself just needs working FatFs.

      Best, Matthias

        1. Hi Giovanni,

          it was the unstable branch at that time, around SVN revision 4211 or git e3bed1c. The only relevant changes are probably in the MMC interface. It should not be hard to port the code to use the normal MMC demos. I’d do it for you, but I’ll be on my 2 weeks vacations starting on Monday. If you do not plan to implement your own flash interface (no MMC/FAT) you could also just throw out this part of the code. The flash writer part is generic – you only have to supply the flash content in increasing order and don’t jump between flash pages.

          Best,
          Matthias

  2. Hi Matthias, I was able to compile on Chibios_2.5.0 branch.

    Now I have to check if everything works as needed ;)

    I have a question: the bin output file is about 16kb long; the elf file is 260kb long: is it still possible to debug?

    bye

    1. Hi Giovanni,

      glad it worked. Check size with arm-none-eabi-size. If it exceeds the application start-up location, you will have to increase it appropriatly in flashconfig.h – just make sure it’s still at the start of a flash page boundary. I also used debugging during development, so it ought to work.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>