Creating a solution with bootloader and application

From SEGGER Wiki
Revision as of 18:13, 1 February 2022 by Nino (talk | contribs)
Jump to: navigation, search

This article contains a guide that explains how a SEGGER Embedded Studio(ES) solution can be created to set up a bootloader and application project. In a typical bootloader setup on micro controllers the bootloader initializes the MCU and verifies that the application that has been flashed may be launched by the bootloader. This is also shown in the example project below with a simple CRC check.

Setup

The following import tutorial will be based on the following Hardware and Software combinations:

Tutorial

This tutorial will be based on the hardware and software combination above. So if you are using another hardware steps might vary, but the general approach stays the same.

  • Start Embedded Studio.
  • Install CPU support Package for your device family via Tools->Package Manager.
  • Create new project via File->New Project->Create the project in a new solution. Henceforth we will refer to this project as bootloader.
  • Select the "A C/C++ executable for..." from the corresponding package. Press Next, select your target device and keep pressing Next until your project is finished.
  • Now create a second project in the same solution via File->New Project->Add the project to the current solution. Make sure it has a different name the the first project.
  • Select the "A C/C++ executable for..." from the corresponding package. Press Next, select your target device and keep pressing Next until your project is finished. Henceforth we will refer to this project as application.
  • You will be prompted with a couple of pop-ups notifying you, that some of the files already exist. Simply confirm the pop-ups.
  • Now you have two projects in the same solution. Note: As the same project template was used for the creation of both projects some files are shared. Should you not want to use shared files in some instances make sure to duplicate and rename them for the project. This will for example be needed for the linker scripts.
  • Now add your bootloader and application sources to the corresponding projects.
  • Duplicate and rename the linker script (.icf file) and set each file in the corresponding project as linker script.
  • Edit the memory regions and section/symbol placements in the linker script to fit your bootloader and application needs. For reference see the example project and the SEGGER Linker documentation.
  • Now you should have a setup where you can debug bootloader and application independently.

To learn how to use additional features that Embedded Studio offers which make the debug experience more enjoyable see the example explanation below.

Example explanation

The provided example project creates a Embedded Studio solution which contains two project. One is the bootloader and the other the application project. The significant memory placement is as follows:

FLASH_START      = 0x08000000
FLASH_TOTAL_SIZE = 0x00080000
BOOTLOADER_START = FLASH_START      
BOOTLOADER_SIZE  = 0x00004000
APP_START        = 0x08004000
APP_SIZE         = 0x0007C000
BOOTHEADER       = APP_START
CRC_LOCATION     = 0x0807FFFC

There are four source files and two linker scripts which are important in this example. Application project:

  • main.c - Simple Systick interrupt sample
  • bootheader.s - Defines an optional bootheader which is usually used to configure the bootloader or pass fixed information to the bootloader via the application.
  • STM32F4xx_Flash_CCM_App.icf - Linker script for the application which places the bootheader and the SEGGER Linker calculated CRC. It also handles the generic placement of all application parts.

Bootloader project:

  • main_boot.c - Prints the content of the bootheader from the application, calculates the CRC via the ST CRC peripheral. Compares the Linker and ST CRC, if successful jumps to the application.
  • boot.s - Handles the jumping to the application.
  • STM32F4xx_Flash_CCM_Boot.icf - Generic placement of the bootloader parts into the bootloader Flash section.

Program Flow

Troubleshooting

Debug with Ozone