├── .github └── workflows │ └── examples.yml ├── .gitignore ├── LICENSE ├── README.md ├── boards ├── lpc11u68.json ├── lpc1768.json ├── lpc54114.json ├── lpc546xx.json ├── lpcxpresso55s16.json └── seeedArchPro.json ├── builder ├── frameworks │ ├── _bare.py │ ├── mbed.py │ └── zephyr.py └── main.py ├── examples ├── mbed-rtos-blink-baremetal │ ├── .gitignore │ ├── README.md │ ├── include │ │ └── README │ ├── lib │ │ └── README │ ├── mbed_app.json │ ├── platformio.ini │ ├── src │ │ └── main.cpp │ └── test │ │ └── README ├── mbed-rtos-blockdevice │ ├── .gitignore │ ├── README.md │ ├── include │ │ └── README │ ├── lib │ │ └── README │ ├── mbed_app.json │ ├── platformio.ini │ ├── src │ │ └── main.cpp │ └── test │ │ └── README ├── mbed-rtos-thread-statistics │ ├── .gitignore │ ├── README.md │ ├── include │ │ └── README │ ├── lib │ │ └── README │ ├── mbed_app.json │ ├── platformio.ini │ ├── src │ │ └── main.cpp │ └── test │ │ └── README ├── zephyr-blink │ ├── .gitignore │ ├── README.md │ ├── include │ │ └── README │ ├── lib │ │ └── README │ ├── platformio.ini │ ├── src │ │ └── main.c │ ├── test │ │ └── README │ └── zephyr │ │ ├── CMakeLists.txt │ │ └── prj.conf ├── zephyr-custom-board │ ├── .gitignore │ ├── .skiptest │ ├── README.md │ ├── boards │ │ └── my_custom_board.json │ ├── include │ │ └── README │ ├── lib │ │ └── README │ ├── platformio.ini │ ├── src │ │ └── main.c │ ├── test │ │ └── README │ └── zephyr │ │ ├── CMakeLists.txt │ │ ├── boards │ │ └── arm │ │ │ └── my_custom_board │ │ │ ├── CMakeLists.txt │ │ │ ├── Kconfig.board │ │ │ ├── Kconfig.defconfig │ │ │ ├── board.cmake │ │ │ ├── lpcxpresso55s16_common.dtsi │ │ │ ├── my_custom_board.dts │ │ │ ├── my_custom_board.yaml │ │ │ ├── my_custom_board_defconfig │ │ │ ├── pinmux.c │ │ │ └── pre_dt_board.cmake │ │ └── prj.conf └── zephyr-synchronization │ ├── .gitignore │ ├── README.md │ ├── include │ └── README │ ├── lib │ └── README │ ├── platformio.ini │ ├── src │ └── main.c │ ├── test │ └── README │ └── zephyr │ ├── CMakeLists.txt │ └── prj.conf ├── misc └── svd │ ├── LPC1102_4_v4.svd │ ├── LPC11Axxv0.6.svd │ ├── LPC11Cxx_v9.svd │ ├── LPC11D14_svd_v4.svd │ ├── LPC11E6x_v0.8.svd │ ├── LPC11Exx_v5.svd │ ├── LPC11Uxx_v7.svd │ ├── LPC11xx_v6.svd │ ├── LPC11xx_v6a.svd │ ├── LPC13Uxx_v1.svd │ ├── LPC13xx_svd_v1.svd │ ├── LPC15xx_v0.7.svd │ ├── LPC176x5x_v0.2.svd │ ├── LPC178x_7x.svd │ ├── LPC178x_7x_v0.8.svd │ ├── LPC18xx_svd_v18.svd │ ├── LPC408x_7x_v0.7.svd │ ├── LPC43xx_43Sxx.svd │ ├── LPC5410x_v0.4.svd │ └── LPC800_v0.3.svd ├── platform.json └── platform.py /.github/workflows/examples.yml: -------------------------------------------------------------------------------- 1 | name: Examples 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | strategy: 8 | fail-fast: false 9 | matrix: 10 | os: [ubuntu-latest, windows-latest, macos-latest] 11 | example: 12 | - "examples/mbed-rtos-blink-baremetal" 13 | - "examples/mbed-rtos-blockdevice" 14 | - "examples/mbed-rtos-thread-statistics" 15 | - "examples/zephyr-blink" 16 | - "examples/zephyr-custom-board" 17 | - "examples/zephyr-synchronization" 18 | runs-on: ${{ matrix.os }} 19 | steps: 20 | - uses: actions/checkout@v3 21 | with: 22 | submodules: "recursive" 23 | - name: Set up Python 24 | uses: actions/setup-python@v3 25 | with: 26 | python-version: "3.9" 27 | - name: Install dependencies 28 | run: | 29 | pip install -U https://github.com/platformio/platformio/archive/develop.zip 30 | pio pkg install --global --platform symlink://. 31 | - name: Build examples 32 | run: | 33 | pio run -d ${{ matrix.example }} 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | -------------------------------------------------------------------------------- /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, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NXP LPC: development platform for [PlatformIO](https://platformio.org) 2 | 3 | [![Build Status](https://github.com/platformio/platform-nxplpc/workflows/Examples/badge.svg)](https://github.com/platformio/platform-nxplpc/actions) 4 | 5 | The NXP LPC is a family of 32-bit microcontroller integrated circuits by NXP Semiconductors. The LPC chips are grouped into related series that are based around the same 32-bit ARM processor core, such as the Cortex-M4F, Cortex-M3, Cortex-M0+, or Cortex-M0. Internally, each microcontroller consists of the processor core, static RAM memory, flash memory, debugging interface, and various peripherals. 6 | 7 | * [Home](https://registry.platformio.org/platforms/platformio/nxplpc) (home page in the PlatformIO Registry) 8 | * [Documentation](https://docs.platformio.org/page/platforms/nxplpc.html) (advanced usage, packages, boards, frameworks, etc.) 9 | 10 | # Usage 11 | 12 | 1. [Install PlatformIO](https://platformio.org) 13 | 2. Create PlatformIO project and configure a platform option in [platformio.ini](https://docs.platformio.org/page/projectconf.html) file: 14 | 15 | ## Stable version 16 | 17 | ```ini 18 | [env:stable] 19 | platform = nxplpc 20 | board = ... 21 | ... 22 | ``` 23 | 24 | ## Development version 25 | 26 | ```ini 27 | [env:development] 28 | platform = https://github.com/platformio/platform-nxplpc.git 29 | board = ... 30 | ... 31 | ``` 32 | 33 | # Configuration 34 | 35 | Please navigate to [documentation](https://docs.platformio.org/page/platforms/nxplpc.html). 36 | -------------------------------------------------------------------------------- /boards/lpc11u68.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m0plus", 4 | "f_cpu": "50000000L", 5 | "mcu": "lpc11u68", 6 | "zephyr": { 7 | "variant": "lpcxpresso11u68" 8 | } 9 | }, 10 | "debug": { 11 | "jlink_device": "LPC11U68", 12 | "openocd_target": "lpc11xx", 13 | "svd_path": "LPC11Uxx_v7.svd" 14 | }, 15 | "frameworks": [ 16 | "zephyr" 17 | ], 18 | "name": "LPCXpresso11U68", 19 | "upload": { 20 | "maximum_ram_size": 36864, 21 | "maximum_size": 262144, 22 | "protocol": "mbed", 23 | "protocols": [ 24 | "cmsis-dap", 25 | "jlink", 26 | "blackmagic", 27 | "mbed" 28 | ] 29 | }, 30 | "url": "https://www.nxp.com/design/microcontrollers-developer-resources/lpc-microcontroller-utilities/lpcxpresso-board-for-lpc11u68:OM13058", 31 | "vendor": "NXP" 32 | } 33 | -------------------------------------------------------------------------------- /boards/lpc1768.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m3", 4 | "f_cpu": "96000000L", 5 | "mcu": "lpc1768" 6 | }, 7 | "connectivity": [ 8 | "can", 9 | "ethernet" 10 | ], 11 | "debug": { 12 | "jlink_device": "LPC1768", 13 | "pyocd_target": "lpc1768", 14 | "svd_path": "LPC176x5x_v0.2.svd" 15 | }, 16 | "frameworks": [ 17 | "mbed" 18 | ], 19 | "name": "NXP mbed LPC1768", 20 | "upload": { 21 | "maximum_ram_size": 65536, 22 | "maximum_size": 524288, 23 | "protocol": "mbed", 24 | "protocols": [ 25 | "jlink", 26 | "blackmagic", 27 | "cmsis-dap", 28 | "mbed" 29 | ] 30 | }, 31 | "url": "http://developer.mbed.org/platforms/mbed-LPC1768/", 32 | "vendor": "NXP" 33 | } 34 | -------------------------------------------------------------------------------- /boards/lpc54114.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m4", 4 | "f_cpu": "100000000L", 5 | "mcu": "lpc54114j256bd64", 6 | "zephyr": { 7 | "variant": "lpcxpresso54114_m4" 8 | } 9 | }, 10 | "debug": { 11 | "jlink_device": "LPC54114J256_M4", 12 | "pyocd_target": "lpc54114", 13 | "svd_path": "LPC5410x_v0.4.svd" 14 | }, 15 | "frameworks": [ 16 | "mbed", 17 | "zephyr" 18 | ], 19 | "name": "NXP LPCXpresso54114", 20 | "upload": { 21 | "maximum_ram_size": 196608, 22 | "maximum_size": 262144, 23 | "protocol": "mbed", 24 | "protocols": [ 25 | "jlink", 26 | "cmsis-dap", 27 | "mbed" 28 | ] 29 | }, 30 | "url": "https://os.mbed.com/platforms/LPCXpresso54114/", 31 | "vendor": "NXP" 32 | } 33 | -------------------------------------------------------------------------------- /boards/lpc546xx.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m4", 4 | "f_cpu": "180000000L", 5 | "mcu": "lpc54608et512" 6 | }, 7 | "connectivity": [ 8 | "ethernet" 9 | ], 10 | "debug": { 11 | "jlink_device": "LPC54608J512", 12 | "onboard_tools": [ 13 | "jlink" 14 | ], 15 | "svd_path": "LPC5410x_v0.4.svd" 16 | }, 17 | "frameworks": [ 18 | "mbed" 19 | ], 20 | "name": "NXP LPCXpresso54608", 21 | "upload": { 22 | "maximum_ram_size": 204800, 23 | "maximum_size": 524288, 24 | "protocol": "mbed", 25 | "protocols": [ 26 | "jlink", 27 | "mbed" 28 | ] 29 | }, 30 | "url": "https://os.mbed.com/platforms/LPCXpresso54608/", 31 | "vendor": "NXP" 32 | } 33 | -------------------------------------------------------------------------------- /boards/lpcxpresso55s16.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m33", 4 | "f_cpu": "150000000L", 5 | "mcu": "lpc55s16" 6 | }, 7 | "connectivity": [ 8 | "ethernet" 9 | ], 10 | "debug": { 11 | "jlink_device": "LPC55S16", 12 | "onboard_tools": [ 13 | "jlink" 14 | ] 15 | }, 16 | "frameworks": [ 17 | "zephyr" 18 | ], 19 | "name": "NXP LPCXpresso55S16", 20 | "upload": { 21 | "maximum_ram_size": 98304, 22 | "maximum_size": 262144, 23 | "protocol": "jlink", 24 | "protocols": [ 25 | "jlink", 26 | "mbed" 27 | ] 28 | }, 29 | "url": "https://www.nxp.com/design/development-boards/lpcxpresso-boards/lpcxpresso55s16-development-board:LPC55S16-EVK", 30 | "vendor": "NXP" 31 | } 32 | -------------------------------------------------------------------------------- /boards/seeedArchPro.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m3", 4 | "f_cpu": "96000000L", 5 | "mcu": "lpc1768" 6 | }, 7 | "connectivity": [ 8 | "ethernet" 9 | ], 10 | "debug": { 11 | "svd_path": "LPC176x5x_v0.2.svd", 12 | "pyocd_target": "lpc1768" 13 | }, 14 | "frameworks": [ 15 | "mbed" 16 | ], 17 | "name": "Seeed Arch Pro", 18 | "upload": { 19 | "maximum_ram_size": 65536, 20 | "maximum_size": 524288, 21 | "protocol": "mbed", 22 | "protocols": [ 23 | "cmsis-dap", 24 | "mbed" 25 | ] 26 | }, 27 | "url": "https://developer.mbed.org/platforms/Seeeduino-Arch-Pro/", 28 | "vendor": "SeeedStudio" 29 | } 30 | -------------------------------------------------------------------------------- /builder/frameworks/_bare.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-present PlatformIO 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # 16 | # Default flags for bare-metal programming (without any framework layers) 17 | # 18 | 19 | from SCons.Script import DefaultEnvironment 20 | 21 | env = DefaultEnvironment() 22 | 23 | env.Append( 24 | ASFLAGS=[ 25 | "-mthumb", 26 | ], 27 | ASPPFLAGS=[ 28 | "-x", "assembler-with-cpp", 29 | ], 30 | 31 | CCFLAGS=[ 32 | "-Os", # optimize for size 33 | "-ffunction-sections", # place each function in its own section 34 | "-fdata-sections", 35 | "-Wall", 36 | "-mthumb", 37 | "-nostdlib" 38 | ], 39 | 40 | CXXFLAGS=[ 41 | "-fno-rtti", 42 | "-fno-exceptions" 43 | ], 44 | 45 | CPPDEFINES=[ 46 | ("F_CPU", "$BOARD_F_CPU") 47 | ], 48 | 49 | LINKFLAGS=[ 50 | "-Os", 51 | "-Wl,--gc-sections,--relax", 52 | "-mthumb", 53 | "--specs=nano.specs", 54 | "--specs=nosys.specs" 55 | ], 56 | 57 | LIBS=["c", "gcc", "m", "stdc++", "nosys"] 58 | ) 59 | 60 | if "BOARD" in env: 61 | env.Append( 62 | ASFLAGS=[ 63 | "-mcpu=%s" % env.BoardConfig().get("build.cpu") 64 | ], 65 | CCFLAGS=[ 66 | "-mcpu=%s" % env.BoardConfig().get("build.cpu") 67 | ], 68 | LINKFLAGS=[ 69 | "-mcpu=%s" % env.BoardConfig().get("build.cpu") 70 | ] 71 | ) 72 | -------------------------------------------------------------------------------- /builder/frameworks/mbed.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-present PlatformIO 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | mbed 16 | 17 | The mbed framework The mbed SDK has been designed to provide enough 18 | hardware abstraction to be intuitive and concise, yet powerful enough to 19 | build complex projects. It is built on the low-level ARM CMSIS APIs, 20 | allowing you to code down to the metal if needed. In addition to RTOS, 21 | USB and Networking libraries, a cookbook of hundreds of reusable 22 | peripheral and module libraries have been built on top of the SDK by 23 | the mbed Developer Community. 24 | 25 | http://mbed.org/ 26 | """ 27 | 28 | from os.path import join 29 | 30 | from SCons.Script import Import, SConscript 31 | 32 | Import("env") 33 | 34 | # https://github.com/platformio/builder-framework-mbed.git 35 | SConscript( 36 | join(env.PioPlatform().get_package_dir("framework-mbed"), "platformio", 37 | "platformio-build.py")) 38 | -------------------------------------------------------------------------------- /builder/frameworks/zephyr.py: -------------------------------------------------------------------------------- 1 | # Copyright 2019-present PlatformIO 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | """ 15 | The Zephyr Project is a scalable real-time operating system (RTOS) supporting multiple 16 | hardware architectures, optimized for resource constrained devices, and built with 17 | safety and security in mind. 18 | 19 | https://github.com/zephyrproject-rtos/zephyr 20 | """ 21 | 22 | from os.path import join 23 | 24 | from SCons.Script import Import, SConscript 25 | 26 | Import("env") 27 | 28 | SConscript( 29 | join(env.PioPlatform().get_package_dir("framework-zephyr"), "scripts", 30 | "platformio", "platformio-build.py"), exports="env") 31 | -------------------------------------------------------------------------------- /builder/main.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-present PlatformIO 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import sys 16 | from platform import system 17 | from os import makedirs 18 | from os.path import isdir, isfile, join 19 | from struct import unpack, pack 20 | 21 | from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild, 22 | Builder, Default, DefaultEnvironment) 23 | 24 | 25 | def add_image_checksum(source, target, env): 26 | # According to https://community.nxp.com/t5/LPCXpresso-IDE-FAQs/LPC-Image-Checksums/m-p/471035 27 | # NXP LPC parts use a word in the vector table of the processor to store a checksum 28 | # that is examined by the bootloader to identify a valid image. 29 | bin_path = target[0].path 30 | if isfile(bin_path): 31 | # From https://github.com/ARMmbed/mbed-os/blob/master/tools/targets/LPC.py 32 | with open(bin_path, "r+b") as fp: 33 | # Read entries 0 through 6 (Little Endian 32bits words) 34 | vector = [unpack(" THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blink-baremetal/mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "requires": ["bare-metal"], 3 | "target_overrides": { 4 | "*": { 5 | "target.c_lib": "small", 6 | "target.printf_lib": "minimal-printf", 7 | "platform.minimal-printf-enable-floating-point": false, 8 | "platform.stdio-minimal-console-only": true 9 | } 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blink-baremetal/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:lpc1768] 11 | platform = nxplpc 12 | framework = mbed 13 | board = lpc1768 14 | 15 | [env:lpc54114] 16 | platform = nxplpc 17 | framework = mbed 18 | board = lpc54114 19 | 20 | [env:lpc546xx] 21 | platform = nxplpc 22 | framework = mbed 23 | board = lpc546xx -------------------------------------------------------------------------------- /examples/mbed-rtos-blink-baremetal/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2019 ARM Limited 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include "mbed.h" 7 | 8 | #define WAIT_TIME_MS 500 9 | DigitalOut led1(LED1); 10 | 11 | int main() 12 | { 13 | printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); 14 | 15 | while (true) 16 | { 17 | led1 = !led1; 18 | thread_sleep_for(WAIT_TIME_MS); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blink-baremetal/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/README.md: -------------------------------------------------------------------------------- 1 | How to build PlatformIO based project 2 | ===================================== 3 | 4 | 1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) 5 | 2. Download [development platform with examples](https://github.com/platformio/platform-nxplpc/archive/develop.zip) 6 | 3. Extract ZIP archive 7 | 4. Run these commands: 8 | 9 | ```shell 10 | # Change directory to example 11 | $ cd platform-nxplpc/examples/mbed-rtos-blockdevice 12 | 13 | # Build project 14 | $ pio run 15 | 16 | # Upload firmware 17 | $ pio run --target upload 18 | 19 | # Clean build files 20 | $ pio run --target clean 21 | ``` 22 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "target_overrides": { 3 | "*": { 4 | "platform.stdio-convert-newlines": true 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:lpc1768] 11 | platform = nxplpc 12 | framework = mbed 13 | board = lpc1768 14 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2018 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mbed.h" 17 | #include 18 | #include 19 | 20 | // Block devices 21 | #if COMPONENT_QSPIF 22 | #include "QSPIFBlockDevice.h" 23 | #endif 24 | 25 | #if COMPONENT_SPIF 26 | #include "SPIFBlockDevice.h" 27 | #endif 28 | 29 | #if COMPONENT_DATAFLASH 30 | #include "DataFlashBlockDevice.h" 31 | #endif 32 | 33 | #if COMPONENT_SD 34 | #include "SDBlockDevice.h" 35 | #endif 36 | 37 | #include "HeapBlockDevice.h" 38 | 39 | 40 | HeapBlockDevice bd(1024*512, 512); 41 | 42 | 43 | // Entry point for the example 44 | int main() { 45 | printf("--- Mbed OS block device example ---\n"); 46 | 47 | // Initialize the block device 48 | printf("bd.init()\n"); 49 | int err = bd.init(); 50 | printf("bd.init -> %d\n", err); 51 | 52 | // Get device geometry 53 | bd_size_t read_size = bd.get_read_size(); 54 | bd_size_t program_size = bd.get_program_size(); 55 | bd_size_t erase_size = bd.get_erase_size(); 56 | bd_size_t size = bd.size(); 57 | 58 | printf("--- Block device geometry ---\n"); 59 | printf("read_size: %lld B\n", read_size); 60 | printf("program_size: %lld B\n", program_size); 61 | printf("erase_size: %lld B\n", erase_size); 62 | printf("size: %lld B\n", size); 63 | printf("---\n"); 64 | 65 | // Allocate a block with enough space for our data, aligned to the 66 | // nearest program_size. This is the minimum size necessary to write 67 | // data to a block. 68 | size_t buffer_size = sizeof("Hello Storage!") + program_size-1; 69 | buffer_size = buffer_size - (buffer_size % program_size); 70 | char *buffer = new char[buffer_size]; 71 | 72 | // Read what is currently stored on the block device. We haven't written 73 | // yet so this may be garbage 74 | printf("bd.read(%p, %d, %d)\n", buffer, 0, buffer_size); 75 | err = bd.read(buffer, 0, buffer_size); 76 | printf("bd.read -> %d\n", err); 77 | 78 | printf("--- Stored data ---\n"); 79 | for (size_t i = 0; i < buffer_size; i += 16) { 80 | for (size_t j = 0; j < 16; j++) { 81 | if (i+j < buffer_size) { 82 | printf("%02x ", buffer[i+j]); 83 | } else { 84 | printf(" "); 85 | } 86 | } 87 | 88 | printf(" %.*s\n", buffer_size - i, &buffer[i]); 89 | } 90 | printf("---\n"); 91 | 92 | // Update buffer with our string we want to store 93 | strncpy(buffer, "Hello Storage!", buffer_size); 94 | 95 | // Write data to first block, write occurs in two parts, 96 | // an erase followed by a program 97 | printf("bd.erase(%d, %lld)\n", 0, erase_size); 98 | err = bd.erase(0, erase_size); 99 | printf("bd.erase -> %d\n", err); 100 | 101 | printf("bd.program(%p, %d, %d)\n", buffer, 0, buffer_size); 102 | err = bd.program(buffer, 0, buffer_size); 103 | printf("bd.program -> %d\n", err); 104 | 105 | // Clobber the buffer so we don't get old data 106 | memset(buffer, 0xcc, buffer_size); 107 | 108 | // Read the data from the first block, note that the program_size must be 109 | // a multiple of the read_size, so we don't have to check for alignment 110 | printf("bd.read(%p, %d, %d)\n", buffer, 0, buffer_size); 111 | err = bd.read(buffer, 0, buffer_size); 112 | printf("bd.read -> %d\n", err); 113 | 114 | printf("--- Stored data ---\n"); 115 | for (size_t i = 0; i < buffer_size; i += 16) { 116 | for (size_t j = 0; j < 16; j++) { 117 | if (i+j < buffer_size) { 118 | printf("%02x ", buffer[i+j]); 119 | } else { 120 | printf(" "); 121 | } 122 | } 123 | 124 | printf(" %.*s\n", buffer_size - i, &buffer[i]); 125 | } 126 | printf("---\n"); 127 | 128 | // Deinitialize the block device 129 | printf("bd.deinit()\n"); 130 | err = bd.deinit(); 131 | printf("bd.deinit -> %d\n", err); 132 | 133 | printf("--- done! ---\n"); 134 | } 135 | 136 | -------------------------------------------------------------------------------- /examples/mbed-rtos-blockdevice/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/.gitignore: -------------------------------------------------------------------------------- 1 | .pio 2 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/README.md: -------------------------------------------------------------------------------- 1 | How to build PlatformIO based project 2 | ===================================== 3 | 4 | 1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) 5 | 2. Download [development platform with examples](https://github.com/platformio/platform-nxplpc/archive/develop.zip) 6 | 3. Extract ZIP archive 7 | 4. Run these commands: 8 | 9 | ```shell 10 | # Change directory to example 11 | $ cd platform-nxplpc/examples/thread-statistics 12 | 13 | # Build project 14 | $ pio run 15 | 16 | # Upload firmware 17 | $ pio run --target upload 18 | 19 | # Clean build files 20 | $ pio run --target clean 21 | ``` 22 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/mbed_app.json: -------------------------------------------------------------------------------- 1 | { 2 | "target_overrides": { 3 | "*": { 4 | "platform.thread-stats-enabled": true 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:lpc1768] 11 | platform = nxplpc 12 | framework = mbed 13 | board = lpc1768 14 | 15 | [env:lpc54114] 16 | platform = nxplpc 17 | framework = mbed 18 | board = lpc54114 19 | 20 | [env:lpc546xx] 21 | platform = nxplpc 22 | framework = mbed 23 | board = lpc546xx -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/src/main.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2018 Arm Limited 2 | * 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 "mbed.h" 18 | #include 19 | 20 | #if !defined(MBED_THREAD_STATS_ENABLED) 21 | #error "Thread statistics not enabled" 22 | #endif 23 | 24 | #define MAX_THREAD_STATS 0x8 25 | #define BLINKY_THREAD_STACK 224 26 | #define IDLE_THREAD_STACK 384 27 | #define STOP_FLAG 0xEF 28 | #define WAIT_TIME_MS 500 29 | 30 | // Initialise the digital pin LED1 as an output 31 | DigitalOut led1(LED1); 32 | static EventFlags idle_ef; 33 | 34 | void blinky() 35 | { 36 | while (1) { 37 | led1 = !led1; 38 | thread_sleep_for(WAIT_TIME_MS); 39 | } 40 | } 41 | 42 | void idle() 43 | { 44 | idle_ef.wait_all(STOP_FLAG); 45 | } 46 | 47 | int main() 48 | { 49 | Thread *blinky_thread = new Thread(osPriorityNormal, BLINKY_THREAD_STACK, nullptr, "blinky_thread"); 50 | blinky_thread->start(blinky); 51 | 52 | Thread *idle_thread = new Thread(osPriorityNormal, IDLE_THREAD_STACK, nullptr, "idle_thread"); 53 | idle_thread->start(idle); 54 | 55 | // Sleep helps other created threads to run 56 | thread_sleep_for(10); 57 | mbed_stats_thread_t *stats = new mbed_stats_thread_t[MAX_THREAD_STATS]; 58 | int count = mbed_stats_thread_get_each(stats, MAX_THREAD_STATS); 59 | 60 | for (int i = 0; i < count; i++) { 61 | printf("ID: 0x%" PRIx32 "\n", stats[i].id); 62 | printf("Name: %s \n", stats[i].name); 63 | printf("State: %" PRId32 "\n", stats[i].state); 64 | printf("Priority: %" PRId32 "\n", stats[i].priority); 65 | printf("Stack Size: %" PRId32 "\n", stats[i].stack_size); 66 | printf("Stack Space: %" PRId32 "\n", stats[i].stack_space); 67 | printf("\n"); 68 | } 69 | 70 | blinky_thread->terminate(); 71 | idle_thread->terminate(); 72 | return 0; 73 | } 74 | -------------------------------------------------------------------------------- /examples/mbed-rtos-thread-statistics/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/zephyr-blink/.gitignore: -------------------------------------------------------------------------------- 1 | .pio -------------------------------------------------------------------------------- /examples/zephyr-blink/README.md: -------------------------------------------------------------------------------- 1 | How to build PlatformIO based project 2 | ===================================== 3 | 4 | 1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) 5 | 2. Download [development platform with examples](https://github.com/platformio/platform-nxplpc/archive/develop.zip) 6 | 3. Extract ZIP archive 7 | 4. Run these commands: 8 | 9 | ```shell 10 | # Change directory to example 11 | $ cd platform-nxplpc/examples/zephyr-blink 12 | 13 | # Build project 14 | $ pio run 15 | 16 | # Upload firmware 17 | $ pio run --target upload 18 | 19 | # Clean build files 20 | $ pio run --target clean 21 | ``` 22 | -------------------------------------------------------------------------------- /examples/zephyr-blink/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /examples/zephyr-blink/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/zephyr-blink/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:lpc54114] 11 | platform = nxplpc 12 | framework = zephyr 13 | board = lpc54114 14 | 15 | [env:lpcxpresso55s16] 16 | platform = nxplpc 17 | framework = zephyr 18 | board = lpcxpresso55s16 19 | -------------------------------------------------------------------------------- /examples/zephyr-blink/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2016 Intel Corporation 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | /* 1000 msec = 1 sec */ 13 | #define SLEEP_TIME_MS 1000 14 | 15 | /* The devicetree node identifier for the "led0" alias. */ 16 | #define LED0_NODE DT_ALIAS(led0) 17 | 18 | #if DT_NODE_HAS_STATUS(LED0_NODE, okay) 19 | #define LED0 DT_GPIO_LABEL(LED0_NODE, gpios) 20 | #define PIN DT_GPIO_PIN(LED0_NODE, gpios) 21 | #define FLAGS DT_GPIO_FLAGS(LED0_NODE, gpios) 22 | #else 23 | /* A build error here means your board isn't set up to blink an LED. */ 24 | #error "Unsupported board: led0 devicetree alias is not defined" 25 | #define LED0 "" 26 | #define PIN 0 27 | #define FLAGS 0 28 | #endif 29 | 30 | void main(void) 31 | { 32 | const struct device *dev; 33 | bool led_is_on = true; 34 | int ret; 35 | 36 | dev = device_get_binding(LED0); 37 | if (dev == NULL) { 38 | return; 39 | } 40 | 41 | ret = gpio_pin_configure(dev, PIN, GPIO_OUTPUT_ACTIVE | FLAGS); 42 | if (ret < 0) { 43 | return; 44 | } 45 | 46 | while (1) { 47 | gpio_pin_set(dev, PIN, (int)led_is_on); 48 | led_is_on = !led_is_on; 49 | k_msleep(SLEEP_TIME_MS); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /examples/zephyr-blink/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/zephyr-blink/zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | cmake_minimum_required(VERSION 3.13.1) 4 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) 5 | project(blinky) 6 | 7 | target_sources(app PRIVATE ../src/main.c) 8 | -------------------------------------------------------------------------------- /examples/zephyr-blink/zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_GPIO=y 2 | CONFIG_SERIAL=n 3 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/.gitignore: -------------------------------------------------------------------------------- 1 | .pio -------------------------------------------------------------------------------- /examples/zephyr-custom-board/.skiptest: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/platformio/platform-nxplpc/874201af396477967f540d13513ff14a8edaf730/examples/zephyr-custom-board/.skiptest -------------------------------------------------------------------------------- /examples/zephyr-custom-board/README.md: -------------------------------------------------------------------------------- 1 | How to build PlatformIO based project 2 | ===================================== 3 | 4 | 1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) 5 | 2. Download [development platform with examples](https://github.com/platformio/platform-nxplpc/archive/develop.zip) 6 | 3. Extract ZIP archive 7 | 4. Run these commands: 8 | 9 | ```shell 10 | # Change directory to example 11 | $ cd platform-nxplpc/examples/zephyr-custom-board 12 | 13 | # Build project 14 | $ pio run 15 | 16 | # Upload firmware 17 | $ pio run --target upload 18 | 19 | # Clean build files 20 | $ pio run --target clean 21 | ``` 22 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/boards/my_custom_board.json: -------------------------------------------------------------------------------- 1 | { 2 | "build": { 3 | "cpu": "cortex-m33", 4 | "f_cpu": "150000000L", 5 | "mcu": "lpc55s16", 6 | "zephyr": { 7 | "variant": "lpcxpresso55s16" 8 | } 9 | }, 10 | "connectivity": [ 11 | "ethernet" 12 | ], 13 | "debug": { 14 | "jlink_device": "LPC55S16", 15 | "onboard_tools": [ 16 | "jlink" 17 | ] 18 | }, 19 | "frameworks": [ 20 | "zephyr" 21 | ], 22 | "name": "Custom board based lpc55s16", 23 | "upload": { 24 | "maximum_ram_size": 98304, 25 | "maximum_size": 262144, 26 | "protocol": "jlink", 27 | "protocols": [ 28 | "jlink", 29 | "mbed" 30 | ] 31 | }, 32 | "url": "https://www.nxp.com/design/development-boards/lpcxpresso-boards/lpcxpresso55s16-development-board:LPC55S16-EVK", 33 | "vendor": "NXP" 34 | } 35 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:my_custom_board] 11 | platform = nxplpc 12 | framework = zephyr 13 | board = my_custom_board 14 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012-2014 Wind River Systems, Inc. 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | void main(void) 11 | { 12 | printk("Hello World! %s\n", CONFIG_BOARD); 13 | } 14 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | set (BOARD_ROOT "${CMAKE_CURRENT_SOURCE_DIR}") 4 | 5 | cmake_minimum_required(VERSION 3.13.1) 6 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) 7 | project(custom-board) 8 | 9 | target_sources(app PRIVATE ../src/main.c) 10 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 Henrik Brix Andersen 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | if(CONFIG_PINMUX_MCUX_LPC) 8 | zephyr_library() 9 | zephyr_library_include_directories(${ZEPHYR_BASE}/drivers) 10 | zephyr_library_sources(pinmux.c) 11 | endif() 12 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/Kconfig.board: -------------------------------------------------------------------------------- 1 | # LPCXpresso55S16 board 2 | 3 | # Copyright (c) 2020 Henrik Brix Andersen 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | config BOARD_MY_CUSTOM_BOARD 7 | bool "BOARD BASED ON LPC55S16" 8 | depends on SOC_SERIES_LPC55XXX 9 | select SOC_PART_NUMBER_LPC55S16JBD100 10 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/Kconfig.defconfig: -------------------------------------------------------------------------------- 1 | # My custom board 2 | 3 | # Copyright (c) 2020 Henrik Brix Andersen 4 | # SPDX-License-Identifier: Apache-2.0 5 | 6 | if BOARD_MY_CUSTOM_BOARD 7 | 8 | config BOARD 9 | default "my_custom_board" 10 | 11 | if PINMUX_MCUX_LPC 12 | 13 | config PINMUX_MCUX_LPC_PORT0 14 | default y 15 | 16 | config PINMUX_MCUX_LPC_PORT1 17 | default y 18 | 19 | endif # PINMUX_MCUX_LPC 20 | 21 | if GPIO_MCUX_LPC 22 | 23 | config GPIO_MCUX_LPC_PORT0 24 | default y 25 | 26 | config GPIO_MCUX_LPC_PORT1 27 | default y 28 | 29 | endif # GPIO_MCUX_LPC 30 | 31 | config FXOS8700_DRDY_INT1 32 | default y 33 | depends on FXOS8700_TRIGGER 34 | 35 | endif # BOARD_MY_CUSTOM_BOARD 36 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/board.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 Henrik Brix Andersen 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | board_set_debugger_ifnset(jlink) 8 | board_set_flasher_ifnset(jlink) 9 | 10 | board_runner_args(jlink "--device=LPC55S16") 11 | 12 | include(${ZEPHYR_BASE}/boards/common/jlink.board.cmake) 13 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/lpcxpresso55s16_common.dtsi: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Henrik Brix Andersen 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | / { 8 | chosen { 9 | zephyr,sram = &sram0; 10 | zephyr,flash = &flash0; 11 | zephyr,code-partition = &sramx; 12 | zephyr,console = &flexcomm0; 13 | zephyr,shell-uart = &flexcomm0; 14 | zephyr,entropy = &rng; 15 | }; 16 | 17 | aliases{ 18 | led0 = &red_led; 19 | led1 = &green_led; 20 | led2 = &blue_led; 21 | sw0 = &btn_wk; 22 | sw1 = &btn_usr; 23 | sw2 = &btn_isp; 24 | usart-0 = &flexcomm0; 25 | }; 26 | 27 | leds { 28 | compatible = "gpio-leds"; 29 | red_led: led_0 { 30 | gpios = <&gpio1 4 0>; 31 | label = "Red LED"; 32 | }; 33 | green_led: led_1 { 34 | gpios = <&gpio1 7 0>; 35 | label = "Green LED"; 36 | }; 37 | blue_led: led_2 { 38 | gpios = <&gpio1 6 0>; 39 | label = "Blue LED"; 40 | }; 41 | }; 42 | 43 | gpio_keys { 44 | compatible = "gpio-keys"; 45 | btn_wk: button_0 { 46 | label = "Wakeup button"; 47 | gpios = <&gpio1 18 GPIO_ACTIVE_LOW>; 48 | }; 49 | btn_usr: button_1 { 50 | label = "USR button"; 51 | gpios = <&gpio1 9 GPIO_ACTIVE_LOW>; 52 | }; 53 | btn_isp: button_2 { 54 | label = "ISP button"; 55 | gpios = <&gpio0 5 GPIO_ACTIVE_LOW>; 56 | }; 57 | }; 58 | }; 59 | 60 | &flexcomm0 { 61 | status = "okay"; 62 | compatible = "nxp,lpc-usart"; 63 | current-speed = <115200>; 64 | }; 65 | 66 | arduino_i2c: &flexcomm4 { 67 | status = "okay"; 68 | compatible = "nxp,lpc-i2c"; 69 | clock-frequency = ; 70 | #address-cells = <1>; 71 | #size-cells = <0>; 72 | 73 | fxos8700@1e { 74 | compatible = "nxp,fxos8700"; 75 | reg = <0x1e>; 76 | label = "FXOS8700"; 77 | int1-gpios = <&gpio1 26 GPIO_ACTIVE_LOW>; 78 | }; 79 | }; 80 | 81 | arduino_spi: &hs_lspi { 82 | status = "okay"; 83 | }; 84 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/my_custom_board.dts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Henrik Brix Andersen 3 | * 4 | * SPDX-License-Identifier: Apache-2.0 5 | */ 6 | 7 | /dts-v1/; 8 | 9 | #include 10 | #include "lpcxpresso55s16_common.dtsi" 11 | 12 | / { 13 | model = "My custom board (non-secure)"; 14 | compatible = "nxp,lpc55xxx", "nxp,lpc"; 15 | }; 16 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/my_custom_board.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 Henrik Brix Andersen 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | identifier: my_custom_board 8 | name: My custom board based on LPC55S16 9 | type: mcu 10 | arch: arm 11 | ram: 96 12 | flash: 256 13 | toolchain: 14 | - zephyr 15 | - gnuarmemb 16 | - xtools 17 | supported: 18 | - arduino_i2c 19 | - arduino_spi 20 | - gpio 21 | - i2c 22 | - spi 23 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/my_custom_board_defconfig: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2020 Henrik Brix Andersen 3 | # 4 | # SPDX-License-Identifier: Apache-2.0 5 | # 6 | 7 | CONFIG_SOC_SERIES_LPC55XXX=y 8 | CONFIG_SOC_LPC55S16=y 9 | CONFIG_BOARD_MY_CUSTOM_BOARD=y 10 | CONFIG_CONSOLE=y 11 | CONFIG_UART_CONSOLE=y 12 | CONFIG_SERIAL=y 13 | CONFIG_UART_INTERRUPT_DRIVEN=y 14 | CONFIG_CORTEX_M_SYSTICK=y 15 | CONFIG_GPIO=y 16 | CONFIG_PINMUX=y 17 | CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC=96000000 18 | CONFIG_ARM_MPU=y 19 | 20 | # TrustZone-M non-secure 21 | CONFIG_TRUSTED_EXECUTION_NONSECURE=y 22 | 23 | CONFIG_RUNTIME_NMI=y 24 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/pinmux.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Henrik Brix Andersen 3 | * SPDX-License-Identifier: Apache-2.0 4 | */ 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | static int lpcxpresso_55s16_pinmux_init(struct device *dev) 13 | { 14 | ARG_UNUSED(dev); 15 | 16 | #ifdef CONFIG_PINMUX_MCUX_LPC_PORT0 17 | __unused struct device *port0 = 18 | device_get_binding(CONFIG_PINMUX_MCUX_LPC_PORT0_NAME); 19 | #endif 20 | 21 | #ifdef CONFIG_PINMUX_MCUX_LPC_PORT1 22 | __unused struct device *port1 = 23 | device_get_binding(CONFIG_PINMUX_MCUX_LPC_PORT1_NAME); 24 | #endif 25 | 26 | #if DT_PHA_HAS_CELL(DT_ALIAS(sw0), gpios, pin) 27 | /* Wakeup button */ 28 | const u32_t sw0_config = ( 29 | IOCON_PIO_FUNC0 | 30 | IOCON_PIO_INV_DI | 31 | IOCON_PIO_DIGITAL_EN | 32 | IOCON_PIO_INPFILT_OFF | 33 | IOCON_PIO_OPENDRAIN_DI 34 | ); 35 | pinmux_pin_set(port1, DT_GPIO_PIN(DT_ALIAS(sw0), gpios), sw0_config); 36 | #endif 37 | 38 | #if DT_PHA_HAS_CELL(DT_ALIAS(sw1), gpios, pin) 39 | /* USR button */ 40 | const u32_t sw1_config = ( 41 | IOCON_PIO_FUNC0 | 42 | IOCON_PIO_INV_DI | 43 | IOCON_PIO_DIGITAL_EN | 44 | IOCON_PIO_INPFILT_OFF | 45 | IOCON_PIO_OPENDRAIN_DI 46 | ); 47 | pinmux_pin_set(port1, DT_GPIO_PIN(DT_ALIAS(sw1), gpios), sw1_config); 48 | #endif 49 | 50 | #if DT_PHA_HAS_CELL(DT_ALIAS(sw2), gpios, pin) 51 | /* ISP button */ 52 | const u32_t sw2_config = ( 53 | IOCON_PIO_FUNC0 | 54 | IOCON_PIO_INV_DI | 55 | IOCON_PIO_DIGITAL_EN | 56 | IOCON_PIO_INPFILT_OFF | 57 | IOCON_PIO_OPENDRAIN_DI 58 | ); 59 | pinmux_pin_set(port0, DT_GPIO_PIN(DT_ALIAS(sw2), gpios), sw2_config); 60 | #endif 61 | 62 | #if DT_PHA_HAS_CELL(DT_ALIAS(led0), gpios, pin) 63 | /* Red LED */ 64 | const u32_t led0_config = ( 65 | IOCON_PIO_FUNC0 | 66 | IOCON_PIO_INV_DI | 67 | IOCON_PIO_DIGITAL_EN | 68 | IOCON_PIO_INPFILT_OFF | 69 | IOCON_PIO_OPENDRAIN_DI 70 | ); 71 | pinmux_pin_set(port1, DT_GPIO_PIN(DT_ALIAS(led0), gpios), led0_config); 72 | #endif 73 | 74 | #if DT_PHA_HAS_CELL(DT_ALIAS(led1), gpios, pin) 75 | /* Green LED */ 76 | const u32_t led1_config = ( 77 | IOCON_PIO_FUNC0 | 78 | IOCON_PIO_INV_DI | 79 | IOCON_PIO_DIGITAL_EN | 80 | IOCON_PIO_INPFILT_OFF | 81 | IOCON_PIO_OPENDRAIN_DI 82 | ); 83 | pinmux_pin_set(port1, DT_GPIO_PIN(DT_ALIAS(led1), gpios), led1_config); 84 | #endif 85 | 86 | #if DT_PHA_HAS_CELL(DT_ALIAS(led2), gpios, pin) 87 | /* Blue LED */ 88 | const u32_t led2_config = ( 89 | IOCON_PIO_FUNC0 | 90 | IOCON_PIO_INV_DI | 91 | IOCON_PIO_DIGITAL_EN | 92 | IOCON_PIO_INPFILT_OFF | 93 | IOCON_PIO_OPENDRAIN_DI 94 | ); 95 | pinmux_pin_set(port1, DT_GPIO_PIN(DT_ALIAS(led2), gpios), led2_config); 96 | #endif 97 | 98 | #if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm0), nxp_lpc_usart, okay) && CONFIG_SERIAL 99 | /* USART0 RX, TX */ 100 | const u32_t port0_pin29_config = ( 101 | IOCON_PIO_FUNC1 | 102 | IOCON_PIO_MODE_INACT | 103 | IOCON_PIO_INV_DI | 104 | IOCON_PIO_DIGITAL_EN | 105 | IOCON_PIO_SLEW_STANDARD | 106 | IOCON_PIO_OPENDRAIN_DI 107 | ); 108 | const u32_t port0_pin30_config = ( 109 | IOCON_PIO_FUNC1 | 110 | IOCON_PIO_MODE_INACT | 111 | IOCON_PIO_INV_DI | 112 | IOCON_PIO_DIGITAL_EN | 113 | IOCON_PIO_SLEW_STANDARD | 114 | IOCON_PIO_OPENDRAIN_DI 115 | ); 116 | pinmux_pin_set(port0, 29, port0_pin29_config); 117 | pinmux_pin_set(port0, 30, port0_pin30_config); 118 | #endif 119 | 120 | #if DT_NODE_HAS_COMPAT_STATUS(DT_NODELABEL(flexcomm4), nxp_lpc_i2c, okay) && CONFIG_I2C 121 | /* PORT1 PIN20 is configured as FC4_TXD_SCL_MISO_WS */ 122 | pinmux_pin_set(port1, 20, IOCON_PIO_FUNC5 | 123 | IOCON_PIO_MODE_INACT | 124 | IOCON_PIO_SLEW_STANDARD | 125 | IOCON_PIO_INV_DI | 126 | IOCON_PIO_DIGITAL_EN | 127 | IOCON_PIO_OPENDRAIN_DI); 128 | 129 | /* PORT1 PIN21 is configured as FC4_RXD_SDA_MOSI_DATA */ 130 | pinmux_pin_set(port1, 21, IOCON_PIO_FUNC5 | 131 | IOCON_PIO_MODE_INACT | 132 | IOCON_PIO_SLEW_STANDARD | 133 | IOCON_PIO_INV_DI | 134 | IOCON_PIO_DIGITAL_EN | 135 | IOCON_PIO_OPENDRAIN_DI); 136 | #endif 137 | 138 | #ifdef CONFIG_FXOS8700_TRIGGER 139 | pinmux_pin_set(port1, 26, IOCON_PIO_FUNC0 | 140 | IOCON_PIO_MODE_PULLUP | 141 | IOCON_PIO_INV_DI | 142 | IOCON_PIO_DIGITAL_EN | 143 | IOCON_PIO_INPFILT_OFF | 144 | IOCON_PIO_SLEW_STANDARD | 145 | IOCON_PIO_OPENDRAIN_DI); 146 | #endif 147 | 148 | #if DT_NODE_HAS_STATUS(DT_NODELABEL(hs_lspi), okay) && CONFIG_SPI 149 | /* PORT0 PIN26 is configured as HS_SPI_MOSI */ 150 | pinmux_pin_set(port0, 26, IOCON_PIO_FUNC9 | 151 | IOCON_PIO_MODE_PULLUP | 152 | IOCON_PIO_INV_DI | 153 | IOCON_PIO_DIGITAL_EN | 154 | IOCON_PIO_SLEW_STANDARD | 155 | IOCON_PIO_OPENDRAIN_DI); 156 | 157 | /* PORT1 PIN1 is configured as HS_SPI_SSEL1 */ 158 | pinmux_pin_set(port1, 1, IOCON_PIO_FUNC5 | 159 | IOCON_PIO_MODE_PULLUP | 160 | IOCON_PIO_INV_DI | 161 | IOCON_PIO_DIGITAL_EN | 162 | IOCON_PIO_SLEW_STANDARD | 163 | IOCON_PIO_OPENDRAIN_DI); 164 | 165 | /* PORT1 PIN2 is configured as HS_SPI_SCK */ 166 | pinmux_pin_set(port1, 2, IOCON_PIO_FUNC6 | 167 | IOCON_PIO_MODE_PULLUP | 168 | IOCON_PIO_INV_DI | 169 | IOCON_PIO_DIGITAL_EN | 170 | IOCON_PIO_SLEW_STANDARD | 171 | IOCON_PIO_OPENDRAIN_DI); 172 | 173 | /* PORT1 PIN3 is configured as HS_SPI_MISO */ 174 | pinmux_pin_set(port1, 3, IOCON_PIO_FUNC6 | 175 | IOCON_PIO_MODE_PULLUP | 176 | IOCON_PIO_INV_DI | 177 | IOCON_PIO_DIGITAL_EN | 178 | IOCON_PIO_SLEW_STANDARD | 179 | IOCON_PIO_OPENDRAIN_DI); 180 | #endif 181 | 182 | return 0; 183 | } 184 | 185 | SYS_INIT(lpcxpresso_55s16_pinmux_init, PRE_KERNEL_1, 186 | CONFIG_PINMUX_INIT_PRIORITY); 187 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/boards/arm/my_custom_board/pre_dt_board.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2020 Henrik Brix Andersen 2 | # SPDX-License-Identifier: Apache-2.0 3 | 4 | # Suppress "simple_bus_reg" on LPC boards as all GPIO ports use the same register. 5 | list(APPEND EXTRA_DTC_FLAGS "-Wno-simple_bus_reg") 6 | -------------------------------------------------------------------------------- /examples/zephyr-custom-board/zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_LOG=y 2 | CONFIG_WDT_LOG_LEVEL_DBG=y 3 | CONFIG_WATCHDOG=y 4 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/.gitignore: -------------------------------------------------------------------------------- 1 | .pio -------------------------------------------------------------------------------- /examples/zephyr-synchronization/README.md: -------------------------------------------------------------------------------- 1 | How to build PlatformIO based project 2 | ===================================== 3 | 4 | 1. [Install PlatformIO Core](https://docs.platformio.org/page/core.html) 5 | 2. Download [development platform with examples](https://github.com/platformio/platform-nxplpc/archive/develop.zip) 6 | 3. Extract ZIP archive 7 | 4. Run these commands: 8 | 9 | ```shell 10 | # Change directory to example 11 | $ cd platform-nxplpc/examples/zephyr-synchronization 12 | 13 | # Build project 14 | $ pio run 15 | 16 | # Upload firmware 17 | $ pio run --target upload 18 | 19 | # Clean build files 20 | $ pio run --target clean 21 | ``` 22 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/include/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project header files. 3 | 4 | A header file is a file containing C declarations and macro definitions 5 | to be shared between several project source files. You request the use of a 6 | header file in your project source file (C, C++, etc) located in `src` folder 7 | by including it, with the C preprocessing directive `#include'. 8 | 9 | ```src/main.c 10 | 11 | #include "header.h" 12 | 13 | int main (void) 14 | { 15 | ... 16 | } 17 | ``` 18 | 19 | Including a header file produces the same results as copying the header file 20 | into each source file that needs it. Such copying would be time-consuming 21 | and error-prone. With a header file, the related declarations appear 22 | in only one place. If they need to be changed, they can be changed in one 23 | place, and programs that include the header file will automatically use the 24 | new version when next recompiled. The header file eliminates the labor of 25 | finding and changing all the copies as well as the risk that a failure to 26 | find one copy will result in inconsistencies within a program. 27 | 28 | In C, the usual convention is to give header files names that end with `.h'. 29 | It is most portable to use only letters, digits, dashes, and underscores in 30 | header file names, and at most one dot. 31 | 32 | Read more about using header files in official GCC documentation: 33 | 34 | * Include Syntax 35 | * Include Operation 36 | * Once-Only Headers 37 | * Computed Includes 38 | 39 | https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html 40 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/lib/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for project specific (private) libraries. 3 | PlatformIO will compile them to static libraries and link into executable file. 4 | 5 | The source code of each library should be placed in a an own separate directory 6 | ("lib/your_library_name/[here are source files]"). 7 | 8 | For example, see a structure of the following two libraries `Foo` and `Bar`: 9 | 10 | |--lib 11 | | | 12 | | |--Bar 13 | | | |--docs 14 | | | |--examples 15 | | | |--src 16 | | | |- Bar.c 17 | | | |- Bar.h 18 | | | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html 19 | | | 20 | | |--Foo 21 | | | |- Foo.c 22 | | | |- Foo.h 23 | | | 24 | | |- README --> THIS FILE 25 | | 26 | |- platformio.ini 27 | |--src 28 | |- main.c 29 | 30 | and a contents of `src/main.c`: 31 | ``` 32 | #include 33 | #include 34 | 35 | int main (void) 36 | { 37 | ... 38 | } 39 | 40 | ``` 41 | 42 | PlatformIO Library Dependency Finder will find automatically dependent 43 | libraries scanning project source files. 44 | 45 | More information about PlatformIO Library Dependency Finder 46 | - https://docs.platformio.org/page/librarymanager/ldf.html 47 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/platformio.ini: -------------------------------------------------------------------------------- 1 | ; PlatformIO Project Configuration File 2 | ; 3 | ; Build options: build flags, source filter, extra scripting 4 | ; Upload options: custom port, speed and extra flags 5 | ; Library options: dependencies, extra library storages 6 | ; 7 | ; Please visit documentation for the other options and examples 8 | ; https://docs.platformio.org/page/projectconf.html 9 | 10 | [env:lpc54114] 11 | platform = nxplpc 12 | framework = zephyr 13 | board = lpc54114 14 | 15 | [env:lpcxpresso55s16] 16 | platform = nxplpc 17 | framework = zephyr 18 | board = lpcxpresso55s16 19 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/src/main.c: -------------------------------------------------------------------------------- 1 | /* main.c - Hello World demo */ 2 | 3 | /* 4 | * Copyright (c) 2012-2014 Wind River Systems, Inc. 5 | * 6 | * SPDX-License-Identifier: Apache-2.0 7 | */ 8 | 9 | #include 10 | #include 11 | 12 | /* 13 | * The hello world demo has two threads that utilize semaphores and sleeping 14 | * to take turns printing a greeting message at a controlled rate. The demo 15 | * shows both the static and dynamic approaches for spawning a thread; a real 16 | * world application would likely use the static approach for both threads. 17 | */ 18 | 19 | 20 | /* size of stack area used by each thread */ 21 | #define STACKSIZE 1024 22 | 23 | /* scheduling priority used by each thread */ 24 | #define PRIORITY 7 25 | 26 | /* delay between greetings (in ms) */ 27 | #define SLEEPTIME 500 28 | 29 | 30 | /* 31 | * @param my_name thread identification string 32 | * @param my_sem thread's own semaphore 33 | * @param other_sem other thread's semaphore 34 | */ 35 | void helloLoop(const char *my_name, 36 | struct k_sem *my_sem, struct k_sem *other_sem) 37 | { 38 | const char *tname; 39 | uint8_t cpu; 40 | struct k_thread *current_thread; 41 | 42 | while (1) { 43 | /* take my semaphore */ 44 | k_sem_take(my_sem, K_FOREVER); 45 | 46 | current_thread = k_current_get(); 47 | tname = k_thread_name_get(current_thread); 48 | #if CONFIG_SMP 49 | cpu = arch_curr_cpu()->id; 50 | #else 51 | cpu = 0; 52 | #endif 53 | /* say "hello" */ 54 | if (tname == NULL) { 55 | printk("%s: Hello World from cpu %d on %s!\n", 56 | my_name, cpu, CONFIG_BOARD); 57 | } else { 58 | printk("%s: Hello World from cpu %d on %s!\n", 59 | tname, cpu, CONFIG_BOARD); 60 | } 61 | 62 | /* wait a while, then let other thread have a turn */ 63 | k_busy_wait(100000); 64 | k_msleep(SLEEPTIME); 65 | k_sem_give(other_sem); 66 | } 67 | } 68 | 69 | /* define semaphores */ 70 | 71 | K_SEM_DEFINE(threadA_sem, 1, 1); /* starts off "available" */ 72 | K_SEM_DEFINE(threadB_sem, 0, 1); /* starts off "not available" */ 73 | 74 | 75 | /* threadB is a dynamic thread that is spawned by threadA */ 76 | 77 | void threadB(void *dummy1, void *dummy2, void *dummy3) 78 | { 79 | ARG_UNUSED(dummy1); 80 | ARG_UNUSED(dummy2); 81 | ARG_UNUSED(dummy3); 82 | 83 | /* invoke routine to ping-pong hello messages with threadA */ 84 | helloLoop(__func__, &threadB_sem, &threadA_sem); 85 | } 86 | 87 | K_THREAD_STACK_DEFINE(threadB_stack_area, STACKSIZE); 88 | static struct k_thread threadB_data; 89 | 90 | /* threadA is a static thread that is spawned automatically */ 91 | 92 | void threadA(void *dummy1, void *dummy2, void *dummy3) 93 | { 94 | ARG_UNUSED(dummy1); 95 | ARG_UNUSED(dummy2); 96 | ARG_UNUSED(dummy3); 97 | 98 | /* spawn threadB */ 99 | k_tid_t tid = k_thread_create(&threadB_data, threadB_stack_area, 100 | STACKSIZE, threadB, NULL, NULL, NULL, 101 | PRIORITY, 0, K_FOREVER); 102 | 103 | k_thread_name_set(tid, "thread_b"); 104 | #if CONFIG_SCHED_CPU_MASK 105 | k_thread_cpu_mask_disable(&threadB_data, 1); 106 | k_thread_cpu_mask_enable(&threadB_data, 0); 107 | #endif 108 | k_thread_start(&threadB_data); 109 | 110 | /* invoke routine to ping-pong hello messages with threadB */ 111 | helloLoop(__func__, &threadA_sem, &threadB_sem); 112 | } 113 | 114 | K_THREAD_DEFINE(thread_a, STACKSIZE, threadA, NULL, NULL, NULL, 115 | PRIORITY, 0, 0); 116 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/test/README: -------------------------------------------------------------------------------- 1 | 2 | This directory is intended for PIO Unit Testing and project tests. 3 | 4 | Unit Testing is a software testing method by which individual units of 5 | source code, sets of one or more MCU program modules together with associated 6 | control data, usage procedures, and operating procedures, are tested to 7 | determine whether they are fit for use. Unit testing finds problems early 8 | in the development cycle. 9 | 10 | More information about PIO Unit Testing: 11 | - https://docs.platformio.org/page/plus/unit-testing.html 12 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/zephyr/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | 3 | cmake_minimum_required(VERSION 3.13.1) 4 | 5 | include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) 6 | project(synchronization) 7 | 8 | target_sources(app PRIVATE ../src/main.c) 9 | -------------------------------------------------------------------------------- /examples/zephyr-synchronization/zephyr/prj.conf: -------------------------------------------------------------------------------- 1 | CONFIG_STDOUT_CONSOLE=y 2 | # enable to use thread names 3 | CONFIG_THREAD_NAME=y 4 | -------------------------------------------------------------------------------- /platform.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nxplpc", 3 | "title": "NXP LPC", 4 | "description": "The NXP LPC is a family of 32-bit microcontroller integrated circuits by NXP Semiconductors. The LPC chips are grouped into related series that are based around the same 32-bit ARM processor core, such as the Cortex-M4F, Cortex-M3, Cortex-M0+, or Cortex-M0. Internally, each microcontroller consists of the processor core, static RAM memory, flash memory, debugging interface, and various peripherals.", 5 | "homepage": "http://www.nxp.com/products/microcontrollers/", 6 | "license": "Apache-2.0", 7 | "keywords": [ 8 | "dev-platform", 9 | "ARM", 10 | "Cortex-M", 11 | "NXP Semiconductors", 12 | "LPC" 13 | ], 14 | "engines": { 15 | "platformio": "^6" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "https://github.com/platformio/platform-nxplpc.git" 20 | }, 21 | "version": "10.0.0", 22 | "frameworks": { 23 | "mbed": { 24 | "package": "framework-mbed", 25 | "script": "builder/frameworks/mbed.py" 26 | }, 27 | "zephyr": { 28 | "package": "framework-zephyr", 29 | "script": "builder/frameworks/zephyr.py" 30 | } 31 | }, 32 | "packages": { 33 | "toolchain-gccarmnoneeabi": { 34 | "type": "toolchain", 35 | "owner": "platformio", 36 | "version": "~1.80201.0", 37 | "optionalVersions": [ 38 | "~1.90201.0" 39 | ] 40 | }, 41 | "framework-mbed": { 42 | "type": "framework", 43 | "optional": true, 44 | "owner": "platformio", 45 | "version": "~6.61700.0" 46 | }, 47 | "framework-zephyr": { 48 | "type": "framework", 49 | "optional": true, 50 | "owner": "platformio", 51 | "version": "~2.20701.0" 52 | }, 53 | "tool-openocd": { 54 | "type": "debugger", 55 | "optional": true, 56 | "owner": "platformio", 57 | "version": "~3.1200.0" 58 | }, 59 | "tool-pyocd": { 60 | "type": "debugger", 61 | "optional": true, 62 | "owner": "platformio", 63 | "version": "~1.2900.0" 64 | }, 65 | "tool-jlink": { 66 | "type": "uploader", 67 | "optional": true, 68 | "owner": "platformio", 69 | "version": "^1.63208.0" 70 | }, 71 | "tool-cmake": { 72 | "optional": true, 73 | "owner": "platformio", 74 | "version": "~3.21.0" 75 | }, 76 | "tool-dtc": { 77 | "optional": true, 78 | "owner": "platformio", 79 | "version": "~1.4.7" 80 | }, 81 | "tool-ninja": { 82 | "optional": true, 83 | "owner": "platformio", 84 | "version": "^1.7.0" 85 | }, 86 | "tool-gperf": { 87 | "optional": true, 88 | "owner": "platformio", 89 | "version": "^3.0.0" 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /platform.py: -------------------------------------------------------------------------------- 1 | # Copyright 2014-present PlatformIO 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import json 16 | import os 17 | import sys 18 | 19 | from platformio.public import PlatformBase 20 | 21 | IS_WINDOWS = sys.platform.startswith("win") 22 | 23 | 24 | class NxplpcPlatform(PlatformBase): 25 | 26 | def is_embedded(self): 27 | return True 28 | 29 | def configure_default_packages(self, variables, targets): 30 | if variables.get("board"): 31 | board = variables.get("board") 32 | upload_protocol = variables.get("upload_protocol", 33 | self.board_config( 34 | variables.get("board")).get( 35 | "upload.protocol", "")) 36 | if upload_protocol == "cmsis-dap": 37 | self.packages["tool-pyocd"]["type"] = "uploader" 38 | 39 | if "mbed" in variables.get("pioframework", []): 40 | self.packages["toolchain-gccarmnoneeabi"]["version"] = "~1.90201.0" 41 | 42 | if "zephyr" in variables.get("pioframework", []): 43 | for p in self.packages: 44 | if p in ("tool-cmake", "tool-dtc", "tool-ninja"): 45 | self.packages[p]["optional"] = False 46 | if not IS_WINDOWS: 47 | self.packages["tool-gperf"]["optional"] = False 48 | 49 | # configure J-LINK tool 50 | jlink_conds = [ 51 | "jlink" in variables.get(option, "") 52 | for option in ("upload_protocol", "debug_tool") 53 | ] 54 | if variables.get("board"): 55 | board_config = self.board_config(variables.get("board")) 56 | jlink_conds.extend([ 57 | "jlink" in board_config.get(key, "") 58 | for key in ("debug.default_tools", "upload.protocol") 59 | ]) 60 | jlink_pkgname = "tool-jlink" 61 | if not any(jlink_conds) and jlink_pkgname in self.packages: 62 | del self.packages[jlink_pkgname] 63 | 64 | return super().configure_default_packages(variables, targets) 65 | 66 | def get_boards(self, id_=None): 67 | result = super().get_boards(id_) 68 | if not result: 69 | return result 70 | if id_: 71 | return self._add_default_debug_tools(result) 72 | else: 73 | for key, value in result.items(): 74 | result[key] = self._add_default_debug_tools(result[key]) 75 | return result 76 | 77 | def _add_default_debug_tools(self, board): 78 | debug = board.manifest.get("debug", {}) 79 | upload_protocols = board.manifest.get("upload", {}).get( 80 | "protocols", []) 81 | if "tools" not in debug: 82 | debug["tools"] = {} 83 | 84 | # J-Link / BlackMagic Probe 85 | for link in ("blackmagic", "cmsis-dap", "jlink"): 86 | if link not in upload_protocols or link in debug["tools"]: 87 | continue 88 | 89 | if link == "blackmagic": 90 | debug["tools"]["blackmagic"] = { 91 | "hwids": [["0x1d50", "0x6018"]], 92 | "require_debug_port": True 93 | } 94 | 95 | elif link == "cmsis-dap": 96 | if debug.get("pyocd_target"): 97 | pyocd_target = debug.get("pyocd_target") 98 | assert pyocd_target 99 | debug["tools"][link] = { 100 | "onboard": True, 101 | "server": { 102 | "package": "tool-pyocd", 103 | "executable": "$PYTHONEXE", 104 | "arguments": [ 105 | "pyocd-gdbserver.py", 106 | "-t", 107 | pyocd_target 108 | ], 109 | "ready_pattern": "GDB server started on port" 110 | } 111 | } 112 | else: 113 | openocd_target = debug.get("openocd_target") 114 | assert openocd_target 115 | debug["tools"][link] = { 116 | "load_cmd": "preload", 117 | "onboard": True, 118 | "server": { 119 | "executable": "bin/openocd", 120 | "package": "tool-openocd", 121 | "arguments": [ 122 | "-s", "$PACKAGE_DIR/openocd/scripts", 123 | "-f", "interface/cmsis-dap.cfg", 124 | "-f", "target/%s.cfg" % openocd_target 125 | ] 126 | } 127 | } 128 | 129 | elif link == "jlink": 130 | assert debug.get("jlink_device"), ( 131 | "Missed J-Link Device ID for %s" % board.id) 132 | debug["tools"][link] = { 133 | "server": { 134 | "package": "tool-jlink", 135 | "arguments": [ 136 | "-singlerun", 137 | "-if", "SWD", 138 | "-select", "USB", 139 | "-device", debug.get("jlink_device"), 140 | "-port", "2331" 141 | ], 142 | "executable": ("JLinkGDBServerCL.exe" 143 | if IS_WINDOWS else 144 | "JLinkGDBServer") 145 | }, 146 | "onboard": link in debug.get("onboard_tools", []) 147 | } 148 | 149 | board.manifest["debug"] = debug 150 | return board 151 | 152 | def configure_debug_session(self, debug_config): 153 | if debug_config.speed: 154 | server_executable = (debug_config.server or {}).get("executable", "").lower() 155 | if "openocd" in server_executable: 156 | debug_config.server["arguments"].extend( 157 | ["-c", "adapter speed %s" % debug_config.speed] 158 | ) 159 | elif "jlink" in server_executable: 160 | debug_config.server["arguments"].extend( 161 | ["-speed", debug_config.speed] 162 | ) 163 | elif "pyocd" in debug_config.server["package"]: 164 | debug_config.server["arguments"].extend( 165 | ["--frequency", debug_config.speed] 166 | ) 167 | --------------------------------------------------------------------------------