Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blinky example minor improvement #225

Merged
merged 4 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ It uses cmake and GCC, along with newlib (libc), STM32Cube. Supports F0 F1 F2 F3
* `fetch-cube` ([examples/fetch-cube](examples/fetch-cube)) - example of using FetchContent for fetching STM32Cube from ST's git.
* `fetch-cmsis-hal` ([examples/fetch-cmsis-hal](examples/fetch-cmsis-hal)) - example of using FetchContent for fetching STM32 CMSIS and HAL from ST's git.
* `blinky` ([examples/blinky](examples/blinky)) - blink led using STM32 HAL library and SysTick.
It will compile a project for the `F4` family by default, but you can also compile for the
`L0` and `F1` family by passing `L0_EXAMPLE=ON` or `F1_EXAMPLE=ON` to the CMake generation call.
* `freertos` ([examples/freertos](examples/freertos)) - blink led using STM32 HAL library and FreeRTOS.

# Usage
Expand Down
90 changes: 60 additions & 30 deletions examples/blinky/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@ set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake/stm32_gcc.cmake
project(stm32-blinky C ASM)
set(CMAKE_INCLUDE_CURRENT_DIR TRUE)

find_package(CMSIS COMPONENTS STM32L0 STM32F1 STM32F4 REQUIRED)
find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 RCC GPIO CORTEX REQUIRED)
# Find all drivers:
# Configure here which STM32 target(s) to build
option(BLINKY_F4_EXAMPLE "Compile F4 example" ON)
option(BLINKY_F1_EXAMPLE "Compile F1 example" OFF)
option(BLINKY_L0_EXAMPLE "Compile L0 example" OFF)

set(HAL_COMP_LIST RCC GPIO CORTEX)
set(CMSIS_COMP_LIST "")

if(BLINKY_F4_EXAMPLE)
list(APPEND CMSIS_COMP_LIST STM32F4)
list(APPEND HAL_COMP_LIST STM32F4)
endif()

if(BLINKY_F1_EXAMPLE)
list(APPEND CMSIS_COMP_LIST STM32F1)
list(APPEND HAL_COMP_LIST STM32F1)
endif()

if(BLINKY_L0_EXAMPLE)
list(APPEND CMSIS_COMP_LIST STM32L0)
list(APPEND HAL_COMP_LIST STM32L0)
endif()

find_package(CMSIS COMPONENTS "${CMSIS_COMP_LIST}" REQUIRED)
find_package(HAL COMPONENTS "${HAL_COMP_LIST}" REQUIRED)

# Find all device specific drivers:
#find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 REQUIRED)
# Find drivers for all families:
#find_package(HAL COMPONENTS RCC GPIO CORTEX REQUIRED)
Expand All @@ -16,34 +40,40 @@ find_package(HAL COMPONENTS STM32L0 STM32F1 STM32F4 RCC GPIO CORTEX REQUIRED)
#find_package(HAL REQUIRED)

# STM32F4-Discovery
add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
target_link_libraries(stm32-blinky-f4
HAL::STM32::F4::RCC
HAL::STM32::F4::GPIO
HAL::STM32::F4::CORTEX
CMSIS::STM32::F407VG
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-f4)
if(BLINKY_F4_EXAMPLE)
add_executable(stm32-blinky-f4 blinky.c stm32f4xx_hal_conf.h)
target_link_libraries(stm32-blinky-f4
HAL::STM32::F4::RCC
HAL::STM32::F4::GPIO
HAL::STM32::F4::CORTEX
CMSIS::STM32::F407VG
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-f4)
endif()

# STM32VL-Discovery
add_executable(stm32-blinky-f1 blinky.c stm32f1xx_hal_conf.h)
target_link_libraries(stm32-blinky-f1
HAL::STM32::F1::RCC
HAL::STM32::F1::GPIO
HAL::STM32::F1::CORTEX
CMSIS::STM32::F100RB
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-f1)
if(BLINKY_F1_EXAMPLE)
add_executable(stm32-blinky-f1 blinky.c stm32f1xx_hal_conf.h)
target_link_libraries(stm32-blinky-f1
HAL::STM32::F1::RCC
HAL::STM32::F1::GPIO
HAL::STM32::F1::CORTEX
CMSIS::STM32::F100RB
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-f1)
endif()

# STM32L0538-Discovery
add_executable(stm32-blinky-l0 blinky.c stm32l0xx_hal_conf.h)
target_link_libraries(stm32-blinky-l0
HAL::STM32::L0::RCC
HAL::STM32::L0::GPIO
HAL::STM32::L0::CORTEX
CMSIS::STM32::L053C8
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-l0)
if(BLINKY_L0_EXAMPLE)
add_executable(stm32-blinky-l0 blinky.c stm32l0xx_hal_conf.h)
target_link_libraries(stm32-blinky-l0
HAL::STM32::L0::RCC
HAL::STM32::L0::GPIO
HAL::STM32::L0::CORTEX
CMSIS::STM32::L053C8
STM32::NoSys
)
stm32_print_size_of_target(stm32-blinky-l0)
endif()