This bootloader solution allows you to update firmware on STM32 MCUs. It accepts data from serial ports and updates the firmware on the internal flash. The internal flash also has sector allocated to store application specific data. The solution can be customized to meet your specific needs.

    Requirements

    1. Download and install stlink_setup.exe, and add the path to environment variables
      C:\Program Files (x86)\STMicroelectronics\STM32 ST-LINK Utility\ST-LINK Utility
    2. Clone the repository.
      git clone https://github.com/BuildStormTechnologies/stm32_bootloader_library

    Connections

    Bootloader and application use UART2(PA2, PA3) for firmware update and printing the device logs.

    Test Setup

    1. Open Command Prompt, change the working directory to the cloned repository.
      cd stm32_bootloader_library/cli-tool
    2. Connect the device using USB-to-serial and note down the COM port.
    3. Ensure the USB-to-Serial is connected to UART2 of Stm32 (PA2 &PA3).
    4. Run the command
      stm32UpdateTool-win.exe <COM_PORT>
      for example, stm32UpdateTool-win.exe COM7
    5. CLI tool will print the supported commands as shown below.

    stm32_tool_info.png

     

    Testing Bootloader

    • The bootloader binary is available in .\binaries folder and same is hardcoded in the CLI tool. For flashing the bootloader, user need not provide the path.
    • For testing, two application binaries are available in .\binaries folder. The required application binary file path has to be provided for flashing the application. CLI also allows to flash the custom application by providing the absolute path to the below commands.
      • flash all <application file path> This will flash the bootloader from .\binaries\bootloader.bin and application from the specified path.
      • flash app <application file path> This will only flash the application from the specified path.

    Flash Bootloader and Application

    1. Flash both bootloader and application using the flash all command as shown below.
      flash all .\binaries\application_v200.bin
    2. CLI will takes care of flashing the bootloader and application one after the other.
    3. After successful update of the firmware, device will print the versions numbers. Notice the version number and LED pattern.

    image.png

    Flash application only

    1. In the previous section we have flashed bootloader and application v200, this time only application needs to be flashed.
      flash app .\binaries\application_v201.bin
    2. After successful update, notice the change in firmware version and LED pattern

    image.png

    Custom Application Example

    Use the f407_led_demo project to build the custom application. It uses the pre-compiled library object which will be linked with user application.

    Memory Map and linker settings

    Type Address size No of Sectors Sector index
    Bootloader 0x08000000 14KB 1 0
    Bootloader Config 0x08004000 16KB 1 1
    Application 0x08010000 448KB 4 4 – 7
    Temporary Download Partition 0x08070000 512KB 4 8 – 11

    Linker Settings

    Application resides at 0x08010000 and same has to be configured in the linker settings as shown below.

    MEMORY
    {
      CCMRAM    (xrw)    : ORIGIN = 0x10000000,   LENGTH = 64K
      RAM    (xrw)    : ORIGIN = 0x20000000,   LENGTH = 128K
      FLASH    (rx)    : ORIGIN = 0x8010000,   LENGTH = 448K
    }

     

    Include Libraries

    Include the utils folder containing the library header files to the project.

    image.png

    Include Object file

    Include the precompiled object file to the project.
    image.png

    Post build script

    The final application binary file will be encrypted using executable script(BS_ENCRYPT.exe). It has to added to project settings.
    image.png

    Application Binary

    The final encrypted application binary will be generated in Debug folder as projectName_release.bin. This file can be used for Serial/OTA firmware updates.

    Supported Controllers

    The bootloader and application have been tested on the below controllers with 1Mb flash memory. It can be customized to use on any of STM32 controllers.

    • STM32F407
    • STM32F413
    • STM32F429

    Licensing and Custom Solutions

    The free usage of library is limited to 20 boot cycles It is meant for testing and demonstration only. To know more about the solution or obtaining a license, contact us at hello@buildstorm.com If you like seeing the solution in action schedule a demo.