Skip to content

Latest commit

 

History

History
338 lines (312 loc) · 9.55 KB

File metadata and controls

338 lines (312 loc) · 9.55 KB

STM32F0xx Runtimes

This repository generates GNAT runtimes that support all MCUs in the STM32F0 family.

The following runtime profiles are supported:

  • light
  • light-tasking
  • embedded

Usage

Using the light-tasking-stm32f0xx runtime as an example, first edit your alire.toml file and add the following elements:

  • Add light_tasking_stm32f0xx in the dependency list:
    [[depends-on]]
    light_tasking_stm32f0xx = "*"
  • if applicable, apply any runtime configuration variables (see "Runtime Configuration" below).

Then edit your project file to add the following elements:

  • "with" the run-time project file:
    with "runtime_build.gpr";
  • if you are using the light-tasking or embedded runtime profile, then you also need to "with" ravenscar_build.gpr:
    with "ravenscar_build.gpr";
  • specify the Target and Runtime attributes:
    for Target use runtime_build'Target;
    for Runtime ("Ada") use runtime_build'Runtime ("Ada");
  • specify the Linker switches:
    package Linker is
      for Switches ("Ada") use Runtime_Build.Linker_Switches;
    end Linker;

Runtime Configuration

Crate Configuration

The runtime is configurable through the crate configuration variables.

The following variables configure the specific STM32F0 MCU that is being targeted:

Variable Values Default Description
MCU_Sub_Family "F030", "F031", "F038", "F042", "F048", "F051", "F058", "F070", "F071", "F072", "F078", "F091", "F098" "F072" Specifies the sub-family part of the STM32F0 part number. For example, choose "F072" for the STM32F072RB.
MCU_Pin_Count "C", "E", "F", "G", "K", "R", "V" "R" Specifies the pin count part of the STM32F0 part number. For example, this is the "R" in "STM32F072RB".
MCU_User_Code_Memory_Size "4", "6", "8", "B", "C" "B" Specifies the "user code memory size" part of the STM32F0 part number. For example, this is the "B" in "STM32F072RB".

By default, the runtime is configured for the STM32F072RB. If you are using a different MCU, then you will need to configure the runtime by adding the following to your alire.toml. For example, to configure the runtime for the STM32F030F4:

[configuration.values]
light_tasking_stm32f0xx.MCU_Sub_Family            = "F030"
light_tasking_stm32f0xx.MCU_Pin_Count             = "F"
light_tasking_stm32f0xx.MCU_User_Code_Memory_Size = "4"

By default, the runtime configures the clocks to provide a 48 MHz system clock from the high-speed internal (HSI) oscillator. The following crate configuration variables can be used to use a different clock tree configuration:

Variable Values Default Description
LSI_Enabled true, false, true When true, the runtime will enable the low-speed internal (LSI) oscillator at startup.
HSE_Bypass true, false, false When true, the runtime will use enable the HSE bypass feature to allow an external clock source to be used (setting HSEBYP in the clock configuration registers). When false, the HSE will be configured for an external crystal/ceramic resonator.
HSE_Clock_Frequency 4000000 .. 32000000 8000000 Specifies the frequency of the HSE clock in Hertz. The default is 8 MHz.
SYSCLK_Src "HSI", "HSE", "PLL", "HSI48", PLL Specifies the clock source to use for the system clock (SYSCLK).
  • "HSI" selects the 8 MHz high-speed internal (HSI) clock.
  • "HSE" selects the high-speed external (HSE) clock.
  • "PLL" selects the phase-locked loop (PLL) clock.
  • "HSI48" selects the 48 MHz high-speed internal (HSI48) clock.
PLL_Src "HSI_2", "HSI_PREDIV", "HSE_PREDIV", "HSI48_PREDIV", HSI_2 Specifies the clock source to use for the input into the PLL.
  • "HSI_2" selects HSI divided by 2 as the PLL clock source (4 MHz).
  • "HSI_PREDIV" selects HSI divided by PREDIV as the PLL clock source.
  • "HSE_PREDIV" selects HSE divided by PREDIV as the PLL clock source.
  • "HSI48_PREDIV" selects HSI48 divided by PREDIV as the PLL clock source.
PREDIV 1 .. 16 2 Specifies the divider to use for the PLL clock input.
PLLMUL 2 .. 16 12 Specifies the PLL multiplier to use.
AHB_Pre "DIV1", "DIV2", "DIV4", "DIV8", "DIV16", "DIV64", "DIV128", "DIV256", "DIV512" DIV1 Specifies the divider to use for the AHB prescaler.
APB_Pre "DIV1", "DIV2", "DIV4", "DIV8", "DIV16" DIV1 Specifies the divider to use for the APB prescaler.

Here's an example of configuring the runtime in alire.toml for a 32 MHz system clock from a 16 MHz HSE oscillator:

[configuration.values]
# Configure a 16 MHz HSE crystal oscillator
light_tasking_stm32f0xx.HSE_Clock_Frequency = 16000000
light_tasking_stm32f0xx.HSE_Bypass = false

# Use the PLL as the SYSCLK source
light_tasking_stm32f0xx.SYSCLK_Src = "PLL"

# Configure the PLL input for a 16 MHz input from the HSE
light_tasking_stm32f0xx.PLL_Src = "HSE_PREDIV"
light_tasking_stm32f0xx.PREDIV = 1

# Configure the PLL to output 32 MHz (16 MHz * 2)
light_tasking_stm32f0xx.PLLMUL = 2

# Configure the AHB an APB to also run at 32 MHz
light_tasking_stm32f0xx.AHB_Pre = "DIV1"
light_tasking_stm32f0xx.APB_Pre = "DIV1"

The following variables configure the interrupt stack sizes:

Variable Values Default Description
Interrupt_Stack_Size Any positive integer 1024 Specifies the size of the primary stack used for interrupt handlers.
Interrupt_Secondary_Stack_Size Any positive integer 128 Specifies the size of the secondary stack used for interrupt handlers.

GPR Scenario Variables

The runtime project files expose *_BUILD and and *_LIBRARY_TYPE GPR scenario variables to configure the build mode (e.g. debug/production) and library type. These variables are prefixed with the name of the runtime in upper case. For example, for the light-tasking-stm32f0xx runtime the variables are LIGHT_TASKING_STM32F0XX_BUILD and LIGHT_TASKING_STM32F0XX_LIBRARY_TYPE respectively.

The *_BUILD variable can be set to the following values:

  • Production (default) builds the runtime with optimization enabled and with all run-time checks suppressed.
  • Debug disables optimization and adds debug symbols.
  • Assert enables assertions.
  • Gnatcov disables optimization and enables flags to help coverage.

The *_LIBRARY_TYPE variable can be set to either static (default) or dynamic, though only static libraries are supported on this target.

You can usually leave these set to their defaults, but if you want to set them explicitly then you can set them either by passing them on the command line when building your project with Alire:

alr build -- -XLIGHT_TASKING_STM32F0XX_BUILD=Debug

or by setting them in your project's alire.toml:

[gpr-set-externals]
LIGHT_TASKING_STM32F0XX_BUILD = "Debug"