forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 26
Add support for DFU upload methods #443
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # Copyright (c) 2025 Jamie Smith | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # ---------------------------------------------- | ||
| # CMake finder for the dfu_util tool | ||
| # | ||
| # | ||
| # This module defines: | ||
| # dfu_util_PATH - full path to dfu-util executable | ||
| # dfu_util_FOUND - whether or not the ArduinoBossac executable was found | ||
|
|
||
| set(dfu_util_PATHS "") | ||
|
|
||
| # try to figure out where dfu_util may be installed. | ||
| # We will look for it both from the Arduino IDE, and from a manual install. | ||
| if("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Windows") | ||
|
|
||
| # on Windows, assume that the user extracted the binaries to Program Files | ||
| # if the host is 64 bit, there will be a Program Files (x86) folder, this covers both | ||
| file(GLOB dfu_util_PATHS "C:/Program Files*/dfu-util*/") | ||
|
|
||
| # On my computer the path is C:\Users\jamie\AppData\Local\Arduino15\packages\arduino\tools\dfu-util\0.10.0-arduino1\dfu-util.exe | ||
| file(GLOB dfu_util_arduino_PATHS "$ENV{LocalAppData}/Arduino*/packages/arduino/tools/dfu-util/0*") | ||
| list(APPEND dfu_util_PATHS ${dfu_util_arduino_PATHS}) | ||
| else() | ||
|
|
||
| # Linux / Mac | ||
| # a possible path would be $HOME/.arduino15/packages/arduino/tools/dfu-util/0.10.0-arduino1/dfu-util | ||
| file(GLOB dfu_util_PATHS "$ENV{HOME}/.arduino*/packages/arduino/tools/dfu-util/0*") | ||
|
|
||
| endif() | ||
|
|
||
| find_program(dfu_util_PATH NAMES dfu-util HINTS ${dfu_util_PATHS} DOC "Path to the dfu-util executable") | ||
|
|
||
| if(EXISTS "${dfu_util_PATH}") | ||
| # Detect version | ||
| execute_process(COMMAND ${dfu_util_PATH} --version | ||
| OUTPUT_VARIABLE dfu_util_VERSION_OUTPUT) | ||
|
|
||
| # The output looks like "dfu-util 0.11\n", so use a regex to grab the version | ||
| string(REGEX REPLACE "dfu-util ([^\n]+).+" "\\1" dfu_util_VERSION ${dfu_util_VERSION_OUTPUT}) | ||
| endif() | ||
|
|
||
| find_package_handle_standard_args(dfu_util REQUIRED_VARS dfu_util_PATH VERSION_VAR dfu_util_VERSION) | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Copyright (c) 2025 Jamie Smith | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| ### dfu_util upload method | ||
| ### This method can be used for chips with DFU bootloaders that talk to the dfu-util program. | ||
| ### The chip must be rebooted into bootloader mode for the upload method to work. | ||
| # This method creates the following parameters: | ||
| # DFU_UTIL_TARGET_VID_PID - VID:PID pair of the target device being programmed. | ||
| # DFU_UTIL_TARGET_INTERFACE - Interface number of the interface on the target that should be programmed. | ||
|
|
||
| set(UPLOAD_SUPPORTS_DEBUG FALSE) | ||
|
|
||
| ### Check if upload method can be enabled on this machine | ||
| find_package(dfu_util) | ||
| set(UPLOAD_DFU_UTIL_FOUND ${dfu_util_FOUND}) | ||
|
|
||
| ### Function to generate upload target | ||
| function(gen_upload_target TARGET_NAME BINARY_FILE) | ||
|
|
||
| set(DFU_UTIL_SERIAL_ARGS "") | ||
| if(NOT "${MBED_UPLOAD_SERIAL_NUMBER}" STREQUAL "") | ||
| list(APPEND DFU_UTIL_SERIAL_ARGS --serial ${MBED_UPLOAD_SERIAL_NUMBER}) | ||
| endif() | ||
|
|
||
| add_custom_target(flash-${TARGET_NAME} | ||
| COMMAND ${dfu_util_PATH} | ||
| --device ${DFU_UTIL_TARGET_VID_PID} | ||
| --download ${BINARY_FILE} | ||
| --alt ${DFU_UTIL_TARGET_INTERFACE} | ||
| ${DFU_UTIL_SERIAL_ARGS} | ||
| --dfuse-address ${MBED_UPLOAD_BASE_ADDR}:leave | ||
| VERBATIM | ||
| USES_TERMINAL) | ||
|
|
||
| endfunction(gen_upload_target) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tools/cmake/upload_methods/UploadMethodSTM32CUBE_DFU.cmake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| # Copyright (c) 2025 Jamie Smith | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| ### STM32Cube DFU Upload Method | ||
| # This method needs the following parameters: | ||
| # STM32CUBE_DFU_CONNECT_COMMAND - "Connect" (-c) command to pass to the programmer | ||
|
|
||
| ### Check if upload method can be enabled on this machine | ||
| find_package(STLINKTools COMPONENTS STM32CubeProg) | ||
| set(UPLOAD_STM32CUBE_DFU_FOUND ${STLINKTools_FOUND}) | ||
|
|
||
| set(UPLOAD_SUPPORTS_DEBUG FALSE) | ||
|
|
||
| ### Function to generate upload target | ||
|
|
||
| function(gen_upload_target TARGET_NAME BINARY_FILE) | ||
|
|
||
| set(STM32CUBE_UPLOAD_PROBE_ARGS sn=${MBED_UPLOAD_SERIAL_NUMBER}) | ||
|
|
||
| add_custom_target(flash-${TARGET_NAME} | ||
| COMMENT "Flashing ${TARGET_NAME} with STM32CubeProg..." | ||
| COMMAND ${STM32CubeProg_COMMAND} | ||
| -c ${STM32CUBE_DFU_CONNECT_COMMAND} | ||
| ${STM32CUBE_UPLOAD_PROBE_ARGS} # probe arg must be immediately after -c command as it gets appended to -c | ||
| -w ${BINARY_FILE} ${MBED_UPLOAD_BASE_ADDR} | ||
| VERBATIM | ||
| USES_TERMINAL) | ||
|
|
||
| endfunction(gen_upload_target) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.