<libmaple/stm32.h>

STM32 chip header. This header supplies various series-specific and chip-specific macros for the current build target. It’s useful both to abstract away hardware details (e.g. through use of STM32_NR_INTERRUPTS) and to decide what to do when you want something nonportable (e.g. by checking STM32_MCU_SERIES).

Determining the Target Series

The STM32 series (e.g. STM32F1, STM32F2, etc.) of the current target can be inspected with STM32_MCU_SERIES.

STM32_MCU_SERIES

STM32 series value for the MCU being targeted.

At time of writing, allowed values are: STM32_SERIES_F1, STM32_SERIES_F2. This set of values will expand as libmaple adds support for more STM32 series MCUs.

Allowed values for STM32_MCU_SERIES are the following. This set is expected to grow over time.

STM32_SERIES_F1

STM32F1 series.

STM32_SERIES_F2

STM32F2 series.

STM32_SERIES_L1

STM32L1 series.

STM32_SERIES_F4

STM32F4 series.

Series-Specific Characteristics

The macros in this section are only available on some STM32 series.

STM32F1

Note

These macros are only available when the current target is an STM32F1 series MCU (i.e., when STM32_MCU_SERIES is STM32_SERIES_F1).

The STM32F1 series is further subdivided into lines. The line of the current target can be inspected with STM32_F1_LINE.

STM32_F1_LINE

STM32 line value for the STM32F1 MCU being targeted.

At time of writing, allowed values are: STM32_F1_LINE_PERFORMANCE, STM32_F1_LINE_VALUE. This set of values may expand as libmaple adds support for more STM32F1 lines.

There are five STM32F1 lines. The corresponding values STM32_F1_LINE can take are the following, though libmaple doesn’t currently support all of them.

STM32_F1_LINE_VALUE

STM32F1 value line (STM32F100 MCUs).

STM32_F1_LINE_ACCESS

STM32F1 access line (STM32F101 MCUs).

STM32_F1_LINE_USB_ACCESS

STM32F1 USB access line (STM32F102 MCUs).

STM32_F1_LINE_PERFORMANCE

STM32F1 performance line (STM32F103 MCUs).

STM32_F1_LINE_CONNECTIVITY

STM32F1 connectivity line (STM32F105/F107 MCUs).

MCU Feature Tests

The following defines can be used to determine if the target MCU has a particular feature.

STM32_HAVE_FSMC

1 if the target MCU has the FSMC peripheral, and 0 otherwise.

Note that the feature set of the FSMC peripheral is restricted on some MCUs.

STM32_HAVE_USB

1 if the target MCU has a USB peripheral, and 0 otherwise.

Note that a variety of USB peripherals are available across the different series, with widely varying feature sets and programming interfaces. This macro will be 1 if any such peripheral is present.

MCU Characteristics

The following defines give salient characteristics of the target MCU.

STM32_NR_GPIO_PORTS

Number of GPIO ports.

STM32_NR_INTERRUPTS

Number of interrupts in the vector table.

This does not include Cortex-M interrupts (NMI, HardFault, etc.).

STM32_SRAM_END

Pointer to end of built-in SRAM.

Points to the address which is 1 byte past the last valid SRAM address.

Clock Speeds

The macros in this section are related to clock rates. As such, they are really part of the configuration of the MCU, rather than inherent characteristics of the MCU itself. For instance, it’s possible to change the PCLK1 and PCLK2 clock rates by reconfiguring the RCC. libmaple proper never changes any clock rates, but it does have APIs for doing so (such as rcc_configure_pll()). Because of this, be careful when using the macros in this section, as they assume that some values are constant which in fact may be changed.

The values these macros actually take are typically the maximum values supported by the MCU. Since these are their actual values in practice (at least in LeafLabs’ current use cases, which have the chips running as fast as possible), they’re still considered useful.

STM32_PCLK1

APB1 clock speed, in Hz.

STM32_PCLK2

APB2 clock speed, in Hz.

The following macro, STM32_DELAY_US_MULT, is a libmaple implementation detail. It was included in this public API page in a previous release by mistake, and is not deprecated, but using it in your own code is a bad idea.

STM32_DELAY_US_MULT

Multiplier to convert microseconds into loop iterations in delay_us().

See
delay_us()

Deprecated Macros

Warning

The macros in this section are deprecated, and are available for backwards compatibility only. Do not use them in new code.

PCLK1

Deprecated.

Use STM32_PCLK1 instead.

PCLK2

Deprecated.

Use STM32_PCLK2 instead.

NR_INTERRUPTS

Deprecated.

Use STM32_NR_INTERRUPTS instead.

NR_GPIO_PORTS

Deprecated.

Use STM32_NR_GPIO_PORTS instead.

DELAY_US_MULT

Deprecated.

Use STM32_DELAY_US_MULT instead.