|
@@ -47,22 +47,17 @@ as environmental variables.
|
|
|
* `TARGET_TRIPLET` - toolchain target triplet, **default**: `arm-none-eabi`
|
|
* `TARGET_TRIPLET` - toolchain target triplet, **default**: `arm-none-eabi`
|
|
|
* `STM32_CUBE_<FAMILY>_PATH` - path to STM32Cube directory, where `<FAMILY>` is one of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube<FAMILY>`
|
|
* `STM32_CUBE_<FAMILY>_PATH` - path to STM32Cube directory, where `<FAMILY>` is one of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube<FAMILY>`
|
|
|
|
|
|
|
|
-## <a id="cmsis"></a> Common usage
|
|
|
|
|
|
|
+## Common usage
|
|
|
|
|
|
|
|
First thing that you need to do after toolchain configuration in your `CMakeLists.txt` script is to find CMSIS package:
|
|
First thing that you need to do after toolchain configuration in your `CMakeLists.txt` script is to find CMSIS package:
|
|
|
```cmake
|
|
```cmake
|
|
|
find_package(CMSIS [CMSIS_version] COMPONENTS STM32F4 REQUIRED)
|
|
find_package(CMSIS [CMSIS_version] COMPONENTS STM32F4 REQUIRED)
|
|
|
```
|
|
```
|
|
|
-You can specify STM32 family or even specific device (`STM32F407VG`) in `COMPONENTS` or omit
|
|
|
|
|
-`COMPONENTS` totally - in that case stm32-cmake will find ALL sources for ALL families and
|
|
|
|
|
-ALL chips (you'll need ALL STM32Cube packages somewhere).
|
|
|
|
|
|
|
+You can specify STM32 family or even specific device (`STM32F407VG`) in `COMPONENTS` or omit `COMPONENTS` totally - in that case stm32-cmake will find ALL sources for ALL families and ALL chips (you'll need ALL STM32Cube packages somewhere).
|
|
|
|
|
|
|
|
-[CMSIS_version] is an optional version requirement. See
|
|
|
|
|
-[find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4).
|
|
|
|
|
-This parameter does not make sense if multiple STM32 families are requested.
|
|
|
|
|
|
|
+[CMSIS_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiple STM32 families are requested.
|
|
|
|
|
|
|
|
-Each STM32 device can be categorized into family and device type groups, for example STM32F407VG
|
|
|
|
|
-is device from `F4` family, with type `F407xx`.
|
|
|
|
|
|
|
+Each STM32 device can be categorized into family and device type groups, for example STM32F407VG is device from `F4` family, with type `F407xx`.
|
|
|
|
|
|
|
|
***Note**: Some devices in STM32H7 family have two different cores (Cortex-M7 and Cortex-M4).
|
|
***Note**: Some devices in STM32H7 family have two different cores (Cortex-M7 and Cortex-M4).
|
|
|
For those devices the name used must include the core name e.g STM32H7_M7 and STM32H7_M4.
|
|
For those devices the name used must include the core name e.g STM32H7_M7 and STM32H7_M4.
|
|
@@ -74,10 +69,7 @@ CMSIS consists of three main components:
|
|
|
* Device-specific linker scripts which requires information about memory sizes
|
|
* Device-specific linker scripts which requires information about memory sizes
|
|
|
|
|
|
|
|
stm32-cmake uses modern CMake features notably imported targets and target properties.
|
|
stm32-cmake uses modern CMake features notably imported targets and target properties.
|
|
|
-Every CMSIS component is CMake's target (aka library), which defines compiler definitions,
|
|
|
|
|
-compiler flags, include dirs, sources, etc. to build and propagate them as dependencies.
|
|
|
|
|
-So in a simple use-case all you need is to link your executable with library `CMSIS::STM32::<device>`:
|
|
|
|
|
-
|
|
|
|
|
|
|
+Every CMSIS component is CMake's target (aka library), which defines compiler definitions, compiler flags, include dirs, sources, etc. to build and propagate them as dependencies. So in a simple use-case all you need is to link your executable with library `CMSIS::STM32::<device>`:
|
|
|
```cmake
|
|
```cmake
|
|
|
add_executable(stm32-template main.c)
|
|
add_executable(stm32-template main.c)
|
|
|
target_link_libraries(stm32-template CMSIS::STM32::F407VG)
|
|
target_link_libraries(stm32-template CMSIS::STM32::F407VG)
|
|
@@ -90,35 +82,22 @@ CMSIS creates the following targets:
|
|
|
* `CMSIS::STM32::<TYPE>` (e.g. `CMSIS::STM32::F407xx`) - common startup source for device type, depends on `CMSIS::STM32::<FAMILY>`
|
|
* `CMSIS::STM32::<TYPE>` (e.g. `CMSIS::STM32::F407xx`) - common startup source for device type, depends on `CMSIS::STM32::<FAMILY>`
|
|
|
* `CMSIS::STM32::<DEVICE>` (e.g. `CMSIS::STM32::F407VG`) - linker script for device, depends on `CMSIS::STM32::<TYPE>`
|
|
* `CMSIS::STM32::<DEVICE>` (e.g. `CMSIS::STM32::F407VG`) - linker script for device, depends on `CMSIS::STM32::<TYPE>`
|
|
|
|
|
|
|
|
-So, if you don't need the linker script or want to adapt it for your own needs, you can link
|
|
|
|
|
-only `CMSIS::STM32::<TYPE>` library and provide your own script using `stm32_add_linker_script`
|
|
|
|
|
-function
|
|
|
|
|
|
|
+So, if you don't need linker script, you can link only `CMSIS::STM32::<TYPE>` library and provide your own script using `stm32_add_linker_script` function
|
|
|
|
|
|
|
|
-***Note**: For H7 family, because of its multi-core architecture, all H7 targets also have a suffix (::M7 or ::M4).
|
|
|
|
|
-For example, targets created for STM32H747BI will look like `CMSIS::STM32::H7::M7`,
|
|
|
|
|
-`CMSIS::STM32::H7::M4`, `CMSIS::STM32::H747BI::M7`, `CMSIS::STM32::H747BI::M4`, etc.*
|
|
|
|
|
|
|
+***Note**: For H7 family, because of it's multi-core architecture, all H7 targets also have a suffix (::M7 or ::M4).
|
|
|
|
|
+For example, targets created for STM32H747BI will look like `CMSIS::STM32::H7::M7`, `CMSIS::STM32::H7::M4`, `CMSIS::STM32::H747BI::M7`, `CMSIS::STM32::H747BI::M4`, etc.*
|
|
|
|
|
|
|
|
-The GCC C/C++ standard libraries are added by linking the library `STM32::NoSys`. This will add
|
|
|
|
|
-the `--specs=nosys.specs` to compiler and linker flags.
|
|
|
|
|
-If you want to use C++ on MCUs with little flash, you might instead want to link the newlib-nano to
|
|
|
|
|
-reduce the code size. You can do so by linking `STM32::Nano`, which will add the
|
|
|
|
|
-`--specs=nano.specs` flags to both compiler and linker.
|
|
|
|
|
-Keep in mind that when using `STM32::Nano`, by default you cannot use floats in printf/scanf calls,
|
|
|
|
|
-and you have to provide implementations for several OS interfacing
|
|
|
|
|
-functions (`_sbrk`, `_close`, `_fstat`, and others). You can enable printf/scanf floating point
|
|
|
|
|
-support with newlib-nano by linking against `STM32::Nano::FloatPrint` and/or
|
|
|
|
|
-`STM32::Nano::FloatScan`. It is also possible to combine `STM32::Nano` and `STM32::NoSys`
|
|
|
|
|
-to have the benefits of reduced code size while not being forced to implement system calls.
|
|
|
|
|
|
|
+The GCC C/C++ standard libraries are added by linking the library `STM32::NoSys`. This will add the `--specs=nosys.specs` to compiler and linker flags.
|
|
|
|
|
+If you want to use C++ on MCUs with little flash, you might instead want to link the newlib-nano to reduce the code size. You can do so by linking `STM32::Nano`, which will add the `--specs=nano.specs` flags to both compiler and linker.
|
|
|
|
|
+Keep in mind that when using `STM32::Nano`, by default you cannot use floats in printf/scanf calls, and you have to provide implementations for several OS interfacing functions (_sbrk, _close, _fstat, and others).
|
|
|
|
|
|
|
|
-## <a id="hal"></a> HAL
|
|
|
|
|
|
|
+## HAL
|
|
|
|
|
|
|
|
STM32 HAL can be used similar to CMSIS.
|
|
STM32 HAL can be used similar to CMSIS.
|
|
|
-
|
|
|
|
|
```cmake
|
|
```cmake
|
|
|
find_package(HAL [HAL_version] COMPONENTS STM32F4 REQUIRED)
|
|
find_package(HAL [HAL_version] COMPONENTS STM32F4 REQUIRED)
|
|
|
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
|
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)
|
|
|
```
|
|
```
|
|
|
-
|
|
|
|
|
*`CMAKE_INCLUDE_CURRENT_DIR` here because HAL requires `stm32<family>xx_hal_conf.h` file being in include headers path.*
|
|
*`CMAKE_INCLUDE_CURRENT_DIR` here because HAL requires `stm32<family>xx_hal_conf.h` file being in include headers path.*
|
|
|
|
|
|
|
|
[HAL_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiple STM32 families are requested.
|
|
[HAL_version] is an optional version requirement. See [find_package documentation](https://cmake.org/cmake/help/v3.13/command/find_package.html?highlight=find%20package#id4). This parameter does not make sense if multiple STM32 families are requested.
|
|
@@ -132,11 +111,11 @@ HAL module will search all drivers supported by family and create the following
|
|
|
|
|
|
|
|
***Note**: Targets for STM32H7 will look like `HAL::STM32::<FAMILY>::[M7|M4]`, `HAL::STM32::<FAMILY>::[M7|M4]::<DRIVER>`, etc.*
|
|
***Note**: Targets for STM32H7 will look like `HAL::STM32::<FAMILY>::[M7|M4]`, `HAL::STM32::<FAMILY>::[M7|M4]::<DRIVER>`, etc.*
|
|
|
|
|
|
|
|
-Here is typical usage for a F4 device:
|
|
|
|
|
|
|
+Here is typical usage:
|
|
|
|
|
|
|
|
```cmake
|
|
```cmake
|
|
|
-add_executable(${TARGET_NAME} blinky.c stm32f4xx_hal_conf.h)
|
|
|
|
|
-target_link_libraries(${TARGET_NAME}
|
|
|
|
|
|
|
+add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
|
|
|
|
|
+target_link_libraries(stm32-blinky-f4
|
|
|
HAL::STM32::F4::RCC
|
|
HAL::STM32::F4::RCC
|
|
|
HAL::STM32::F4::GPIO
|
|
HAL::STM32::F4::GPIO
|
|
|
HAL::STM32::F4::CORTEX
|
|
HAL::STM32::F4::CORTEX
|
|
@@ -145,18 +124,6 @@ target_link_libraries(${TARGET_NAME}
|
|
|
)
|
|
)
|
|
|
```
|
|
```
|
|
|
|
|
|
|
|
-Here is another usage for a H7 device with the M7 core:
|
|
|
|
|
-
|
|
|
|
|
-```cmake
|
|
|
|
|
-target_link_libraries(${TARGET_NAME} PRIVATE
|
|
|
|
|
- HAL::STM32::H7::M7::RCC
|
|
|
|
|
- HAL::STM32::H7::M7::GPIO
|
|
|
|
|
- HAL::STM32::H7::M7::CORTEX
|
|
|
|
|
- CMSIS::STM32::H743ZI::M7
|
|
|
|
|
- STM32::NoSys
|
|
|
|
|
-)
|
|
|
|
|
-```
|
|
|
|
|
-
|
|
|
|
|
### Building
|
|
### Building
|
|
|
|
|
|
|
|
```sh
|
|
```sh
|