Skip to content

Implement AMBIQ_SVL upload method for Ambiq Apollo3 #472

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 3 commits into from
Jul 2, 2025
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
27 changes: 2 additions & 25 deletions targets/upload_method_cfg/SFE_ARTEMIS.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,2 @@
# Mbed OS upload method configuration file for target SFE_ARTEMIS.
# To change any of these parameters from their default values, set them in your build script between where you
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.

# Notes:
# 1. This board does not have an onboard debugger. You must use an external debugger, e.g. a PicoProbe
# or J-Link, if you wish to debug code.
# 2. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
# pip install git+https://github.com/pyocd/pyOCD.git

set(UPLOAD_METHOD_DEFAULT NONE)

# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
set(PYOCD_CLOCK_SPEED 4000k)

# Config options for JLINK
# -------------------------------------------------------------
set(JLINK_UPLOAD_ENABLED TRUE)
set(JLINK_CPU_NAME AMA3B1KK-KBR)
set(JLINK_CLOCK_SPEED 4000)
set(JLINK_UPLOAD_INTERFACE SWD)
# Upload method configuration is the same as other SparkFun Artemis boards
include(${CMAKE_CURRENT_LIST_DIR}/common/sparkfun_artemis.cmake)
2 changes: 2 additions & 0 deletions targets/upload_method_cfg/SFE_ARTEMIS_ATP.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Upload method configuration is the same as other SparkFun Artemis boards
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
2 changes: 2 additions & 0 deletions targets/upload_method_cfg/SFE_ARTEMIS_NANO.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Upload method configuration is the same as other SparkFun Artemis boards
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
2 changes: 2 additions & 0 deletions targets/upload_method_cfg/SFE_ARTEMIS_THING_PLUS.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Upload method configuration is the same as other SparkFun Artemis boards
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
22 changes: 22 additions & 0 deletions targets/upload_method_cfg/common/SFE_ARTEMIS_DK.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Mbed OS upload method configuration file for SparkFun Artemis DK
# To change any of these parameters from their default values, set them in your build script between where you
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.

# Notes:
# 1. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
# pip install git+https://github.com/pyocd/pyOCD.git
# 2. Unlike all other SparkFun Artemis boards, this board has a CMSIS-DAP interface MCU on it, so it
# should be debuggable & flashable out of the box via PyOCD.

set(UPLOAD_METHOD_DEFAULT MBED)

# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
set(PYOCD_CLOCK_SPEED 4000k)

# Config options for MBED
# -------------------------------------------------------------
set(MBED_UPLOAD_ENABLED TRUE)
29 changes: 29 additions & 0 deletions targets/upload_method_cfg/common/sparkfun_artemis.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Mbed OS upload method configuration file for most SparkFun Artemis devices
# To change any of these parameters from their default values, set them in your build script between where you
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.

# Notes:
# 1. This board does not have an onboard debugger. You must use an external debugger, e.g. a PicoProbe
# or J-Link, if you wish to debug code.
# 2. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
# pip install git+https://github.com/pyocd/pyOCD.git

set(UPLOAD_METHOD_DEFAULT AMBIQ_SVL)

# Config options for PYOCD
# -------------------------------------------------------------
set(PYOCD_UPLOAD_ENABLED TRUE)
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
set(PYOCD_CLOCK_SPEED 4000k)

# Config options for JLINK
# -------------------------------------------------------------
set(JLINK_UPLOAD_ENABLED TRUE)
set(JLINK_CPU_NAME AMA3B1KK-KBR)
set(JLINK_CLOCK_SPEED 4000)
set(JLINK_UPLOAD_INTERFACE SWD)

# Config options for AMBIQ_SVL
# -------------------------------------------------------------
set(AMBIQ_SVL_UPLOAD_ENABLED TRUE)
12 changes: 9 additions & 3 deletions tools/cmake/mbed_python_interpreter.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,25 @@ endif()
find_program(mbed_tools
NAMES mbed-tools
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
DOC "Path to mbed-tools Python script."
DOC "Path to mbed-tools Python script. This script is part of the mbed-ce-tools python package."
REQUIRED)

