NuMaker mbed OS v5.x LoRaWAN

Committer:
cyliang
Date:
Tue Sep 01 21:06:51 2020 +0800
Revision:
0:895bbd4e6398
Mbed OS v5.x LoRaWAN example for NuMaker platforms based on https://github.com/ARMmbed/mbed-os-example-lorawan.git

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cyliang 0:895bbd4e6398 1 properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [
cyliang 0:895bbd4e6398 2 [$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"'],
cyliang 0:895bbd4e6398 3 [$class: 'BooleanParameterDefinition', name: 'regions_build_test', defaultValue: true, description: 'Test build all available regions']
cyliang 0:895bbd4e6398 4 ]]])
cyliang 0:895bbd4e6398 5
cyliang 0:895bbd4e6398 6 library 'mbed-lib'
cyliang 0:895bbd4e6398 7
cyliang 0:895bbd4e6398 8 if (env.MBED_OS_REVISION == null) {
cyliang 0:895bbd4e6398 9 echo 'First run in this branch, using default parameter values'
cyliang 0:895bbd4e6398 10 env.MBED_OS_REVISION = ''
cyliang 0:895bbd4e6398 11 }
cyliang 0:895bbd4e6398 12 if (env.MBED_OS_REVISION == '') {
cyliang 0:895bbd4e6398 13 echo 'Using mbed OS revision from mbed-os.lib'
cyliang 0:895bbd4e6398 14 } else {
cyliang 0:895bbd4e6398 15 echo "Using given mbed OS revision: ${env.MBED_OS_REVISION}"
cyliang 0:895bbd4e6398 16 if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
cyliang 0:895bbd4e6398 17 echo "Revision is a Pull Request"
cyliang 0:895bbd4e6398 18 }
cyliang 0:895bbd4e6398 19 }
cyliang 0:895bbd4e6398 20
cyliang 0:895bbd4e6398 21 // All available regions
cyliang 0:895bbd4e6398 22 def regions = [
cyliang 0:895bbd4e6398 23 "\"0\"", "\"1\"", "\"2\"", "\"3\"", "\"4\"", "\"5\"", "\"6\"", "\"7\"", "\"8\"",
cyliang 0:895bbd4e6398 24 "\"EU868\"", "\"AS923\"", "\"AU915\"", "\"CN470\"", "\"CN779\"", "\"EU433\"",
cyliang 0:895bbd4e6398 25 "\"IN865\"", "\"KR920\"", "\"US915\""
cyliang 0:895bbd4e6398 26 ]
cyliang 0:895bbd4e6398 27
cyliang 0:895bbd4e6398 28 // Supported targets
cyliang 0:895bbd4e6398 29 def targets = [
cyliang 0:895bbd4e6398 30 "K64F",
cyliang 0:895bbd4e6398 31 "MTB_MTS_XDOT",
cyliang 0:895bbd4e6398 32 "MTB_MURATA_ABZ",
cyliang 0:895bbd4e6398 33 "MTS_MDOT_F411RE",
cyliang 0:895bbd4e6398 34 "DISCO_L072CZ_LRWAN1",
cyliang 0:895bbd4e6398 35 "MTB_ADV_WISE_1510",
cyliang 0:895bbd4e6398 36 "MTB_RAK811"
cyliang 0:895bbd4e6398 37 ]
cyliang 0:895bbd4e6398 38
cyliang 0:895bbd4e6398 39 // Supported toolchains
cyliang 0:895bbd4e6398 40 def toolchains = [
cyliang 0:895bbd4e6398 41 "ARM",
cyliang 0:895bbd4e6398 42 "GCC_ARM",
cyliang 0:895bbd4e6398 43 "IAR"
cyliang 0:895bbd4e6398 44 ]
cyliang 0:895bbd4e6398 45
cyliang 0:895bbd4e6398 46 def stepsForParallel = [:]
cyliang 0:895bbd4e6398 47
cyliang 0:895bbd4e6398 48 // Jenkins pipeline does not support map.each, we need to use oldschool for loop
cyliang 0:895bbd4e6398 49 for (int i = 0; i < targets.size(); i++) {
cyliang 0:895bbd4e6398 50 for(int j = 0; j < toolchains.size(); j++) {
cyliang 0:895bbd4e6398 51 def target = targets.get(i)
cyliang 0:895bbd4e6398 52 def toolchain = toolchains.get(j)
cyliang 0:895bbd4e6398 53
cyliang 0:895bbd4e6398 54 // Skip unwanted combination
cyliang 0:895bbd4e6398 55 if (target == "MTB_MURATA_ABZ" && toolchain == "GCC_ARM") {
cyliang 0:895bbd4e6398 56 continue
cyliang 0:895bbd4e6398 57 }
cyliang 0:895bbd4e6398 58 if (target == "DISCO_L072CZ_LRWAN1" && toolchain == "GCC_ARM") {
cyliang 0:895bbd4e6398 59 continue
cyliang 0:895bbd4e6398 60 }
cyliang 0:895bbd4e6398 61 if (target == "MTB_RAK811" && toolchain == "GCC_ARM") {
cyliang 0:895bbd4e6398 62 continue
cyliang 0:895bbd4e6398 63 }
cyliang 0:895bbd4e6398 64
cyliang 0:895bbd4e6398 65 def stepName = "${target} ${toolchain}"
cyliang 0:895bbd4e6398 66
cyliang 0:895bbd4e6398 67 stepsForParallel[stepName] = buildStep(target, toolchain)
cyliang 0:895bbd4e6398 68 }
cyliang 0:895bbd4e6398 69 }
cyliang 0:895bbd4e6398 70
cyliang 0:895bbd4e6398 71 def stepsForRegional = [:]
cyliang 0:895bbd4e6398 72
cyliang 0:895bbd4e6398 73 if (params.regions_build_test == true) {
cyliang 0:895bbd4e6398 74 stepsForRegional["REGION BUILDER"] = build_regions(regions)
cyliang 0:895bbd4e6398 75 }
cyliang 0:895bbd4e6398 76
cyliang 0:895bbd4e6398 77 timestamps {
cyliang 0:895bbd4e6398 78 parallel stepsForParallel
cyliang 0:895bbd4e6398 79 parallel stepsForRegional
cyliang 0:895bbd4e6398 80 }
cyliang 0:895bbd4e6398 81
cyliang 0:895bbd4e6398 82 def buildStep(target, toolchain) {
cyliang 0:895bbd4e6398 83 return {
cyliang 0:895bbd4e6398 84 stage ("${target}_${toolchain}") {
cyliang 0:895bbd4e6398 85 node ("all-in-one-build-slave") {
cyliang 0:895bbd4e6398 86 deleteDir()
cyliang 0:895bbd4e6398 87 dir("mbed-os-example-lorawan") {
cyliang 0:895bbd4e6398 88 checkout scm
cyliang 0:895bbd4e6398 89
cyliang 0:895bbd4e6398 90 // A workaround for mbed-cli caching issues
cyliang 0:895bbd4e6398 91 try {
cyliang 0:895bbd4e6398 92 execute("mbed deploy --protocol ssh")
cyliang 0:895bbd4e6398 93 } catch (err) {
cyliang 0:895bbd4e6398 94 echo "mbed deploy failed - retrying after 10s"
cyliang 0:895bbd4e6398 95 sleep(10)
cyliang 0:895bbd4e6398 96 execute("mbed deploy --protocol ssh")
cyliang 0:895bbd4e6398 97 }
cyliang 0:895bbd4e6398 98
cyliang 0:895bbd4e6398 99 // Set mbed-os to revision received as parameter
cyliang 0:895bbd4e6398 100 if (env.MBED_OS_REVISION != '') {
cyliang 0:895bbd4e6398 101 dir("mbed-os") {
cyliang 0:895bbd4e6398 102 if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
cyliang 0:895bbd4e6398 103 // Use mbed-os PR and switch to branch created
cyliang 0:895bbd4e6398 104 execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_")
cyliang 0:895bbd4e6398 105 execute("git checkout _PR_")
cyliang 0:895bbd4e6398 106 } else {
cyliang 0:895bbd4e6398 107 execute("git checkout ${env.MBED_OS_REVISION}")
cyliang 0:895bbd4e6398 108 }
cyliang 0:895bbd4e6398 109 }
cyliang 0:895bbd4e6398 110 }
cyliang 0:895bbd4e6398 111
cyliang 0:895bbd4e6398 112 // Adjust stack size and crystal values
cyliang 0:895bbd4e6398 113 if ("${target}" == "DISCO_L072CZ_LRWAN1") {
cyliang 0:895bbd4e6398 114 execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10)/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x13)/' \
cyliang 0:895bbd4e6398 115 mbed-os/targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rcc.h")
cyliang 0:895bbd4e6398 116 }
cyliang 0:895bbd4e6398 117
cyliang 0:895bbd4e6398 118 if ("${target}" == "MTB_MURATA_ABZ") {
cyliang 0:895bbd4e6398 119 execute("sed -i 's/define symbol __size_heap__ = 0x800;/define symbol __size_heap__ = 0x1000;/' \
cyliang 0:895bbd4e6398 120 mbed-os/targets/TARGET_STM/TARGET_STM32L0/TARGET_STM32L0x2xZ/device/TOOLCHAIN_IAR/stm32l082xZ.icf")
cyliang 0:895bbd4e6398 121 execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10)/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x16)/' \
cyliang 0:895bbd4e6398 122 mbed-os/targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rcc.h")
cyliang 0:895bbd4e6398 123 }
cyliang 0:895bbd4e6398 124
cyliang 0:895bbd4e6398 125 if ("${target}" == "MTB_MTS_XDOT") {
cyliang 0:895bbd4e6398 126 execute("sed -i 's/define symbol __size_heap__ = 0x800;/define symbol __size_heap__ = 0x1800;/' \
cyliang 0:895bbd4e6398 127 mbed-os/targets/TARGET_STM/TARGET_STM32L1/TARGET_MTB_MTS_XDOT/device/TOOLCHAIN_IAR/stm32l152xc.icf")
cyliang 0:895bbd4e6398 128 }
cyliang 0:895bbd4e6398 129
cyliang 0:895bbd4e6398 130 if ("${target}" == "MTB_RAK811") {
cyliang 0:895bbd4e6398 131 execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT (0x10U)/#define RCC_HSICALIBRATION_DEFAULT (0x11U)/' \
cyliang 0:895bbd4e6398 132 mbed-os/targets/TARGET_STM/TARGET_STM32L1/device/stm32l1xx_hal_rcc.h")
cyliang 0:895bbd4e6398 133 execute("sed -i 's/define symbol __size_heap__ = 0x800;/define symbol __size_heap__ = 0x1800;/' \
cyliang 0:895bbd4e6398 134 mbed-os/targets/TARGET_STM/TARGET_STM32L1/TARGET_MTB_RAK811/device/TOOLCHAIN_IAR/stm32l152xba.icf")
cyliang 0:895bbd4e6398 135 }
cyliang 0:895bbd4e6398 136
cyliang 0:895bbd4e6398 137 execute("mbed compile --build out/${target}_${toolchain}/ -m ${target} -t ${toolchain} -c")
cyliang 0:895bbd4e6398 138 }
cyliang 0:895bbd4e6398 139 stash name: "${target}_${toolchain}", includes: '**/mbed-os-example-lorawan.bin'
cyliang 0:895bbd4e6398 140 archive '**/mbed-os-example-lorawan.bin'
cyliang 0:895bbd4e6398 141 step([$class: 'WsCleanup'])
cyliang 0:895bbd4e6398 142 }
cyliang 0:895bbd4e6398 143 }
cyliang 0:895bbd4e6398 144 }
cyliang 0:895bbd4e6398 145 }
cyliang 0:895bbd4e6398 146
cyliang 0:895bbd4e6398 147 def build_regions(regions) {
cyliang 0:895bbd4e6398 148 return {
cyliang 0:895bbd4e6398 149 stage ("region_builder_K64F_GCC_ARM") {
cyliang 0:895bbd4e6398 150 node ("all-in-one-build-slave") {
cyliang 0:895bbd4e6398 151 deleteDir()
cyliang 0:895bbd4e6398 152 dir("mbed-os-example-lorawan") {
cyliang 0:895bbd4e6398 153 checkout scm
cyliang 0:895bbd4e6398 154
cyliang 0:895bbd4e6398 155 // A workaround for mbed-cli caching issues
cyliang 0:895bbd4e6398 156 try {
cyliang 0:895bbd4e6398 157 execute("mbed deploy --protocol ssh")
cyliang 0:895bbd4e6398 158 } catch (err) {
cyliang 0:895bbd4e6398 159 echo "mbed deploy failed - retrying after 10s"
cyliang 0:895bbd4e6398 160 sleep(10)
cyliang 0:895bbd4e6398 161 execute("mbed deploy --protocol ssh")
cyliang 0:895bbd4e6398 162 }
cyliang 0:895bbd4e6398 163
cyliang 0:895bbd4e6398 164 if (env.MBED_OS_REVISION != '') {
cyliang 0:895bbd4e6398 165 dir("mbed-os") {
cyliang 0:895bbd4e6398 166 if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) {
cyliang 0:895bbd4e6398 167 execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_")
cyliang 0:895bbd4e6398 168 execute("git checkout _PR_")
cyliang 0:895bbd4e6398 169 } else {
cyliang 0:895bbd4e6398 170 execute("git checkout ${env.MBED_OS_REVISION}")
cyliang 0:895bbd4e6398 171 }
cyliang 0:895bbd4e6398 172 }
cyliang 0:895bbd4e6398 173 }
cyliang 0:895bbd4e6398 174 //Initial sed to string format for find & replacing
cyliang 0:895bbd4e6398 175 execute("sed -i 's/\"lora.phy\": 0,/\"lora.phy\": \"0\",/' mbed_app.json")
cyliang 0:895bbd4e6398 176 //lora.phy 0 build tested above already
cyliang 0:895bbd4e6398 177 for (int i = 1; i < regions.size(); i++) {
cyliang 0:895bbd4e6398 178 def curr_region = regions.get(i)
cyliang 0:895bbd4e6398 179 def prev_region = regions.get(i-1)
cyliang 0:895bbd4e6398 180 execute("sed -i 's/\"lora.phy\": ${prev_region},/\"lora.phy\": ${curr_region},/' mbed_app.json")
cyliang 0:895bbd4e6398 181 echo "Building region: ${curr_region}"
cyliang 0:895bbd4e6398 182 execute("mbed compile -t GCC_ARM -m K64F")
cyliang 0:895bbd4e6398 183 }
cyliang 0:895bbd4e6398 184 }
cyliang 0:895bbd4e6398 185 }
cyliang 0:895bbd4e6398 186 }
cyliang 0:895bbd4e6398 187 }
cyliang 0:895bbd4e6398 188 }