Initial support for RP2040

This commit is contained in:
valeros 2021-04-22 17:43:48 +03:00
parent f25997ba12
commit aa251bf2e1
26 changed files with 41808 additions and 0 deletions

31
.github/workflows/examples.yml vendored Normal file
View File

@ -0,0 +1,31 @@
name: Examples
on: [push, pull_request]
jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-16.04, windows-latest, macos-latest]
python-version: [3.7]
example:
- "examples/arduino-blink"
- "examples/arduino-external-libs"
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
with:
submodules: "recursive"
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U https://github.com/platformio/platformio/archive/develop.zip
platformio platform install file://.
- name: Build examples
run: |
platformio run -d ${{ matrix.example }}

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
*.pyc
.piolibdeps
.pio

3
.gitmodules vendored Normal file
View File

@ -0,0 +1,3 @@
[submodule "builder/frameworks/arduino/mbed-core"]
path = builder/frameworks/arduino/mbed-core
url = https://github.com/platformio/builder-framework-arduino-core-mbed.git

35
README.md Normal file
View File

@ -0,0 +1,35 @@
# Raspberry Pi RP2040: development platform for [PlatformIO](https://platformio.org)
[![Build Status](https://github.com/platformio/platform-raspberrypi/workflows/Examples/badge.svg)](https://github.com/platformio/platform-raspberrypi/actions)
RP2040 is a low-cost, high-performance microcontroller device with with a large on-chip memory, symmetric dual-core processor complex, deterministic bus fabric, and rich peripheral set augmented with a unique Programmable I/O (PIO) subsystem, it provides professional users with unrivalled power and flexibility.
* [Home](http://platformio.org/platforms/raspberrypi) (home page in PlatformIO Platform Registry)
* [Documentation](http://docs.platformio.org/page/platforms/raspberrypi.html) (advanced usage, packages, boards, frameworks, etc.)
# Usage
1. [Install PlatformIO](http://platformio.org)
2. Create PlatformIO project and configure a platform option in [platformio.ini](http://docs.platformio.org/page/projectconf.html) file:
## Stable version
```ini
[env:stable]
platform = raspberrypi
board = ...
...
```
## Development version
```ini
[env:development]
platform = https://github.com/platformio/platform-raspberrypi.git
board = ...
...
```
# Configuration
Please navigate to [documentation](http://docs.platformio.org/page/platforms/raspberrypi.html).

View File

@ -0,0 +1,44 @@
{
"build": {
"core": "arduino",
"cpu": "cortex-m0plus",
"extra_flags": "-D NANO_RP2040_CONNECT -DARDUINO_ARCH_RP2040",
"f_cpu": "133000000L",
"hwids": [
[
"0x2341",
"0x005E"
],
[
"0x2341",
"0x805E"
]
],
"mcu": "rp2040",
"variant": "NANO_RP2040_CONNECT"
},
"debug": {
"jlink_device": "RP2040_M0_0",
"openocd_target": "rp2040.cfg",
"svd_path": "rp2040.svd"
},
"frameworks": [
"arduino"
],
"name": "Arduino Nano RP2040 Connect",
"upload": {
"maximum_ram_size": 270336,
"maximum_size": 2097152,
"require_upload_port": true,
"native_usb": true,
"use_1200bps_touch": true,
"wait_for_upload_port": false,
"protocols": [
"cmsis-dap",
"raspberrypi-swd",
"stlink"
]
},
"url": "https://blog.arduino.cc/2021/01/20/welcome-raspberry-pi-to-the-world-of-microcontrollers/",
"vendor": "Arduino"
}

40
boards/pico.json Normal file
View File

@ -0,0 +1,40 @@
{
"build": {
"core": "arduino",
"cpu": "cortex-m0plus",
"extra_flags": "-D RASPBERRY_PI_PICO -DARDUINO_ARCH_RP2040",
"f_cpu": "133000000L",
"hwids": [
[
"0x2E8A",
"0x00C0"
]
],
"mcu": "rp2040",
"variant": "RASPBERRY_PI_PICO"
},
"debug": {
"jlink_device": "RP2040_M0_0",
"openocd_target": "rp2040.cfg",
"svd_path": "rp2040.svd"
},
"frameworks": [
"arduino"
],
"name": "Raspberry Pi Pico",
"upload": {
"maximum_ram_size": 270336,
"maximum_size": 2097152,
"require_upload_port": true,
"native_usb": true,
"use_1200bps_touch": true,
"wait_for_upload_port": false,
"protocols": [
"cmsis-dap",
"raspberrypi-swd",
"stlink"
]
},
"url": "https://www.raspberrypi.org/products/raspberry-pi-pico/",
"vendor": "Raspberry Pi"
}

View File

@ -0,0 +1,66 @@
# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# 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.
#
# Default flags for bare-metal programming (without any framework layers)
#
from SCons.Script import DefaultEnvironment
env = DefaultEnvironment()
env.Append(
ASFLAGS=["-x", "assembler-with-cpp"],
CCFLAGS=[
"-Os", # optimize for size
"-ffunction-sections", # place each function in its own section
"-fdata-sections",
"-Wall",
"-mthumb",
"-nostdlib"
],
CXXFLAGS=[
"-fno-rtti",
"-fno-exceptions"
],
CPPDEFINES=[
("F_CPU", "$BOARD_F_CPU")
],
LINKFLAGS=[
"-Os",
"-Wl,--gc-sections,--relax",
"-mthumb",
"--specs=nano.specs",
"--specs=nosys.specs"
],
LIBS=["c", "gcc", "m", "stdc++", "nosys"]
)
if "BOARD" in env:
env.Append(
CCFLAGS=[
"-mcpu=%s" % env.BoardConfig().get("build.cpu")
],
LINKFLAGS=[
"-mcpu=%s" % env.BoardConfig().get("build.cpu")
]
)
# copy CCFLAGS to ASFLAGS (-x assembler-with-cpp mode)
env.Append(ASFLAGS=env.get("CCFLAGS", [])[:])

@ -0,0 +1 @@
Subproject commit ceb4f608f9b4834ac4fa5472e1db2a2c2f9d216e

222
builder/main.py Normal file
View File

@ -0,0 +1,222 @@
# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# 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.
import sys
from platform import system
from os import makedirs
from os.path import isdir, join
from platformio.util import get_serial_ports
from SCons.Script import (ARGUMENTS, COMMAND_LINE_TARGETS, AlwaysBuild,
Builder, Default, DefaultEnvironment)
def BeforeUpload(target, source, env): # pylint: disable=W0613,W0621
upload_options = {}
if "BOARD" in env:
upload_options = env.BoardConfig().get("upload", {})
env.AutodetectUploadPort()
before_ports = get_serial_ports()
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))
env = DefaultEnvironment()
platform = env.PioPlatform()
board = env.BoardConfig()
env.Replace(
AR="arm-none-eabi-ar",
AS="arm-none-eabi-as",
CC="arm-none-eabi-gcc",
CXX="arm-none-eabi-g++",
GDB="arm-none-eabi-gdb",
OBJCOPY="arm-none-eabi-objcopy",
RANLIB="arm-none-eabi-ranlib",
SIZETOOL="arm-none-eabi-size",
ARFLAGS=["rc"],
SIZEPROGREGEXP=r"^(?:\.text|\.data|\.rodata|\.text.align|\.ARM.exidx)\s+(\d+).*",
SIZEDATAREGEXP=r"^(?:\.data|\.bss|\.noinit)\s+(\d+).*",
SIZECHECKCMD="$SIZETOOL -A -d $SOURCES",
SIZEPRINTCMD='$SIZETOOL -B -d $SOURCES',
PROGSUFFIX=".elf"
)
# Allow user to override via pre:script
if env.get("PROGNAME", "program") == "program":
env.Replace(PROGNAME="firmware")
env.Append(
BUILDERS=dict(
ElfToBin=Builder(
action=env.VerboseAction(" ".join([
"$OBJCOPY",
"-O",
"binary",
"$SOURCES",
"$TARGET"
]), "Building $TARGET"),
suffix=".bin"
),
ElfToHex=Builder(
action=env.VerboseAction(" ".join([
"$OBJCOPY",
"-O",
"ihex",
"-R",
".eeprom",
"$SOURCES",
"$TARGET"
]), "Building $TARGET"),
suffix=".hex"
)
)
)
if not env.get("PIOFRAMEWORK"):
env.SConscript("frameworks/_bare.py")
#
# Target: Build executable and linkable firmware
#
target_elf = None
if "nobuild" in COMMAND_LINE_TARGETS:
target_elf = join("$BUILD_DIR", "${PROGNAME}.elf")
target_firm = join("$BUILD_DIR", "${PROGNAME}.bin")
else:
target_elf = env.BuildProgram()
target_firm = env.ElfToBin(join("$BUILD_DIR", "${PROGNAME}"), target_elf)
env.Depends(target_firm, "checkprogsize")
AlwaysBuild(env.Alias("nobuild", target_firm))
target_buildprog = env.Alias("buildprog", target_firm, target_firm)
#
# Target: Print binary size
#
target_size = env.Alias(
"size", target_elf,
env.VerboseAction("$SIZEPRINTCMD", "Calculating size $SOURCE"))
AlwaysBuild(target_size)
#
# Target: Upload by default .bin file
#
debug_tools = env.BoardConfig().get("debug.tools", {})
upload_protocol = env.subst("$UPLOAD_PROTOCOL") or "picotool"
upload_actions = []
upload_source = target_firm
if upload_protocol == "mbed":
upload_actions = [
env.VerboseAction(env.AutodetectUploadPort, "Looking for upload disk..."),
env.VerboseAction(env.UploadToDisk, "Uploading $SOURCE")
]
elif upload_protocol == "picotool":
env.Replace(
UPLOADER=join(platform.get_package_dir("tool-rp2040tools") or "", "rp2040load"),
UPLOADERFLAGS=["-v", "-D"],
UPLOADCMD="$UPLOADER $UPLOADERFLAGS $SOURCES"
)
upload_actions = [
env.VerboseAction(BeforeUpload, "Looking for upload port..."),
env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE"),
]
upload_source = target_elf
elif upload_protocol.startswith("jlink"):
def _jlink_cmd_script(env, source):
build_dir = env.subst("$BUILD_DIR")
if not isdir(build_dir):
makedirs(build_dir)
script_path = join(build_dir, "upload.jlink")
commands = [
"h",
"loadbin %s, %s" % (source, board.get(
"upload.offset_address", "0x0")),
"r",
"q"
]
with open(script_path, "w") as fp:
fp.write("\n".join(commands))
return script_path
env.Replace(
__jlink_cmd_script=_jlink_cmd_script,
UPLOADER="JLink.exe" if system() == "Windows" else "JLinkExe",
UPLOADERFLAGS=[
"-device", board.get("debug", {}).get("jlink_device"),
"-speed", env.GetProjectOption("debug_speed", "4000"),
"-if", ("jtag" if upload_protocol == "jlink-jtag" else "swd"),
"-autoconnect", "1",
"-NoGui", "1"
],
UPLOADCMD='$UPLOADER $UPLOADERFLAGS -CommanderScript "${__jlink_cmd_script(__env__, SOURCE)}"'
)
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
elif upload_protocol in debug_tools:
openocd_args = [
"-d%d" % (2 if int(ARGUMENTS.get("PIOVERBOSE", 0)) else 1)
]
openocd_args.extend(
debug_tools.get(upload_protocol).get("server").get("arguments", []))
if env.GetProjectOption("debug_speed"):
openocd_args.extend(
["-c", "adapter speed %s" % env.GetProjectOption("debug_speed")]
)
openocd_args.extend([
"-c", "program {$SOURCE} %s verify reset; shutdown;" %
board.get("upload.offset_address", "")
])
openocd_args = [
f.replace("$PACKAGE_DIR", platform.get_package_dir(
"tool-openocd-raspberrypi") or "")
for f in openocd_args
]
env.Replace(
UPLOADER="openocd",
UPLOADERFLAGS=openocd_args,
UPLOADCMD="$UPLOADER $UPLOADERFLAGS")
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
# custom upload tool
elif upload_protocol == "custom":
upload_actions = [env.VerboseAction("$UPLOADCMD", "Uploading $SOURCE")]
if not upload_actions:
sys.stderr.write("Warning! Unknown upload protocol %s\n" % upload_protocol)
AlwaysBuild(env.Alias("upload", upload_source, upload_actions))
#
# Default targets
#
Default([target_buildprog, target_size])

1
examples/arduino-blink/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.pio

View File

@ -0,0 +1,32 @@
.. Copyright 2014-present PlatformIO <contact@platformio.org>
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 Core <http://docs.platformio.org/page/core.html>`_
2. Download `development platform with examples <https://github.com/platformio/platform-raspberrypi/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:
.. code-block:: bash
# Change directory to example
> cd platform-raspberrypi/examples/arduino-blink
# Build project
> platformio run
# Upload firmware
> platformio run --target upload
# Clean build files
> platformio run --target clean

View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -0,0 +1,18 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter, extra scripting
; Upload options: custom port, speed and extra flags
; Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env]
platform = raspberrypi
framework = arduino
[env:pico]
board = pico
[env:nanorp2040connect]
board = nanorp2040connect

View File

@ -0,0 +1,15 @@
#include <Arduino.h>
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

View File

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html

View File

@ -0,0 +1 @@
.pio

View File

@ -0,0 +1,38 @@
.. Copyright 2014-present PlatformIO <contact@platformio.org>
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 Core <http://docs.platformio.org/page/core.html>`_
2. Download `development platform with examples <https://github.com/platformio/platform-raspberrypi/archive/develop.zip>`_
3. Extract ZIP archive
4. Run these commands:
.. code-block:: bash
# Change directory to example
> cd platform-raspberrypi/examples/arduino-external-libs
# Build project
> platformio run
# Upload firmware
> platformio run --target upload
# Build specific environment
> platformio run -e pico
# Upload firmware for the specific environment
> platformio run -e pico --target upload
# Clean build files
> platformio run --target clean

View File

@ -0,0 +1,39 @@
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html

View File

@ -0,0 +1,46 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.
The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").
For example, see a structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- README --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
and a contents of `src/main.c`:
```
#include <Foo.h>
#include <Bar.h>
int main (void)
{
...
}
```
PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -0,0 +1,23 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter, extra scripting
; Upload options: custom port, speed and extra flags
; Library options: dependencies, extra library storages
;
; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html
[env]
platform = raspberrypi
framework = arduino
lib_deps =
SPI
adafruit/Adafruit 9DOF
arduino-libraries/Ethernet
[env:pico]
board = pico
[env:nanorp2040connect]
board = nanorp2040connect

View File

@ -0,0 +1,109 @@
#include <Arduino.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include <Adafruit_9DOF.h>
/* Assign a unique ID to the sensors */
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(30301);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(30302);
Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
void displaySensorDetails(void)
{
sensor_t sensor;
accel.getSensor(&sensor);
Serial.println(F("----------- ACCELEROMETER ----------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" m/s^2"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" m/s^2"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" m/s^2"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
gyro.getSensor(&sensor);
Serial.println(F("------------- GYROSCOPE -----------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" rad/s"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" rad/s"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" rad/s"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
mag.getSensor(&sensor);
Serial.println(F("----------- MAGNETOMETER -----------"));
Serial.print (F("Sensor: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F(" uT"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F(" uT"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F(" uT"));
Serial.println(F("------------------------------------"));
Serial.println(F(""));
delay(500);
}
void setup(void)
{
Serial.begin(115200);
Serial.println(F("Adafruit 9DOF Tester")); Serial.println("");
/* Initialise the sensors */
if(!accel.begin())
{
/* There was a problem detecting the ADXL345 ... check your connections */
Serial.println(F("Ooops, no LSM303 detected ... Check your wiring!"));
while(1);
}
if(!mag.begin())
{
/* There was a problem detecting the LSM303 ... check your connections */
Serial.println("Ooops, no LSM303 detected ... Check your wiring!");
while(1);
}
if(!gyro.begin())
{
/* There was a problem detecting the L3GD20 ... check your connections */
Serial.print("Ooops, no L3GD20 detected ... Check your wiring or I2C ADDR!");
while(1);
}
/* Display some basic information on this sensor */
displaySensorDetails();
}
void loop(void)
{
/* Get a new sensor event */
sensors_event_t event;
/* Display the results (acceleration is measured in m/s^2) */
accel.getEvent(&event);
Serial.print(F("ACCEL "));
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.acceleration.z); Serial.print(" ");Serial.println("m/s^2 ");
/* Display the results (magnetic vector values are in micro-Tesla (uT)) */
mag.getEvent(&event);
Serial.print(F("MAG "));
Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print(" ");Serial.println("uT");
/* Display the results (gyrocope values in rad/s) */
gyro.getEvent(&event);
Serial.print(F("GYRO "));
Serial.print("X: "); Serial.print(event.gyro.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print(" ");
Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print(" ");Serial.println("rad/s ");
Serial.println(F(""));
delay(1000);
}

View File

@ -0,0 +1,11 @@
This directory is intended for PIO Unit Testing and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PIO Unit Testing:
- https://docs.platformio.org/page/plus/unit-testing.html

40763
misc/svd/rp2040.svd Normal file

File diff suppressed because it is too large Load Diff

53
platform.json Normal file
View File

@ -0,0 +1,53 @@
{
"name": "raspberrypi",
"title": "Raspberry Pi RP2040",
"description": "RP2040 is a low-cost, high-performance microcontroller device with with a large on-chip memory, symmetric dual-core processor complex, and rich peripheral.",
"homepage": "https://www.raspberrypi.org/documentation/rp2040/getting-started/",
"license": "Apache-2.0",
"keywords": [
"dev-platform",
"ARM",
"Cortex-M",
"Raspberry Pi",
"RP2040"
],
"engines": {
"platformio": "^5"
},
"repository": {
"type": "git",
"url": "https://github.com/platformio/platform-raspberrypi.git"
},
"version": "0.0.0",
"frameworks": {
"arduino": {
"package": "framework-arduino-mbed",
"script": "builder/frameworks/arduino/mbed-core/arduino-core-mbed.py"
}
},
"packages": {
"toolchain-gccarmnoneeabi": {
"type": "toolchain",
"owner": "platformio",
"version": "~1.90201.0"
},
"framework-arduino-mbed": {
"type": "framework",
"optional": true,
"owner": "platformio",
"version": "~2.0.0"
},
"tool-rp2040tools": {
"type": "uploader",
"optional": true,
"owner": "platformio",
"version": "~1.0.2"
},
"tool-openocd-raspberrypi": {
"type": "uploader",
"optional": true,
"owner": "platformio",
"version": "~2.1100.0"
}
}
}

118
platform.py Normal file
View File

@ -0,0 +1,118 @@
# Copyright 2014-present PlatformIO <contact@platformio.org>
#
# 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.
import copy
import platform
from platformio.managers.platform import PlatformBase
class RaspberrypiPlatform(PlatformBase):
def is_embedded(self):
return True
def configure_default_packages(self, variables, targets):
# configure J-LINK tool
jlink_conds = [
"jlink" in variables.get(option, "")
for option in ("upload_protocol", "debug_tool")
]
if variables.get("board"):
board_config = self.board_config(variables.get("board"))
jlink_conds.extend([
"jlink" in board_config.get(key, "")
for key in ("debug.default_tools", "upload.protocol")
])
jlink_pkgname = "tool-jlink"
if not any(jlink_conds) and jlink_pkgname in self.packages:
del self.packages[jlink_pkgname]
return PlatformBase.configure_default_packages(self, variables, targets)
def get_boards(self, id_=None):
result = PlatformBase.get_boards(self, id_)
if not result:
return result
if id_:
return self._add_default_debug_tools(result)
else:
for key, value in result.items():
result[key] = self._add_default_debug_tools(result[key])
return result
def _add_default_debug_tools(self, board):
debug = board.manifest.get("debug", {})
upload_protocols = board.manifest.get("upload", {}).get(
"protocols", [])
if "tools" not in debug:
debug["tools"] = {}
for link in ("cmsis-dap", "jlink", "raspberrypi-swd", "stlink"):
if link not in upload_protocols or link in debug["tools"]:
continue
if link == "jlink":
assert debug.get("jlink_device"), (
"Missed J-Link Device ID for %s" % board.id)
debug["tools"][link] = {
"server": {
"package": "tool-jlink",
"arguments": [
"-singlerun",
"-if", "SWD",
"-select", "USB",
"-device", debug.get("jlink_device"),
"-port", "2331"
],
"executable": ("JLinkGDBServerCL.exe"
if platform.system() == "Windows" else
"JLinkGDBServer")
},
"onboard": link in debug.get("onboard_tools", [])
}
else:
openocd_target = debug.get("openocd_target")
assert openocd_target, ("Missing target configuration for %s" % board.id)
debug["tools"][link] = {
"server": {
"executable": "bin/openocd",
"package": "tool-openocd-raspberrypi",
"arguments": [
"-s", "$PACKAGE_DIR/share/openocd/scripts",
"-f", "interface/%s.cfg" % link,
"-f", "target/%s" % openocd_target
]
}
}
board.manifest["debug"] = debug
return board
def configure_debug_options(self, initial_debug_options, ide_data):
debug_options = copy.deepcopy(initial_debug_options)
adapter_speed = initial_debug_options.get("speed")
if adapter_speed:
server_options = debug_options.get("server") or {}
server_executable = server_options.get("executable", "").lower()
if "openocd" in server_executable:
debug_options["server"]["arguments"].extend(
["-c", "adapter speed %s" % adapter_speed]
)
elif "jlink" in server_executable:
debug_options["server"]["arguments"].extend(
["-speed", adapter_speed]
)
return debug_options