diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..0d20b648 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..73092eab --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "builder/frameworks/mbed"] + path = builder/frameworks/mbed + url = https://ivankravets@github.com/platformio/builder-framework-mbed.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..336e9212 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,19 @@ +language: python +python: + - "2.7" + +env: + - PLATFORMIO_PROJECT_DIR=examples/arduino-blink + - PLATFORMIO_PROJECT_DIR=examples/arduino-external-libs + - PLATFORMIO_PROJECT_DIR=examples/arduino-internal-libs + - PLATFORMIO_PROJECT_DIR=examples/mbed-blink + - PLATFORMIO_PROJECT_DIR=examples/mbed-dsp + - PLATFORMIO_PROJECT_DIR=examples/mbed-serial + - PLATFORMIO_PROJECT_DIR=examples/simba-blink + +install: + - pip install -U https://github.com/platformio/platformio/archive/feature/platformio-30.zip + - platformio platform install file://. + +script: + - platformio run -d $PLATFORMIO_PROJECT_DIR diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..2f79a3b3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,174 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, +and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by +the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all +other entities that control, are controlled by, or are under common +control with that entity. For the purposes of this definition, +"control" means (i) the power, direct or indirect, to cause the +direction or management of such entity, whether by contract or +otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity +exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, +including but not limited to software source code, documentation +source, and configuration files. + +"Object" form shall mean any form resulting from mechanical +transformation or translation of a Source form, including but +not limited to compiled object code, generated documentation, +and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or +Object form, made available under the License, as indicated by a +copyright notice that is included in or attached to the work +(an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object +form, that is based on (or derived from) the Work and for which the +editorial revisions, annotations, elaborations, or other modifications +represent, as a whole, an original work of authorship. For the purposes +of this License, Derivative Works shall not include works that remain +separable from, or merely link (or bind by name) to the interfaces of, +the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including +the original version of the Work and any modifications or additions +to that Work or Derivative Works thereof, that is intentionally +submitted to Licensor for inclusion in the Work by the copyright owner +or by an individual or Legal Entity authorized to submit on behalf of +the copyright owner. For the purposes of this definition, "submitted" +means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, +and issue tracking systems that are managed by, or on behalf of, the +Licensor for the purpose of discussing and improving the Work, but +excluding communication that is conspicuously marked or otherwise +designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity +on behalf of whom a Contribution has been received by Licensor and +subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the +Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of +this License, each Contributor hereby grants to You a perpetual, +worldwide, non-exclusive, no-charge, royalty-free, irrevocable +(except as stated in this section) patent license to make, have made, +use, offer to sell, sell, import, and otherwise transfer the Work, +where such license applies only to those patent claims licensable +by such Contributor that are necessarily infringed by their +Contribution(s) alone or by combination of their Contribution(s) +with the Work to which such Contribution(s) was submitted. If You +institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work +or a Contribution incorporated within the Work constitutes direct +or contributory patent infringement, then any patent licenses +granted to You under this License for that Work shall terminate +as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the +Work or Derivative Works thereof in any medium, with or without +modifications, and in Source or Object form, provided that You +meet the following conditions: + +(a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + +(b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + +(c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + +(d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + +You may add Your own copyright statement to Your modifications and +may provide additional or different license terms and conditions +for use, reproduction, or distribution of Your modifications, or +for any such Derivative Works as a whole, provided Your use, +reproduction, and distribution of the Work otherwise complies with +the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, +any Contribution intentionally submitted for inclusion in the Work +by You to the Licensor shall be under the terms and conditions of +this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify +the terms of any separate license agreement you may have executed +with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade +names, trademarks, service marks, or product names of the Licensor, +except as required for reasonable and customary use in describing the +origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or +agreed to in writing, Licensor provides the Work (and each +Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +implied, including, without limitation, any warranties or conditions +of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A +PARTICULAR PURPOSE. You are solely responsible for determining the +appropriateness of using or redistributing the Work and assume any +risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, +whether in tort (including negligence), contract, or otherwise, +unless required by applicable law (such as deliberate and grossly +negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, +incidental, or consequential damages of any character arising as a +result of this License or out of the use or inability to use the +Work (including but not limited to damages for loss of goodwill, +work stoppage, computer failure or malfunction, or any and all +other commercial damages or losses), even if such Contributor +has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing +the Work or Derivative Works thereof, You may choose to offer, +and charge a fee for, acceptance of support, warranty, indemnity, +or other liability obligations and/or rights consistent with this +License. However, in accepting such obligations, You may act only +on Your own behalf and on Your sole responsibility, not on behalf +of any other Contributor, and only if You agree to indemnify, +defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason +of your accepting any such warranty or additional liability. diff --git a/README.md b/README.md index 6e0a6fff..0e7d1351 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,20 @@ -# platform-atmelsam -Atmel SAM: development platform for PlatformIO +# Atmel SAM: development platform for [PlatformIO](http://platformio.org) +[![Build Status](https://travis-ci.org/platformio/platform-atmelsam.svg?branch=develop)](https://travis-ci.org/platformio/platform-atmelsam) +[![Build status](https://ci.appveyor.com/api/projects/status/dj1c3b2d6fyxkoxq/branch/develop?svg=true)](https://ci.appveyor.com/project/ivankravets/platform-atmelsam/branch/develop) + +Atmel | SMART offers Flash- based ARM products based on the ARM Cortex-M0+, Cortex-M3 and Cortex-M4 architectures, ranging from 8KB to 2MB of Flash including a rich peripheral and feature mix. + +* [Home](http://platformio.org/platforms/atmelsam) (home page in PlatformIO Platform Registry) +* [Documentation](http://docs.platformio.org/en/latest/platforms/atmelsam.html) (advanced usage, packages, boards, frameworks, etc.) + +# Usage + +1. [Install PlatformIO CLI](http://docs.platformio.org/en/latest/installation.html) +2. Install Atmel SAM development platform: +```bash +# isntall the latest stable version +> platformio platform install atmelsam + +# install development version +> platformio platform install https://github.com/platformio/platform-atmelsam/archive/develop.zip +``` diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..d90a6811 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,20 @@ +build: off +environment: + + matrix: + - PLATFORMIO_PROJECT_DIR: "examples/arduino-blink" + - PLATFORMIO_PROJECT_DIR: "examples/arduino-external-libs" + - PLATFORMIO_PROJECT_DIR: "examples/arduino-internal-libs" + - PLATFORMIO_PROJECT_DIR: "examples/mbed-blink" + - PLATFORMIO_PROJECT_DIR: "examples/mbed-dsp" + - PLATFORMIO_PROJECT_DIR: "examples/mbed-serial" + - PLATFORMIO_PROJECT_DIR: "examples/simba-blink" + +install: +- cmd: git submodule update --init --recursive +- cmd: SET PATH=%PATH%;C:\Python27\Scripts +- cmd: pip install -U https://github.com/platformio/platformio/archive/feature/platformio-30.zip +- cmd: platformio platform install file://. + +test_script: +- cmd: platformio run -d %PLATFORMIO_PROJECT_DIR% diff --git a/boards/digix.json b/boards/digix.json new file mode 100644 index 00000000..160c3efb --- /dev/null +++ b/boards/digix.json @@ -0,0 +1,33 @@ +{ + "build": { + "core": "digispark_digix", + "cpu": "cortex-m3", + "extra_flags": "-w -D__SAM3X8E__ -DARDUINO_SAM_DIGIX -DARDUINO_ARCH_SAM", + "f_cpu": "84000000L", + "hwids": [ + [ + "0x16D0", + "0x078A" + ] + ], + "ldscript": "sam3x8e.ld", + "mcu": "at91sam3x8e", + "usb_product": "Digistump DigiX", + "variant": "digispark_digix" + }, + "frameworks": [ + "arduino" + ], + "name": "Digistump DigiX", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 28672, + "maximum_size": 524288, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "http://digistump.com/products/50", + "vendor": "Digistump" +} \ No newline at end of file diff --git a/boards/due.json b/boards/due.json new file mode 100644 index 00000000..58d46fcd --- /dev/null +++ b/boards/due.json @@ -0,0 +1,38 @@ +{ + "build": { + "core": "arduino", + "cpu": "cortex-m3", + "extra_flags": "-D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM", + "f_cpu": "84000000L", + "hwids": [ + [ + "0x2341", + "0x003D" + ], + [ + "0x2A03", + "0x003D" + ] + ], + "ldscript": "sam3x8e.ld", + "mcu": "sam3x8e", + "usb_product": "Arduino Due", + "variant": "arduino_due_x" + }, + "frameworks": [ + "arduino", + "simba" + ], + "name": "Arduino Due (Programming Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 524288, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": false + }, + "url": "http://www.arduino.org/products/boards/4-arduino-boards/arduino-due", + "vendor": "Arduino" +} \ No newline at end of file diff --git a/boards/dueUSB.json b/boards/dueUSB.json new file mode 100644 index 00000000..1ace14b4 --- /dev/null +++ b/boards/dueUSB.json @@ -0,0 +1,37 @@ +{ + "build": { + "core": "arduino", + "cpu": "cortex-m3", + "extra_flags": "-D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM", + "f_cpu": "84000000L", + "hwids": [ + [ + "0x2341", + "0x003E" + ], + [ + "0x2A03", + "0x003E" + ] + ], + "ldscript": "sam3x8e.ld", + "mcu": "sam3x8e", + "usb_product": "Arduino Due", + "variant": "arduino_due_x" + }, + "frameworks": [ + "arduino" + ], + "name": "Arduino Due (USB Native Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 524288, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "http://www.arduino.org/products/boards/4-arduino-boards/arduino-due", + "vendor": "Arduino" +} \ No newline at end of file diff --git a/boards/sainSmartDue.json b/boards/sainSmartDue.json new file mode 100644 index 00000000..81b27bf4 --- /dev/null +++ b/boards/sainSmartDue.json @@ -0,0 +1,33 @@ +{ + "build": { + "core": "arduino", + "cpu": "cortex-m3", + "extra_flags": "-D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM", + "f_cpu": "84000000L", + "hwids": [ + [ + "0x2341", + "0x003E" + ] + ], + "ldscript": "sam3x8e.ld", + "mcu": "at91sam3x8e", + "usb_product": "Arduino Due", + "variant": "arduino_due_x" + }, + "frameworks": [ + "arduino" + ], + "name": "SainSmart Due (Programming Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 524288, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": false + }, + "url": "http://www.sainsmart.com/arduino/control-boards/sainsmart-due-atmel-sam3x8e-arm-cortex-m3-board-black.html", + "vendor": "SainSmart" +} \ No newline at end of file diff --git a/boards/sainSmartDueUSB.json b/boards/sainSmartDueUSB.json new file mode 100644 index 00000000..ff843e42 --- /dev/null +++ b/boards/sainSmartDueUSB.json @@ -0,0 +1,33 @@ +{ + "build": { + "core": "arduino", + "cpu": "cortex-m3", + "extra_flags": "-D__SAM3X8E__ -DARDUINO_SAM_DUE -DARDUINO_ARCH_SAM", + "f_cpu": "84000000L", + "hwids": [ + [ + "0x2341", + "0x003E" + ] + ], + "ldscript": "sam3x8e.ld", + "mcu": "at91sam3x8e", + "usb_product": "Arduino Due", + "variant": "arduino_due_x" + }, + "frameworks": [ + "arduino" + ], + "name": "SainSmart Due (USB Native Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 524288, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "http://www.sainsmart.com/arduino/control-boards/sainsmart-due-atmel-sam3x8e-arm-cortex-m3-board-black.html", + "vendor": "SainSmart" +} \ No newline at end of file diff --git a/boards/samd21_xpro.json b/boards/samd21_xpro.json new file mode 100644 index 00000000..10a88d14 --- /dev/null +++ b/boards/samd21_xpro.json @@ -0,0 +1,17 @@ +{ + "build": { + "cpu": "cortex-m0plus", + "f_cpu": "48000000L", + "mcu": "atsamd21j18a" + }, + "frameworks": [ + "mbed" + ], + "name": "Atmel SAMD21-XPRO", + "upload": { + "maximum_ram_size": 32768, + "maximum_size": 262144 + }, + "url": "https://developer.mbed.org/platforms/SAMD21-XPRO/", + "vendor": "Atmel" +} \ No newline at end of file diff --git a/boards/saml21_xpro_b.json b/boards/saml21_xpro_b.json new file mode 100644 index 00000000..106f8b1d --- /dev/null +++ b/boards/saml21_xpro_b.json @@ -0,0 +1,17 @@ +{ + "build": { + "cpu": "cortex-m0plus", + "f_cpu": "48000000L", + "mcu": "atsaml21j18b" + }, + "frameworks": [ + "mbed" + ], + "name": "Atmel SAML21-XPRO-B", + "upload": { + "maximum_ram_size": 32768, + "maximum_size": 262144 + }, + "url": "https://developer.mbed.org/platforms/SAML21-XPRO/", + "vendor": "Atmel" +} \ No newline at end of file diff --git a/boards/samr21_xpro.json b/boards/samr21_xpro.json new file mode 100644 index 00000000..f733581d --- /dev/null +++ b/boards/samr21_xpro.json @@ -0,0 +1,17 @@ +{ + "build": { + "cpu": "cortex-m0plus", + "f_cpu": "48000000L", + "mcu": "atsamr21g18a" + }, + "frameworks": [ + "mbed" + ], + "name": "Atmel ATSAMR21-XPRO", + "upload": { + "maximum_ram_size": 32768, + "maximum_size": 262144 + }, + "url": "https://developer.mbed.org/platforms/SAMR21-XPRO/", + "vendor": "Atmel" +} \ No newline at end of file diff --git a/boards/zero.json b/boards/zero.json new file mode 100644 index 00000000..bd650b92 --- /dev/null +++ b/boards/zero.json @@ -0,0 +1,37 @@ +{ + "build": { + "core": "arduino_zero", + "cpu": "cortex-m0plus", + "extra_flags": "-DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", + "f_cpu": "48000000L", + "hwids": [ + [ + "0x2341", + "0x804D" + ], + [ + "0x03EB", + "0x2157" + ] + ], + "ldscript": "flash_with_bootloader.ld", + "mcu": "samd21g18a", + "usb_product": "Arduino Zero", + "variant": "arduino_zero" + }, + "frameworks": [ + "arduino" + ], + "name": "Arduino Zero (Programming Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "sam-ba", + "require_upload_port": false, + "use_1200bps_touch": false, + "wait_for_upload_port": false + }, + "url": "https://www.arduino.cc/en/Main/ArduinoBoardZero", + "vendor": "Arduino" +} \ No newline at end of file diff --git a/boards/zeroUSB.json b/boards/zeroUSB.json new file mode 100644 index 00000000..e3037702 --- /dev/null +++ b/boards/zeroUSB.json @@ -0,0 +1,41 @@ +{ + "build": { + "core": "arduino_zero", + "cpu": "cortex-m0plus", + "extra_flags": "-DARDUINO_SAMD_ZERO -DARDUINO_ARCH_SAMD -D__SAMD21G18A__", + "f_cpu": "48000000L", + "hwids": [ + [ + "0x2341", + "0x804D" + ], + [ + "0x2341", + "0x004D" + ], + [ + "0x2341", + "0x824D" + ] + ], + "ldscript": "flash_with_bootloader.ld", + "mcu": "samd21g18a", + "usb_product": "Arduino Zero", + "variant": "arduino_zero" + }, + "frameworks": [ + "arduino" + ], + "name": "Arduino Zero (USB Native Port)", + "upload": { + "disable_flushing": true, + "maximum_ram_size": 32768, + "maximum_size": 262144, + "protocol": "sam-ba", + "require_upload_port": true, + "use_1200bps_touch": true, + "wait_for_upload_port": true + }, + "url": "https://www.arduino.cc/en/Main/ArduinoBoardZero", + "vendor": "Arduino" +} \ No newline at end of file diff --git a/builder/frameworks/arduino.py b/builder/frameworks/arduino.py new file mode 100644 index 00000000..1f66d29c --- /dev/null +++ b/builder/frameworks/arduino.py @@ -0,0 +1,157 @@ +# Copyright 2014-present Ivan Kravets +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +Arduino + +Arduino Wiring-based Framework allows writing cross-platform software to +control devices attached to a wide range of Arduino boards to create all +kinds of creative coding, interactive objects, spaces or physical experiences. + +http://arduino.cc/en/Reference/HomePage +""" + +from os import walk +from os.path import isdir, isfile, join + +from SCons.Script import DefaultEnvironment + +env = DefaultEnvironment() +platform = env.DevPlatform() + +FRAMEWORK_DIR = platform.get_package_dir("framework-arduinosam") +FRAMEWORK_VERSION = platform.get_package_version("framework-arduinosam") +assert isdir(FRAMEWORK_DIR) + +ARDUINO_VERSION = int( + open(join(FRAMEWORK_DIR, "version.txt")).read().replace(".", "").strip()) + +# USB flags +ARDUINO_USBDEFINES = ["ARDUINO=%s" % FRAMEWORK_VERSION.split(".")[1]] +if "build.usb_product" in env.BoardConfig(): + ARDUINO_USBDEFINES += [ + "USB_VID=%s" % env.BoardConfig().get("build.hwids")[0][0], + "USB_PID=%s" % env.BoardConfig().get("build.hwids")[0][1], + 'USB_PRODUCT=\\"%s\\"' % ( + env.BoardConfig().get("build.usb_product", "").replace('"', "")), + 'USB_MANUFACTURER=\\"%s\\"' % ( + env.BoardConfig().get("vendor", "").replace('"', "")) + ] + +env.Append( + CPPDEFINES=ARDUINO_USBDEFINES, + + CPPPATH=[ + join("$BUILD_DIR", "FrameworkArduino"), + join("$BUILD_DIR", "FrameworkCMSISInc"), + join("$BUILD_DIR", "FrameworkLibSam"), + join("$BUILD_DIR", "FrameworkLibSam", "include"), + join("$BUILD_DIR", "FrameworkDeviceInc"), + join("$BUILD_DIR", "FrameworkDeviceInc", + env.BoardConfig().get("build.mcu", "")[3:], "include") + ], + + LIBPATH=[ + join(FRAMEWORK_DIR, "variants", + env.BoardConfig().get("build.variant"), "linker_scripts", "gcc") + ] +) + +env.VariantDirWrap( + join("$BUILD_DIR", "FrameworkCMSISInc"), + join(FRAMEWORK_DIR, "system", "CMSIS", "CMSIS", "Include") +) +env.VariantDirWrap( + join("$BUILD_DIR", "FrameworkDeviceInc"), + join(FRAMEWORK_DIR, "system", "CMSIS", "Device", "ATMEL") +) +env.VariantDirWrap( + join("$BUILD_DIR", "FrameworkLibSam"), + join(FRAMEWORK_DIR, "system", "libsam") +) + +env.VariantDirWrap( + join("$BUILD_DIR", "FrameworkArduinoInc"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) +) + + +# search relative includes in lib SAM directories +core_dir = join(FRAMEWORK_DIR, "system", "libsam") +for root, _, files in walk(core_dir): + for lib_file in files: + file_path = join(root, lib_file) + if not isfile(file_path): + continue + content = None + content_changed = False + with open(file_path) as fp: + content = fp.read() + if '#include "../' in content: + content_changed = True + content = content.replace('#include "../', '#include "') + if not content_changed: + continue + with open(file_path, "w") as fp: + fp.write(content) + +# +# Lookup for specific core's libraries +# + +BOARD_CORELIBDIRNAME = ( + "digispark" if "digispark" in env.BoardConfig().get("build.core", "") + else env.BoardConfig().get("build.core", "")) +env.Append( + LIBSOURCE_DIRS=[ + join(FRAMEWORK_DIR, "libraries", "__cores__", BOARD_CORELIBDIRNAME), + join(FRAMEWORK_DIR, "libraries") + ] +) + +# +# Target: Build Core Library +# + +libs = [] + +if "build.variant" in env.BoardConfig(): + env.Append( + CPPPATH=[ + join("$BUILD_DIR", "FrameworkArduinoVariant") + ] + ) + libs.append(env.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduinoVariant"), + join(FRAMEWORK_DIR, "variants", env.BoardConfig().get("build.variant")) + )) + +envsafe = env.Clone() + +libs.append(envsafe.BuildLibrary( + join("$BUILD_DIR", "FrameworkArduino"), + join(FRAMEWORK_DIR, "cores", env.BoardConfig().get("build.core")) +)) + +if "sam3x8e" in env.BoardConfig().get("build.mcu", ""): + env.Append( + LIBPATH=[ + join(FRAMEWORK_DIR, "variants", + env.BoardConfig().get("build.variant")) + ] + ) + + libs.append("sam_sam3x8e_gcc_rel") + +env.Prepend(LIBS=libs) diff --git a/builder/frameworks/mbed b/builder/frameworks/mbed new file mode 160000 index 00000000..7167dac0 --- /dev/null +++ b/builder/frameworks/mbed @@ -0,0 +1 @@ +Subproject commit 7167dac0023505f9a433a5e4215bdeaafa46d41f diff --git a/builder/frameworks/simba.py b/builder/frameworks/simba.py new file mode 100755 index 00000000..13b97cd6 --- /dev/null +++ b/builder/frameworks/simba.py @@ -0,0 +1,35 @@ +# Copyright 2014-present Ivan Kravets +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +"""Simba + +Simba is an RTOS and build framework. It aims to make embedded +programming easy and portable. + +http://simba-os.readthedocs.org + +""" + +from os.path import join + +from SCons.Script import DefaultEnvironment, SConscript + +env = DefaultEnvironment() + +env.Replace( + PLATFORMFW_DIR=env.DevPlatform().get_package_dir("framework-simba") +) + +SConscript( + [env.subst(join("$PLATFORMFW_DIR", "make", "platformio.sconscript"))]) diff --git a/builder/main.py b/builder/main.py new file mode 100644 index 00000000..9313c55f --- /dev/null +++ b/builder/main.py @@ -0,0 +1,261 @@ +# Copyright 2014-present Ivan Kravets +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" + Builder for Atmel SAM series of microcontrollers +""" + +from os.path import basename, join + +from SCons.Script import (COMMAND_LINE_TARGETS, AlwaysBuild, Builder, Default, + DefaultEnvironment) + +from platformio.util import get_serialports + + +def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621 + env.AutodetectUploadPort() + + board_type = env.subst("$BOARD") + if "zero" not in board_type: + env.Append( + UPLOADERFLAGS=[ + "-U", + "true" if ("usb" in board_type.lower( + ) or board_type == "digix") else "false" + ]) + + upload_options = {} + if "BOARD" in env: + upload_options = env.BoardConfig().get("upload", {}) + + if not upload_options.get("disable_flushing", False): + env.FlushSerialBuffer("$UPLOAD_PORT") + + before_ports = [i['port'] for i in get_serialports()] + + if upload_options.get("use_1200bps_touch", False): + env.TouchSerialPort("$UPLOAD_PORT", 1200) + + if upload_options.get("wait_for_upload_port", False): + env.Replace(UPLOAD_PORT=env.WaitForNewSerialPort(before_ports)) + + # use only port name for BOSSA + if "/" in env.subst("$UPLOAD_PORT"): + env.Replace(UPLOAD_PORT=basename(env.subst("$UPLOAD_PORT"))) + + +env = DefaultEnvironment() + +env.Replace( + AR="arm-none-eabi-ar", + AS="arm-none-eabi-as", + CC="arm-none-eabi-gcc", + CXX="arm-none-eabi-g++", + OBJCOPY="arm-none-eabi-objcopy", + RANLIB="arm-none-eabi-ranlib", + SIZETOOL="arm-none-eabi-size", + + ARFLAGS=["rcs"], + + ASFLAGS=["-x", "assembler-with-cpp"], + + CFLAGS=[ + "-std=gnu11" + ], + + CCFLAGS=[ + "-g", # include debugging info (so errors include line numbers) + "-Os", # optimize for size + "-ffunction-sections", # place each function in its own section + "-fdata-sections", + "-Wall", + "-mthumb", + "-nostdlib", + "--param", "max-inline-insns-single=500" + ], + + CXXFLAGS=[ + "-fno-rtti", + "-fno-exceptions", + "-std=gnu++11", + "-fno-threadsafe-statics" + ], + + CPPDEFINES=[ + "F_CPU=$BOARD_F_CPU", + "USBCON" + ], + + LINKFLAGS=[ + "-Os", + "-Wl,--gc-sections,--relax", + "-mthumb", + "-Wl,--check-sections", + "-Wl,--unresolved-symbols=report-all", + "-Wl,--warn-common", + "-Wl,--warn-section-align" + ], + + LIBS=["c", "gcc", "m"], + + SIZEPRINTCMD='$SIZETOOL -B -d $SOURCES', + + PROGNAME="firmware", + PROGSUFFIX=".elf" +) + +if "BOARD" in env: + env.Append( + CCFLAGS=[ + "-mcpu=%s" % env.BoardConfig().get("build.cpu") + ], + LINKFLAGS=[ + "-mcpu=%s" % env.BoardConfig().get("build.cpu") + ] + ) + +env.Append( + ASFLAGS=env.get("CCFLAGS", [])[:], + + BUILDERS=dict( + ElfToBin=Builder( + action=" ".join([ + "$OBJCOPY", + "-O", + "binary", + "$SOURCES", + "$TARGET"]), + suffix=".bin" + ), + ElfToHex=Builder( + action=" ".join([ + "$OBJCOPY", + "-O", + "ihex", + "-R", + ".eeprom", + "$SOURCES", + "$TARGET"]), + suffix=".hex" + ) + ) +) + +if env.subst("$BOARD") == "zero": + env.Replace( + UPLOADER="openocd", + UPLOADERFLAGS=[ + "-d2", + "-s", + join(env.DevPlatform().get_package_dir("tool-openocd") or "", + "share", "openocd", "scripts"), + "-f", + join( + env.DevPlatform().get_package_dir( + "framework-arduinosam") or "", + "variants", env.BoardConfig().get("build.variant"), + "openocd_scripts", + "%s.cfg" % env.BoardConfig().get("build.variant") + ), + "-c", "\"telnet_port", "disabled;", + "program", "{{$SOURCES}}", + "verify", "reset", "0x00002000;", "shutdown\"" + ], + UPLOADCMD='$UPLOADER $UPLOADERFLAGS' + ) +else: + env.Replace( + UPLOADER="bossac", + UPLOADERFLAGS=[ + "--info", + "--port", '"$UPLOAD_PORT"', + "--erase", + "--write", + "--verify", + "--reset", + "--debug" + ], + UPLOADCMD='$UPLOADER $UPLOADERFLAGS $SOURCES' + ) + +if "BOARD" in env and "sam3x8e" in env.BoardConfig().get("build.mcu", ""): + env.Append( + CPPDEFINES=[ + "printf=iprintf" + ], + + LINKFLAGS=[ + "-Wl,--entry=Reset_Handler", + "-Wl,--start-group" + ], + + UPLOADERFLAGS=[ + "--boot", + ] + + ) +elif "zero" in env.subst("$BOARD"): + env.Append( + LINKFLAGS=[ + "--specs=nosys.specs", + "--specs=nano.specs" + ] + ) + +# +# Target: Build executable and linkable firmware +# + +target_elf = env.BuildProgram() + +# +# Target: Build the .bin file +# + +if "uploadlazy" in COMMAND_LINE_TARGETS: + target_firm = join("$BUILD_DIR", "firmware.bin") +else: + target_firm = env.ElfToBin(join("$BUILD_DIR", "firmware"), target_elf) + +# +# Target: Print binary size +# + +target_size = env.Alias("size", target_elf, "$SIZEPRINTCMD") +AlwaysBuild(target_size) + +# +# Target: Upload by default .bin file +# + +if env.subst("$BOARD") == "zero": + upload = env.Alias(["upload", "uploadlazy"], target_firm, "$UPLOADCMD") +else: + upload = env.Alias(["upload", "uploadlazy"], target_firm, + [BeforeUpload, "$UPLOADCMD"]) + +AlwaysBuild(upload) + +# +# Target: Unit Testing +# + +AlwaysBuild(env.Alias("test", [target_firm, target_size])) + +# +# Setup default targets +# + +Default([target_firm, target_size]) diff --git a/examples/arduino-blink/.gitignore b/examples/arduino-blink/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/arduino-blink/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/arduino-blink/.travis.yml b/examples/arduino-blink/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/arduino-blink/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-blink/README.rst b/examples/arduino-blink/README.rst new file mode 100644 index 00000000..0bbd4875 --- /dev/null +++ b/examples/arduino-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/arduino-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e due + + # Upload firmware for the specific environment + > platformio run -e due --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-blink/lib/readme.txt b/examples/arduino-blink/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/arduino-blink/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/arduino-blink/platformio.ini b/examples/arduino-blink/platformio.ini new file mode 100644 index 00000000..ce20660f --- /dev/null +++ b/examples/arduino-blink/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:due] +platform = atmelsam +framework = arduino +board = due + +[env:zero] +platform = atmelsam +framework = arduino +board = zero + +[env:digix] +platform = atmelsam +framework = arduino +board = digix diff --git a/examples/arduino-blink/src/Blink.cpp b/examples/arduino-blink/src/Blink.cpp new file mode 100644 index 00000000..e99d8b08 --- /dev/null +++ b/examples/arduino-blink/src/Blink.cpp @@ -0,0 +1,25 @@ +/* + * Blink + * Turns on an LED on for one second, + * then off for one second, repeatedly. + */ + +#include + +void setup() +{ + // initialize LED digital pin as an output. + pinMode(LED_BUILTIN, OUTPUT); +} + +void loop() +{ + // turn the LED on (HIGH is the voltage level) + digitalWrite(LED_BUILTIN, HIGH); + // wait for a second + delay(1000); + // turn the LED off by making the voltage LOW + digitalWrite(LED_BUILTIN, LOW); + // wait for a second + delay(1000); +} diff --git a/examples/arduino-external-libs/.gitignore b/examples/arduino-external-libs/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/arduino-external-libs/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/arduino-external-libs/.travis.yml b/examples/arduino-external-libs/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/arduino-external-libs/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-external-libs/README.rst b/examples/arduino-external-libs/README.rst new file mode 100644 index 00000000..d3eb8a0c --- /dev/null +++ b/examples/arduino-external-libs/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/arduino-external-libs + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e due + + # Upload firmware for the specific environment + > platformio run -e due --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-external-libs/lib/BMP180/SFE_BMP180.cpp b/examples/arduino-external-libs/lib/BMP180/SFE_BMP180.cpp new file mode 100644 index 00000000..4383fc55 --- /dev/null +++ b/examples/arduino-external-libs/lib/BMP180/SFE_BMP180.cpp @@ -0,0 +1,387 @@ +/* + SFE_BMP180.cpp + Bosch BMP180 pressure sensor library for the Arduino microcontroller + Mike Grusin, SparkFun Electronics + + Uses floating-point equations from the Weather Station Data Logger project + http://wmrx00.sourceforge.net/ + http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf + + Forked from BMP085 library by M.Grusin + + version 1.0 2013/09/20 initial version + + Our example code uses the "beerware" license. You can do anything + you like with this code. No really, anything. If you find it useful, + buy me a (root) beer someday. +*/ + +#include +#include +#include +#include + + +SFE_BMP180::SFE_BMP180() +// Base library type +{ +} + + +char SFE_BMP180::begin() +// Initialize library for subsequent pressure measurements +{ + double c3,c4,b1; + + // Start up the Arduino's "wire" (I2C) library: + + Wire.begin(); + + // The BMP180 includes factory calibration data stored on the device. + // Each device has different numbers, these must be retrieved and + // used in the calculations when taking pressure measurements. + + // Retrieve calibration data from device: + + if (readInt(0xAA,AC1) && + readInt(0xAC,AC2) && + readInt(0xAE,AC3) && + readUInt(0xB0,AC4) && + readUInt(0xB2,AC5) && + readUInt(0xB4,AC6) && + readInt(0xB6,VB1) && + readInt(0xB8,VB2) && + readInt(0xBA,MB) && + readInt(0xBC,MC) && + readInt(0xBE,MD)) + { + + // All reads completed successfully! + + // If you need to check your math using known numbers, + // you can uncomment one of these examples. + // (The correct results are commented in the below functions.) + + // Example from Bosch datasheet + // AC1 = 408; AC2 = -72; AC3 = -14383; AC4 = 32741; AC5 = 32757; AC6 = 23153; + // B1 = 6190; B2 = 4; MB = -32768; MC = -8711; MD = 2868; + + // Example from http://wmrx00.sourceforge.net/Arduino/BMP180-Calcs.pdf + // AC1 = 7911; AC2 = -934; AC3 = -14306; AC4 = 31567; AC5 = 25671; AC6 = 18974; + // VB1 = 5498; VB2 = 46; MB = -32768; MC = -11075; MD = 2432; + + /* + Serial.print("AC1: "); Serial.println(AC1); + Serial.print("AC2: "); Serial.println(AC2); + Serial.print("AC3: "); Serial.println(AC3); + Serial.print("AC4: "); Serial.println(AC4); + Serial.print("AC5: "); Serial.println(AC5); + Serial.print("AC6: "); Serial.println(AC6); + Serial.print("VB1: "); Serial.println(VB1); + Serial.print("VB2: "); Serial.println(VB2); + Serial.print("MB: "); Serial.println(MB); + Serial.print("MC: "); Serial.println(MC); + Serial.print("MD: "); Serial.println(MD); + */ + + // Compute floating-point polynominals: + + c3 = 160.0 * pow(2,-15) * AC3; + c4 = pow(10,-3) * pow(2,-15) * AC4; + b1 = pow(160,2) * pow(2,-30) * VB1; + c5 = (pow(2,-15) / 160) * AC5; + c6 = AC6; + mc = (pow(2,11) / pow(160,2)) * MC; + md = MD / 160.0; + x0 = AC1; + x1 = 160.0 * pow(2,-13) * AC2; + x2 = pow(160,2) * pow(2,-25) * VB2; + y0 = c4 * pow(2,15); + y1 = c4 * c3; + y2 = c4 * b1; + p0 = (3791.0 - 8.0) / 1600.0; + p1 = 1.0 - 7357.0 * pow(2,-20); + p2 = 3038.0 * 100.0 * pow(2,-36); + + /* + Serial.println(); + Serial.print("c3: "); Serial.println(c3); + Serial.print("c4: "); Serial.println(c4); + Serial.print("c5: "); Serial.println(c5); + Serial.print("c6: "); Serial.println(c6); + Serial.print("b1: "); Serial.println(b1); + Serial.print("mc: "); Serial.println(mc); + Serial.print("md: "); Serial.println(md); + Serial.print("x0: "); Serial.println(x0); + Serial.print("x1: "); Serial.println(x1); + Serial.print("x2: "); Serial.println(x2); + Serial.print("y0: "); Serial.println(y0); + Serial.print("y1: "); Serial.println(y1); + Serial.print("y2: "); Serial.println(y2); + Serial.print("p0: "); Serial.println(p0); + Serial.print("p1: "); Serial.println(p1); + Serial.print("p2: "); Serial.println(p2); + */ + + // Success! + return(1); + } + else + { + // Error reading calibration data; bad component or connection? + return(0); + } +} + + +char SFE_BMP180::readInt(char address, int &value) +// Read a signed integer (two bytes) from device +// address: register to start reading (plus subsequent register) +// value: external variable to store data (function modifies value) +{ + unsigned char data[2]; + + data[0] = address; + if (readBytes(data,2)) + { + value = (((int)data[0]<<8)|(int)data[1]); + //if (*value & 0x8000) *value |= 0xFFFF0000; // sign extend if negative + return(1); + } + value = 0; + return(0); +} + + +char SFE_BMP180::readUInt(char address, unsigned int &value) +// Read an unsigned integer (two bytes) from device +// address: register to start reading (plus subsequent register) +// value: external variable to store data (function modifies value) +{ + unsigned char data[2]; + + data[0] = address; + if (readBytes(data,2)) + { + value = (((unsigned int)data[0]<<8)|(unsigned int)data[1]); + return(1); + } + value = 0; + return(0); +} + + +char SFE_BMP180::readBytes(unsigned char *values, char length) +// Read an array of bytes from device +// values: external array to hold data. Put starting register in values[0]. +// length: number of bytes to read +{ + char x; + + Wire.beginTransmission(BMP180_ADDR); + Wire.write(values[0]); + _error = Wire.endTransmission(); + if (_error == 0) + { + Wire.requestFrom(BMP180_ADDR,length); + while(Wire.available() != length) ; // wait until bytes are ready + for(x=0;x= 100 +#include "Arduino.h" +#else +#include "WProgram.h" +#endif + +class SFE_BMP180 +{ + public: + SFE_BMP180(); // base type + + char begin(); + // call pressure.begin() to initialize BMP180 before use + // returns 1 if success, 0 if failure (bad component or I2C bus shorted?) + + char startTemperature(void); + // command BMP180 to start a temperature measurement + // returns (number of ms to wait) for success, 0 for fail + + char getTemperature(double &T); + // return temperature measurement from previous startTemperature command + // places returned value in T variable (deg C) + // returns 1 for success, 0 for fail + + char startPressure(char oversampling); + // command BMP180 to start a pressure measurement + // oversampling: 0 - 3 for oversampling value + // returns (number of ms to wait) for success, 0 for fail + + char getPressure(double &P, double &T); + // return absolute pressure measurement from previous startPressure command + // note: requires previous temperature measurement in variable T + // places returned value in P variable (mbar) + // returns 1 for success, 0 for fail + + double sealevel(double P, double A); + // convert absolute pressure to sea-level pressure (as used in weather data) + // P: absolute pressure (mbar) + // A: current altitude (meters) + // returns sealevel pressure in mbar + + double altitude(double P, double P0); + // convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.) + // P: absolute pressure (mbar) + // P0: fixed baseline pressure (mbar) + // returns signed altitude in meters + + char getError(void); + // If any library command fails, you can retrieve an extended + // error code using this command. Errors are from the wire library: + // 0 = Success + // 1 = Data too long to fit in transmit buffer + // 2 = Received NACK on transmit of address + // 3 = Received NACK on transmit of data + // 4 = Other error + + private: + + char readInt(char address, int &value); + // read an signed int (16 bits) from a BMP180 register + // address: BMP180 register address + // value: external signed int for returned value (16 bits) + // returns 1 for success, 0 for fail, with result in value + + char readUInt(char address, unsigned int &value); + // read an unsigned int (16 bits) from a BMP180 register + // address: BMP180 register address + // value: external unsigned int for returned value (16 bits) + // returns 1 for success, 0 for fail, with result in value + + char readBytes(unsigned char *values, char length); + // read a number of bytes from a BMP180 register + // values: array of char with register address in first location [0] + // length: number of bytes to read back + // returns 1 for success, 0 for fail, with read bytes in values[] array + + char writeBytes(unsigned char *values, char length); + // write a number of bytes to a BMP180 register (and consecutive subsequent registers) + // values: array of char with register address in first location [0] + // length: number of bytes to write + // returns 1 for success, 0 for fail + + int AC1,AC2,AC3,VB1,VB2,MB,MC,MD; + unsigned int AC4,AC5,AC6; + double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2; + char _error; +}; + +#define BMP180_ADDR 0x77 // 7-bit address + +#define BMP180_REG_CONTROL 0xF4 +#define BMP180_REG_RESULT 0xF6 + +#define BMP180_COMMAND_TEMPERATURE 0x2E +#define BMP180_COMMAND_PRESSURE0 0x34 +#define BMP180_COMMAND_PRESSURE1 0x74 +#define BMP180_COMMAND_PRESSURE2 0xB4 +#define BMP180_COMMAND_PRESSURE3 0xF4 + +#endif diff --git a/examples/arduino-external-libs/lib/readme.txt b/examples/arduino-external-libs/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/arduino-external-libs/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/arduino-external-libs/platformio.ini b/examples/arduino-external-libs/platformio.ini new file mode 100644 index 00000000..ce20660f --- /dev/null +++ b/examples/arduino-external-libs/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:due] +platform = atmelsam +framework = arduino +board = due + +[env:zero] +platform = atmelsam +framework = arduino +board = zero + +[env:digix] +platform = atmelsam +framework = arduino +board = digix diff --git a/examples/arduino-external-libs/src/BMP180_altitude_example.ino b/examples/arduino-external-libs/src/BMP180_altitude_example.ino new file mode 100644 index 00000000..c06ce1bb --- /dev/null +++ b/examples/arduino-external-libs/src/BMP180_altitude_example.ino @@ -0,0 +1,169 @@ +/* SFE_BMP180 altitude example sketch + +This sketch shows how to use the Bosch BMP180 pressure sensor +as an altimiter. +https://www.sparkfun.com/products/11824 + +Like most pressure sensors, the BMP180 measures absolute pressure. +Since absolute pressure varies with altitude, you can use the pressure +to determine your altitude. + +Because pressure also varies with weather, you must first take a pressure +reading at a known baseline altitude. Then you can measure variations +from that pressure + +Hardware connections: + +- (GND) to GND ++ (VDD) to 3.3V + +(WARNING: do not connect + to 5V or the sensor will be damaged!) + +You will also need to connect the I2C pins (SCL and SDA) to your +Arduino. The pins are different on different Arduinos: + +Any Arduino pins labeled: SDA SCL +Uno, Redboard, Pro: A4 A5 +Mega2560, Due: 20 21 +Leonardo: 2 3 + +Leave the IO (VDDIO) pin unconnected. This pin is for connecting +the BMP180 to systems with lower logic levels such as 1.8V + +Have fun! -Your friends at SparkFun. + +The SFE_BMP180 library uses floating-point equations developed by the +Weather Station Data Logger project: http://wmrx00.sourceforge.net/ + +Our example code uses the "beerware" license. You can do anything +you like with this code. No really, anything. If you find it useful, +buy me a beer someday. + +V10 Mike Grusin, SparkFun Electronics 10/24/2013 +*/ + +// Your sketch must #include this library, and the Wire library. +// (Wire is a standard library included with Arduino.): + +#include +#include +#include + +// You will need to create an SFE_BMP180 object, here called "pressure": + +SFE_BMP180 pressure; + +double baseline; // baseline pressure + +void setup() +{ + Serial.begin(9600); + Serial.println("REBOOT"); + + // Initialize the sensor (it is important to get calibration values stored on the device). + + if (pressure.begin()) + Serial.println("BMP180 init success"); + else + { + // Oops, something went wrong, this is usually a connection problem, + // see the comments at the top of this sketch for the proper connections. + + Serial.println("BMP180 init fail (disconnected?)\n\n"); + while(1); // Pause forever. + } + + // Get the baseline pressure: + + baseline = getPressure(); + + Serial.print("baseline pressure: "); + Serial.print(baseline); + Serial.println(" mb"); +} + +void loop() +{ + double a,P; + + // Get a new pressure reading: + + P = getPressure(); + + // Show the relative altitude difference between + // the new reading and the baseline reading: + + a = pressure.altitude(P,baseline); + + Serial.print("relative altitude: "); + if (a >= 0.0) Serial.print(" "); // add a space for positive numbers + Serial.print(a,1); + Serial.print(" meters, "); + if (a >= 0.0) Serial.print(" "); // add a space for positive numbers + Serial.print(a*3.28084,0); + Serial.println(" feet"); + + delay(500); +} + + +double getPressure() +{ + char status; + double T,P,p0,a; + + // You must first get a temperature measurement to perform a pressure reading. + + // Start a temperature measurement: + // If request is successful, the number of ms to wait is returned. + // If request is unsuccessful, 0 is returned. + + status = pressure.startTemperature(); + if (status != 0) + { + // Wait for the measurement to complete: + + delay(status); + + // Retrieve the completed temperature measurement: + // Note that the measurement is stored in the variable T. + // Use '&T' to provide the address of T to the function. + // Function returns 1 if successful, 0 if failure. + + status = pressure.getTemperature(T); + if (status != 0) + { + // Start a pressure measurement: + // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait). + // If request is successful, the number of ms to wait is returned. + // If request is unsuccessful, 0 is returned. + + status = pressure.startPressure(3); + if (status != 0) + { + // Wait for the measurement to complete: + delay(status); + + // Retrieve the completed pressure measurement: + // Note that the measurement is stored in the variable P. + // Use '&P' to provide the address of P. + // Note also that the function requires the previous temperature measurement (T). + // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.) + // Function returns 1 if successful, 0 if failure. + + status = pressure.getPressure(P,T); + if (status != 0) + { + return(P); + } + else Serial.println("error retrieving pressure measurement\n"); + } + else Serial.println("error starting pressure measurement\n"); + } + else Serial.println("error retrieving temperature measurement\n"); + } + else Serial.println("error starting temperature measurement\n"); +} + + + diff --git a/examples/arduino-internal-libs/.gitignore b/examples/arduino-internal-libs/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/arduino-internal-libs/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/arduino-internal-libs/.travis.yml b/examples/arduino-internal-libs/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/arduino-internal-libs/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/arduino-internal-libs/README.rst b/examples/arduino-internal-libs/README.rst new file mode 100644 index 00000000..2a57bf2a --- /dev/null +++ b/examples/arduino-internal-libs/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/arduino-internal-libs + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e due + + # Upload firmware for the specific environment + > platformio run -e due --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/arduino-internal-libs/lib/readme.txt b/examples/arduino-internal-libs/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/arduino-internal-libs/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/arduino-internal-libs/platformio.ini b/examples/arduino-internal-libs/platformio.ini new file mode 100644 index 00000000..ce20660f --- /dev/null +++ b/examples/arduino-internal-libs/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:due] +platform = atmelsam +framework = arduino +board = due + +[env:zero] +platform = atmelsam +framework = arduino +board = zero + +[env:digix] +platform = atmelsam +framework = arduino +board = digix diff --git a/examples/arduino-internal-libs/src/BarometricPressureSensor.ino b/examples/arduino-internal-libs/src/BarometricPressureSensor.ino new file mode 100644 index 00000000..50ca8a2d --- /dev/null +++ b/examples/arduino-internal-libs/src/BarometricPressureSensor.ino @@ -0,0 +1,144 @@ +/* + SCP1000 Barometric Pressure Sensor Display + + Shows the output of a Barometric Pressure Sensor on a + Uses the SPI library. For details on the sensor, see: + http://www.sparkfun.com/commerce/product_info.php?products_id=8161 + http://www.vti.fi/en/support/obsolete_products/pressure_sensors/ + + This sketch adapted from Nathan Seidle's SCP1000 example for PIC: + http://www.sparkfun.com/datasheets/Sensors/SCP1000-Testing.zip + + Circuit: + SCP1000 sensor attached to pins 6, 7, 10 - 13: + DRDY: pin 6 + CSB: pin 7 + MOSI: pin 11 + MISO: pin 12 + SCK: pin 13 + + created 31 July 2010 + modified 14 August 2010 + by Tom Igoe + */ + +#include +// the sensor communicates using SPI, so include the library: +#include + +//Sensor's memory register addresses: +const int PRESSURE = 0x1F; //3 most significant bits of pressure +const int PRESSURE_LSB = 0x20; //16 least significant bits of pressure +const int TEMPERATURE = 0x21; //16 bit temperature reading +const byte READ = 0b11111100; // SCP1000's read command +const byte WRITE = 0b00000010; // SCP1000's write command + +// pins used for the connection with the sensor +// the other you need are controlled by the SPI library): +const int dataReadyPin = 6; +const int chipSelectPin = 7; + +void setup() { + Serial.begin(9600); + + // start the SPI library: + SPI.begin(); + + // initalize the data ready and chip select pins: + pinMode(dataReadyPin, INPUT); + pinMode(chipSelectPin, OUTPUT); + + //Configure SCP1000 for low noise configuration: + writeRegister(0x02, 0x2D); + writeRegister(0x01, 0x03); + writeRegister(0x03, 0x02); + // give the sensor time to set up: + delay(100); +} + +void loop() { + //Select High Resolution Mode + writeRegister(0x03, 0x0A); + + // don't do anything until the data ready pin is high: + if (digitalRead(dataReadyPin) == HIGH) { + //Read the temperature data + int tempData = readRegister(0x21, 2); + + // convert the temperature to celsius and display it: + float realTemp = (float)tempData / 20.0; + Serial.print("Temp[C]="); + Serial.print(realTemp); + + + //Read the pressure data highest 3 bits: + byte pressure_data_high = readRegister(0x1F, 1); + pressure_data_high &= 0b00000111; //you only needs bits 2 to 0 + + //Read the pressure data lower 16 bits: + unsigned int pressure_data_low = readRegister(0x20, 2); + //combine the two parts into one 19-bit number: + long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4; + + // display the temperature: + Serial.println("\tPressure [Pa]=" + String(pressure)); + } +} + +//Read from or write to register from the SCP1000: +unsigned int readRegister(byte thisRegister, int bytesToRead ) { + byte inByte = 0; // incoming byte from the SPI + unsigned int result = 0; // result to return + Serial.print(thisRegister, BIN); + Serial.print("\t"); + // SCP1000 expects the register name in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the address and the command into one byte + byte dataToSend = thisRegister & READ; + Serial.println(thisRegister, BIN); + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + // send the device the register you want to read: + SPI.transfer(dataToSend); + // send a value of 0 to read the first byte returned: + result = SPI.transfer(0x00); + // decrement the number of bytes left to read: + bytesToRead--; + // if you still have another byte to read: + if (bytesToRead > 0) { + // shift the first byte left, then get the second byte: + result = result << 8; + inByte = SPI.transfer(0x00); + // combine the byte you just got with the previous one: + result = result | inByte; + // decrement the number of bytes left to read: + bytesToRead--; + } + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); + // return the result: + return(result); +} + + +//Sends a write command to SCP1000 + +void writeRegister(byte thisRegister, byte thisValue) { + + // SCP1000 expects the register address in the upper 6 bits + // of the byte. So shift the bits left by two bits: + thisRegister = thisRegister << 2; + // now combine the register address and the command into one byte: + byte dataToSend = thisRegister | WRITE; + + // take the chip select low to select the device: + digitalWrite(chipSelectPin, LOW); + + SPI.transfer(dataToSend); //Send register location + SPI.transfer(thisValue); //Send value to record into register + + // take the chip select high to de-select: + digitalWrite(chipSelectPin, HIGH); +} + diff --git a/examples/mbed-blink/.gitignore b/examples/mbed-blink/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/mbed-blink/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/mbed-blink/.travis.yml b/examples/mbed-blink/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/mbed-blink/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/mbed-blink/README.rst b/examples/mbed-blink/README.rst new file mode 100644 index 00000000..1f93d65b --- /dev/null +++ b/examples/mbed-blink/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/mbed-blink + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e samd21_xpro + + # Upload firmware for the specific environment + > platformio run -e samd21_xpro --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/mbed-blink/lib/readme.txt b/examples/mbed-blink/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/mbed-blink/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/mbed-blink/platformio.ini b/examples/mbed-blink/platformio.ini new file mode 100644 index 00000000..2b9c3af9 --- /dev/null +++ b/examples/mbed-blink/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:samd21_xpro] +platform = atmelsam +framework = mbed +board = samd21_xpro + +[env:saml21_xpro_b] +platform = atmelsam +framework = mbed +board = saml21_xpro_b + +[env:samr21_xpro] +platform = atmelsam +framework = mbed +board = samr21_xpro diff --git a/examples/mbed-blink/src/main.cpp b/examples/mbed-blink/src/main.cpp new file mode 100644 index 00000000..8247a2e9 --- /dev/null +++ b/examples/mbed-blink/src/main.cpp @@ -0,0 +1,12 @@ +#include "mbed.h" + +DigitalOut myled(LED1); + +int main() { + while(1) { + myled = 1; + wait(1); + myled = 0; + wait(1); + } +} \ No newline at end of file diff --git a/examples/mbed-dsp/.gitignore b/examples/mbed-dsp/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/mbed-dsp/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/mbed-dsp/.travis.yml b/examples/mbed-dsp/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/mbed-dsp/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/mbed-dsp/README.rst b/examples/mbed-dsp/README.rst new file mode 100644 index 00000000..4f7ff238 --- /dev/null +++ b/examples/mbed-dsp/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/mbed-dsp + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e samd21_xpro + + # Upload firmware for the specific environment + > platformio run -e samd21_xpro --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/mbed-dsp/lib/readme.txt b/examples/mbed-dsp/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/mbed-dsp/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/mbed-dsp/platformio.ini b/examples/mbed-dsp/platformio.ini new file mode 100644 index 00000000..2b9c3af9 --- /dev/null +++ b/examples/mbed-dsp/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:samd21_xpro] +platform = atmelsam +framework = mbed +board = samd21_xpro + +[env:saml21_xpro_b] +platform = atmelsam +framework = mbed +board = saml21_xpro_b + +[env:samr21_xpro] +platform = atmelsam +framework = mbed +board = samr21_xpro diff --git a/examples/mbed-dsp/src/data.cpp b/examples/mbed-dsp/src/data.cpp new file mode 100644 index 00000000..d946b36b --- /dev/null +++ b/examples/mbed-dsp/src/data.cpp @@ -0,0 +1,94 @@ +#include "arm_math.h" + +/* ---------------------------------------------------------------------- +** Test input signal contains 1000Hz + 15000 Hz +** ------------------------------------------------------------------- */ + +float32_t testInput_f32_1kHz_15kHz[320] = +{ ++0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, +-0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, ++0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, ++0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, ++0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, ++0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, +-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, +-0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, ++0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, ++0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, +-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, ++0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +-0.8660254038f, -0.4619397663f, -1.3194792169f, -1.1827865776f, -0.5000000000f, -1.1827865776f, -1.3194792169f, -0.4619397663f, +-0.8660254038f, -1.2552931065f, -0.3535533906f, -0.4174197128f, -1.0000000000f, -0.1913417162f, +0.0947343455f, -0.5924659585f, +-0.0000000000f, +0.5924659585f, -0.0947343455f, +0.1913417162f, +1.0000000000f, +0.4174197128f, +0.3535533906f, +1.2552931065f, ++0.8660254038f, +0.4619397663f, +1.3194792169f, +1.1827865776f, +0.5000000000f, +1.1827865776f, +1.3194792169f, +0.4619397663f, ++0.8660254038f, +1.2552931065f, +0.3535533906f, +0.4174197128f, +1.0000000000f, +0.1913417162f, -0.0947343455f, +0.5924659585f, ++0.0000000000f, -0.5924659585f, +0.0947343455f, -0.1913417162f, -1.0000000000f, -0.4174197128f, -0.3535533906f, -1.2552931065f, +}; + +float32_t refOutput[320] = +{ ++0.0000000000f, -0.0010797829f, -0.0007681386f, -0.0001982932f, +0.0000644313f, +0.0020854271f, +0.0036891871f, +0.0015855941f, +-0.0026280805f, -0.0075907658f, -0.0119390538f, -0.0086665968f, +0.0088981202f, +0.0430539279f, +0.0974468742f, +0.1740405600f, ++0.2681416601f, +0.3747720089f, +0.4893362230f, +0.6024154672f, +0.7058740791f, +0.7968348987f, +0.8715901940f, +0.9277881093f, ++0.9682182661f, +0.9934674267f, +1.0012052245f, +0.9925859371f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, -0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, -0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f, ++0.7085021596f, +0.6100062330f, +0.5012752767f, +0.3834386057f, +0.2592435399f, +0.1309866321f, +0.0000000000f, -0.1309866321f, +-0.2592435399f, -0.3834386057f, -0.5012752767f, -0.6100062330f, -0.7085021596f, -0.7952493046f, -0.8679010068f, -0.9257026822f, +-0.9681538347f, -0.9936657199f, -1.0019733630f, -0.9936657199f, -0.9681538347f, -0.9257026822f, -0.8679010068f, -0.7952493046f, +-0.7085021596f, -0.6100062330f, -0.5012752767f, -0.3834386057f, -0.2592435399f, -0.1309866321f, +0.0000000000f, +0.1309866321f, ++0.2592435399f, +0.3834386057f, +0.5012752767f, +0.6100062330f, +0.7085021596f, +0.7952493046f, +0.8679010068f, +0.9257026822f, ++0.9681538347f, +0.9936657199f, +1.0019733630f, +0.9936657199f, +0.9681538347f, +0.9257026822f, +0.8679010068f, +0.7952493046f +}; + diff --git a/examples/mbed-dsp/src/main.cpp b/examples/mbed-dsp/src/main.cpp new file mode 100644 index 00000000..f6bdb4b7 --- /dev/null +++ b/examples/mbed-dsp/src/main.cpp @@ -0,0 +1,65 @@ +#include "arm_math.h" +#include "math_helper.h" +#include + +#define BLOCK_SIZE 32 +#define NUM_BLOCKS 10 + +#define TEST_LENGTH_SAMPLES (BLOCK_SIZE * NUM_BLOCKS) + +#define SNR_THRESHOLD_F32 140.0f +#define NUM_TAPS 29 + +/* ------------------------------------------------------------------- + * The input signal and reference output (computed with MATLAB) + * are defined externally in arm_fir_lpf_data.c. + * ------------------------------------------------------------------- */ +extern float32_t testInput_f32_1kHz_15kHz[TEST_LENGTH_SAMPLES]; +extern float32_t refOutput[TEST_LENGTH_SAMPLES]; + +/* ------------------------------------------------------------------- + * Declare State buffer of size (numTaps + blockSize - 1) + * ------------------------------------------------------------------- */ +static float32_t firStateF32[BLOCK_SIZE + NUM_TAPS - 1]; + +/* ---------------------------------------------------------------------- + * FIR Coefficients buffer generated using fir1() MATLAB function. + * fir1(28, 6/24) + * ------------------------------------------------------------------- */ +const float32_t firCoeffs32[NUM_TAPS] = { + -0.0018225230f, -0.0015879294f, +0.0000000000f, +0.0036977508f, +0.0080754303f, + +0.0085302217f, -0.0000000000f, -0.0173976984f, -0.0341458607f, -0.0333591565f, + +0.0000000000f, +0.0676308395f, +0.1522061835f, +0.2229246956f, +0.2504960933f, + +0.2229246956f, +0.1522061835f, +0.0676308395f, +0.0000000000f, -0.0333591565f, + -0.0341458607f, -0.0173976984f, -0.0000000000f, +0.0085302217f, +0.0080754303f, + +0.0036977508f, +0.0000000000f, -0.0015879294f, -0.0018225230f +}; + +/* ---------------------------------------------------------------------- + * FIR LPF Example + * ------------------------------------------------------------------- */ +int main(void) { + /* Call FIR init function to initialize the instance structure. */ + arm_fir_instance_f32 S; + arm_fir_init_f32(&S, NUM_TAPS, (float32_t *)&firCoeffs32[0], &firStateF32[0], BLOCK_SIZE); + + /* ---------------------------------------------------------------------- + * Call the FIR process function for every blockSize samples + * ------------------------------------------------------------------- */ + for (uint32_t i=0; i < NUM_BLOCKS; i++) { + float32_t* signal = testInput_f32_1kHz_15kHz + (i * BLOCK_SIZE); + arm_fir_f32(&S, signal, signal, BLOCK_SIZE); + } + + /* ---------------------------------------------------------------------- + * Compare the generated output against the reference output computed + * in MATLAB. + * ------------------------------------------------------------------- */ + float32_t snr = arm_snr_f32(refOutput, testInput_f32_1kHz_15kHz, TEST_LENGTH_SAMPLES); + printf("snr: %f\n\r", snr); + if (snr < SNR_THRESHOLD_F32) { + printf("Failed\n\r"); + } else { + printf("Success\n\r"); + } +} diff --git a/examples/mbed-serial/.gitignore b/examples/mbed-serial/.gitignore new file mode 100644 index 00000000..5402c188 --- /dev/null +++ b/examples/mbed-serial/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/mbed-serial/.travis.yml b/examples/mbed-serial/.travis.yml new file mode 100644 index 00000000..b6361844 --- /dev/null +++ b/examples/mbed-serial/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choose one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/mbed-serial/README.rst b/examples/mbed-serial/README.rst new file mode 100644 index 00000000..064edb64 --- /dev/null +++ b/examples/mbed-serial/README.rst @@ -0,0 +1,38 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/mbed-serial + + # Build project + > platformio run + + # Upload firmware + > platformio run --target upload + + # Build specific environment + > platformio run -e samd21_xpro + + # Upload firmware for the specific environment + > platformio run -e samd21_xpro --target upload + + # Clean build files + > platformio run --target clean diff --git a/examples/mbed-serial/lib/readme.txt b/examples/mbed-serial/lib/readme.txt new file mode 100644 index 00000000..607a92af --- /dev/null +++ b/examples/mbed-serial/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organized `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/mbed-serial/platformio.ini b/examples/mbed-serial/platformio.ini new file mode 100644 index 00000000..2b9c3af9 --- /dev/null +++ b/examples/mbed-serial/platformio.ini @@ -0,0 +1,33 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:samd21_xpro] +platform = atmelsam +framework = mbed +board = samd21_xpro + +[env:saml21_xpro_b] +platform = atmelsam +framework = mbed +board = saml21_xpro_b + +[env:samr21_xpro] +platform = atmelsam +framework = mbed +board = samr21_xpro diff --git a/examples/mbed-serial/src/main.cpp b/examples/mbed-serial/src/main.cpp new file mode 100644 index 00000000..132ba174 --- /dev/null +++ b/examples/mbed-serial/src/main.cpp @@ -0,0 +1,10 @@ +#include "mbed.h" + +Serial pc(USBTX, USBRX); // tx, rx + +int main() { + pc.printf("Hello World!\n\r"); + while(1) { + pc.putc(pc.getc() + 1); // echo input back to terminal + } +} \ No newline at end of file diff --git a/examples/simba-blink/.gitignore b/examples/simba-blink/.gitignore new file mode 100755 index 00000000..5402c188 --- /dev/null +++ b/examples/simba-blink/.gitignore @@ -0,0 +1,3 @@ +.pioenvs +.clang_complete +.gcc-flags.json diff --git a/examples/simba-blink/.skiptest b/examples/simba-blink/.skiptest new file mode 100644 index 00000000..e69de29b diff --git a/examples/simba-blink/.travis.yml b/examples/simba-blink/.travis.yml new file mode 100755 index 00000000..62dedda8 --- /dev/null +++ b/examples/simba-blink/.travis.yml @@ -0,0 +1,65 @@ +# Continuous Integration (CI) is the practice, in software +# engineering, of merging all developer working copies with a shared mainline +# several times a day < http://docs.platformio.org/en/latest/ci/index.html > +# +# Documentation: +# +# * Travis CI Embedded Builds with PlatformIO +# < https://docs.travis-ci.com/user/integration/platformio/ > +# +# * PlatformIO integration with Travis CI +# < http://docs.platformio.org/en/latest/ci/travis.html > +# +# * User Guide for `platformio ci` command +# < http://docs.platformio.org/en/latest/userguide/cmd_ci.html > +# +# +# Please choice one of the following templates (proposed below) and uncomment +# it (remove "# " before each line) or use own configuration according to the +# Travis CI documentation (see above). +# + + +# +# Template #1: General project. Test it using existing `platformio.ini`. +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# install: +# - pip install -U platformio +# +# script: +# - platformio run + + +# +# Template #2: The project is intended to by used as a library with examples +# + +# language: python +# python: +# - "2.7" +# +# sudo: false +# cache: +# directories: +# - "~/.platformio" +# +# env: +# - PLATFORMIO_CI_SRC=path/to/test/file.c +# - PLATFORMIO_CI_SRC=examples/file.ino +# - PLATFORMIO_CI_SRC=path/to/test/directory +# +# install: +# - pip install -U platformio +# +# script: +# - platformio ci --lib="." --board=ID_1 --board=ID_2 --board=ID_N diff --git a/examples/simba-blink/README.rst b/examples/simba-blink/README.rst new file mode 100755 index 00000000..92f6ead5 --- /dev/null +++ b/examples/simba-blink/README.rst @@ -0,0 +1,29 @@ +.. Copyright 2014-present Ivan Kravets + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +How to build PlatformIO based project +===================================== + +1. `Install PlatformIO `_ +2. Download `development platform with examples `_ +3. Extract ZIP archive +4. Run these commands: + +.. code-block:: bash + + # Change directory to example + > cd platform-atmelsam/examples/simba-blink + + # Process example project + > platformio run + + # Upload firmware + > platformio run --target upload diff --git a/examples/simba-blink/lib/readme.txt b/examples/simba-blink/lib/readme.txt new file mode 100755 index 00000000..b06c9408 --- /dev/null +++ b/examples/simba-blink/lib/readme.txt @@ -0,0 +1,38 @@ + +This directory is intended for the project specific (private) libraries. +PlatformIO will compile them to static libraries and link to executable file. + +The source code of each library should be placed in separate directory, like +"lib/private_lib/[here are source files]". + +For example, see how can be organised `Foo` and `Bar` libraries: + +|--lib +| |--Bar +| | |--docs +| | |--examples +| | |--src +| | |- Bar.c +| | |- Bar.h +| |--Foo +| | |- Foo.c +| | |- Foo.h +| |- readme.txt --> THIS FILE +|- platformio.ini +|--src + |- main.c + +Then in `src/main.c` you should use: + +#include +#include + +// rest H/C/CPP code + +PlatformIO will find your libraries automatically, configure preprocessor's +include paths and build them. + +See additional options for PlatformIO Library Dependency Finder `lib_*`: + +http://docs.platformio.org/en/latest/projectconf.html#lib-install + diff --git a/examples/simba-blink/platformio.ini b/examples/simba-blink/platformio.ini new file mode 100755 index 00000000..b61c7b18 --- /dev/null +++ b/examples/simba-blink/platformio.ini @@ -0,0 +1,23 @@ +# +# Project Configuration File +# +# A detailed documentation with the EXAMPLES is located here: +# http://docs.platformio.org/en/latest/projectconf.html +# + +# A sign `#` at the beginning of the line indicates a comment +# Comment lines are ignored. + +# Simple and base environment +# [env:mybaseenv] +# platform = %INSTALLED_PLATFORM_NAME_HERE% +# framework = +# board = +# +# Automatic targets - enable auto-uploading +# targets = upload + +[env:due] +platform = atmelsam +framework = simba +board = due diff --git a/examples/simba-blink/src/main.c b/examples/simba-blink/src/main.c new file mode 100755 index 00000000..73656817 --- /dev/null +++ b/examples/simba-blink/src/main.c @@ -0,0 +1,42 @@ +/** + * @file main.c + * @version 1.0 + * + * @section License + * Copyright (C) 2015-2016, Erik Moqvist + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * This file is part of the Simba project. + */ + +#include "simba.h" + +int main() +{ + struct pin_driver_t led; + + /* Start the kernel. */ + sys_start(); + + /* Initialize the LED pin as output. */ + pin_init(&led, &pin_led_dev, PIN_OUTPUT); + + while (1) { + /* Wait for a seconds. */ + thrd_usleep(1000000); + + /* Toggle the LED on/off. */ + pin_toggle(&led); + } + + return (0); +} diff --git a/ldscripts/sam3x8e.ld b/ldscripts/sam3x8e.ld new file mode 100755 index 00000000..53f2b5f1 --- /dev/null +++ b/ldscripts/sam3x8e.ld @@ -0,0 +1,146 @@ +/* ---------------------------------------------------------------------------- + * SAM Software Package License + * ---------------------------------------------------------------------------- + * Copyright (c) 2012, Atmel Corporation + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following condition is met: + * + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the disclaimer below. + * + * Atmel's name may not be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE + * DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, + * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * ---------------------------------------------------------------------------- + */ + +OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm") +OUTPUT_ARCH(arm) +SEARCH_DIR(.) + +/* Memory Spaces Definitions */ +MEMORY +{ + rom (rx) : ORIGIN = 0x00080000, LENGTH = 0x00080000 /* Flash, 512K */ + sram0 (rwx) : ORIGIN = 0x20000000, LENGTH = 0x00010000 /* sram0, 64K */ + sram1 (rwx) : ORIGIN = 0x20080000, LENGTH = 0x00008000 /* sram1, 32K */ + ram (rwx) : ORIGIN = 0x20070000, LENGTH = 0x00018000 /* sram, 96K */ +} + +/* Section Definitions */ +SECTIONS +{ + .text : + { + . = ALIGN(4); + _sfixed = .; + KEEP(*(.vectors .vectors.*)) + *(.text .text.* .gnu.linkonce.t.*) + *(.glue_7t) *(.glue_7) + *(.rodata .rodata* .gnu.linkonce.r.*) + *(.ARM.extab* .gnu.linkonce.armextab.*) + + /* Support C constructors, and C destructors in both user code + and the C library. This also provides support for C++ code. */ + . = ALIGN(4); + KEEP(*(.init)) + . = ALIGN(4); + __preinit_array_start = .; + KEEP (*(.preinit_array)) + __preinit_array_end = .; + + . = ALIGN(4); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + + . = ALIGN(0x4); + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*crtend.o(.ctors)) + + . = ALIGN(4); + KEEP(*(.fini)) + + . = ALIGN(4); + __fini_array_start = .; + KEEP (*(.fini_array)) + KEEP (*(SORT(.fini_array.*))) + __fini_array_end = .; + + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE (*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*crtend.o(.dtors)) + + . = ALIGN(4); + _efixed = .; /* End of text section */ + } > rom + + /* .ARM.exidx is sorted, so has to go in its own output section. */ + PROVIDE_HIDDEN (__exidx_start = .); + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > rom + PROVIDE_HIDDEN (__exidx_end = .); + + . = ALIGN(4); + _etext = .; + + .relocate : AT (_etext) + { + . = ALIGN(4); + _srelocate = .; + *(.ramfunc .ramfunc.*); + *(.data .data.*); + . = ALIGN(4); + _erelocate = .; + } > ram + + /* .bss section which is used for uninitialized data */ + .bss ALIGN(4) (NOLOAD) : + { + . = ALIGN(4); + _sbss = . ; + _szero = .; + *(.bss .bss.*) + *(COMMON) + . = ALIGN(4); + _ebss = . ; + _ezero = .; + } > ram + + . = ALIGN(4); + _end = . ; + + /* .stack_dummy section doesn't contains any symbols. It is only + used for linker to calculate size of stack sections, and assign + values to stack symbols later */ + .stack_dummy : + { + *(.stack*) + } > ram + + /* Set stack top to end of ram, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(ram) + LENGTH(ram); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(_sstack = __StackLimit); + PROVIDE(_estack = __StackTop); +} diff --git a/platform.json b/platform.json new file mode 100644 index 00000000..e9d153d4 --- /dev/null +++ b/platform.json @@ -0,0 +1,70 @@ +{ + "name": "atmelsam", + "title": "Atmel SAM", + "description": "Atmel | SMART offers Flash- based ARM products based on the ARM Cortex-M0+, Cortex-M3 and Cortex-M4 architectures, ranging from 8KB to 2MB of Flash including a rich peripheral and feature mix.", + "url": "http://www.atmel.com/products/microcontrollers/arm/default.aspx", + "homepage": "http://platformio.org/platforms/atmelsam", + "license": { + "type": "Apache-2.0", + "url": "http://opensource.org/licenses/apache2.0.php" + }, + "engines": { + "platformio": "~3.0.0", + "scons": ">=2.3.0,<2.6.0" + }, + "repository": { + "type": "git", + "url": "https://github.com/platformio/platform-atmelsam.git" + }, + "version": "0.0.0", + "packageRepositories": [ + "https://dl.bintray.com/platformio/dl-packages/manifest.json", + "https://sourceforge.net/projects/platformio-storage/files/packages/manifest.json/download", + "http://dl.platformio.org/packages/manifest.json" + ], + "frameworks": { + "arduino": { + "package": "framework-arduinosam", + "script": "builder/frameworks/arduino.py" + }, + "mbed": { + "package": "framework-mbed", + "script": "builder/frameworks/mbed/mbed.py" + }, + "simba": { + "package": "framework-simba", + "script": "builder/frameworks/simba.py" + } + }, + "packages": { + "toolchain-gccarmnoneeabi": { + "type": "toolchain", + "version": ">=1.40803.0,<=1.40804.0" + }, + "framework-arduinosam": { + "type": "framework", + "optional": true, + "version": "~1.10607.0" + }, + "framework-mbed": { + "type": "framework", + "optional": true, + "version": "~1.117.0" + }, + "framework-simba": { + "type": "framework", + "optional": true, + "version": "~1.500.0" + }, + "tool-bossac": { + "type": "uploader", + "optional": true, + "version": "~1.10500.0" + }, + "tool-openocd": { + "type": "uploader", + "optional": true, + "version": "~1.900.0" + } + } +} diff --git a/platform.py b/platform.py new file mode 100644 index 00000000..7c9fb6b5 --- /dev/null +++ b/platform.py @@ -0,0 +1,29 @@ +# Copyright 2014-present Ivan Kravets +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from platformio.managers.platform import BasePlatform + + +class AtmelsamPlatform(BasePlatform): + + def configure_default_packages(self, variables, targets): + if variables.get("board"): + disable_tool = "tool-openocd" + if variables.get("board") == "zero": + disable_tool = "tool-bossac" + if disable_tool in self.get_packages(): + del self.get_packages()[disable_tool] + + return BasePlatform.configure_default_packages( + self, variables, targets)