1- # Copyright (c) 2020 ARM Limited. All rights reserved.
1+ # Copyright (c) 2024 ARM Limited. All rights reserved.
22# SPDX-License-Identifier: Apache-2.0
33
44# ----------------------------------------------
55# CMake finder for STMicro's STM32 upload and debugging tools
66#
77# This module accepts the following components (blame ST for the capitalization, not me):
8- # STM32CubeProg
9- # STLINK_gdbserver
8+ # - STM32CubeProg
9+ # - STLINK_gdbserver
1010#
1111# This module defines:
1212# STLINKTools_FOUND - Whether the requested components were found.
1515# STM32CubeProg_COMMAND - Command to run the STM32 command line programmer.
1616# STLINK_gdbserver_COMMAND - Command to run the ST-Link GDB server.
1717
18- # first try to locate STM32Cube IDE in its default location
18+ # first try to locate STM32CubeXXX tools in their default location
1919set (STM32CUBE_IDE_LINUX_HINTS "" )
2020set (STM32CUBE_IDE_WINDOWS_HINTS "" )
21+ set (STM32CUBE_CLT_LINUX_HINTS "" )
22+ set (STM32CUBE_CLT_WINDOWS_HINTS "" )
2123if (EXISTS "/opt/st" )
2224 # Linux directory has version number
23- file (GLOB STM32CUBE_IDE_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/*" )
25+ file (GLOB STM32CUBE_IDE_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/stm32cubeide*" )
26+ file (GLOB STM32CUBE_CLT_LINUX_HINTS LIST_DIRECTORIES TRUE "/opt/st/stm32cubeclt*" )
2427endif ()
2528if (EXISTS "C:/ST/" )
26- # On Windows, STM32CubeIDE by default is installed into a subdirectory of
27- # C:\ST\STM32CubeIDE_ <version>\STM32CubeIDE , but may also be installed into
28- # C:\ST\STM32CubeIDE directly
29+ # On Windows, STM32CubeXXX tools by default are installed into a subdirectory of
30+ # C:\ST\STM32CubeXXX_ <version>\STM32CubeXXX , but may also be installed into
31+ # C:\ST\STM32CubeXXX directly
2932
3033 # Identify all the subdirectories and sub-subdirectories of C:\ST
31- file (GLOB STM32CUBE_IDE_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/*/*" "C:/ST/*" )
34+ file (GLOB STM32CUBE_IDE_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/STM32CubeIDE*/*" "C:/ST/STM32CubeIDE*" )
35+ file (GLOB STM32CUBE_CLT_WINDOWS_HINTS LIST_DIRECTORIES TRUE "C:/ST/STM32CubeCLT*/*" "C:/ST/STM32CubeCLT*" )
3236endif ()
3337find_path (STM32CUBE_IDE_PATH
3438 NAMES stm32cubeide.ini
35- DOC "Path to STM32Cube IDE . Used to find the ST-Link Tools"
39+ DOC "Path to STM32CubeIDE . Used to find the ST-Link Tools"
3640 PATHS
3741 ${STM32CUBE_IDE_WINDOWS_HINTS} # Windows
3842 ${STM32CUBE_IDE_LINUX_HINTS} # Linux
3943 /Applications/STM32CubeIDE.app/Contents/Eclipse # OS X
4044 )
45+ find_path (STM32CUBE_CLT_PATH
46+ NAMES
47+ STM32CubeCLT_metadata.bat # Windows
48+ STM32CubeCLT_metadata.sh # Linux
49+ DOC "Path to STM32CubeCLT. Used to find the ST-Link Tools"
50+ PATHS
51+ ${STM32CUBE_CLT_WINDOWS_HINTS} # Windows
52+ ${STM32CUBE_CLT_LINUX_HINTS} # Linux
53+ #/Applications/STM32CubeIDE.app/Contents/Eclipse # OS X
54+ )
4155
4256set (STLINKTools_HINTS "" )
43- if (EXISTS "${STM32CUBE_IDE_PATH} " )
57+ if (EXISTS "${STM32CUBE_CLT_PATH} " )
58+ message (STATUS "Located STM32CubeCLT: ${STM32CUBE_CLT_PATH} " )
59+
60+ # find install dirs inside IDE, which also have version numbers
61+ file (GLOB GDB_SERVER_INSTALL_DIRS LIST_DIRECTORIES TRUE "${STM32CUBE_CLT_PATH} /STLink-gdb-server/bin" )
62+ list (GET GDB_SERVER_INSTALL_DIRS 0 GDB_SERVER_INSTALL_DIR) # If glob returns multiple just pick one
63+ if (EXISTS "${GDB_SERVER_INSTALL_DIR} " )
64+ list (APPEND STLINKTools_HINTS ${GDB_SERVER_INSTALL_DIR} )
65+ endif ()
66+
67+ file (GLOB CUBEPROG_INSTALL_DIRS LIST_DIRECTORIES TRUE "${STM32CUBE_CLT_PATH} /STM32CubeProgrammer/bin" )
68+ list (GET CUBEPROG_INSTALL_DIRS 0 CUBEPROG_INSTALL_DIR) # If glob returns multiple just pick one
69+ if (EXISTS "${CUBEPROG_INSTALL_DIR} " )
70+ list (APPEND STLINKTools_HINTS ${CUBEPROG_INSTALL_DIR} )
71+ endif ()
72+ elseif (EXISTS "${STM32CUBE_IDE_PATH} " )
4473 message (STATUS "Located STM32CubeIDE: ${STM32CUBE_IDE_PATH} " )
4574
4675 # find install dirs inside IDE, which also have version numbers
@@ -55,8 +84,8 @@ if(EXISTS "${STM32CUBE_IDE_PATH}")
5584 if (EXISTS "${CUBEPROG_INSTALL_DIR} " )
5685 list (APPEND STLINKTools_HINTS ${CUBEPROG_INSTALL_DIR} )
5786 endif ()
58- elseif ()
59- 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." )
87+ else ()
88+ 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 ." )
6089endif ()
6190set (STLINKTools_REQUIRED_VARS "" )
6291
@@ -107,5 +136,3 @@ if(EXISTS "${STLINK_gdbserver_PATH}")
107136endif ()
108137
109138find_package_handle_standard_args(STLINKTools REQUIRED_VARS ${STLINKTools_REQUIRED_VARS} )
110-
111-
0 commit comments