Starting a new project - IntergatedCircuits/STM32_XPD GitHub Wiki

This tutorial page explains how to set up an initial executable project based on the XPD library. The preferred development environment is Atollic TrueSTUDIO for STM32. Nevertheless there are a number of free IDEs that can be used (the full list is available here). The demonstration uses the STM32F303CBT6 chip as an example, for other devices all the STM32[...] folder and file references change reflecting the device type.

Step 1: Create a new project

In TrueSTUDIO select File / New / C Project, then go through the steps to create an Executable/Empty Project with Atollic ARM Tools as toolchain. When it is created, go to Project / Properties / C/C++ Build / Target Settings and select your device from the available list. You can also let it generate a linker script for your device.

Step 2: Import the necessary library files to your project

The following folders with their entire contents are required for the XPD library to compile:

These folders (in case of XPD library, /inc) shall be added to the compiler include path.

In Eclipse-based IDEs (such as TrueSTUDIO) it is recommended to link the CMSIS and XPD library instead of copying it to the project:

  1. In Project / Properties go to C/C++ General / Paths and Symbols / Source location.
  2. Select Link Folder... and link to folder in the file system, then browse and add the location of the CMSIS and STM32[F3]_XPD folders.
  3. Exclude the CMSIS and STM32[F3]_XPD/templates folders from the build.

Step 3: Copy and customize the template files

The template files have to be copied in your project location. The CMSIS startup assembly templates are found in the CMSIS device-specific source templates (e.g. for STM32F3xx). These are the assembly code for startup RAM initialization and jumping to main, as well as defines the interrupt vector table. It shall be selected according to the toolchain compiler and the device type (e.g. for GNU ARM Compiler: startup_stm32f303xc.s). Editing this file is only recommended for programmers with assembly knowledge.

The XPD-specific templates are found in the libraries' /templates folder.

The system_stm32f3xx.c file is the CMSIS system initialization template customized for the XPD library. It implements the SystemInit() function, which is called during startup, before entering the main() function. This function's implementation can be customized depending on the user application needs, however the RCC_vDeinit() and XPD_vInit() calls shall be kept in all cases to ensure proper XPD operation.

The xpd_config.h file specifies the exact device header and additional hardware parameters that are required for the XPD library operation:

  • the device descriptor (e.g. #include "stm32f303xc.h")
  • define certain system external information (supply voltages, external oscillator values)
  • define a custom vector table location, which is then used by SystemInit()

Step 4: Create and configure linker file(s)

Depending on the toolchain a separate linker script has to be added to the project. One can acquire a linker script by generating a project using STM32CubeMX (which tool is recommended for peripheral mapping purposes as well) and extracting the resulting file. Alternatively, the linker scripts contained in Projects can be used as template - for GNU ARM Compiler.

Step 5: Implement user code

A functioning program requires the implementation of a main.c source with the following minimal contents:

int main(void)
{
    while(1) { }
}

In order to utilize the XPD provided API, the appropriate XPD module headers shall be included. Further details on the usage of XPD are explained in the other Wiki chapters.

Step 6: Compile, flash and debug on the target

After having completed the previous steps and properly setting up the toolchain, the project should build successfully. To flash the program on the target through multiple connections you can use STM32CubeProgrammer. IDEs such as TrueSTUDIO can also be used to debug the application on the target using e.g. ST-LINK connection.