-
Notifications
You must be signed in to change notification settings - Fork 339
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
Target all HAL libraries for a family #322
Comments
Yes. Supposing you talk about cmakefile and not makefile. |
Yes, I was talking about cmake file, but I can't make it work. # Necessary tag
cmake_minimum_required(VERSION 3.16)
cmake_path(SET STM32_CUBE_F4_PATH "./")
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/Lib/stm32-cmake/cmake/stm32_gcc.cmake)
project(tlb_battery)
enable_language(C ASM)
find_package(CMSIS COMPONENTS STM32F446RET REQUIRED)
find_package(HAL COMPONENTS STM32F4 REQUIRED)
set(PROJECT_INCLUDE_DIRECTORIES
${CMAKE_CURRENT_SOURCE_DIR}/Core/Inc)
file(GLOB_RECURSE PROJECT_C_SOURCES FOLLOW_SYMLINKS
${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/*.c)
# Define the executable variable (name of the compiled output)
set(EXECUTABLE ${PROJECT_NAME})
# Generate the Executable target
add_executable(${EXECUTABLE})
target_compile_definitions(${EXECUTABLE} PRIVATE
STM32F446RET
USE_HAL_DRIVER)
target_sources(${EXECUTABLE} PRIVATE
${PROJECT_C_SOURCES})
target_include_directories(${EXECUTABLE} PRIVATE
${PROJECT_INCLUDE_DIRECTORIES}
)
stm32_add_linker_script(${EXECUTABLE} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/STM32F446RETx_FLASH.ld)
target_link_libraries(${EXECUTABLE}
CMSIS::STM32::F446xx # this target adds common includes, compiler flags and startup file (TODO: change to STM32::F4, startup file should be added manually)
#CMSIS::STM32::F4
#HAL::STM32::F4::RCC
#HAL::STM32::F4::CORTEX
#HAL::STM32::F4::GPIO
#HAL::STM32::F4::TIM
#HAL::STM32::F4::TIMEx
#HAL::STM32::F4::ADC # include all drivers for the f4 family
#HAL::STM32::F4::CAN
#HAL::STM32::F4::UART
HAL::STM32::F4
STM32::Nano
STM32::NoSys
#STM32::Nano::FloatPrintf
)
stm32_generate_binary_file(${EXECUTABLE})
stm32_generate_hex_file(${EXECUTABLE})
stm32_print_size_of_target(${EXECUTABLE}) I run the cmake and get a list of errors at linking time (the custom linker used is the same provided with the cmsis just in a different position since I'm using an STMCubeMX generated project)
|
Actually this is not possible out of the box. |
Unfortunately I have a use case where the development team can't change the way it used to work. Since the stm32-vscode plugin does that in the make file I need to re-create this feature in the cmake. Therefore, do I need to hack around in the stm32-cmake library or in my makefile? Can we re-open the issue? |
I would mention #315 as a way to auto-define what peripheral needs to be compiled and what not? Can the user just comments out the used peripherals in |
Cmake, make, VScode and cubeMX are different tools that may not play well together. They are different way to manage projects. I'm not sure to fully understand your need. Are you confortable with cmake ? As a side note, ideally CubeMX would provide a way to generate Cmake projects and we would not even need this repo. CubeMX is a great tool, but people here are (in general) more in a mindset where they avoid using this type of tools and want to have full control over code. This does not play well with tools that want to control same things. |
Yes I'm comfortable with cmake but my team uses CubeMX for code generation. For now this is not a problem because stm32-cmake can be used alongside CubeMX. |
What you propose is probably possible but would require work and is not current approach. The idea itself is not bad. If you don't care about compile time, just enable all peripheral in
|
My use case is to have a somewhat stable CMAkeList file that needs little change from projet to project (the developer must learn cmake but not the library so much to understand it's inner working). Idealy for future projects I could use the cmake file that I provided in this issue, change the device family name and a new project can be compiled.
I can't do that: if I want a stable cmakefile that can be used as a template for all (no dualcore or wireless) stm devices I need to know which peripherals are available, and that information is known by the stm32-cmake library only. So I can't write a cmake that has all the HAL drivers as targets, some of them could not be available on a different platform.
@atsju previously said that I can just add |
I don't think there's anything preventing you from creating your own cmake include file, and in it you could define a library target like you're thinking, one that links all the peripheral targets. Then your end users just need to link to your new one, and automatically get all the others. |
Is it possible to target all hall libraries of a device via something like:
so that each time a new peripheral is used the makefile won't need changes?
The text was updated successfully, but these errors were encountered: