• STM32-base
  • Home
  • Overview
  • Roadmap and scope
  • About this project
  • Guides
  • Getting started with STM32
  • Setting up STM32-base
  • Flashing
  • Boards
  • Boards overview
  • Blue pill (STM32F103C8T6)
  • Black pill (STM32F103C8T6)
  • Cheatsheets
  • Linker: Memory blocks
  • Device name mapping
  • Makefile options
  • External
  • STM32-base project
  • STMicroelectronics
  • Guide: Flashing

    When your code successfully compiles, you need a way of “uploading” the compiled code to your device. This process is called flashing. This guide assumes you’ve already set up the STM32-base project and you’re able to successfully compile the code found in any one of the templates. If not, please see the Setup Guide.

    Checklist

    Before flashing code on your device, there are some things to be checked first. The device name should be set properly, you might need to change the “blinking” pin, or you might even need to connect an LED. Refer to the following sub-sections for more information on the things to check before flashing your device.

    Device name

    Each template contains a make file located at the root of the template and is called Makefile. This make file contains a variable called DEVICE. This variable should contain the name of the device you want to compile your code for. You should format the name of your device like this: STM32____x_, where the “_” should be replaced by characters from the actual name (uppercase!) and the “x” is fixed. There are some exceptions to this naming scheme for STM32F4 devices, see the Device name mapping page for more information.

    Connect an LED

    This step is optional. You should not have to do this if your board already has an LED built-in.

    If you connect an external LED to your development board, connect:

    Change the GPIO pin

    The templates assume you’ve got a LED connected to pin PC13 of your device. This works for the famous Blue Pill, but there are a lot more boards out there. If your development board has a built-in LED connected to another pin or you have connected an LED yourself (to another pin), you must change the pin being “blinked”. Refer to the Changing template code guide for more information on how to do that.

    Connecting your device

    You must have your device connected to a debugger. For more information on how to do this, refer to the Connecting your debugger guide.

    Put your device in programming mode

    Most development boards come with jumpers or (DIP-)switches to set the BOOT-mode. You should set BOOT0 to “1” and BOOT1 (if present) to “0”. Then you should reset your device. At this point, your device waits for the programmer to do somthing.

    Flashing

    Before flashing your device, make sure to have done all the things on this checklist:

    If you’ve checked all these things, flashing is really simple and straight forward. Just run:

    > make flash
    

    Now your device should be flashed with the code you’ve just compiled.