|
| 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/ttyACM0' |
| 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) |
0 commit comments