diff --git a/README.md b/README.md index a1008b75..100b333d 100644 --- a/README.md +++ b/README.md @@ -36,14 +36,52 @@ It will compile a project for the `F4` family by default, but you can also compi # Usage -First of all you need to configure toolchain and library paths using CMake variables. -You can do this by passing values through command line during cmake run or by setting variables inside your `CMakeLists.txt` +First of all you need to configure toolchain and library paths using CMake variables. There are +generally three ways to do this: + +1. Pass the variables through command line during cmake run with passed to CMake with + `-D=...` +2. Set the variables inside your `CMakeLists.txt` +3. Pass these variables to CMake by setting them as environmental variables. + +The most important set of variables which needs to be set can be found in the following section. ## Configuration +These configuration options need to be set for the build process to work properly: + * `STM32_TOOLCHAIN_PATH` - where toolchain is located, **default**: `/usr` +* `STM32_CUBE__PATH` - path to STM32Cube directory, where `` is one + of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube` + +These configuration variables are optional: + * `TARGET_TRIPLET` - toolchain target triplet, **default**: `arm-none-eabi` -* `STM32_CUBE__PATH` - path to STM32Cube directory, where `` is one of `F0 G0 L0 F1 L1 F2 F3 F4 G4 L4 F7 H7` **default**: `/opt/STM32Cube` +* `FREERTOS_PATH` - Path to the FreeRTOS kernel when compiling with a RTOS. Does not need to be + specified when using CMSIS + +### Helper script on Unix shells + +If you have access to a Unix shell, which is the default terminal on Linux, or tools like +`MinGW64` or `git bash` on Windows, you can write a small `path_helper.sh` script like this: + +```sh +export STM32_TOOLCHAIN_PATH="" +export TARGET_TRIPLET=arm-none-eabi +export STM32_CUBE__PATH="" +``` + +and then use `. path_helper.sh` to set up the environment for the local terminal instance in one go. + +### Helper script in Powershell + +On Windows, you can use a Powershell script `path_helper.ps1`to set up the environment: + +```sh +$env:STM32_TOOLCHAIN_PATH = "" +$env:TARGET_TRIPLET = arm-none-eabi +$env:STM32_CUBE__PATH="" +``` ## Common usage @@ -146,9 +184,14 @@ CMSIS package will generate linker script for your device automatically (target stm32-cmake contains additional CMake modules for finding and configuring various libraries and RTOSes used in the embedded world. -## FreeRTOS +## FreeRTOS -[cmake/FindFreeRTOS](cmake/FindFreeRTOS) - finds FreeRTOS sources in location specified by `FREERTOS_PATH` (*default*: `/opt/FreeRTOS`) variable and format them as `IMPORTED` targets. `FREERTOS_PATH` can be either the path to the whole [FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) github repo, or the path to FreeRTOS-Kernel (usually located in the subfolder `FreeRTOS` on a downloaded release) +[cmake/FindFreeRTOS](cmake/FindFreeRTOS.cmake) - finds FreeRTOS sources in location specified by +`FREERTOS_PATH` (*default*: `/opt/FreeRTOS`) variable and format them as `IMPORTED` targets. +`FREERTOS_PATH` can be either the path to the whole +[FreeRTOS/FreeRTOS](https://github.com/FreeRTOS/FreeRTOS) github repo, or the path to +FreeRTOS-Kernel (usually located in the subfolder `FreeRTOS` on a downloaded release). +You can supply `FREERTOS_PATH` as an environmental variable as well. Typical usage: @@ -166,4 +209,3 @@ Other FreeRTOS libraries: * `FreeRTOS::StreamBuffer` - stream buffer (`stream_buffer.c`) * `FreeRTOS::Timers` - timers (`timers.c`) * `FreeRTOS::Heap::` - heap implementation (`heap_.c`), ``: [1-5] - diff --git a/cmake/FindBSP.cmake b/cmake/FindBSP.cmake index c4db5988..951c6321 100644 --- a/cmake/FindBSP.cmake +++ b/cmake/FindBSP.cmake @@ -262,6 +262,10 @@ foreach(COMP ${BSP_FIND_COMPONENTS}) set(FAMILY ${CMAKE_MATCH_1}) string(TOLOWER ${FAMILY} FAMILY_L) + if(NOT STM32_CUBE_${FAMILY}_PATH) + set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}") + endif() + if(NOT STM32_CUBE_${FAMILY}_PATH) set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}") message(STATUS "No STM32_CUBE_${FAMILY}_PATH specified using default: ${STM32_CUBE_${FAMILY}_PATH}") diff --git a/cmake/FindCMSIS.cmake b/cmake/FindCMSIS.cmake index 6ee3f804..3821538f 100644 --- a/cmake/FindCMSIS.cmake +++ b/cmake/FindCMSIS.cmake @@ -71,6 +71,10 @@ foreach(COMP ${CMSIS_FIND_COMPONENTS}) string(TOLOWER ${FAMILY} FAMILY_L) + if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH)) + set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}") + endif() + if((NOT STM32_CMSIS_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH)) set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}") message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_CMSIS_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}") diff --git a/cmake/FindFreeRTOS.cmake b/cmake/FindFreeRTOS.cmake index 144c5bea..0bd61010 100644 --- a/cmake/FindFreeRTOS.cmake +++ b/cmake/FindFreeRTOS.cmake @@ -7,6 +7,10 @@ list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS) set(FreeRTOS_HEAPS 1 2 3 4 5) +if(NOT FREERTOS_PATH) + set(FREERTOS_PATH $ENV{FREERTOS_PATH} CACHE PATH "Path to FreeRTOS") +endif() + if(NOT FREERTOS_PATH) set(FREERTOS_PATH /opt/FreeRTOS CACHE PATH "Path to FreeRTOS") message(STATUS "No FREERTOS_PATH specified using default: ${FREERTOS_PATH}") diff --git a/cmake/FindHAL.cmake b/cmake/FindHAL.cmake index 6af022a4..655d19e3 100644 --- a/cmake/FindHAL.cmake +++ b/cmake/FindHAL.cmake @@ -237,6 +237,10 @@ foreach(COMP ${HAL_FIND_COMPONENTS_FAMILIES}) set(FAMILY ${CMAKE_MATCH_1}) string(TOLOWER ${FAMILY} FAMILY_L) + if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH)) + set(STM32_CUBE_${FAMILY}_PATH $ENV{STM32_CUBE_${FAMILY}_PATH} CACHE PATH "Path to STM32Cube${FAMILY}") + endif() + if((NOT STM32_HAL_${FAMILY}_PATH) AND (NOT STM32_CUBE_${FAMILY}_PATH)) set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}") message(STATUS "Neither STM32_CUBE_${FAMILY}_PATH nor STM32_HAL_${FAMILY}_PATH specified using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")