From 3fcfbbdb57780f88dab1785d50f41ccfd876600e Mon Sep 17 00:00:00 2001 From: Jamie Smith Date: Tue, 16 Apr 2024 21:44:02 -0500 Subject: [PATCH] Fix some issues with building on K64F, add K64F upload methods (#267) * Fix some issues with building on K64F, add K64F upload methods * Add Mbed upload method * Fix pin validate test * Also install json5 * Fix incorrect COMPONENT_SD config --- .github/workflows/basic_checks.yml | 1 + .../drivers/802.15.4_RF/CMakeLists.txt | 2 -- .../TARGET_Freescale/CMakeLists.txt | 1 + .../TARGET_Silicon_Labs/CMakeLists.txt | 1 + hal/tests/pinvalidate/pinvalidate.py | 32 +++++------------ .../blockdevice/COMPONENT_SD/mbed_lib.json | 8 ++--- .../TARGET_MCU_K64F/TARGET_FRDM/PinNames.h | 11 ------ .../TARGET_MCU_K64F/device/cmsis_nvic.h | 17 +++++++++ .../TARGET_MCU_K64F/spi_api.c | 2 +- targets/upload_method_cfg/K64F.cmake | 35 +++++++++++++++++++ targets/upload_method_cfg/LPC1768.cmake | 8 +++++ .../upload_method_cfg/openocd_cfgs/mk64f.cfg | 9 +++++ .../upload_methods/UploadMethodPYOCD.cmake | 2 +- 13 files changed, 86 insertions(+), 43 deletions(-) create mode 100644 targets/upload_method_cfg/K64F.cmake create mode 100644 targets/upload_method_cfg/openocd_cfgs/mk64f.cfg diff --git a/.github/workflows/basic_checks.yml b/.github/workflows/basic_checks.yml index 3d436e35dc2..fdfb2611397 100644 --- a/.github/workflows/basic_checks.yml +++ b/.github/workflows/basic_checks.yml @@ -193,6 +193,7 @@ jobs: name: validate pins run: | set -x + python3 -m pip install json5 git config --global --add safe.directory "$GITHUB_WORKSPACE" git diff --name-only --diff-filter=d origin/${GITHUB_BASE_REF} \ | ( grep '.*[\\|\/]PinNames.h$' || true ) \ diff --git a/connectivity/drivers/802.15.4_RF/CMakeLists.txt b/connectivity/drivers/802.15.4_RF/CMakeLists.txt index 28ab928c07e..7cd94d0f7af 100644 --- a/connectivity/drivers/802.15.4_RF/CMakeLists.txt +++ b/connectivity/drivers/802.15.4_RF/CMakeLists.txt @@ -18,10 +18,8 @@ endmacro(create_mbed_802_15_4_target) if("Freescale" IN_LIST MBED_TARGET_LABELS) - create_mbed_802_15_4_target() add_subdirectory(TARGET_Freescale) elseif("Silicon_Labs" IN_LIST MBED_TARGET_LABELS) - create_mbed_802_15_4_target() add_subdirectory(TARGET_Silicon_Labs) endif() diff --git a/connectivity/drivers/802.15.4_RF/TARGET_Freescale/CMakeLists.txt b/connectivity/drivers/802.15.4_RF/TARGET_Freescale/CMakeLists.txt index 223293d7fd8..2b311fadac9 100644 --- a/connectivity/drivers/802.15.4_RF/TARGET_Freescale/CMakeLists.txt +++ b/connectivity/drivers/802.15.4_RF/TARGET_Freescale/CMakeLists.txt @@ -2,5 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 if("KW41Z" IN_LIST MBED_TARGET_LABELS) + create_mbed_802_15_4_target() add_subdirectory(TARGET_KW41Z) endif() diff --git a/connectivity/drivers/802.15.4_RF/TARGET_Silicon_Labs/CMakeLists.txt b/connectivity/drivers/802.15.4_RF/TARGET_Silicon_Labs/CMakeLists.txt index 2185e82a9dd..12988f36956 100644 --- a/connectivity/drivers/802.15.4_RF/TARGET_Silicon_Labs/CMakeLists.txt +++ b/connectivity/drivers/802.15.4_RF/TARGET_Silicon_Labs/CMakeLists.txt @@ -2,5 +2,6 @@ # SPDX-License-Identifier: Apache-2.0 if("SL_RAIL" IN_LIST MBED_TARGET_LABELS) + create_mbed_802_15_4_target() add_subdirectory(TARGET_SL_RAIL) endif() diff --git a/hal/tests/pinvalidate/pinvalidate.py b/hal/tests/pinvalidate/pinvalidate.py index 6a327c3ce9c..3fd22c8a81b 100755 --- a/hal/tests/pinvalidate/pinvalidate.py +++ b/hal/tests/pinvalidate/pinvalidate.py @@ -17,7 +17,7 @@ """ import argparse -import json +import json5 import pathlib import hashlib import re @@ -26,6 +26,12 @@ from itertools import chain from enum import Enum +# Load targets data from JSON +mbed_os_root = pathlib.Path(__file__).absolute().parents[3] +with ( + mbed_os_root.joinpath("targets", "targets.json5") + ).open() as targets_json_file: + target_data = json5.load(targets_json_file) class ReturnCode(Enum): """Return codes.""" @@ -76,11 +82,6 @@ def find_target_by_path(target_path): print("WARNING: MBED TARGET LIST marker invalid or not found in file " + target_path) print("Target could not be determined. Only the generic test suite will run. You can manually specify additional suites.") - with ( - mbed_os_root.joinpath("targets", "targets.json") - ).open() as targets_json_file: - target_data = json.load(targets_json_file) - # find target in targets.json for target in target_data: if "public" in target_data[target]: @@ -97,7 +98,6 @@ def find_target_by_path(target_path): def find_target_by_name(target_name=""): """Find a target by name.""" - mbed_os_root = pathlib.Path(__file__).absolute().parents[3] targets = dict() @@ -133,15 +133,10 @@ def find_target_by_name(target_name=""): def check_markers(test_mode=False): """Validate markers in PinNames.h files""" - mbed_os_root = pathlib.Path(__file__).absolute().parents[3] + errors = [] - with ( - mbed_os_root.joinpath("targets", "targets.json") - ).open() as targets_json_file: - targets_json = json.load(targets_json_file) - if test_mode: search_dir = pathlib.Path(__file__).parent.joinpath('test_files').absolute() else: @@ -187,8 +182,6 @@ def check_markers(test_mode=False): def check_duplicate_pinnames_files(test_mode=False): """Check for duplicate PinNames.h files""" - mbed_os_root = pathlib.Path(__file__).absolute().parents[3] - errors = [] file_hash_dict = dict() @@ -220,8 +213,6 @@ def check_duplicate_pinnames_files(test_mode=False): def check_duplicate_markers(test_mode=False): """Check target markers in PinNames.h files for duplicates.""" - mbed_os_root = pathlib.Path(__file__).absolute().parents[3] - errors = [] markers = dict() @@ -262,13 +253,6 @@ def check_duplicate_markers(test_mode=False): def target_has_form_factor(target_name, form_factor): """Check if the target has the Arduino form factor.""" - mbed_os_root = pathlib.Path(__file__).absolute().parents[3] - - with ( - mbed_os_root.joinpath("targets", "targets.json") - ).open() as targets_json_file: - target_data = json.load(targets_json_file) - if target_name in target_data: if "supported_form_factors" in target_data[target_name]: form_factors = target_data[target_name]["supported_form_factors"] diff --git a/storage/blockdevice/COMPONENT_SD/mbed_lib.json b/storage/blockdevice/COMPONENT_SD/mbed_lib.json index f32740e91e4..3cfafb47a25 100644 --- a/storage/blockdevice/COMPONENT_SD/mbed_lib.json +++ b/storage/blockdevice/COMPONENT_SD/mbed_lib.json @@ -57,10 +57,10 @@ "SPI_CS": "PTD4" }, "K64F": { - "SPI_CS": "SPI_CS", - "SPI_MOSI": "SPI_MOSI", - "SPI_MISO": "SPI_MISO", - "SPI_CLK": "SPI_SCK" + "SPI_CS": "PTE4", + "SPI_MOSI": "PTE3", + "SPI_MISO": "PTE1", + "SPI_CLK": "PTE2" }, "K66F": { "SPI_MOSI": "PTE3", diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h index ca7676cf7d7..cae15a14161 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/TARGET_FRDM/PinNames.h @@ -262,17 +262,6 @@ typedef enum { #define BUTTON2 SW3 -// SPI Pins for SD card. -// Note: They are different from the Arduino Uno SPI pins -// (ARDUINO_UNO_SPI_xxx) for general purpose uses. -// By default, Mbed OS maps those alias to Arduino Uno pins, but -// for backward compatibility we map them to the SD card SPI. -#define SPI_MOSI PTE3 -#define SPI_MISO PTE1 -#define SPI_SCK PTE2 -#define SPI_CS PTE4 - - #ifdef __cplusplus } #endif diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/cmsis_nvic.h b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/cmsis_nvic.h index 7239e0f2003..6c8d1d35fbe 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/cmsis_nvic.h +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/device/cmsis_nvic.h @@ -42,4 +42,21 @@ extern uint32_t __VECTOR_RAM[]; #define NVIC_NUM_VECTORS (16 + 86) // CORE + MCU Peripherals #define NVIC_RAM_VECTOR_ADDRESS (__VECTOR_RAM) // Vectors positioned at start of RAM +#ifndef MBED_RAM_SIZE +#define MBED_RAM_SIZE 0x30000 +#endif + +#ifndef MBED_RAM_START +#define MBED_RAM_START 0x20000000 +#endif + +#ifndef MBED_RAM1_SIZE +#define MBED_RAM1_SIZE 0x10000 +#endif + +#ifndef MBED_RAM1_START +#define MBED_RAM1_START 0x1FFF0000 +#endif + + #endif diff --git a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c index 1ac6a1856bb..a06fbbbdadd 100644 --- a/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c +++ b/targets/TARGET_Freescale/TARGET_MCUXpresso_MCUS/TARGET_MCU_K64F/spi_api.c @@ -361,7 +361,7 @@ static void spi_buffer_set(spi_t *obj, const void *tx, uint32_t tx_length, void bool spi_master_transfer(spi_t *obj, const void *tx, size_t tx_length, void *rx, size_t rx_length, uint8_t bit_width, uint32_t handler, uint32_t event, DMAUsage hint) { if (spi_active(obj)) { - return; + return false; } /* check corner case */ diff --git a/targets/upload_method_cfg/K64F.cmake b/targets/upload_method_cfg/K64F.cmake new file mode 100644 index 00000000000..0ccf2c5a30f --- /dev/null +++ b/targets/upload_method_cfg/K64F.cmake @@ -0,0 +1,35 @@ +# Mbed OS upload method configuration file for target K64F. +# To change any of these parameters from their default values, set them in your build script between where you +# include app.cmake and where you add mbed os as a subdirectory. +# +# Notes: +# 1. PyOCD did not actually work in my testing as of Apr 2024, though this device is supposed to be supported +# 2. Be sure to update the DAPLink firmware on the board via these instructions: https://os.mbed.com/blog/entry/DAPLink-bootloader-update/ + +# General config parameters +# ------------------------------------------------------------- +set(UPLOAD_METHOD_DEFAULT MBED) + +# Config options for MBED +# ------------------------------------------------------------- + +set(MBED_UPLOAD_ENABLED TRUE) +set(MBED_RESET_BAUDRATE 115200) + +# Config options for PYOCD +# ------------------------------------------------------------- +set(PYOCD_UPLOAD_ENABLED TRUE) +set(PYOCD_TARGET_NAME k64f) +set(PYOCD_CLOCK_SPEED 4000k) + +# Config options for OPENOCD +# ------------------------------------------------------------- + +set(OPENOCD_UPLOAD_ENABLED TRUE) +set(OPENOCD_CHIP_CONFIG_COMMANDS + -f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/mk64f.cfg) + +# Config options for LINKSERVER +# ------------------------------------------------------------- +set(LINKSERVER_UPLOAD_ENABLED TRUE) +set(LINKSERVER_DEVICE MK64FN1M0xxx12:FRDM-K64F) diff --git a/targets/upload_method_cfg/LPC1768.cmake b/targets/upload_method_cfg/LPC1768.cmake index 1ea1d474c12..d64d21a6f26 100644 --- a/targets/upload_method_cfg/LPC1768.cmake +++ b/targets/upload_method_cfg/LPC1768.cmake @@ -2,6 +2,9 @@ # To change any of these parameters from their default values, set them in your build script between where you # include app.cmake and where you add mbed os as a subdirectory. +# Notes: +# 1. LPC1768 is supposed to be supported by LinkServer, and I am able to get through flashing it, but it errors out at the end. + # General config parameters # ------------------------------------------------------------- set(UPLOAD_METHOD_DEFAULT MBED) @@ -33,3 +36,8 @@ set(MBED_RESET_BAUDRATE 115200) set(OPENOCD_UPLOAD_ENABLED TRUE) set(OPENOCD_CHIP_CONFIG_COMMANDS -f ${CMAKE_CURRENT_LIST_DIR}/openocd_cfgs/lpc1768.cfg) + +# Config options for LINKSERVER +# ------------------------------------------------------------- +set(LINKSERVER_UPLOAD_ENABLED TRUE) +set(LINKSERVER_DEVICE LPC1768) \ No newline at end of file diff --git a/targets/upload_method_cfg/openocd_cfgs/mk64f.cfg b/targets/upload_method_cfg/openocd_cfgs/mk64f.cfg new file mode 100644 index 00000000000..e504bbb29d1 --- /dev/null +++ b/targets/upload_method_cfg/openocd_cfgs/mk64f.cfg @@ -0,0 +1,9 @@ +# OpenOCD config file for Kinetis K64F chips using DAPLink + +source [find interface/cmsis-dap.cfg] + +transport select swd + +source [find target/k60.cfg] + +reset_config srst_only \ No newline at end of file diff --git a/tools/cmake/upload_methods/UploadMethodPYOCD.cmake b/tools/cmake/upload_methods/UploadMethodPYOCD.cmake index c9d0db0f272..61f67cbc62a 100644 --- a/tools/cmake/upload_methods/UploadMethodPYOCD.cmake +++ b/tools/cmake/upload_methods/UploadMethodPYOCD.cmake @@ -19,7 +19,7 @@ set(UPLOAD_PYOCD_FOUND ${HAVE_PYOCD}) set(PYOCD_PROBE_UID "" CACHE STRING "Probe UID to pass to pyOCD commands. You can get the UIDs from `python -m pyocd list`. Set to empty to detect any probe.") ### Function to generate upload target -set(PYOCD_PROBE_ARGS "") +set(PYOCD_PROBE_ARGS "" CACHE INTERNAL "" FORCE) if(NOT "${PYOCD_PROBE_UID}" STREQUAL "") set(PYOCD_PROBE_ARGS --probe ${PYOCD_PROBE_UID} CACHE INTERNAL "" FORCE) endif()