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

Update FindSTLINKTools.cmake for STM32CubeCLT #228

Merged
merged 8 commits into from
Feb 8, 2024
Merged
Changes from 6 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
60 changes: 45 additions & 15 deletions tools/cmake/upload_methods/FindSTLINKTools.cmake
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Copyright (c) 2020 ARM Limited. All rights reserved.
# Copyright (c) 2024 ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

# ----------------------------------------------
# CMake finder for STMicro's STM32 upload and debugging tools
#
# This module accepts the following components (blame ST for the capitalization, not me):
# STM32CubeProg
JohnK1987 marked this conversation as resolved.
Show resolved Hide resolved
# STLINK_gdbserver
# - STM32CubeCLT/STM32CubeProg
# - STM32CubeCLT/STLINK_gdbserver
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
# or alternative option
# - STM32CubeIDE/STM32CubeProg
# - STM32CubeIDE/STLINK_gdbserver
#
# This module defines:
# STLINKTools_FOUND - Whether the requested components were found.
Expand All @@ -15,32 +18,61 @@
# STM32CubeProg_COMMAND - Command to run the STM32 command line programmer.
# STLINK_gdbserver_COMMAND - Command to run the ST-Link GDB server.

# first try to locate STM32Cube IDE in its default location
# first try to locate STM32CubeXXX tools in their default location
set(STM32CUBE_IDE_LINUX_HINTS "")
set(STM32CUBE_IDE_WINDOWS_HINTS "")
set(STM32CUBE_CLT_LINUX_HINTS "")
set(STM32CUBE_CLT_WINDOWS_HINTS "")
if(EXISTS "/opt/st")
# Linux directory has version number
file(GLOB STM32CUBE_IDE_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/*")
file(GLOB STM32CUBE_IDE_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/stm32cubeide*")
file(GLOB STM32CUBE_CLT_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/stm32cubeclt*")
endif()
if(EXISTS "C:/ST/")
# On Windows, STM32CubeIDE by default is installed into a subdirectory of
# C:\ST\STM32CubeIDE_<version>\STM32CubeIDE, but may also be installed into
# C:\ST\STM32CubeIDE directly
# On Windows, STM32CubeXXX tools by default are installed into a subdirectory of
# C:\ST\STM32CubeXXX_<version>\STM32CubeXXX, but may also be installed into
# C:\ST\STM32CubeXXX directly

# Identify all the subdirectories and sub-subdirectories of C:\ST
file(GLOB STM32CUBE_IDE_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/*/*" "C:/ST/*")
file(GLOB STM32CUBE_IDE_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/STM32CubeIDE*/*" "C:/ST/STM32CubeIDE*")
file(GLOB STM32CUBE_CLT_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/STM32CubeCLT*/*" "C:/ST/STM32CubeCLT*")
endif()
find_path(STM32CUBE_IDE_PATH
NAMES stm32cubeide.ini
DOC "Path to STM32Cube IDE. Used to find the ST-Link Tools"
DOC "Path to STM32CubeIDE. Used to find the ST-Link Tools"
PATHS
${STM32CUBE_IDE_WINDOWS_HINTS} # Windows
${STM32CUBE_IDE_LINUX_HINTS} # Linux
/Applications/STM32CubeIDE.app/Contents/Eclipse # OS X
)
find_path(STM32CUBE_CLT_PATH
NAMES
STM32CubeCLT_metadata.bat # Windows
uninstall_clt.sh # Linux
DOC "Path to STM32CubeCLT. Used to find the ST-Link Tools"
multiplemonomials marked this conversation as resolved.
Show resolved Hide resolved
PATHS
${STM32CUBE_CLT_WINDOWS_HINTS} # Windows
${STM32CUBE_CLT_LINUX_HINTS} # Linux
#/Applications/STM32CubeIDE.app/Contents/Eclipse # OS X
)

set(STLINKTools_HINTS "")
if(EXISTS "${STM32CUBE_IDE_PATH}")
if(EXISTS "${STM32CUBE_CLT_PATH}")
message(STATUS "Located STM32CubeCLT: ${STM32CUBE_CLT_PATH}")

# find install dirs inside IDE, which also have version numbers
file(GLOB GDB_SERVER_INSTALL_DIRS LIST_DIRECTORIES TRUE "${STM32CUBE_CLT_PATH}/STLink-gdb-server/bin")
list(GET GDB_SERVER_INSTALL_DIRS 0 GDB_SERVER_INSTALL_DIR) # If glob returns multiple just pick one
if(EXISTS "${GDB_SERVER_INSTALL_DIR}")
list(APPEND STLINKTools_HINTS ${GDB_SERVER_INSTALL_DIR})
endif()

file(GLOB CUBEPROG_INSTALL_DIRS LIST_DIRECTORIES TRUE "${STM32CUBE_CLT_PATH}/STM32CubeProgrammer/bin")
list(GET CUBEPROG_INSTALL_DIRS 0 CUBEPROG_INSTALL_DIR) # If glob returns multiple just pick one
if(EXISTS "${CUBEPROG_INSTALL_DIR}")
list(APPEND STLINKTools_HINTS ${CUBEPROG_INSTALL_DIR})
endif()
elseif(EXISTS "${STM32CUBE_IDE_PATH}")
message(STATUS "Located STM32CubeIDE: ${STM32CUBE_IDE_PATH}")

# find install dirs inside IDE, which also have version numbers
Expand All @@ -55,8 +87,8 @@ if(EXISTS "${STM32CUBE_IDE_PATH}")
if(EXISTS "${CUBEPROG_INSTALL_DIR}")
list(APPEND STLINKTools_HINTS ${CUBEPROG_INSTALL_DIR})
endif()
elseif()
set(FAIL_MESSAGE_ARG FAIL_MESSAGE "Warning: Failed to find STM32CubeIDE, will still look for ST-LINK tools on your PATH. Recommend setting STM32CUBE_IDE_PATH to the location of STM32CubeIDE.")
else()
set(FAIL_MESSAGE_ARG FAIL_MESSAGE "Warning: Failed to find STM32CubeCLT or IDE, will still look for ST-LINK tools on your PATH. Recommend setting STM32CUBE_IDE_PATH to the location of STM32CubeIDE or STM32CUBE_CLT_PATH to the location of STM32CubeCLT.")
endif()
set(STLINKTools_REQUIRED_VARS "")

Expand Down Expand Up @@ -107,5 +139,3 @@ if(EXISTS "${STLINK_gdbserver_PATH}")
endif()

find_package_handle_standard_args(STLINKTools REQUIRED_VARS ${STLINKTools_REQUIRED_VARS})


Loading