Skip to content

Commit 0d0f2ea

Browse files
Implement AMBIQ_SVL upload method for Ambiq Apollo3 (#472)
* Implement AMBIQ_SVL upload method for Ambiq Apollo3 * These boards use ttyUSB * Add license
1 parent f598b77 commit 0d0f2ea

File tree

12 files changed

+557
-29
lines changed

12 files changed

+557
-29
lines changed
Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,2 @@
1-
# Mbed OS upload method configuration file for target SFE_ARTEMIS.
2-
# To change any of these parameters from their default values, set them in your build script between where you
3-
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.
4-
5-
# Notes:
6-
# 1. This board does not have an onboard debugger. You must use an external debugger, e.g. a PicoProbe
7-
# or J-Link, if you wish to debug code.
8-
# 2. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
9-
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
10-
# pip install git+https://github.com/pyocd/pyOCD.git
11-
12-
set(UPLOAD_METHOD_DEFAULT NONE)
13-
14-
# Config options for PYOCD
15-
# -------------------------------------------------------------
16-
set(PYOCD_UPLOAD_ENABLED TRUE)
17-
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
18-
set(PYOCD_CLOCK_SPEED 4000k)
19-
20-
# Config options for JLINK
21-
# -------------------------------------------------------------
22-
set(JLINK_UPLOAD_ENABLED TRUE)
23-
set(JLINK_CPU_NAME AMA3B1KK-KBR)
24-
set(JLINK_CLOCK_SPEED 4000)
25-
set(JLINK_UPLOAD_INTERFACE SWD)
1+
# Upload method configuration is the same as other SparkFun Artemis boards
2+
include(${CMAKE_CURRENT_LIST_DIR}/common/sparkfun_artemis.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Upload method configuration is the same as other SparkFun Artemis boards
2+
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Upload method configuration is the same as other SparkFun Artemis boards
2+
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Upload method configuration is the same as other SparkFun Artemis boards
2+
include(${CMAKE_CURRENT_SOURCE_DIR}/common/sparkfun_artemis.cmake)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Mbed OS upload method configuration file for SparkFun Artemis DK
2+
# To change any of these parameters from their default values, set them in your build script between where you
3+
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.
4+
5+
# Notes:
6+
# 1. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
7+
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
8+
# pip install git+https://github.com/pyocd/pyOCD.git
9+
# 2. Unlike all other SparkFun Artemis boards, this board has a CMSIS-DAP interface MCU on it, so it
10+
# should be debuggable & flashable out of the box via PyOCD.
11+
12+
set(UPLOAD_METHOD_DEFAULT MBED)
13+
14+
# Config options for PYOCD
15+
# -------------------------------------------------------------
16+
set(PYOCD_UPLOAD_ENABLED TRUE)
17+
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
18+
set(PYOCD_CLOCK_SPEED 4000k)
19+
20+
# Config options for MBED
21+
# -------------------------------------------------------------
22+
set(MBED_UPLOAD_ENABLED TRUE)
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Mbed OS upload method configuration file for most SparkFun Artemis devices
2+
# To change any of these parameters from their default values, set them in your build script between where you
3+
# include mbed_toolchain_setup and where you add mbed-os as a subdirectory.
4+
5+
# Notes:
6+
# 1. This board does not have an onboard debugger. You must use an external debugger, e.g. a PicoProbe
7+
# or J-Link, if you wish to debug code.
8+
# 2. Support for this device exists in PyOCD main branch but has not been released yet (as of Jun 2025).
9+
# This version will be used automatically by Mbed if the python venv is enabled. If not, you need to install it via:
10+
# pip install git+https://github.com/pyocd/pyOCD.git
11+
12+
set(UPLOAD_METHOD_DEFAULT AMBIQ_SVL)
13+
14+
# Config options for PYOCD
15+
# -------------------------------------------------------------
16+
set(PYOCD_UPLOAD_ENABLED TRUE)
17+
set(PYOCD_TARGET_NAME ama3b1kk_kbr)
18+
set(PYOCD_CLOCK_SPEED 4000k)
19+
20+
# Config options for JLINK
21+
# -------------------------------------------------------------
22+
set(JLINK_UPLOAD_ENABLED TRUE)
23+
set(JLINK_CPU_NAME AMA3B1KK-KBR)
24+
set(JLINK_CLOCK_SPEED 4000)
25+
set(JLINK_UPLOAD_INTERFACE SWD)
26+
27+
# Config options for AMBIQ_SVL
28+
# -------------------------------------------------------------
29+
set(AMBIQ_SVL_UPLOAD_ENABLED TRUE)

tools/cmake/mbed_python_interpreter.cmake

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,19 +126,25 @@ endif()
126126
find_program(mbed_tools
127127
NAMES mbed-tools
128128
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
129-
DOC "Path to mbed-tools Python script."
129+
DOC "Path to mbed-tools Python script. This script is part of the mbed-ce-tools python package."
130130
REQUIRED)
131131

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

138138
find_program(memap
139139
NAMES memap
140140
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
141-
DOC "Path to memap Python script."
141+
DOC "Path to memap Python script. This script is part of the mbed-ce-tools python package."
142+
REQUIRED)
143+
144+
find_program(ambiq_svl
145+
NAMES ambiq_svl
146+
HINTS ${PYTHON_SCRIPT_LOC_HINTS}
147+
DOC "Path to ambiq_svl Python script. This script is part of the mbed-ce-tools python package."
142148
REQUIRED)
143149

144150
#
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright (c) 2025 Jamie Smith
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
### Ambiq SVL upload method
5+
### This upload method allows flashing code over the UART port to SparkFun boards using
6+
### the Ambiq Apollo3 SoC and SVL bootloader.
7+
### Unlike some other bootloader-based upload methods, the SparkFun setup is able to reset the
8+
### MCU into bootloader without needing any buttons to be pressed on the board!
9+
# This method creates the following options:
10+
# AMBIQ_SVL_SERIAL_PORT - Serial port to connect to the SVL bootloader over, e.g. 'COM20' or '/dev/ttyUSB0'
11+
# This method creates the following parameters:
12+
# AMBIQ_SVL_UPLOAD_BAUD - Baudrate to upload at. Defaults to 115200 baud.
13+
14+
set(UPLOAD_SUPPORTS_DEBUG FALSE)
15+
16+
set(AMBIQ_SVL_SERIAL_PORT "" CACHE STRING "Serial port to connect to the SVL bootloader over, e.g. 'COM20' or '/dev/ttyACM0'")
17+
18+
# note: the ambiq_svl script is included under tools/python/ambiq_svl and is already
19+
# found by mbed_python_interpreter.cmake
20+
set(UPLOAD_AMBIQ_SVL_FOUND TRUE)
21+
22+
### Function to generate upload target
23+
function(gen_upload_target TARGET_NAME BINARY_FILE)
24+
25+
if("${AMBIQ_SVL_SERIAL_PORT}" STREQUAL "")
26+
message(FATAL_ERROR "Must specify AMBIQ_SVL_SERIAL_PORT to use the AMBIQ_SVL upload method!")
27+
endif()
28+
29+
if("${AMBIQ_SVL_UPLOAD_BAUD}" STREQUAL "")
30+
set(AMBIQ_SVL_UPLOAD_BAUD 115200)
31+
endif()
32+
33+
add_custom_target(flash-${TARGET_NAME}
34+
COMMAND ${ambiq_svl}
35+
-f ${BINARY_FILE}
36+
-b ${AMBIQ_SVL_UPLOAD_BAUD}
37+
${AMBIQ_SVL_SERIAL_PORT}
38+
VERBATIM
39+
USES_TERMINAL)
40+
41+
endfunction(gen_upload_target)

tools/pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ packages = [
8080
"python/mbed_tools",
8181
"python/memap",
8282
"python/scancode_evaluate",
83+
"python/ambiq_svl"
8384
]
8485

8586
[project.scripts]
8687
mbedhtrun = "mbed_host_tests.mbedhtrun:main"
8788
mbedls = "mbed_lstools.main:mbedls_main"
8889
mbed-tools = "mbed_tools.cli.main:cli"
89-
memap = "memap.memap:main"
90+
memap = "memap.memap:main"
91+
ambiq_svl = "ambiq_svl.svl:cli"

tools/python/ambiq_svl/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# SVL for Ambiq Apollo3
2+
3+
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:
4+
5+
https://github.com/sparkfun/Apollo3_Uploader_SVL/blob/main/svl.py
6+
7+
Slight modifications were made to add an entry point function compatible with Hatchling.

tools/python/ambiq_svl/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
SparkFun Variable Loader
3+
Variable baud rate bootloader for Artemis Apollo3 modules
4+
SPDX-License-Identifier: MIT
5+
"""

0 commit comments

Comments
 (0)