From a42bc5bf83d10202bcfedecbe0772c0a3f847770 Mon Sep 17 00:00:00 2001 From: Chun-Chieh Li Date: Thu, 26 Dec 2024 17:36:14 +0800 Subject: [PATCH] Migrate to Mbed CE 1. Common change for migration to Mbed CE from Mbed CLI 1/2 (1) Remove *.lib originally for library import. Replace with git submodule. (2) Rename mbed_app.json/mbed_lib.json to mbed_app.json5/mbed_lib.json5 (3) Add/update CMakeLists.txt (4) Remove .mbedignore originally for Mbed CLI 1 (5) Update document 2. Support VS Code development 3. Temporary fix to build profile inconsistent with mbed-lora library build See: https://github.com/mbed-ce/mbed-os/issues/407 --- .gitignore | 4 + .vscode/settings.json | 5 + CMakeLists.txt | 69 ++++++++++++++ Jenkinsfile | 158 -------------------------------- cmake-variants.yaml | 73 +++++++++++++++ mbed-os.lib | 1 - mbed_app.json => mbed_app.json5 | 20 ---- 7 files changed, 151 insertions(+), 179 deletions(-) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 CMakeLists.txt delete mode 100644 Jenkinsfile create mode 100644 cmake-variants.yaml delete mode 100644 mbed-os.lib rename mbed_app.json => mbed_app.json5 (85%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..57974bd --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py* diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..169f42e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "cmake.buildDirectory": "${workspaceFolder}/build", + "cmake.generator": "Ninja", + "cmake.configureOnOpen": false +} diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f9ad0a2 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,69 @@ +# Copyright (c) 2022 ARM Limited. All rights reserved. +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.19) +cmake_policy(VERSION 3.19) + +set(MBED_OS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "") + +# Set default path for mbed_app.json5 (no force-write for override) +set(MBED_APP_JSON_PATH mbed_app.json5 CACHE INTERNAL "") + +# Set default path for custom_targets.json5 (no force-write for override) +set(CUSTOM_TARGETS_PATH custom_targets CACHE INTERNAL "") +set(CUSTOM_TARGETS_JSON_PATH ${CUSTOM_TARGETS_PATH}/custom_targets.json5 CACHE INTERNAL "") + +# Load Mbed CE toolchain file and basic build system +include(${MBED_OS_PATH}/tools/cmake/app.cmake) + +set(APP_PROJECT NUMAKER_MBED_CE_LORAWAN_EXAMPLE) +set(APP_TARGET NuMaker-mbed-ce-lorawan-example) + +# Set up project name +project(${APP_PROJECT}) + +# Add Nuvoton CMake list files to CMake default module path +# +# Normally, this is added in ${MBED_OS_PATH}, but ${CUSTOM_TARGETS_PATH} +# is in front and needs it. +list(APPEND CMAKE_MODULE_PATH + ${MBED_OS_PATH}/targets/TARGET_NUVOTON/scripts +) + +# Add Mbed OS library +add_subdirectory(${MBED_OS_PATH}) + +# User-provided MBEDTLS_USER_CONFIG_FILE for mbedtls +target_include_directories(mbed-mbedtls + PUBLIC + . +) + +add_executable(${APP_TARGET}) + +target_include_directories(${APP_TARGET} + PRIVATE + . +) + +target_sources(${APP_TARGET} + PRIVATE + main.cpp + trace_helper.cpp +) + +target_link_libraries(${APP_TARGET} + PRIVATE + mbed-os + mbed-lorawan +) + +# Temporary fix to build profile inconsistent with mbed-lora library build. +# See: https://github.com/mbed-ce/mbed-os/issues/407 +target_link_libraries(mbed-lorawan PUBLIC mbed-rtos-flags) + +# Must call this for each target to set up bin file creation, code upload, etc +mbed_set_post_build(${APP_TARGET}) + +# Make sure this is the last line of the top-level build script +mbed_finalize_build() diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index b7b8588..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,158 +0,0 @@ -properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ - [$class: 'StringParameterDefinition', name: 'mbed_os_revision', defaultValue: '', description: 'Revision of mbed-os to build. To access mbed-os PR use format "pull/PR number/head"'], - [$class: 'BooleanParameterDefinition', name: 'regions_build_test', defaultValue: true, description: 'Test build all available regions'] - ]]]) - -library 'mbed-lib' - -if (env.MBED_OS_REVISION == null) { - echo 'First run in this branch, using default parameter values' - env.MBED_OS_REVISION = '' -} -if (env.MBED_OS_REVISION == '') { - echo 'Using mbed OS revision from mbed-os.lib' -} else { - echo "Using given mbed OS revision: ${env.MBED_OS_REVISION}" - if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { - echo "Revision is a Pull Request" - } -} - -// All available regions -def regions = [ - "\"0\"", "\"1\"", "\"2\"", "\"3\"", "\"4\"", "\"5\"", "\"6\"", "\"7\"", "\"8\"", - "\"EU868\"", "\"AS923\"", "\"AU915\"", "\"CN470\"", "\"CN779\"", "\"EU433\"", - "\"IN865\"", "\"KR920\"", "\"US915\"" -] - -// Supported targets -def targets = [ - "K64F", - "MTS_MDOT_F411RE", - "DISCO_L072CZ_LRWAN1" -] - -// Supported toolchains -def toolchains = [ - "ARM", - "GCC_ARM" -] - -def stepsForParallel = [:] - -// Jenkins pipeline does not support map.each, we need to use oldschool for loop -for (int i = 0; i < targets.size(); i++) { - for(int j = 0; j < toolchains.size(); j++) { - def target = targets.get(i) - def toolchain = toolchains.get(j) - - // Skip unwanted combination - if (target == "DISCO_L072CZ_LRWAN1" && toolchain == "GCC_ARM") { - continue - } - - def stepName = "${target} ${toolchain}" - - stepsForParallel[stepName] = buildStep(target, toolchain) - } -} - -def stepsForRegional = [:] - -if (params.regions_build_test == true) { - stepsForRegional["REGION BUILDER"] = build_regions(regions) -} - -timestamps { - parallel stepsForParallel - parallel stepsForRegional -} - -def buildStep(target, toolchain) { - return { - stage ("${target}_${toolchain}") { - node ("all-in-one-build-slave") { - deleteDir() - dir("mbed-os-example-lorawan") { - checkout scm - - // A workaround for mbed-cli caching issues - try { - execute("mbed deploy --protocol ssh") - } catch (err) { - echo "mbed deploy failed - retrying after 10s" - sleep(10) - execute("mbed deploy --protocol ssh") - } - - // Set mbed-os to revision received as parameter - if (env.MBED_OS_REVISION != '') { - dir("mbed-os") { - if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { - // Use mbed-os PR and switch to branch created - execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_") - execute("git checkout _PR_") - } else { - execute("git checkout ${env.MBED_OS_REVISION}") - } - } - } - - // Adjust stack size and crystal values - if ("${target}" == "DISCO_L072CZ_LRWAN1") { - execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10)/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x13)/' \ - mbed-os/targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rcc.h") - } - - execute("mbed compile --build out/${target}_${toolchain}/ -m ${target} -t ${toolchain} -c") - } - stash name: "${target}_${toolchain}", includes: '**/mbed-os-example-lorawan.bin' - archive '**/mbed-os-example-lorawan.bin' - step([$class: 'WsCleanup']) - } - } - } -} - -def build_regions(regions) { - return { - stage ("region_builder_K64F_GCC_ARM") { - node ("all-in-one-build-slave") { - deleteDir() - dir("mbed-os-example-lorawan") { - checkout scm - - // A workaround for mbed-cli caching issues - try { - execute("mbed deploy --protocol ssh") - } catch (err) { - echo "mbed deploy failed - retrying after 10s" - sleep(10) - execute("mbed deploy --protocol ssh") - } - - if (env.MBED_OS_REVISION != '') { - dir("mbed-os") { - if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { - execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_") - execute("git checkout _PR_") - } else { - execute("git checkout ${env.MBED_OS_REVISION}") - } - } - } - //Initial sed to string format for find & replacing - execute("sed -i 's/\"lora.phy\": 0,/\"lora.phy\": \"0\",/' mbed_app.json") - //lora.phy 0 build tested above already - for (int i = 1; i < regions.size(); i++) { - def curr_region = regions.get(i) - def prev_region = regions.get(i-1) - execute("sed -i 's/\"lora.phy\": ${prev_region},/\"lora.phy\": ${curr_region},/' mbed_app.json") - echo "Building region: ${curr_region}" - execute("mbed compile -t GCC_ARM -m K64F") - } - } - } - } - } -} diff --git a/cmake-variants.yaml b/cmake-variants.yaml new file mode 100644 index 0000000..3599b02 --- /dev/null +++ b/cmake-variants.yaml @@ -0,0 +1,73 @@ +buildType: + default: Develop + choices: + Develop: + short: Develop + long: Emit debug information but also optimize + buildType: Develop + Debug: + short: Debug + long: Emit debug information and don't optimize + buildType: Debug + Release: + short: Release + long: Optimize generated code + buildType: Release +board: + default: NUMAKER_IOT_M467 + choices: + NUMAKER_PFM_NANO130: + short: NUMAKER_PFM_NANO130 + settings: + MBED_TARGET: NUMAKER_PFM_NANO130 + UPLOAD_METHOD: OPENOCD + NUMAKER_PFM_NUC472: + short: NUMAKER_PFM_NUC472 + settings: + MBED_TARGET: NUMAKER_PFM_NUC472 + UPLOAD_METHOD: OPENOCD + NUMAKER_PFM_M453: + short: NUMAKER_PFM_M453 + settings: + MBED_TARGET: NUMAKER_PFM_M453 + UPLOAD_METHOD: OPENOCD + NUMAKER_PFM_M487: + short: NUMAKER_PFM_M487 + settings: + MBED_TARGET: NUMAKER_PFM_M487 + UPLOAD_METHOD: OPENOCD + NUMAKER_IOT_M487: + short: NUMAKER_IOT_M487 + settings: + MBED_TARGET: NUMAKER_IOT_M487 + UPLOAD_METHOD: OPENOCD + NUMAKER_M483KG: + short: NUMAKER_M483KG + settings: + MBED_TARGET: NUMAKER_M483KG + UPLOAD_METHOD: OPENOCD + NUMAKER_IOT_M467: + short: NUMAKER_IOT_M467 + settings: + MBED_TARGET: NUMAKER_IOT_M467 + UPLOAD_METHOD: OPENOCD + NUMAKER_IOT_M252: + short: NUMAKER_IOT_M252 + settings: + MBED_TARGET: NUMAKER_IOT_M252 + UPLOAD_METHOD: OPENOCD + NUMAKER_IOT_M263A: + short: NUMAKER_IOT_M263A + settings: + MBED_TARGET: NUMAKER_IOT_M263A + UPLOAD_METHOD: OPENOCD + NU_M2354: + short: NU_M2354 + settings: + MBED_TARGET: NU_M2354 + UPLOAD_METHOD: OPENOCD + NU_IOT_M2354: + short: NU_IOT_M2354 + settings: + MBED_TARGET: NU_IOT_M2354 + UPLOAD_METHOD: OPENOCD \ No newline at end of file diff --git a/mbed-os.lib b/mbed-os.lib deleted file mode 100644 index 2dd8afb..0000000 --- a/mbed-os.lib +++ /dev/null @@ -1 +0,0 @@ -https://github.com/ARMmbed/mbed-os/#17dc3dc2e6e2817a8bd3df62f38583319f0e4fed \ No newline at end of file diff --git a/mbed_app.json b/mbed_app.json5 similarity index 85% rename from mbed_app.json rename to mbed_app.json5 index bbbd10b..a37ad18 100644 --- a/mbed_app.json +++ b/mbed_app.json5 @@ -103,26 +103,6 @@ "lora-ant-switch": "NC", "lora-pwr-amp-ctl": "NC", "lora-tcxo": "NC" - }, - "K64F": { - "lora-spi-mosi": "D11", - "lora-spi-miso": "D12", - "lora-spi-sclk": "D13", - "lora-cs": "D10", - "lora-reset": "A0", - "lora-dio0": "D2", - "lora-dio1": "D3", - "lora-dio2": "D4", - "lora-dio3": "D5", - "lora-dio4": "D8", - "lora-dio5": "D9", - "lora-rf-switch-ctl1": "NC", - "lora-rf-switch-ctl2": "NC", - "lora-txctl": "NC", - "lora-rxctl": "NC", - "lora-ant-switch": "A4", - "lora-pwr-amp-ctl": "NC", - "lora-tcxo": "NC" } }, "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""]