Difference between revisions of "Creating a solution with bootloader and application"

From SEGGER Wiki
Jump to: navigation, search
(Debug with Ozone)
Line 80: Line 80:
   
 
==Debug with Ozone==
 
==Debug with Ozone==
  +
How to debug bootloader projects with Ozone is explained here: [[Debug_Bootloader_and_Application_in_same_Ozone_project]]

Revision as of 10:27, 2 February 2022

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 make sure that the bootloader runs before your application project make sure to set Debug->Debugger->Start From Entry Point Symbol->No in the application project.

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

Example project 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

  • Bootloader starts from Reset_Handler.
  • Runs System Init.
  • Read Bootheader from application image and print it.
  • Calculate CRC over application Flash area.
  • Compare calculated CRC with CRC provided by application, if they match boot application.
  • Jump to Reset_Handler from application.
  • Run System Init from application. Skip clock init, as this has been done by bootloader already.
  • Set VTOR to vector table of application.
  • Run main application which is a Systick timer sample which ticks every second and prints the tick count.

Recommended settings

  • Make the application project dependent on the bootloader project so the bootloader gets build and downloaded automatically each time the application debug session is started.
    • In the bootloader project set the option Code->Linker->Additional Output Format to hex.
    • In the application project set the option Code->Build->Project Dependencies to the bootloader project.
    • In the application project set the option Debug->Loader->Additional Load File[0] to the hex file of the bootloader project (you might need to have build the bootloader project once after setting it to generate the hex output to see the file)

Troubleshooting

Debug with Ozone

How to debug bootloader projects with Ozone is explained here: Debug_Bootloader_and_Application_in_same_Ozone_project