# Flashing programs to STM32. Embedded Bootloader

ScienceProg •1 June, 2012 ARM microcontrollers, Electronics Tutorial, STM32

There has been several requests among users to explain more about loading programs in to flash memory of STM32 microcontrollers.

This of course is a wide topic but lets focus on how to achieve result – flash program in to MCU. Depending on what arsenal is on your desk you can do in several different ways. Let’s try to go through them in practical way.

### Embedded bootloader

All STM32 microcontrollers comes with built-in bootloaders that are programmed during production. Depending on device type flash memory can be programmed using one of interfaces like USART1 or USART2, USB, CAN. Mostly we are dealing with low, medium and high density devices so they can access bootloader using USART1 interface. USART1 can be connected to computer using RS232 interface or USART to USB driver chip like FT232. In order to enter bootloader special MCU pins has to be set to proper logical values. These are called BOOT0 and BOOT1 pins on a microcontroller. Boot pins can have several cases:

As you can see there are three cases: first case is when BOOT0 pin is tied to ground and BOOT1 is open or at logical state 0 then after reset program is executed from Main Flash Memory. This is your normal configuration when executing programs. Second case (BOOT1=0; BOOT0=1) means that after reset execution starts at System memory where built int bootloader resides. This is the case when we need to upload binaries via USART1. And third case means that program execution is performed in SRAM. So lets focus on second case – System memory. In many development boards you will find jumper pins where you can select BOOT0 and BOOT1 configurations. For instance in STM32F103RBT6 board these looks like this:

In image you can see that jumper settings already selects to run internal bootloader. What we do next is download Flash Loader Demonstrator which is a tool to interact with bootloader. Install it and launch. You will see screen where you will be able to select USART parameters. Be sure to select correct COM port:

Connect board USART1 to PC using RS232 cable and hit reset button. Then you can click Next to go to the next screen.

It confirms that you succesfully entered bootloader. Hit Next to proceed to device selection screen.

Target device is already selected automatically. If not – select right one from drop down list. You can also see here other information like bootloader protocol version (2.2), Flash memory mapping. Click Next if selected device seems OK. You get to screen where you can do all sort of things:

You can erase all or selected memory pages. Download a .hex (.bin or .x19) to microcoller flash memory. Select ‘Jump to the user program‘ if you want to execute program immediately after download. You can also select to Verify after download to make sure if upload was successful. You can also upload existing binary from device Flash memory in to file to back up it. You can enable or disable Flash protection. And finally proceed to ‘Edit option bytes‘ to set User Option bytes or add write protection to selected memory pages.

Let’s leave that behind and simply download .hex file in to device. Simply select file from dialog menu select to verify after download an jump to user program like this:

Hit Next and in a few seconds it is done.

Here we can see that binaries are successfully downloaded and takes 2804 bytes and took 1 second to program.

When programming is done you can return BOOT0 pin to ground in order to execute programs from main Flash memory after next reset.

Continue to next flashing method…

### Share this:

- in Share 4

### Related

#### Downloading binaries using STM32 ST-Link Utility

Just a quick note to finalize STM32 flashing topic. As you may know ST also produces his own debugger/programmer called ST-Link. It supports either JTAG and SWD interfaces. You can purchase ST-Link USB adapter but there is a better option. If you are in to STM32 microcontroller business you probably…

25 June, 2012

In "STM32"

#### Flashing STM32 using J-Flash ARM

Last time we have covered topic about flashing STM32 microcontrollers using bootlaoder. This is easiest and cheapest way of loading programs to MCU memory. But this isn't the only way of doing this. Software can also be downloaded to using JTAG adapter which is used for debugging. This time we…

25 June, 2012

In "STM32"

#### USB bootloaders for AVR microcontrollers

Probably most proper microcontroller programming method is using a bootloader program. Because you don't need any special programming adapters or special knowledge - you just need to connect standard cable from your PC to target board and run special program on PC which communicates with MCU bootloader program. The idea…

24 April, 2008

In "AVR Microcontrollers"

### 6 Comments:

1. Mr Semenov
   26 July, 2012 at 9:29 am

   Dear friend,

   On my board LEDs always blink. Is it correct?

   Reply
2. admin
   27 July, 2012 at 2:09 am

   It depends on what your program really does.

   Reply
3. mustapha
   18 March, 2013 at 8:20 pm

   thank you for your information but I would like to program the STM32-P103 board RS232 I used this technique but it always shows me an error ” No response from the target, the Boot loader can not be started, please verify the boot mode configuration and the flash protection status, Reset your device then try again…”
   I do not know how to solve it thank you for helping me

   Reply
4. sahil
   25 June, 2013 at 4:39 pm

   Hi,
   I am trying to program a stm32f103c6. I have the boot1 =0 permanently. boot0=1 for programming. However i keep getting the error “no response from the target”. PLZ HELP.

   Reply
5. Ali
   16 October, 2014 at 9:03 am

   Hello guys,

   Is it supported for the STM32F030 devices?

   Reply
6. Arunan
   2 December, 2014 at 6:21 pm

   Dude select proper boot pins , press rest button and try

   Reply

### Leave a Reply Cancel reply

Connect with:

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

Comment

Name*

Email*

Website

Notify me of follow-up comments by email.

Notify me of new posts by email.

- ### Recent Comments:

  - Lilian on AVR DDS signal generator V2.0
  - narayanareddy battula on ABCD method for screening skin cancer
  - Loganathan.k on Skin lession boundary tracing algorithm
  - Pankajsehoriya on The Benefits of LED Lighting
  - ScienceProg on AVR DDS signal generator V2.0

- ### Recent Forum Posts

  - Forum: ChatTopic: Overview of machine learning algorithms By: ScienceProg - February 23, 2016
  - Forum: Blog relatedTopic: Small design changes By: ScienceProg - February 5, 2016
  - Forum: Blog relatedTopic: Emails from @live.com By: ScienceProg - February 5, 2016
  - Forum: ProjectsTopic: AVR DDS2 updates and next version consideration By: ScienceProg - January 31, 2016

- ### Login

  Username

  Password

  Remember Me

  Connect with:

- ### Login using:

- ### Follow us:

- ### Categories

  - Arduino
  - ARM microcontrollers
  - AVR controlled signal generator
  - AVR Microcontrollers
  - Biomedical electronics
  - Biomedical Engineering
  - Cool Gadgets
  - DIY
  - DSP Lessons
  - Electronics
  - Electronics Software
  - Electronics Tutorial
  - Embedded General
  - Energy Industry
  - Footprint libraries
  - Free Hobby Electronics Circuits
  - FreeRTOS
  - Hacks
  - Internet
  - Machine Learning
  - MCS-51 family
  - Melanoma
  - Misc
  - Programmable logic
  - Programming
  - Projects
  - Raspberry Pi
  - Robotics
  - Science
  - STM32
  - Technology
  - Ultrasound
  - Uncategorized
  - UV PCB Making
  - Videos About Electronics

- ### Archives

  Archives

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.Accept Read More