├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ └── main.yml ├── .gitignore ├── CMakeLists.txt ├── CONTRIBUTING.md ├── DummySensor.h ├── Jenkinsfile ├── LICENSE ├── README.md ├── custom_targets.json ├── lora_radio_helper.h ├── main.cpp ├── mbed-os.lib ├── mbed_app.json ├── mbedtls_lora_config.h ├── resources └── official_armmbed_example_badge.png ├── trace_helper.cpp └── trace_helper.h /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: 'type: bug' 6 | assignees: '' 7 | 8 | --- 9 | 10 | 28 | 29 | ### Description of defect 30 | 31 | 35 | 36 | 37 | #### Target(s) affected by this defect ? 38 | 39 | 40 | #### Toolchain(s) (name and version) displaying this defect ? 41 | 42 | 43 | #### What version of Mbed-os are you using (tag or sha) ? 44 | 53 | 54 | 55 | #### What version(s) of tools are you using. List all that apply (E.g. mbed-cli) 56 | 57 | 58 | #### How is this defect reproduced ? 59 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Build example application 2 | 3 | on: 4 | pull_request: 5 | push: 6 | 7 | jobs: 8 | build-cli-v1: 9 | container: 10 | image: ghcr.io/armmbed/mbed-os-env:master-latest 11 | 12 | runs-on: ubuntu-latest 13 | 14 | strategy: 15 | matrix: 16 | target: ["K64F"] 17 | profile: [release, debug, develop] 18 | 19 | 20 | steps: 21 | - 22 | name: Checkout 23 | uses: actions/checkout@v2 24 | 25 | - 26 | name: build-example 27 | run: | 28 | set -e 29 | mbed deploy 30 | mbed compile -t GCC_ARM -m ${{ matrix.target }} --profile ${{ matrix.profile }} 31 | 32 | 33 | build-cli-v2: 34 | container: 35 | image: ghcr.io/armmbed/mbed-os-env:master-latest 36 | 37 | runs-on: ubuntu-latest 38 | 39 | strategy: 40 | matrix: 41 | target: ["K64F"] 42 | profile: [release, debug, develop] 43 | 44 | 45 | steps: 46 | - 47 | name: Checkout 48 | uses: actions/checkout@v2 49 | 50 | - 51 | name: build-example-application 52 | run: | 53 | set -e 54 | mbed-tools deploy 55 | mbed-tools compile -t GCC_ARM -m ${{ matrix.target }} --profile ${{ matrix.profile }} 56 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | 24 | # Executables 25 | *.exe 26 | *.out 27 | *.app 28 | 29 | # clion 30 | .idea/ 31 | cmake-build-*/ 32 | 33 | # exporters 34 | GettingStarted.html 35 | 36 | # mbed build system 37 | mbed-os/ 38 | mbed_settings.py 39 | mbed_config.h 40 | *.pyc 41 | BUILD/ 42 | cmake_build/ 43 | 44 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 ARM Limited. All rights reserved. 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR) 5 | 6 | set(MBED_PATH ${CMAKE_CURRENT_SOURCE_DIR}/mbed-os CACHE INTERNAL "") 7 | set(MBED_CONFIG_PATH ${CMAKE_CURRENT_BINARY_DIR} CACHE INTERNAL "") 8 | set(APP_TARGET mbed-os-example-lorawan) 9 | 10 | include(${MBED_PATH}/tools/cmake/app.cmake) 11 | 12 | project(${APP_TARGET}) 13 | 14 | add_subdirectory(${MBED_PATH}) 15 | 16 | add_executable(${APP_TARGET}) 17 | 18 | # Provide Mbed OS with the header file it needs to configure Mbed TLS for LoRa 19 | target_include_directories(${APP_TARGET} 20 | PUBLIC 21 | ${CMAKE_CURRENT_SOURCE_DIR} 22 | ) 23 | 24 | target_sources(${APP_TARGET} 25 | PRIVATE 26 | main.cpp 27 | trace_helper.cpp 28 | ) 29 | 30 | target_link_libraries(${APP_TARGET} 31 | PRIVATE 32 | mbed-os 33 | mbed-lorawan 34 | ) 35 | 36 | # Custom target 37 | add_library(mbed-k64f-sx126x INTERFACE) 38 | 39 | target_link_libraries(mbed-k64f-sx126x INTERFACE mbed-k64f) 40 | 41 | mbed_set_post_build(${APP_TARGET}) 42 | 43 | option(VERBOSE_BUILD "Have a verbose build process") 44 | if(VERBOSE_BUILD) 45 | set(CMAKE_VERBOSE_MAKEFILE ON) 46 | endif() 47 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Mbed OS 2 | 3 | Mbed OS is an open-source, device software platform for the Internet of Things. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor. 4 | 5 | To encourage productive collaboration, as well as robust, consistent and maintainable code, we have a set of guidelines for [contributing to Mbed OS](https://os.mbed.com/docs/mbed-os/latest/contributing/index.html). 6 | -------------------------------------------------------------------------------- /DummySensor.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef MBED_LORAWAN_DUMMYSENSOR_H_ 19 | #define MBED_LORAWAN_DUMMYSENSOR_H_ 20 | 21 | /* 22 | * A dummy sensor for Mbed LoRa Test Application 23 | */ 24 | class DS1820 { 25 | public: 26 | DS1820(uint32_t) 27 | { 28 | value = 1; 29 | }; 30 | bool begin() 31 | { 32 | return true; 33 | }; 34 | void startConversion() {}; 35 | int32_t read() 36 | { 37 | value += 2; 38 | return value; 39 | } 40 | 41 | private: 42 | int32_t value; 43 | }; 44 | 45 | 46 | 47 | #endif /* MBED_LORAWAN_DUMMYSENSOR_H_ */ 48 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | properties ([[$class: 'ParametersDefinitionProperty', parameterDefinitions: [ 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"'], 3 | [$class: 'BooleanParameterDefinition', name: 'regions_build_test', defaultValue: true, description: 'Test build all available regions'] 4 | ]]]) 5 | 6 | library 'mbed-lib' 7 | 8 | if (env.MBED_OS_REVISION == null) { 9 | echo 'First run in this branch, using default parameter values' 10 | env.MBED_OS_REVISION = '' 11 | } 12 | if (env.MBED_OS_REVISION == '') { 13 | echo 'Using mbed OS revision from mbed-os.lib' 14 | } else { 15 | echo "Using given mbed OS revision: ${env.MBED_OS_REVISION}" 16 | if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { 17 | echo "Revision is a Pull Request" 18 | } 19 | } 20 | 21 | // All available regions 22 | def regions = [ 23 | "\"0\"", "\"1\"", "\"2\"", "\"3\"", "\"4\"", "\"5\"", "\"6\"", "\"7\"", "\"8\"", 24 | "\"EU868\"", "\"AS923\"", "\"AU915\"", "\"CN470\"", "\"CN779\"", "\"EU433\"", 25 | "\"IN865\"", "\"KR920\"", "\"US915\"" 26 | ] 27 | 28 | // Supported targets 29 | def targets = [ 30 | "K64F", 31 | "MTS_MDOT_F411RE", 32 | "DISCO_L072CZ_LRWAN1" 33 | ] 34 | 35 | // Supported toolchains 36 | def toolchains = [ 37 | "ARM", 38 | "GCC_ARM" 39 | ] 40 | 41 | def stepsForParallel = [:] 42 | 43 | // Jenkins pipeline does not support map.each, we need to use oldschool for loop 44 | for (int i = 0; i < targets.size(); i++) { 45 | for(int j = 0; j < toolchains.size(); j++) { 46 | def target = targets.get(i) 47 | def toolchain = toolchains.get(j) 48 | 49 | // Skip unwanted combination 50 | if (target == "DISCO_L072CZ_LRWAN1" && toolchain == "GCC_ARM") { 51 | continue 52 | } 53 | 54 | def stepName = "${target} ${toolchain}" 55 | 56 | stepsForParallel[stepName] = buildStep(target, toolchain) 57 | } 58 | } 59 | 60 | def stepsForRegional = [:] 61 | 62 | if (params.regions_build_test == true) { 63 | stepsForRegional["REGION BUILDER"] = build_regions(regions) 64 | } 65 | 66 | timestamps { 67 | parallel stepsForParallel 68 | parallel stepsForRegional 69 | } 70 | 71 | def buildStep(target, toolchain) { 72 | return { 73 | stage ("${target}_${toolchain}") { 74 | node ("all-in-one-build-slave") { 75 | deleteDir() 76 | dir("mbed-os-example-lorawan") { 77 | checkout scm 78 | 79 | // A workaround for mbed-cli caching issues 80 | try { 81 | execute("mbed deploy --protocol ssh") 82 | } catch (err) { 83 | echo "mbed deploy failed - retrying after 10s" 84 | sleep(10) 85 | execute("mbed deploy --protocol ssh") 86 | } 87 | 88 | // Set mbed-os to revision received as parameter 89 | if (env.MBED_OS_REVISION != '') { 90 | dir("mbed-os") { 91 | if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { 92 | // Use mbed-os PR and switch to branch created 93 | execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_") 94 | execute("git checkout _PR_") 95 | } else { 96 | execute("git checkout ${env.MBED_OS_REVISION}") 97 | } 98 | } 99 | } 100 | 101 | // Adjust stack size and crystal values 102 | if ("${target}" == "DISCO_L072CZ_LRWAN1") { 103 | execute("sed -i 's/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x10)/#define RCC_HSICALIBRATION_DEFAULT ((uint32_t)0x13)/' \ 104 | mbed-os/targets/TARGET_STM/TARGET_STM32L0/device/stm32l0xx_hal_rcc.h") 105 | } 106 | 107 | execute("mbed compile --build out/${target}_${toolchain}/ -m ${target} -t ${toolchain} -c") 108 | } 109 | stash name: "${target}_${toolchain}", includes: '**/mbed-os-example-lorawan.bin' 110 | archive '**/mbed-os-example-lorawan.bin' 111 | step([$class: 'WsCleanup']) 112 | } 113 | } 114 | } 115 | } 116 | 117 | def build_regions(regions) { 118 | return { 119 | stage ("region_builder_K64F_GCC_ARM") { 120 | node ("all-in-one-build-slave") { 121 | deleteDir() 122 | dir("mbed-os-example-lorawan") { 123 | checkout scm 124 | 125 | // A workaround for mbed-cli caching issues 126 | try { 127 | execute("mbed deploy --protocol ssh") 128 | } catch (err) { 129 | echo "mbed deploy failed - retrying after 10s" 130 | sleep(10) 131 | execute("mbed deploy --protocol ssh") 132 | } 133 | 134 | if (env.MBED_OS_REVISION != '') { 135 | dir("mbed-os") { 136 | if (env.MBED_OS_REVISION.matches('pull/\\d+/head')) { 137 | execute("git fetch origin ${env.MBED_OS_REVISION}:_PR_") 138 | execute("git checkout _PR_") 139 | } else { 140 | execute("git checkout ${env.MBED_OS_REVISION}") 141 | } 142 | } 143 | } 144 | //Initial sed to string format for find & replacing 145 | execute("sed -i 's/\"lora.phy\": 0,/\"lora.phy\": \"0\",/' mbed_app.json") 146 | //lora.phy 0 build tested above already 147 | for (int i = 1; i < regions.size(); i++) { 148 | def curr_region = regions.get(i) 149 | def prev_region = regions.get(i-1) 150 | execute("sed -i 's/\"lora.phy\": ${prev_region},/\"lora.phy\": ${curr_region},/' mbed_app.json") 151 | echo "Building region: ${curr_region}" 152 | execute("mbed compile -t GCC_ARM -m K64F") 153 | } 154 | } 155 | } 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](./resources/official_armmbed_example_badge.png) 2 | # Example LoRaWAN application for Mbed-OS 3 | 4 | This is an example application based on `Mbed-OS` LoRaWAN protocol APIs. The Mbed-OS LoRaWAN stack implementation is compliant with LoRaWAN v1.0.2 specification. See this [link](https://os.mbed.com/blog/entry/Introducing-LoRaWAN-11-support/) for information on support for other LoRaWAN spec versions. This application can work with any Network Server if you have correct credentials for the said Network Server. 5 | 6 | ## Getting Started 7 | 8 | ### Supported Hardware 9 | [Mbed Enabled board with an Arduino form factor](https://os.mbed.com/platforms/?q=&Form+Factor=Arduino+Compatible) and one of the following: 10 | - [SX126X shield](https://os.mbed.com/components/SX126xMB2xAS/) 11 | - [SX1276 shield](https://os.mbed.com/components/SX1276MB1xAS/) 12 | - [SX1272 shield](https://os.mbed.com/components/SX1272MB2xAS/) 13 | 14 | OR 15 | 16 | Mbed Enabled LoRa MCU: 17 | - STM32WL : [NUCLEO_WL55JC](https://os.mbed.com/platforms/ST-Nucleo-WL55JC/) 18 | 19 | OR 20 | 21 | [Mbed Enabled LoRa Module](#module-support) 22 | 23 | ### Mbed OS build tools 24 | 25 | #### Mbed CLI 2 26 | Starting with version 6.5, Mbed OS uses Mbed CLI 2. It uses Ninja as a build system, and CMake to generate the build environment and manage the build process in a compiler-independent manner. If you are working with Mbed OS version prior to 6.5 then check the section [Mbed CLI 1](#mbed-cli-1). 27 | 1. [Install Mbed CLI 2](https://os.mbed.com/docs/mbed-os/latest/build-tools/install-or-upgrade.html). 28 | 1. From the command-line, import the example: `mbed-tools import mbed-os-example-lorawan` 29 | 1. Change the current directory to where the project was imported. 30 | 31 | #### Mbed CLI 1 32 | 1. [Install Mbed CLI 1](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html). 33 | 1. From the command-line, import the example: `mbed import mbed-os-example-lorawan` 34 | 1. Change the current directory to where the project was imported. 35 | 36 | ### Configuration and radio selection 37 | 38 | For LoRa modules supported by Mbed-OS, the pin set is already provided in the `target-overrides` field of the [`mbed_app.json`](./mbed_app.json) file. For more information on supported modules, please refer to the [module support](#module-support) section. 39 | 40 | ### Add network credentials 41 | 42 | Open the file `mbed_app.json` in the root directory of your application. This file contains all the user specific configurations your application and the Mbed OS LoRaWAN stack need. Network credentials are typically provided by LoRa network provider. 43 | 44 | #### For OTAA 45 | 46 | Please add `Device EUI`, `Application EUI` and `Application Key` needed for Over-the-air-activation(OTAA). For example: 47 | 48 | ```json 49 | "lora.device-eui": "{ YOUR_DEVICE_EUI }", 50 | "lora.application-eui": "{ YOUR_APPLICATION_EUI }", 51 | "lora.application-key": "{ YOUR_APPLICATION_KEY }" 52 | ``` 53 | 54 | #### For ABP 55 | 56 | For Activation-By-Personalization (ABP) connection method, modify the `mbed_app.json` to enable ABP. You can do it by simply turning off OTAA. For example: 57 | 58 | ```json 59 | "lora.over-the-air-activation": false, 60 | ``` 61 | 62 | In addition to that, you need to provide `Application Session Key`, `Network Session Key` and `Device Address`. For example: 63 | 64 | ```json 65 | "lora.appskey": "{ YOUR_APPLICATION_SESSION_KEY }", 66 | "lora.nwkskey": "{ YOUR_NETWORK_SESSION_KEY }", 67 | "lora.device-address": " YOUR_DEVICE_ADDRESS_IN_HEX " 68 | ``` 69 | 70 | ## Configuring the application 71 | 72 | The Mbed OS LoRaWAN stack provides a lot of configuration controls to the application through the Mbed OS configuration system. The previous section discusses some of these controls. This section highlights some useful features that you can configure. 73 | 74 | ### Selecting a PHY 75 | 76 | The LoRaWAN protocol is subject to various country specific regulations concerning radio emissions. That's why the Mbed OS LoRaWAN stack provides a `LoRaPHY` class that you can use to implement any region specific PHY layer. Currently, the Mbed OS LoRaWAN stack provides 10 different country specific implementations of `LoRaPHY` class. Selection of a specific PHY layer happens at compile time. By default, the Mbed OS LoRaWAN stack uses `EU 868 MHz` PHY. An example of selecting a PHY can be: 77 | 78 | ```josn 79 | "phy": { 80 | "help": "LoRa PHY region. 0 = EU868 (default), 1 = AS923, 2 = AU915, 3 = CN470, 4 = CN779, 5 = EU433, 6 = IN865, 7 = KR920, 8 = US915, 9 = US915_HYBRID", 81 | "value": "0" 82 | }, 83 | ``` 84 | 85 | ### Duty cycling 86 | 87 | LoRaWAN v1.0.2 specifcation is exclusively duty cycle based. This application comes with duty cycle enabled by default. In other words, the Mbed OS LoRaWAN stack enforces duty cycle. The stack keeps track of transmissions on the channels in use and schedules transmissions on channels that become available in the shortest time possible. We recommend you keep duty cycle on for compliance with your country specific regulations. 88 | 89 | However, you can define a timer value in the application, which you can use to perform a periodic uplink when the duty cycle is turned off. Such a setup should be used only for testing or with a large enough timer value. For example: 90 | 91 | ```json 92 | "target_overrides": { 93 | "*": { 94 | "lora.duty-cycle-on": false 95 | } 96 | } 97 | ``` 98 | 99 | ## Module support 100 | 101 | Here is a nonexhaustive list of boards and modules that we have tested with the Mbed OS LoRaWAN stack: 102 | 103 | - MultiTech mDot (SX1272) 104 | - MultiTech xDot (SX1272) 105 | - LTEK_FF1705 (SX1272) 106 | - Advantech Wise 1510 (SX1276) 107 | - ST B-L072Z-LRWAN1 LoRa®Discovery kit with Murata CMWX1ZZABZ-091 module (SX1276) 108 | - ST NUCLEO-WL55JC with sub-GHz SoC (STM32WL) 109 | 110 | Here is a list of boards and modules that have been tested by the community: 111 | 112 | - IMST iM880B (SX1272) 113 | - Embedded Planet Agora (SX1276) 114 | 115 | ## Building and running 116 | 117 | 1. Connect a USB cable between the USB port on the target and the host computer. 118 | 1. Run the following command to build the example project and program the microcontroller flash memory: 119 | 120 | * Mbed CLI 2 121 | 122 | ```bash 123 | $ mbed-tools compile -m -t --flash --sterm --baudrate 115200 124 | ``` 125 | 126 | * Mbed CLI 1 127 | 128 | ```bash 129 | $ mbed compile -m -t --flash --sterm --baudrate 115200 130 | ``` 131 | 132 | Your PC may take a few minutes to compile your code. 133 | 134 | The binary is located at: 135 | 136 | * **Mbed CLI 2** - 137 | `./cmake_build//develop//mbed-os-example-lorawan.bin` 138 | 139 | * **Mbed CLI 1** - `./BUILD///mbed-os-example-lorawan.bin`. 140 | 141 | You can manually copy the binary to the target, which gets mounted on the host 142 | computer through USB, rather than using the `--flash` option. 143 | 144 | You can also open a serial terminal separately, rather than using the `--sterm --baudrate 115200` 145 | option, with the following command: 146 | 147 | * Mbed CLI 2 148 | ```bash 149 | $ mbed-tools sterm --baudrate 115200 150 | ``` 151 | 152 | * Mbed CLI 1 153 | ```bash 154 | $ mbed sterm --baudrate 115200 155 | ``` 156 | 157 | ## Expected output 158 | 159 | The serial terminal shows an output similar to: 160 | 161 | ``` 162 | Mbed LoRaWANStack initialized 163 | 164 | CONFIRMED message retries : 3 165 | 166 | Adaptive data rate (ADR) - Enabled 167 | 168 | Connection - In Progress ... 169 | 170 | Connection - Successful 171 | 172 | Dummy Sensor Value = 2.1 173 | 174 | 25 bytes scheduled for transmission 175 | 176 | Message Sent to Network Server 177 | 178 | ``` 179 | 180 | ## [Optional] Adding trace library 181 | To enable Mbed trace, add to your `mbed_app.json` the following fields: 182 | 183 | ```json 184 | "target_overrides": { 185 | "*": { 186 | "mbed-trace.enable": true 187 | } 188 | } 189 | ``` 190 | The trace is disabled by default to save RAM and reduce main stack usage (see chapter Memory optimization). 191 | 192 | **Please note that some targets with small RAM size (e.g. DISCO_L072CZ_LRWAN1 and MTB_MURATA_ABZ) mbed traces cannot be enabled without increasing the default** `"main_stack_size": 1024`**.** 193 | 194 | ## [Optional] Memory optimization 195 | 196 | Using `Arm CC compiler` instead of `GCC` reduces `3K` of RAM. Currently the application takes about `15K` of static RAM with Arm CC, which spills over for the platforms with `20K` of RAM because you need to leave space, about `5K`, for dynamic allocation. So if you reduce the application stack size, you can barely fit into the 20K platforms. 197 | 198 | For example, add the following into `config` section in your `mbed_app.json`: 199 | 200 | ``` 201 | "main_stack_size": { 202 | "value": 2048 203 | } 204 | ``` 205 | 206 | Essentially you can make the whole application with Mbed LoRaWAN stack in 6K if you drop the RTOS from Mbed OS and use a smaller standard C/C++ library like new-lib-nano. Please find instructions [here](https://os.mbed.com/blog/entry/Reducing-memory-usage-with-a-custom-prin/). 207 | 208 | 209 | For more information, please follow this [blog post](https://os.mbed.com/blog/entry/Reducing-memory-usage-by-tuning-RTOS-con/). 210 | 211 | 212 | ### License and contributions 213 | 214 | The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see [contributing.md](CONTRIBUTING.md) for more info. 215 | 216 | This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide. 217 | 218 | -------------------------------------------------------------------------------- /custom_targets.json: -------------------------------------------------------------------------------- 1 | { 2 | "K64F_SX126X": { 3 | "inherits": ["K64F"] 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /lora_radio_helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef APP_LORA_RADIO_HELPER_H_ 19 | #define APP_LORA_RADIO_HELPER_H_ 20 | 21 | #include "lorawan/LoRaRadio.h" 22 | 23 | #if COMPONENT_SX1272 24 | #include "SX1272_LoRaRadio.h" 25 | SX1272_LoRaRadio radio(MBED_CONF_SX1272_LORA_DRIVER_SPI_MOSI, 26 | MBED_CONF_SX1272_LORA_DRIVER_SPI_MISO, 27 | MBED_CONF_SX1272_LORA_DRIVER_SPI_SCLK, 28 | MBED_CONF_SX1272_LORA_DRIVER_SPI_CS, 29 | MBED_CONF_SX1272_LORA_DRIVER_RESET, 30 | MBED_CONF_SX1272_LORA_DRIVER_DIO0, 31 | MBED_CONF_SX1272_LORA_DRIVER_DIO1, 32 | MBED_CONF_SX1272_LORA_DRIVER_DIO2, 33 | MBED_CONF_SX1272_LORA_DRIVER_DIO3, 34 | MBED_CONF_SX1272_LORA_DRIVER_DIO4, 35 | MBED_CONF_SX1272_LORA_DRIVER_DIO5, 36 | MBED_CONF_SX1272_LORA_DRIVER_RF_SWITCH_CTL1, 37 | MBED_CONF_SX1272_LORA_DRIVER_RF_SWITCH_CTL2, 38 | MBED_CONF_SX1272_LORA_DRIVER_TXCTL, 39 | MBED_CONF_SX1272_LORA_DRIVER_RXCTL, 40 | MBED_CONF_SX1272_LORA_DRIVER_ANT_SWITCH, 41 | MBED_CONF_SX1272_LORA_DRIVER_PWR_AMP_CTL, 42 | MBED_CONF_SX1272_LORA_DRIVER_TCXO); 43 | 44 | #elif COMPONENT_SX1276 45 | #include "SX1276_LoRaRadio.h" 46 | SX1276_LoRaRadio radio(MBED_CONF_SX1276_LORA_DRIVER_SPI_MOSI, 47 | MBED_CONF_SX1276_LORA_DRIVER_SPI_MISO, 48 | MBED_CONF_SX1276_LORA_DRIVER_SPI_SCLK, 49 | MBED_CONF_SX1276_LORA_DRIVER_SPI_CS, 50 | MBED_CONF_SX1276_LORA_DRIVER_RESET, 51 | MBED_CONF_SX1276_LORA_DRIVER_DIO0, 52 | MBED_CONF_SX1276_LORA_DRIVER_DIO1, 53 | MBED_CONF_SX1276_LORA_DRIVER_DIO2, 54 | MBED_CONF_SX1276_LORA_DRIVER_DIO3, 55 | MBED_CONF_SX1276_LORA_DRIVER_DIO4, 56 | MBED_CONF_SX1276_LORA_DRIVER_DIO5, 57 | MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL1, 58 | MBED_CONF_SX1276_LORA_DRIVER_RF_SWITCH_CTL2, 59 | MBED_CONF_SX1276_LORA_DRIVER_TXCTL, 60 | MBED_CONF_SX1276_LORA_DRIVER_RXCTL, 61 | MBED_CONF_SX1276_LORA_DRIVER_ANT_SWITCH, 62 | MBED_CONF_SX1276_LORA_DRIVER_PWR_AMP_CTL, 63 | MBED_CONF_SX1276_LORA_DRIVER_TCXO); 64 | 65 | #elif COMPONENT_SX126X 66 | #include "SX126X_LoRaRadio.h" 67 | SX126X_LoRaRadio radio(MBED_CONF_SX126X_LORA_DRIVER_SPI_MOSI, 68 | MBED_CONF_SX126X_LORA_DRIVER_SPI_MISO, 69 | MBED_CONF_SX126X_LORA_DRIVER_SPI_SCLK, 70 | MBED_CONF_SX126X_LORA_DRIVER_SPI_CS, 71 | MBED_CONF_SX126X_LORA_DRIVER_RESET, 72 | MBED_CONF_SX126X_LORA_DRIVER_DIO1, 73 | MBED_CONF_SX126X_LORA_DRIVER_BUSY, 74 | MBED_CONF_SX126X_LORA_DRIVER_FREQ_SELECT, 75 | MBED_CONF_SX126X_LORA_DRIVER_DEVICE_SELECT, 76 | MBED_CONF_SX126X_LORA_DRIVER_CRYSTAL_SELECT, 77 | MBED_CONF_SX126X_LORA_DRIVER_ANT_SWITCH); 78 | 79 | #elif (TARGET_STM32WL) 80 | #include "STM32WL_LoRaRadio.h" 81 | STM32WL_LoRaRadio radio; 82 | #else 83 | #error "Unknown LoRa radio specified (SX126X, SX1272, SX1276, STM32WL are valid)" 84 | #endif 85 | 86 | #endif /* APP_LORA_RADIO_HELPER_H_ */ 87 | -------------------------------------------------------------------------------- /main.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | #include 18 | 19 | #include "lorawan/LoRaWANInterface.h" 20 | #include "lorawan/system/lorawan_data_structures.h" 21 | #include "events/EventQueue.h" 22 | 23 | // Application helpers 24 | #include "DummySensor.h" 25 | #include "trace_helper.h" 26 | #include "lora_radio_helper.h" 27 | 28 | using namespace events; 29 | 30 | // Max payload size can be LORAMAC_PHY_MAXPAYLOAD. 31 | // This example only communicates with much shorter messages (<30 bytes). 32 | // If longer messages are used, these buffers must be changed accordingly. 33 | uint8_t tx_buffer[30]; 34 | uint8_t rx_buffer[30]; 35 | 36 | /* 37 | * Sets up an application dependent transmission timer in ms. Used only when Duty Cycling is off for testing 38 | */ 39 | #define TX_TIMER 10000 40 | 41 | /** 42 | * Maximum number of events for the event queue. 43 | * 10 is the safe number for the stack events, however, if application 44 | * also uses the queue for whatever purposes, this number should be increased. 45 | */ 46 | #define MAX_NUMBER_OF_EVENTS 10 47 | 48 | /** 49 | * Maximum number of retries for CONFIRMED messages before giving up 50 | */ 51 | #define CONFIRMED_MSG_RETRY_COUNTER 3 52 | 53 | /** 54 | * Dummy pin for dummy sensor 55 | */ 56 | #define PC_9 0 57 | 58 | /** 59 | * Dummy sensor class object 60 | */ 61 | DS1820 ds1820(PC_9); 62 | 63 | /** 64 | * This event queue is the global event queue for both the 65 | * application and stack. To conserve memory, the stack is designed to run 66 | * in the same thread as the application and the application is responsible for 67 | * providing an event queue to the stack that will be used for ISR deferment as 68 | * well as application information event queuing. 69 | */ 70 | static EventQueue ev_queue(MAX_NUMBER_OF_EVENTS *EVENTS_EVENT_SIZE); 71 | 72 | /** 73 | * Event handler. 74 | * 75 | * This will be passed to the LoRaWAN stack to queue events for the 76 | * application which in turn drive the application. 77 | */ 78 | static void lora_event_handler(lorawan_event_t event); 79 | 80 | /** 81 | * Constructing Mbed LoRaWANInterface and passing it the radio object from lora_radio_helper. 82 | */ 83 | static LoRaWANInterface lorawan(radio); 84 | 85 | /** 86 | * Application specific callbacks 87 | */ 88 | static lorawan_app_callbacks_t callbacks; 89 | 90 | /** 91 | * Entry point for application 92 | */ 93 | int main(void) 94 | { 95 | // setup tracing 96 | setup_trace(); 97 | 98 | // stores the status of a call to LoRaWAN protocol 99 | lorawan_status_t retcode; 100 | 101 | // Initialize LoRaWAN stack 102 | if (lorawan.initialize(&ev_queue) != LORAWAN_STATUS_OK) { 103 | printf("\r\n LoRa initialization failed! \r\n"); 104 | return -1; 105 | } 106 | 107 | printf("\r\n Mbed LoRaWANStack initialized \r\n"); 108 | 109 | // prepare application callbacks 110 | callbacks.events = mbed::callback(lora_event_handler); 111 | lorawan.add_app_callbacks(&callbacks); 112 | 113 | // Set number of retries in case of CONFIRMED messages 114 | if (lorawan.set_confirmed_msg_retries(CONFIRMED_MSG_RETRY_COUNTER) 115 | != LORAWAN_STATUS_OK) { 116 | printf("\r\n set_confirmed_msg_retries failed! \r\n\r\n"); 117 | return -1; 118 | } 119 | 120 | printf("\r\n CONFIRMED message retries : %d \r\n", 121 | CONFIRMED_MSG_RETRY_COUNTER); 122 | 123 | // Enable adaptive data rate 124 | if (lorawan.enable_adaptive_datarate() != LORAWAN_STATUS_OK) { 125 | printf("\r\n enable_adaptive_datarate failed! \r\n"); 126 | return -1; 127 | } 128 | 129 | printf("\r\n Adaptive data rate (ADR) - Enabled \r\n"); 130 | 131 | retcode = lorawan.connect(); 132 | 133 | if (retcode == LORAWAN_STATUS_OK || 134 | retcode == LORAWAN_STATUS_CONNECT_IN_PROGRESS) { 135 | } else { 136 | printf("\r\n Connection error, code = %d \r\n", retcode); 137 | return -1; 138 | } 139 | 140 | printf("\r\n Connection - In Progress ...\r\n"); 141 | 142 | // make your event queue dispatching events forever 143 | ev_queue.dispatch_forever(); 144 | 145 | return 0; 146 | } 147 | 148 | /** 149 | * Sends a message to the Network Server 150 | */ 151 | static void send_message() 152 | { 153 | uint16_t packet_len; 154 | int16_t retcode; 155 | int32_t sensor_value; 156 | 157 | if (ds1820.begin()) { 158 | ds1820.startConversion(); 159 | sensor_value = ds1820.read(); 160 | printf("\r\n Dummy Sensor Value = %d \r\n", sensor_value); 161 | ds1820.startConversion(); 162 | } else { 163 | printf("\r\n No sensor found \r\n"); 164 | return; 165 | } 166 | 167 | packet_len = sprintf((char *) tx_buffer, "Dummy Sensor Value is %d", 168 | sensor_value); 169 | 170 | retcode = lorawan.send(MBED_CONF_LORA_APP_PORT, tx_buffer, packet_len, 171 | MSG_UNCONFIRMED_FLAG); 172 | 173 | if (retcode < 0) { 174 | retcode == LORAWAN_STATUS_WOULD_BLOCK ? printf("send - WOULD BLOCK\r\n") 175 | : printf("\r\n send() - Error code %d \r\n", retcode); 176 | 177 | if (retcode == LORAWAN_STATUS_WOULD_BLOCK) { 178 | //retry in 3 seconds 179 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { 180 | ev_queue.call_in(3000, send_message); 181 | } 182 | } 183 | return; 184 | } 185 | 186 | printf("\r\n %d bytes scheduled for transmission \r\n", retcode); 187 | memset(tx_buffer, 0, sizeof(tx_buffer)); 188 | } 189 | 190 | /** 191 | * Receive a message from the Network Server 192 | */ 193 | static void receive_message() 194 | { 195 | uint8_t port; 196 | int flags; 197 | int16_t retcode = lorawan.receive(rx_buffer, sizeof(rx_buffer), port, flags); 198 | 199 | if (retcode < 0) { 200 | printf("\r\n receive() - Error code %d \r\n", retcode); 201 | return; 202 | } 203 | 204 | printf(" RX Data on port %u (%d bytes): ", port, retcode); 205 | for (uint8_t i = 0; i < retcode; i++) { 206 | printf("%02x ", rx_buffer[i]); 207 | } 208 | printf("\r\n"); 209 | 210 | memset(rx_buffer, 0, sizeof(rx_buffer)); 211 | } 212 | 213 | /** 214 | * Event handler 215 | */ 216 | static void lora_event_handler(lorawan_event_t event) 217 | { 218 | switch (event) { 219 | case CONNECTED: 220 | printf("\r\n Connection - Successful \r\n"); 221 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { 222 | send_message(); 223 | } else { 224 | ev_queue.call_every(TX_TIMER, send_message); 225 | } 226 | 227 | break; 228 | case DISCONNECTED: 229 | ev_queue.break_dispatch(); 230 | printf("\r\n Disconnected Successfully \r\n"); 231 | break; 232 | case TX_DONE: 233 | printf("\r\n Message Sent to Network Server \r\n"); 234 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { 235 | send_message(); 236 | } 237 | break; 238 | case TX_TIMEOUT: 239 | case TX_ERROR: 240 | case TX_CRYPTO_ERROR: 241 | case TX_SCHEDULING_ERROR: 242 | printf("\r\n Transmission Error - EventCode = %d \r\n", event); 243 | // try again 244 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { 245 | send_message(); 246 | } 247 | break; 248 | case RX_DONE: 249 | printf("\r\n Received message from Network Server \r\n"); 250 | receive_message(); 251 | break; 252 | case RX_TIMEOUT: 253 | case RX_ERROR: 254 | printf("\r\n Error in reception - Code = %d \r\n", event); 255 | break; 256 | case JOIN_FAILURE: 257 | printf("\r\n OTAA Failed - Check Keys \r\n"); 258 | break; 259 | case UPLINK_REQUIRED: 260 | printf("\r\n Uplink required by NS \r\n"); 261 | if (MBED_CONF_LORA_DUTY_CYCLE_ON) { 262 | send_message(); 263 | } 264 | break; 265 | default: 266 | MBED_ASSERT("Unknown Event"); 267 | } 268 | } 269 | 270 | // EOF 271 | -------------------------------------------------------------------------------- /mbed-os.lib: -------------------------------------------------------------------------------- 1 | https://github.com/ARMmbed/mbed-os/ 2 | -------------------------------------------------------------------------------- /mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "main_stack_size": { "value": 4096 } 4 | }, 5 | "target_overrides": { 6 | "*": { 7 | "platform.stdio-convert-newlines": true, 8 | "platform.stdio-baud-rate": 115200, 9 | "platform.default-serial-baud-rate": 115200, 10 | "mbed-trace.enable": false, 11 | "mbed-trace.max-level": "TRACE_LEVEL_DEBUG", 12 | "lora.over-the-air-activation": true, 13 | "lora.duty-cycle-on": true, 14 | "lora.phy": "EU868", 15 | "lora.device-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }", 16 | "lora.application-eui": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }", 17 | "lora.application-key": "{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }" 18 | }, 19 | 20 | "K64F": { 21 | "target.components_add": ["SX1276"], 22 | "sx1276-lora-driver.spi-mosi": "ARDUINO_UNO_D11", 23 | "sx1276-lora-driver.spi-miso": "ARDUINO_UNO_D12", 24 | "sx1276-lora-driver.spi-sclk": "ARDUINO_UNO_D13", 25 | "sx1276-lora-driver.spi-cs": "ARDUINO_UNO_D10", 26 | "sx1276-lora-driver.reset": "ARDUINO_UNO_A0", 27 | "sx1276-lora-driver.dio0": "ARDUINO_UNO_D2", 28 | "sx1276-lora-driver.dio1": "ARDUINO_UNO_D3", 29 | "sx1276-lora-driver.dio2": "ARDUINO_UNO_D4", 30 | "sx1276-lora-driver.dio3": "ARDUINO_UNO_D5", 31 | "sx1276-lora-driver.dio4": "ARDUINO_UNO_D8", 32 | "sx1276-lora-driver.dio5": "ARDUINO_UNO_D9", 33 | "sx1276-lora-driver.ant-switch": "ARDUINO_UNO_A4" 34 | }, 35 | 36 | "K64F_SX126X": { 37 | "target.components_add": ["SX126X"], 38 | "SX126X-lora-driver.spi-mosi": "ARDUINO_UNO_D11", 39 | "SX126X-lora-driver.spi-miso": "ARDUINO_UNO_D12", 40 | "SX126X-lora-driver.spi-sclk": "ARDUINO_UNO_D13", 41 | "SX126X-lora-driver.spi-cs": "ARDUINO_UNO_D7", 42 | "SX126X-lora-driver.reset": "ARDUINO_UNO_A0", 43 | "SX126X-lora-driver.dio1": "ARDUINO_UNO_D5", 44 | "SX126X-lora-driver.busy": "ARDUINO_UNO_D3", 45 | "SX126X-lora-driver.freq-select": "ARDUINO_UNO_A1", 46 | "SX126X-lora-driver.device-select": "ARDUINO_UNO_A2", 47 | "SX126X-lora-driver.crystal-select": "ARDUINO_UNO_A3", 48 | "SX126X-lora-driver.ant-switch": "ARDUINO_UNO_D8" 49 | }, 50 | 51 | "DISCO_L072CZ_LRWAN1": { 52 | "main_stack_size": 1024 53 | }, 54 | 55 | "NUCLEO_WL55JC": { 56 | "stm32wl-lora-driver.debug_rx": "LED1", 57 | "stm32wl-lora-driver.debug_tx": "LED2" 58 | }, 59 | 60 | "MTB_MURATA_ABZ": { 61 | "main_stack_size": 1024, 62 | "target.components_add": ["SX1276"], 63 | "sx1276-lora-driver.spi-mosi": "PA_7", 64 | "sx1276-lora-driver.spi-miso": "PA_6", 65 | "sx1276-lora-driver.spi-sclk": "PB_3", 66 | "sx1276-lora-driver.spi-cs": "PA_15", 67 | "sx1276-lora-driver.reset": "PC_0", 68 | "sx1276-lora-driver.dio0": "PB_4", 69 | "sx1276-lora-driver.dio1": "PB_1", 70 | "sx1276-lora-driver.dio2": "PB_0", 71 | "sx1276-lora-driver.dio3": "PC_13", 72 | "sx1276-lora-driver.txctl": "PC_2", 73 | "sx1276-lora-driver.rxctl": "PA_1", 74 | "sx1276-lora-driver.pwr-amp-ctl": "PC_1", 75 | "sx1276-lora-driver.tcxo": "PA_12" 76 | }, 77 | 78 | "XDOT_L151CC": { 79 | "target.components_add": ["SX1272"], 80 | "sx1272-lora-driver.spi-mosi": "LORA_MOSI", 81 | "sx1272-lora-driver.spi-miso": "LORA_MISO", 82 | "sx1272-lora-driver.spi-sclk": "LORA_SCK", 83 | "sx1272-lora-driver.spi-cs": "LORA_NSS", 84 | "sx1272-lora-driver.reset": "LORA_RESET", 85 | "sx1272-lora-driver.dio0": "LORA_DIO0", 86 | "sx1272-lora-driver.dio1": "LORA_DIO1", 87 | "sx1272-lora-driver.dio2": "LORA_DIO2", 88 | "sx1272-lora-driver.dio3": "LORA_DIO3", 89 | "sx1272-lora-driver.dio4": "LORA_DIO4" 90 | }, 91 | 92 | "MTB_MTS_XDOT": { 93 | "target.components_add": ["SX1272"], 94 | "sx1272-lora-driver.spi-mosi": "LORA_MOSI", 95 | "sx1272-lora-driver.spi-miso": "LORA_MISO", 96 | "sx1272-lora-driver.spi-sclk": "LORA_SCK", 97 | "sx1272-lora-driver.spi-cs": "LORA_NSS", 98 | "sx1272-lora-driver.reset": "LORA_RESET", 99 | "sx1272-lora-driver.dio0": "LORA_DIO0", 100 | "sx1272-lora-driver.dio1": "LORA_DIO1", 101 | "sx1272-lora-driver.dio2": "LORA_DIO2", 102 | "sx1272-lora-driver.dio3": "LORA_DIO3", 103 | "sx1272-lora-driver.dio4": "LORA_DIO4" 104 | }, 105 | 106 | "FF1705_L151CC": { 107 | "target.components_add": ["SX1272"], 108 | "sx1272-lora-driver.spi-mosi": "LORA_MOSI", 109 | "sx1272-lora-driver.spi-miso": "LORA_MISO", 110 | "sx1272-lora-driver.spi-sclk": "LORA_SCK", 111 | "sx1272-lora-driver.spi-cs": "LORA_NSS", 112 | "sx1272-lora-driver.reset": "LORA_RESET", 113 | "sx1272-lora-driver.dio0": "LORA_DIO0", 114 | "sx1272-lora-driver.dio1": "LORA_DIO1", 115 | "sx1272-lora-driver.dio2": "LORA_DIO2", 116 | "sx1272-lora-driver.dio3": "LORA_DIO3", 117 | "sx1272-lora-driver.dio4": "LORA_DIO4" 118 | }, 119 | 120 | "MTS_MDOT_F411RE": { 121 | "target.components_add": ["SX1272"], 122 | "sx1272-lora-driver.spi-mosi": "LORA_MOSI", 123 | "sx1272-lora-driver.spi-miso": "LORA_MISO", 124 | "sx1272-lora-driver.spi-sclk": "LORA_SCK", 125 | "sx1272-lora-driver.spi-cs": "LORA_NSS", 126 | "sx1272-lora-driver.reset": "LORA_RESET", 127 | "sx1272-lora-driver.dio0": "LORA_DIO0", 128 | "sx1272-lora-driver.dio1": "LORA_DIO1", 129 | "sx1272-lora-driver.dio2": "LORA_DIO2", 130 | "sx1272-lora-driver.dio3": "LORA_DIO3", 131 | "sx1272-lora-driver.dio4": "LORA_DIO4", 132 | "sx1272-lora-driver.dio5": "LORA_DIO5", 133 | "sx1272-lora-driver.txctl": "LORA_TXCTL", 134 | "sx1272-lora-driver.rxctl": "LORA_RXCTL" 135 | }, 136 | 137 | "MTB_ADV_WISE_1510": { 138 | "target.components_add": ["SX1276"], 139 | "sx1276-lora-driver.spi-mosi": "SPI_RF_MOSI", 140 | "sx1276-lora-driver.spi-miso": "SPI_RF_MISO", 141 | "sx1276-lora-driver.spi-sclk": "SPI_RF_SCK", 142 | "sx1276-lora-driver.spi-cs": "SPI_RF_CS", 143 | "sx1276-lora-driver.reset": "SPI_RF_RESET", 144 | "sx1276-lora-driver.dio0": "DIO0", 145 | "sx1276-lora-driver.dio1": "DIO1", 146 | "sx1276-lora-driver.dio2": "DIO2", 147 | "sx1276-lora-driver.dio3": "DIO3", 148 | "sx1276-lora-driver.dio4": "DIO4", 149 | "sx1276-lora-driver.dio5": "DIO5", 150 | "sx1276-lora-driver.ant-switch": "ANT_SWITCH" 151 | }, 152 | 153 | "MTB_RAK811": { 154 | "target.components_add": ["SX1276"], 155 | "sx1276-lora-driver.spi-mosi": "SPI_RF_MOSI", 156 | "sx1276-lora-driver.spi-miso": "SPI_RF_MISO", 157 | "sx1276-lora-driver.spi-sclk": "SPI_RF_SCK", 158 | "sx1276-lora-driver.spi-cs": "SPI_RF_CS", 159 | "sx1276-lora-driver.reset": "SPI_RF_RESET", 160 | "sx1276-lora-driver.dio0": "DIO0", 161 | "sx1276-lora-driver.dio1": "DIO1", 162 | "sx1276-lora-driver.dio2": "DIO2", 163 | "sx1276-lora-driver.dio3": "DIO3", 164 | "sx1276-lora-driver.dio4": "DIO4", 165 | "sx1276-lora-driver.txctl": "ANT_CTX_PA", 166 | "sx1276-lora-driver.rxctl": "ANT_CRX_RX", 167 | "sx1276-lora-driver.tcxo": "RF_TCXO_EN" 168 | }, 169 | 170 | "IM880B": { 171 | "main_stack_size": 1024, 172 | "target.components_add": ["SX1272"], 173 | "sx1272-lora-driver.spi-mosi": "SPI_RF_MOSI", 174 | "sx1272-lora-driver.spi-miso": "SPI_RF_MISO", 175 | "sx1272-lora-driver.spi-sclk": "SPI_RF_SCK", 176 | "sx1272-lora-driver.spi-cs": "SPI_RF_NSS", 177 | "sx1272-lora-driver.reset": "SPI_RF_RESET", 178 | "sx1272-lora-driver.dio0": "DIO0", 179 | "sx1272-lora-driver.dio1": "DIO1", 180 | "sx1272-lora-driver.dio2": "DIO2", 181 | "sx1272-lora-driver.dio3": "DIO3", 182 | "sx1272-lora-driver.dio4": "DIO4", 183 | "sx1272-lora-driver.txctl": "ANT_CTX_PA", 184 | "sx1272-lora-driver.rxctl": "ANT_CRX_RX" 185 | }, 186 | 187 | "EP_AGORA": { 188 | "target.macros_add": ["NRFX_GPIOTE_CONFIG_NUM_OF_LOW_POWER_EVENTS=4"], 189 | "target.components_add": ["SX1276"], 190 | "sx1276-lora-driver.spi-mosi": "PIN_NAME_LORA_MOSI", 191 | "sx1276-lora-driver.spi-miso": "PIN_NAME_LORA_MISO", 192 | "sx1276-lora-driver.spi-sclk": "PIN_NAME_LORA_SCLK", 193 | "sx1276-lora-driver.spi-cs": "PIN_NAME_LORA_SSN", 194 | "sx1276-lora-driver.reset": "PIN_NAME_LORA_RESETN", 195 | "sx1276-lora-driver.dio0": "PIN_NAME_LORA_DIO0", 196 | "sx1276-lora-driver.dio1": "PIN_NAME_LORA_DIO1", 197 | "sx1276-lora-driver.dio2": "PIN_NAME_LORA_DIO2", 198 | "sx1276-lora-driver.dio3": "PIN_NAME_LORA_DIO3" 199 | }, 200 | 201 | "NUCLEO_L073RZ": { 202 | "main_stack_size": 2048, 203 | "target.components_add": ["SX126X"], 204 | "SX126X-lora-driver.spi-mosi": "ARDUINO_UNO_D11", 205 | "SX126X-lora-driver.spi-miso": "ARDUINO_UNO_D12", 206 | "SX126X-lora-driver.spi-sclk": "ARDUINO_UNO_D13", 207 | "SX126X-lora-driver.spi-cs": "ARDUINO_UNO_D7", 208 | "SX126X-lora-driver.reset": "ARDUINO_UNO_A0", 209 | "SX126X-lora-driver.dio1": "ARDUINO_UNO_D5", 210 | "SX126X-lora-driver.busy": "ARDUINO_UNO_D3", 211 | "SX126X-lora-driver.freq-select": "ARDUINO_UNO_A1", 212 | "SX126X-lora-driver.device-select": "ARDUINO_UNO_A2", 213 | "SX126X-lora-driver.crystal-select": "ARDUINO_UNO_A3", 214 | "SX126X-lora-driver.ant-switch": "ARDUINO_UNO_D8" 215 | } 216 | }, 217 | "macros": ["MBEDTLS_USER_CONFIG_FILE=\"mbedtls_lora_config.h\""] 218 | } 219 | 220 | -------------------------------------------------------------------------------- /mbedtls_lora_config.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef MBEDTLS_LORA_CONFIG_H 19 | #define MBEDTLS_LORA_CONFIG_H 20 | 21 | /* 22 | * Configure mbedtls for LoRa stack. 23 | * 24 | * These settings are just a customization of the main mbedtls config 25 | * mbed-os/features/mbedtls/inc/mbedtls/config.h 26 | */ 27 | 28 | // Ensure LoRa required ciphers are enabled 29 | #define MBEDTLS_CIPHER_C 30 | #define MBEDTLS_AES_C 31 | #define MBEDTLS_CMAC_C 32 | 33 | // Reduce ROM usage by optimizing some mbedtls features. 34 | // These are only reference configurations for this LoRa example application. 35 | // Other LoRa applications might need different configurations. 36 | #define MBEDTLS_AES_FEWER_TABLES 37 | 38 | #undef MBEDTLS_GCM_C 39 | #undef MBEDTLS_CHACHA20_C 40 | #undef MBEDTLS_CHACHAPOLY_C 41 | #undef MBEDTLS_POLY1305_C 42 | 43 | #endif /* MBEDTLS_LORA_CONFIG_H */ 44 | -------------------------------------------------------------------------------- /resources/official_armmbed_example_badge.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ARMmbed/mbed-os-example-lorawan/56840acee35cca35bf22bf9efadd6f77cd7702de/resources/official_armmbed_example_badge.png -------------------------------------------------------------------------------- /trace_helper.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | /** 19 | * If we have tracing library available, we can see traces from within the 20 | * stack. The library could be made unavailable by removing FEATURE_COMMON_PAL 21 | * from the mbed_app.json to save RAM. 22 | */ 23 | 24 | #include "mbed_trace.h" 25 | 26 | #ifdef FEA_TRACE_SUPPORT 27 | #include "platform/PlatformMutex.h" 28 | 29 | /** 30 | * Local mutex object for synchronization 31 | */ 32 | static PlatformMutex mutex; 33 | 34 | static void serial_lock(); 35 | static void serial_unlock(); 36 | 37 | /** 38 | * Sets up trace for the application 39 | * Wouldn't do anything if the FEATURE_COMMON_PAL is not added 40 | * or if the trace is disabled using mbed_app.json 41 | */ 42 | void setup_trace() 43 | { 44 | // setting up Mbed trace. 45 | mbed_trace_mutex_wait_function_set(serial_lock); 46 | mbed_trace_mutex_release_function_set(serial_unlock); 47 | mbed_trace_init(); 48 | } 49 | 50 | /** 51 | * Lock provided for serial printing used by trace library 52 | */ 53 | static void serial_lock() 54 | { 55 | mutex.lock(); 56 | } 57 | 58 | /** 59 | * Releasing lock provided for serial printing used by trace library 60 | */ 61 | static void serial_unlock() 62 | { 63 | mutex.unlock(); 64 | } 65 | #else 66 | void setup_trace() 67 | { 68 | 69 | } 70 | #endif 71 | 72 | 73 | -------------------------------------------------------------------------------- /trace_helper.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2017, Arm Limited and affiliates. 3 | * SPDX-License-Identifier: Apache-2.0 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #ifndef APP_TRACE_HELPER_H_ 19 | #define APP_TRACE_HELPER_H_ 20 | 21 | /** 22 | * Helper function for the application to setup Mbed trace. 23 | * It Wouldn't do anything if the FEATURE_COMMON_PAL is not added 24 | * or if the trace is disabled using mbed_app.json 25 | */ 26 | void setup_trace(); 27 | 28 | #endif /* APP_TRACE_HELPER_H_ */ 29 | --------------------------------------------------------------------------------