4
\$\begingroup\$

I want to write a bootloader for my MCU. It's an STM32F103RET6. I searched for information about writing a bootloader for it, but I couldn't find anything. Now I have these questions:

  1. Where can I find any information (website, book etc.) about writing a bootloader?
  2. Can I write a bootloader for my MCU just using C language and the Keil compiler?
\$\endgroup\$
  • 1
    \$\begingroup\$ The following is written using C, although I'm not sure how many (if any) changes it would need to work with Keil: wiki.eluaproject.net/STM32F103 \$\endgroup\$ – PeterJ May 27 '14 at 8:25
  • \$\begingroup\$ @PeterJ Is this Peter!!??? is this Peter!!??? LoL! Thanks My brother! my board is this, Peter: eshop.eca.ir/… \$\endgroup\$ – Roh May 27 '14 at 8:31
  • \$\begingroup\$ I don't know why I can't find a good source for writing a bootloader! \$\endgroup\$ – Roh May 27 '14 at 8:32
  • 1
    \$\begingroup\$ I think the above would be a worth a shot with that board but it looks like the crystal speeds are different so you might need a few changes. But someone might have some better ideas I've only ever used the STM32 on one project and it didn't need a bootloader. \$\endgroup\$ – PeterJ May 27 '14 at 8:42
  • \$\begingroup\$ @PeterJ In fact, My orginal purpose is that learn writing bootlaoder. \$\endgroup\$ – Roh May 27 '14 at 8:49
8
\$\begingroup\$

A bootloader is no different from a normal program. You will need to think of the following things first:

  • What do I want my bootloader to do?
  • Since it usually takes care of upgrading software, where do I get the new application image from?
  • Do I want to be able to communicate with the bootloader via UART/USB/?
  • How do I make sure that a valid program is loaded at the specific memory address?
  • How do I make sure that I am always able to enter the bootloader somehow?

There is no single "bootloader" - it depends on your requirements.

\$\endgroup\$
  • \$\begingroup\$ Thanks Tom, I have already looked at some bootlaoders. they have some odd parts. for example vector table. I think they have some special parts and concepts that I have to learn. Is it correct? \$\endgroup\$ – Roh May 27 '14 at 9:14
  • 1
    \$\begingroup\$ Yes and no. That very much depends on the architecture of your bootloader. For example, I have written a bootloader which is purely based on values in flash. Also, once the bootloader is done, the application starts. I do not manipulate any vectors. My bootloader is a normal program which checks for a specific value in flash. If it is there (and only then) it will try to start the application. Should the application ever become corrupted, there is either a button which triggers the bootloader upon reset or through UART after a reset. It will then try to load an application from USB or UART. \$\endgroup\$ – Tom L. May 27 '14 at 9:40
  • \$\begingroup\$ Tom, How did you learn to write bootloader? What's your compiler? Do you use assembly or you can write your bootloader just by C? \$\endgroup\$ – Roh May 27 '14 at 12:38
  • \$\begingroup\$ I wrote normal applications first and when a bootloader was required for a project, I basically built it just like a normal application. I write programs mainly for the AVR32 platform, so the compiler is a normal GCC and the IDE is Atmel Studio 6. No, I did not require a single line of assembler. You will need to pay attention to linker settings though (you will need to link your application to some memory location and not the reset vector (because this is where the bootloader will be ;-) ). \$\endgroup\$ – Tom L. May 27 '14 at 14:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.