find_program(mbedhtrun
NAMES mbedhtrun
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
DOC "Path to mbedhtrun Python script."
DOC "Path to mbedhtrun Python script. This script is part of the mbed-ce-tools python package."
REQUIRED)

find_program(memap
NAMES memap
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
DOC "Path to memap Python script."
DOC "Path to memap Python script. This script is part of the mbed-ce-tools python package."
REQUIRED)

find_program(ambiq_svl
NAMES ambiq_svl
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
DOC "Path to ambiq_svl Python script. This script is part of the mbed-ce-tools python package."
REQUIRED)

#
Expand Down
41 changes: 41 additions & 0 deletions tools/cmake/upload_methods/UploadMethodAMBIQ_SVL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (c) 2025 Jamie Smith
# SPDX-License-Identifier: Apache-2.0

### Ambiq SVL upload method
### This upload method allows flashing code over the UART port to SparkFun boards using
### the Ambiq Apollo3 SoC and SVL bootloader.
### Unlike some other bootloader-based upload methods, the SparkFun setup is able to reset the
### MCU into bootloader without needing any buttons to be pressed on the board!
# This method creates the following options:
# AMBIQ_SVL_SERIAL_PORT - Serial port to connect to the SVL bootloader over, e.g. 'COM20' or '/dev/ttyUSB0'
# This method creates the following parameters:
# AMBIQ_SVL_UPLOAD_BAUD - Baudrate to upload at. Defaults to 115200 baud.

set(UPLOAD_SUPPORTS_DEBUG FALSE)

set(AMBIQ_SVL_SERIAL_PORT "" CACHE STRING "Serial port to connect to the SVL bootloader over, e.g. 'COM20' or '/dev/ttyACM0'")

# note: the ambiq_svl script is included under tools/python/ambiq_svl and is already
# found by mbed_python_interpreter.cmake
set(UPLOAD_AMBIQ_SVL_FOUND TRUE)

### Function to generate upload target
function(gen_upload_target TARGET_NAME BINARY_FILE)

if("${AMBIQ_SVL_SERIAL_PORT}" STREQUAL "")
message(FATAL_ERROR "Must specify AMBIQ_SVL_SERIAL_PORT to use the AMBIQ_SVL upload method!")
endif()

if("${AMBIQ_SVL_UPLOAD_BAUD}" STREQUAL "")
set(AMBIQ_SVL_UPLOAD_BAUD 115200)
endif()

add_custom_target(flash-${TARGET_NAME}
COMMAND ${ambiq_svl}
-f ${BINARY_FILE}
-b ${AMBIQ_SVL_UPLOAD_BAUD}
${AMBIQ_SVL_SERIAL_PORT}
VERBATIM
USES_TERMINAL)

endfunction(gen_upload_target)
4 changes: 3 additions & 1 deletion tools/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,12 @@ packages = [
"python/mbed_tools",
"python/memap",
"python/scancode_evaluate",
"python/ambiq_svl"
]

[project.scripts]
mbedhtrun = "mbed_host_tests.mbedhtrun:main"
mbedls = "mbed_lstools.main:mbedls_main"
mbed-tools = "mbed_tools.cli.main:cli"
memap = "memap.memap:main"
memap = "memap.memap:main"
ambiq_svl = "ambiq_svl.svl:cli"
7 changes: 7 additions & 0 deletions tools/python/ambiq_svl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SVL for Ambiq Apollo3

This folder contains the script to flash Ambiq Apollo3 MCUs using the SparkFun Variable Loader (SVL) UART bootloader. This script appears to be under the MIT license, and was copied from its development repository here:

https://github.com/sparkfun/Apollo3_Uploader_SVL/blob/main/svl.py

Slight modifications were made to add an entry point function compatible with Hatchling.
5 changes: 5 additions & 0 deletions tools/python/ambiq_svl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"""
SparkFun Variable Loader
Variable baud rate bootloader for Artemis Apollo3 modules
SPDX-License-Identifier: MIT
"""
Loading