Compare commits

...
42 Commits
Author SHA1 Message Date
Earle F. Philhower, III a1dc348ec7 Fix over/underclock support (#147)
Removed needed header from main.cpp during prior cleanup.  Re-add.

Fixes #146
2021-05-19 12:28:47 -07:00
Earle F. Philhower, III a0dac52e0e Rationalize Adafruit Feather infra, update docs (#145)
Use same board.txt format as other Adafruit boards.
Add in quick note about the new USB stack to the docs.
2021-05-19 10:07:03 -07:00
Ha Thach 010039578f Add Adafruit ItsyBitsy and QTPy RP2040 (#144)
* add adafruit qtpy and itsybitsy rp2040
* change qtpy boot2 to generic_03h_4
2021-05-19 09:39:19 -07:00
Ha Thach f8a2f38fe7 Port Adafruit_TinyUSB_Arduino lib (#127)
* initial tinyusb lib port

* add Adafruit_TinyUSB_Arduino as submodules

* add yield() to main loop

* sync with tinyusb lib latest

* add USB manufacturer and product

* fix typo in tinyusb lib

* sync with master

updating implementation

* Rationalize link stage command line

Make the build process less insane.

* clean up delay

* clean up platform and board

* update makeboards.py for generating usbstack menu

* update tinyusb lib to 1.0.0
2021-05-18 18:10:47 -07:00
Earle F. Philhower, III 39d1a286a8 Rationalize link stage command line (#143) 2021-05-18 02:47:57 -07:00
Khoi Hoang 7dc0aa16ec Add defs for compatibility (#142)
Add definitions for compatibility to many platforms and libraries
- clockCyclesPerMicrosecond()
- clockCyclesToMicroseconds(a)
- microsecondsToClockCycles(a)
2021-05-16 20:48:44 -07:00
Khoi Hoang b504feaa50 Add -DBOARD_NAME="{build.board}" (#136)
Add -DBOARD_NAME="{build.board}" to Compile patterns to facilitate using BOARD_NAME in sketches
2021-05-16 08:10:10 -07:00
Earle F. Philhower, III fa982c8dd0 Update index.md 2021-05-16 04:14:37 -07:00
Earle F. Philhower, III f1f62264fe Split newlib syscall support to its own file (#141) 2021-05-16 03:59:32 -07:00
Earle F. Philhower, III 1de1d04fb4 Remove hack sync__synchronize from main.cpp (#139)
Was required before due to C++ internals, but is not needed anymore thanks
to #137
2021-05-16 03:49:22 -07:00
Earle F. Philhower, III af8b548e29 Add time support (time, gettimeofday, etc.) (#138) 2021-05-16 03:23:25 -07:00
Earle F. Philhower, III 0550fe75b2 Massively reduce generated code and RAM size (#137)
Older builds included C++ locale information in RAM/flash as well as a
bunch of exception code which can't get called since they're not enabled.

Remove them by adjusting final link command and not instantiating them
in main.cpp in the first place.

Blink went from:
> Sketch uses 215604 bytes (10%) of program storage space. Maximum is 2093056 bytes.
> Global variables use 18152 bytes (6%) of dynamic memory, leaving 243992 bytes for local variables. Maximum is 262144 bytes.

To:
> Sketch uses 56112 bytes (5%) of program storage space. Maximum is 1044480 bytes.
> Global variables use 12152 bytes (4%) of dynamic memory, leaving 249992 bytes for local variables. Maximum is 262144 bytes.

For a savings of **155KB of flash** and **6KB of RAM**
2021-05-16 02:14:58 -07:00
Earle F. Philhower, III ef6024911a Merge branch 'master' of https://github.com/earlephilhower/arduino-pico 2021-05-15 16:29:46 -07:00
Earle F. Philhower, III 78c021aadf Add forgotten USB header 2021-05-15 16:29:32 -07:00
Earle F. Philhower, III fdcfe549cb Add forgotten USB header 2021-05-15 16:29:08 -07:00
Earle F. Philhower, III a64339b195 Update README.md 2021-05-15 16:19:55 -07:00
Earle F. Philhower, III 9725155f25 Fix SPI default pinouts to SPI0, not SPI1 pins (#135)
Should fix #134 .  The SPI pin macros were set using the SPI1 set, not
the SPI0 set of pins it should have been using.
2021-05-15 16:13:11 -07:00
Earle F. Philhower, III cdc2831103 Update install.rst 2021-05-15 12:24:14 -07:00
Earle F. Philhower, III d3c5039c2f Clean up USB includes and naming 2021-05-14 12:08:00 -07:00
Earle F. Philhower, III 13f4be33bc Update index.rst 2021-05-14 08:18:33 -07:00
Earle F. Philhower, III 6cf90add8c Add basic USB documentation 2021-05-14 07:58:32 -07:00
Earle F. Philhower, III 2723a6e71d Update README.md 2021-05-14 07:51:31 -07:00
Earle F. Philhower, III 4a8ac3d902 Add support for shared USB Serial, Keyboard, Mouse (#132)
Use a shared infrastructure based on TinyUSB, allow users to use sketches
with ported Arduino Keyboard and Mouse libraries.
2021-05-13 19:20:24 -07:00
Earle F. Philhower, III 9c17986ae6 Point people to READTHEDOCS for help, not GitHub
Most users w/the Library Manager will get a little nervous with the GH site.
The ReadTheDocs site includes links to the GH site, too, so they can still
find the origin.
2021-05-13 17:47:56 -07:00
Earle F. Philhower, III 93c30e0233 Reorder TOC slightly 2021-05-13 00:20:48 -07:00
Earle F. Philhower, III f327e09e3e Add stdlib_noniso.h to Arduino.h (#131)
Per #130 request, the dtostrf() definition and others were not visible.
2021-05-13 00:15:22 -07:00
drmpf c2cf09acbf SF_printable_fix (#130)
Added Printable.h in dir where it can be found
2021-05-13 00:06:16 -07:00
Earle F. Philhower, III 72a644f77d Update README.md 2021-05-11 12:31:02 -07:00
Earle F. Philhower, III a259eb7396 Clean up directory organization, libpico build (#129)
Also add a README.md to the tools directory.
2021-05-11 12:30:14 -07:00
Earle F. Philhower, III 7f8f0cc137 Clean up platform.txt, libpico build (#128)
Add -fno-exceptions and -fno-rtti where possible.
Move insanely long strings to @files to shrink platform.txt and make
build command line shorter.
2021-05-10 17:57:24 -07:00
Earle F. Philhower, III d776ec2f56 Fix memory leak in tone/noTone calls (#125)
Was never deleting the tone object on noTone, so eventually the leaked
objects would fill up heap and cause a crash.

Fixes #121
2021-05-08 11:19:32 -07:00
Earle F. Philhower, III 8ae69a3463 Minor keyword and mutex fixes for multicore 2021-05-08 11:13:26 -07:00
Earle F. Philhower, III 763846aee8 Additional multicore fixes, BOOTSEL and PIO (#123)
BOOTSEL needs to be multicore protected, too.
Reading BOOTSEL required disabling the flash interface, so the other
core needs to be idles while this runs.

Make the PIO program object multicore safe, too, so that if both cores
try to load a program they won't step on each other.
2021-05-07 16:03:21 -07:00
Earle F. Philhower, III 2da190f5b4 Update README.md 2021-05-06 20:57:51 -07:00
Earle F. Philhower, III 9b2f40c06a Update multicore.rst
Fix some typos
2021-05-06 20:48:06 -07:00
Earle F. Philhower, III f1e77995f5 Look for UF2 drives in additional spots on Linux (#37)
Fixes #28
2021-05-06 20:04:36 -07:00
Earle F. Philhower, III 70a30dc219 Add multicore safety, FIFO, update pico-sdk (#122)
Update pico-sdk to 1.1.2

Add methods to block the opposite core while doing flash updates.
Ensure opposite core is stopped in LittleFS and EEPROM while doing
flash updates.

Update documentation with new calls.
2021-05-06 19:57:21 -07:00
Earle F. Philhower, III 6cf0b30fdf Merge branch 'master' of https://github.com/earlephilhower/arduino-pico 2021-05-06 08:28:35 -07:00
Earle F. Philhower, III a62075d8f1 Add HWSerial redirect
Fixes #120
2021-05-06 08:28:08 -07:00
Oğuzhan Başer 47915df2da PWM functions definitions missing (#114)
* add keywords file

* Add PWM function definitions
2021-04-27 07:11:02 -07:00
Earle F. Philhower, III 1815c45f92 Add multicore support with setup1/loop1 (#113)
Support running code on the second core by adding a setup1() and/or
a loop1() routine to a sketch.  These functions operate exactly like
the normal Arduino ones, and anything they call will be run on
the second core automatically.

Add a simple multicore example.
2021-04-24 11:40:29 -07:00
Earle F. Philhower, III 2d58f08bf2 Update README.md 2021-04-22 10:39:29 -07:00
53 changed files with 2560 additions and 647 deletions
+9
View File
@@ -16,3 +16,12 @@
[submodule "pico-extras"]
path = pico-extras
url = https://github.com/raspberrypi/pico-extras.git
[submodule "libraries/Keyboard"]
path = libraries/Keyboard
url = https://github.com/earlephilhower/Keyboard
[submodule "libraries/Mouse"]
path = libraries/Mouse
url = https://github.com/earlephilhower/Mouse
[submodule "libraries/Adafruit_TinyUSB_Arduino"]
path = libraries/Adafruit_TinyUSB_Arduino
url = https://github.com/adafruit/Adafruit_TinyUSB_Arduino.git
+19 -25
View File
@@ -2,14 +2,17 @@
Raspberry Pi Pico Arduino core, for all RP2040 boards
This is a port of the RP2040 (Raspberry Pi Pico processor) to the Arduino ecosystem.
This is a port of the RP2040 (Raspberry Pi Pico processor) to the Arduino ecosystem. It uses the bare Raspberry Pi Pico SDK and a custom GCC 10.2/Newlib 4.0 toolchain.
It uses a custom toolset with GCC 10.2 and Newlib 4.0.0, not depending on system-installed prerequisites. https://github.com/earlephilhower/pico-quick-toolchain
# Documentation
See https://arduino-pico.readthedocs.io/en/latest/ along with the examples for more detailed usage information.
There is automated discovery of boards in bootloader mode, so they show up in the IDE, and the upload command works using the Microsoft UF2 tool (included).
# Detailed Documentation
Refer to the examples and https://arduino-pico.readthedocs.io/en/latest/ for more detailed usage information.
# Supported Boards
* Raspberry Pi Pico
* Adafruit Feather RP2040
* Adafruit ItsyBitsy RP2040
* Adafruit QTPy RP2040
* Generic (configurable flash, I/O pins)
# Installing via Arduino Boards Manager
**Windows Users**: Please do not use the Windows Store version of the actual Arduino application
@@ -19,7 +22,6 @@ drivers it suggests. Otherwise the Pico board may not be detected. Also, if tr
2.0 beta Arduino please install the release 1.8 version beforehand to ensure needed device drivers
are present. (See #20 for more details.)
Open up the Arduino IDE and go to File->Preferences.
In the dialog that pops up, enter the following URL in the "Additional Boards Manager URLs" field:
@@ -45,7 +47,7 @@ cd ~/Arduino/hardware/pico/rp2040
git submodule update --init
cd pico-sdk
git submodule update --init
cd pico-extras
cd ../pico-extras
git submodule update --init
cd ../tools
python3 ./get.py
@@ -96,22 +98,14 @@ Once Picoprobe permissions are set up properly, then select the board "Raspberry
# Debugging with Picoprobe, OpenOCD, and GDB
The installed tools include a version of OpenOCD (in the pqt-openocd directory) and GDB (in the pqt-gcc directory). These may be used to run GDB in an interactive window as documented in the Pico Getting Started manuals from the Raspberry Pi Foundation.
# Status of Port
Relatively stable and very functional, but bug reports and PRs always accepted.
* digitalWrite/Read
* shiftIn/Out
* SPI master
* analogWrite/PWM
* tone/noTone
* Wire/I2C Master and Slave
* EEPROM
* USB Serial(ACM) w/automatic reboot-to-UF2 upload)
* Hardware UART
* Servo, glitchless
* Overclocking and underclocking from the menus
* analogRead and Pico chip temperature
# Features
* Adafruit TinyUSB Arduino (USB mouse, keyboard, flash drive, generic HID, CDC Serial, MIDI, WebUSB, others)
* Generic Arduino USB Serial, Keyboard, and Mouse emulation
* Filesystems (LittleFS and SD/SDFS)
* I2S audio output
* Multicore support (setup1() and loop1())
* Overclocking and underclocking from the menus
* digitalWrite/Read, shiftIn/Out, tone, analogWrite(PWM)/Read, temperature
* Peripherals: SPI master, Wire(I2C) master/slave, dual UART, emulated EEPROM, I2S audio output, Servo
* printf (i.e. debug) output over USB serial
The RP2040 PIO state machines (SMs) are used to generate jitter-free:
@@ -134,9 +128,9 @@ If you want to contribute or have bugfixes, drop me a note at <earlephilhower@ya
* The [Arduino IDE and ArduinoCore-API](https://arduino.cc) are developed and maintained by the Arduino team. The IDE is licensed under GPL.
* The [RP2040 GCC-based toolchain](https://github.com/earlephilhower/pico-quick-toolchain) is licensed under under the GPL.
* The [Pico-SDK](https://github.com/raspberrypi/pico-sdk) and [Pico-Extras](https://github.com/raspberrypi/pico-extras) are by Raspberry Pi (Trading) Ltd and licensed under the BSD 3-Clause license.
* [Arduino-Pico](https://github.com/earlephilhower/arduino-pico) core files are licenses under the LGPL.
* [Arduino-Pico](https://github.com/earlephilhower/arduino-pico) core files are licensed under the LGPL.
* [LittleFS](https://github.com/ARMmbed/littlefs) library written by ARM Limited and released under the [BSD 3-clause license](https://github.com/ARMmbed/littlefs/blob/master/LICENSE.md).
* [UF2CONV.PY](https://github.com/microsoft/uf2) is by Microsoft Corporatio and licensed under the MIT license.
* [UF2CONV.PY](https://github.com/microsoft/uf2) is by Microsoft Corporation and licensed under the MIT license.
* Some filesystem code taken from the [ESP8266 Arduino Core](https://github.com/esp8266/Arduino) and licensed under the LGPL.
-Earle F. Philhower, III
+925 -268
View File
File diff suppressed because it is too large Load Diff
+19 -1
View File
@@ -24,10 +24,13 @@
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
// Wacky deprecated AVR compatibilty functions
#include "stdlib_noniso.h"
#include "api/ArduinoAPI.h"
#include <pins_arduino.h>
// Required for the port*Register macros
#include "hardware/gpio.h"
@@ -37,6 +40,11 @@
extern "C"{
#endif // __cplusplus
// For compatibility to many platforms and libraries
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
// Disable/reenable all interrupts. Safely handles nested disables
void interrupts();
void noInterrupts();
@@ -68,6 +76,9 @@ float analogReadTemp(); // Returns core temp in Centigrade
// PWM
void analogWrite(pin_size_t pinNumber, int value);
void analogWriteFreq(uint32_t freq);
void analogWriteRange(uint32_t range);
void analogWriteResolution(int res);
// Timing
void delay(unsigned long);
@@ -84,7 +95,14 @@ unsigned long millis();
#define HAVE_HWSERIAL2
#ifdef __cplusplus
#include "SerialUSB.h"
#ifdef USE_TINYUSB
// Needed for declaring Serial
#include "Adafruit_USBD_CDC.h"
#else
#include "SerialUSB.h"
#endif
#include "SerialUART.h"
#include "RP2040.h"
#include "Bootsel.h"
+4 -2
View File
@@ -26,7 +26,8 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() {
// Must disable interrupts, as interrupt handlers may be in flash, and we
// are about to temporarily disable flash access!
uint32_t flags = save_and_disable_interrupts();
noInterrupts();
rp2040.idleOtherCore();
// Set chip select to Hi-Z
hw_write_masked(&ioqspi_hw->io[CS_PIN_INDEX].ctrl,
@@ -46,7 +47,8 @@ static bool __no_inline_not_in_flash_func(get_bootsel_button)() {
GPIO_OVERRIDE_NORMAL << IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_LSB,
IO_QSPI_GPIO_QSPI_SS_CTRL_OEOVER_BITS);
restore_interrupts(flags);
interrupts();
rp2040.resumeOtherCore();
return button_state;
}
+1
View File
@@ -0,0 +1 @@
#include "api/HardwareSerial.h"
+1
View File
@@ -0,0 +1 @@
#include "api/Printable.h"
+100 -2
View File
@@ -18,8 +18,97 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <hardware/pio.h>
#include <hardware/clocks.h>
#include <hardware/irq.h>
#include <hardware/pio.h>
#include <pico/multicore.h>
#include <pico/util/queue.h>
#include <CoreMutex.h>
class _MFIFO {
public:
_MFIFO() { /* noop */ };
~_MFIFO() { /* noop */ };
void begin(int cores) {
constexpr int FIFOCNT = 8;
if (cores == 1) {
_multicore = false;
return;
}
mutex_init(&_idleMutex);
queue_init(&_queue[0], sizeof(uint32_t), FIFOCNT);
queue_init(&_queue[1], sizeof(uint32_t), FIFOCNT);
_multicore = true;
}
void registerCore() {
multicore_fifo_clear_irq();
irq_set_exclusive_handler(SIO_IRQ_PROC0 + get_core_num(), _irq);
irq_set_enabled(SIO_IRQ_PROC0 + get_core_num(), true);
}
void push(uint32_t val) {
while (!push_nb(val)) { /* noop */ }
}
bool push_nb(uint32_t val) {
// Push to the other FIFO
return queue_try_add(&_queue[get_core_num()^1], &val);
}
uint32_t pop() {
uint32_t ret;
while (!pop_nb(&ret)) { /* noop */ }
return ret;
}
bool pop_nb(uint32_t *val) {
// Pop from my own FIFO
return queue_try_remove(&_queue[get_core_num()], val);
}
int available() {
return queue_get_level(&_queue[get_core_num()]);
}
void idleOtherCore() {
if (!_multicore) return;
mutex_enter_blocking(&_idleMutex);
_otherIdled = false;
multicore_fifo_push_blocking(_GOTOSLEEP);
while (!_otherIdled) { /* noop */ }
}
void resumeOtherCore() {
if (!_multicore) return;
mutex_exit(&_idleMutex);
_otherIdled = false;
// Other core will exit busy-loop and return to operation
// once otherIdled == false.
}
private:
static void __no_inline_not_in_flash_func(_irq)() {
multicore_fifo_clear_irq();
noInterrupts(); // We need total control, can't run anything
while (multicore_fifo_rvalid()) {
if (_GOTOSLEEP == multicore_fifo_pop_blocking()) {
_otherIdled = true;
while (_otherIdled) { /* noop */ }
break;
}
}
interrupts();
}
bool _multicore = false;
mutex_t _idleMutex;
static volatile bool _otherIdled;
queue_t _queue[2];
static constexpr int _GOTOSLEEP = 0x66666666;
};
class RP2040 {
public:
@@ -33,10 +122,17 @@ public:
static int f_cpu() {
return clock_get_hz(clk_sys);
}
void idleOtherCore() { fifo.idleOtherCore(); }
void resumeOtherCore() { fifo.resumeOtherCore(); }
// Multicore comms FIFO
_MFIFO fifo;
};
extern RP2040 rp2040;
// Wrapper class for PIO programs, abstracting common operations out
// TODO - Make dualcore safe
// TODO - Add unload/destructor
class PIOProgram {
public:
@@ -44,6 +140,8 @@ public:
// Possibly load into a PIO and allocate a SM
bool prepare(PIO *pio, int *sm, int *offset) {
extern mutex_t _pioMutex;
CoreMutex m(&_pioMutex);
// Is there an open slot to run in, first?
if (!_findFreeSM(pio, sm)) return false;
// Is it loaded on that PIO?
+323
View File
@@ -0,0 +1,323 @@
/*
* Shared USB for the Raspberry Pi Pico RP2040
* Allows for multiple endpoints to share the USB controller
*
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
*
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef USE_TINYUSB
#include <Arduino.h>
#include "CoreMutex.h"
#include "RP2040USB.h"
#include "tusb.h"
#include "class/hid/hid_device.h"
#include "class/audio/audio.h"
#include "class/midi/midi.h"
#include "pico/time.h"
#include "hardware/irq.h"
#include "pico/mutex.h"
#include "pico/unique_id.h"
// Big, global USB mutex, shared with all USB devices to make sure we don't
// have multiple cores updating the TUSB state in parallel
mutex_t __usb_mutex;
// USB processing will be a periodic timer task
#define USB_TASK_INTERVAL 1000
#define USB_TASK_IRQ 31
// USB VID/PID (note that PID can change depending on the add'l interfaces)
#define USBD_VID (0x2E8A) // Raspberry Pi
#ifdef SERIALUSB_PID
#define USBD_PID (SERIALUSB_PID)
#else
#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC
#endif
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
#define USBD_MAX_POWER_MA (250)
#define USBD_ITF_CDC (0) // needs 2 interfaces
#define USBD_ITF_MAX (2)
#define USBD_CDC_EP_CMD (0x81)
#define USBD_CDC_EP_OUT (0x02)
#define USBD_CDC_EP_IN (0x82)
#define USBD_CDC_CMD_MAX_SIZE (8)
#define USBD_CDC_IN_OUT_MAX_SIZE (64)
#define USBD_STR_0 (0x00)
#define USBD_STR_MANUF (0x01)
#define USBD_STR_PRODUCT (0x02)
#define USBD_STR_SERIAL (0x03)
#define USBD_STR_CDC (0x04)
#define EPNUM_HID 0x83
#define EPNUM_MIDI 0x01
const uint8_t *tud_descriptor_device_cb(void) {
static tusb_desc_device_t usbd_desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_CDC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = USBD_VID,
.idProduct = USBD_PID,
.bcdDevice = 0x0100,
.iManufacturer = USBD_STR_MANUF,
.iProduct = USBD_STR_PRODUCT,
.iSerialNumber = USBD_STR_SERIAL,
.bNumConfigurations = 1
};
if (__USBInstallSerial && !__USBInstallKeyboard && !__USBInstallMouse && !__USBInstallMIDI) {
// Can use as-is, this is the default USB case
return (const uint8_t *)&usbd_desc_device;
}
// Need a multi-endpoint config which will require changing the PID to help Windows not barf
if (__USBInstallKeyboard) {
usbd_desc_device.idProduct |= 0x8000;
}
if (__USBInstallMouse) {
usbd_desc_device.idProduct |= 0x4000;
}
if (__USBInstallMIDI) {
usbd_desc_device.idProduct |= 0x2000;
}
// Set the device class to 0 to indicate multiple device classes
usbd_desc_device.bDeviceClass = 0;
usbd_desc_device.bDeviceSubClass = 0;
usbd_desc_device.bDeviceProtocol = 0;
return (const uint8_t *)&usbd_desc_device;
}
int __USBGetKeyboardReportID() {
return 1;
}
int __USBGetMouseReportID() {
return __USBInstallKeyboard ? 2 : 1;
}
static uint8_t *GetDescHIDReport(int *len) {
if (__USBInstallKeyboard && __USBInstallMouse) {
static uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1) ),
TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(2) )
};
if (len) {
*len = sizeof(desc_hid_report);
}
return desc_hid_report;
} else if (__USBInstallKeyboard && ! __USBInstallMouse) {
static uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(1) )
};
if (len) {
*len = sizeof(desc_hid_report);
}
return desc_hid_report;
} else { // if (!__USBInstallKeyboard && __USBInstallMouse) {
static uint8_t desc_hid_report[] = {
TUD_HID_REPORT_DESC_MOUSE( HID_REPORT_ID(1) )
};
if (len) {
*len = sizeof(desc_hid_report);
}
return desc_hid_report;
}
}
// Invoked when received GET HID REPORT DESCRIPTOR
// Application return pointer to descriptor
// Descriptor contents must exist long enough for transfer to complete
uint8_t const * tud_hid_descriptor_report_cb(void)
{
return GetDescHIDReport(nullptr);
}
const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index;
int len = 0;
static uint8_t *usbd_desc_cfg;
if (!usbd_desc_cfg) {
bool hasHID = __USBInstallKeyboard || __USBInstallMouse;
uint8_t interface_count = (__USBInstallSerial ? 2 : 0) + (hasHID ? 1 : 0) + (__USBInstallMIDI ? 2 : 0);
static uint8_t cdc_desc[TUD_CDC_DESC_LEN] = {
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE)
};
int hid_report_len;
GetDescHIDReport(&hid_report_len);
uint8_t hid_itf = __USBInstallSerial ? 2 : 0;
static uint8_t hid_desc[TUD_HID_DESC_LEN] = {
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
TUD_HID_DESCRIPTOR(hid_itf, 0, HID_PROTOCOL_NONE, hid_report_len, EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10)
};
uint8_t midi_itf = hid_itf + (hasHID ? 1 : 0);
static uint8_t midi_desc[TUD_MIDI_DESC_LEN] = {
// Interface number, string index, EP Out & EP In address, EP size
TUD_MIDI_DESCRIPTOR(midi_itf, 0, EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64)
};
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof(cdc_desc) : 0) + (hasHID ? sizeof(hid_desc) : 0) + (__USBInstallMIDI ? sizeof(midi_desc) : 0);
static uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
// Config number, interface count, string index, total length, attribute, power in mA
TUD_CONFIG_DESCRIPTOR(1, interface_count, USBD_STR_0, usbd_desc_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA)
};
// Combine to one descriptor
usbd_desc_cfg = (uint8_t *)malloc(usbd_desc_len);
bzero(usbd_desc_cfg, usbd_desc_len);
uint8_t *ptr = usbd_desc_cfg;
memcpy(ptr, tud_cfg_desc, sizeof(tud_cfg_desc));
ptr += sizeof(tud_cfg_desc);
if (__USBInstallSerial) {
memcpy(ptr, cdc_desc, sizeof(cdc_desc));
ptr += sizeof(cdc_desc);
}
if (hasHID) {
memcpy(ptr, hid_desc, sizeof(hid_desc));
ptr += sizeof(hid_desc);
}
if (__USBInstallMIDI) {
memcpy(ptr, midi_desc, sizeof(midi_desc));
}
}
return usbd_desc_cfg;
}
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
#define DESC_STR_MAX (20)
static uint16_t desc_str[DESC_STR_MAX];
static char idString[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1];
static const char *const usbd_desc_str[] = {
[USBD_STR_0] = "",
[USBD_STR_MANUF] = "Raspberry Pi",
[USBD_STR_PRODUCT] = "PicoArduino",
[USBD_STR_SERIAL] = idString,
[USBD_STR_CDC] = "Board CDC",
};
if (!idString[0]) {
// Get ID string into human readable serial number on the first pass
pico_unique_board_id_t id;
pico_get_unique_board_id(&id);
idString[0] = 0;
for (auto i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) {
char hx[3];
sprintf(hx, "%02X", id.id[i]);
strcat(idString, hx);
}
}
uint8_t len;
if (index == 0) {
desc_str[1] = 0x0409; // supported language is English
len = 1;
} else {
if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) {
return NULL;
}
const char *str = usbd_desc_str[index];
for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) {
desc_str[1 + len] = str[len];
}
}
// first byte is length (including header), second byte is string type
desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * len + 2);
return desc_str;
}
static void usb_irq() {
// if the mutex is already owned, then we are in user code
// in this file which will do a tud_task itself, so we'll just do nothing
// until the next tick; we won't starve
if (mutex_try_enter(&__usb_mutex, NULL)) {
tud_task();
mutex_exit(&__usb_mutex);
}
}
static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
irq_set_pending(USB_TASK_IRQ);
return USB_TASK_INTERVAL;
}
void __USBStart() {
if (tusb_inited()) {
// Already called
return;
}
mutex_init(&__usb_mutex);
tusb_init();
irq_set_exclusive_handler(USB_TASK_IRQ, usb_irq);
irq_set_enabled(USB_TASK_IRQ, true);
add_alarm_in_us(USB_TASK_INTERVAL, timer_task, NULL, true);
}
// Invoked when received GET_REPORT control request
// Application must fill buffer report's content and return its length.
// Return zero will cause the stack to STALL request
uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen)
{
// TODO not Implemented
(void) report_id;
(void) report_type;
(void) buffer;
(void) reqlen;
return 0;
}
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize)
{
// TODO set LED based on CAPLOCK, NUMLOCK etc...
(void) report_id;
(void) report_type;
(void) buffer;
(void) bufsize;
}
#endif
+39
View File
@@ -0,0 +1,39 @@
/*
* Shared USB for the Raspberry Pi Pico RP2040
* Allows for multiple endpoints to share the USB controller
*
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
*
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "pico/mutex.h"
// Weak function definitions for each type of endpoint
extern void __USBInstallSerial() __attribute__((weak));
extern void __USBInstallKeyboard() __attribute__((weak));
extern void __USBInstallMouse() __attribute__((weak));
extern void __USBInstallMIDI() __attribute__((weak));
// Big, global USB mutex, shared with all USB devices to make sure we don't
// have multiple cores updating the TUSB state in parallel
extern mutex_t __usb_mutex;
// HID report ID inquiry (report ID will vary depending on the number/type of other HID)
int __USBGetKeyboardReportID();
int __USBGetMouseReportID();
// Called by main() to init the USB HW/SW.
void __USBStart();
+17 -139
View File
@@ -20,6 +20,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef USE_TINYUSB
#include <Arduino.h>
#include "CoreMutex.h"
@@ -32,6 +34,11 @@
#include "hardware/watchdog.h"
#include "pico/unique_id.h"
#ifndef DISABLE_USB_SERIAL
// Ensure we are installed in the USB chain
void __USBInstallSerial() { /* noop */ }
#endif
// SerialEvent functions are weak, so when the user doesn't define them,
// the linker just sets their address to 0 (which is checked below).
// The Serialx_available is just a wrapper around Serialx.available(),
@@ -39,121 +46,8 @@
// HardwareSerial instance if the user doesn't also refer to it.
extern void serialEvent() __attribute__((weak));
#define PICO_STDIO_USB_TASK_INTERVAL_US 1000
#define PICO_STDIO_USB_LOW_PRIORITY_IRQ 31
#define USBD_VID (0x2E8A) // Raspberry Pi
#ifdef SERIALUSB_PID
#define USBD_PID (SERIALUSB_PID)
#else
#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC
#endif
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
#define USBD_MAX_POWER_MA (250)
#define USBD_ITF_CDC (0) // needs 2 interfaces
#define USBD_ITF_MAX (2)
#define USBD_CDC_EP_CMD (0x81)
#define USBD_CDC_EP_OUT (0x02)
#define USBD_CDC_EP_IN (0x82)
#define USBD_CDC_CMD_MAX_SIZE (8)
#define USBD_CDC_IN_OUT_MAX_SIZE (64)
#define USBD_STR_0 (0x00)
#define USBD_STR_MANUF (0x01)
#define USBD_STR_PRODUCT (0x02)
#define USBD_STR_SERIAL (0x03)
#define USBD_STR_CDC (0x04)
// Note: descriptors returned from callbacks must exist long enough for transfer to complete
static const tusb_desc_device_t usbd_desc_device = {
.bLength = sizeof(tusb_desc_device_t),
.bDescriptorType = TUSB_DESC_DEVICE,
.bcdUSB = 0x0200,
.bDeviceClass = TUSB_CLASS_CDC,
.bDeviceSubClass = MISC_SUBCLASS_COMMON,
.bDeviceProtocol = MISC_PROTOCOL_IAD,
.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,
.idVendor = USBD_VID,
.idProduct = USBD_PID,
.bcdDevice = 0x0100,
.iManufacturer = USBD_STR_MANUF,
.iProduct = USBD_STR_PRODUCT,
.iSerialNumber = USBD_STR_SERIAL,
.bNumConfigurations = 1,
};
static const uint8_t usbd_desc_cfg[USBD_DESC_LEN] = {
TUD_CONFIG_DESCRIPTOR(1, USBD_ITF_MAX, USBD_STR_0, USBD_DESC_LEN,
TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA),
TUD_CDC_DESCRIPTOR(USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD,
USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE),
};
static char _idString[PICO_UNIQUE_BOARD_ID_SIZE_BYTES * 2 + 1];
static const char *const usbd_desc_str[] = {
[USBD_STR_0] = "",
[USBD_STR_MANUF] = "Raspberry Pi",
[USBD_STR_PRODUCT] = "PicoArduino",
[USBD_STR_SERIAL] = _idString,
[USBD_STR_CDC] = "Board CDC",
};
const uint8_t *tud_descriptor_device_cb(void) {
return (const uint8_t *)&usbd_desc_device;
}
const uint8_t *tud_descriptor_configuration_cb(uint8_t index) {
(void)index;
return usbd_desc_cfg;
}
const uint16_t *tud_descriptor_string_cb(uint8_t index, uint16_t langid) {
#define DESC_STR_MAX (20)
static uint16_t desc_str[DESC_STR_MAX];
uint8_t len;
if (index == 0) {
desc_str[1] = 0x0409; // supported language is English
len = 1;
} else {
if (index >= sizeof(usbd_desc_str) / sizeof(usbd_desc_str[0])) {
return NULL;
}
const char *str = usbd_desc_str[index];
for (len = 0; len < DESC_STR_MAX - 1 && str[len]; ++len) {
desc_str[1 + len] = str[len];
}
}
// first byte is length (including header), second byte is string type
desc_str[0] = (TUSB_DESC_STRING << 8) | (2 * len + 2);
return desc_str;
}
static mutex_t usb_mutex;
static void low_priority_worker_irq() {
// if the mutex is already owned, then we are in user code
// in this file which will do a tud_task itself, so we'll just do nothing
// until the next tick; we won't starve
if (mutex_try_enter(&usb_mutex, NULL)) {
tud_task();
mutex_exit(&usb_mutex);
}
}
static int64_t timer_task(__unused alarm_id_t id, __unused void *user_data) {
irq_set_pending(PICO_STDIO_USB_LOW_PRIORITY_IRQ);
return PICO_STDIO_USB_TASK_INTERVAL_US;
}
extern mutex_t __usb_mutex;
void SerialUSB::begin(unsigned long baud) {
(void) baud; //ignored
@@ -162,24 +56,6 @@ void SerialUSB::begin(unsigned long baud) {
return;
}
// Get ID string into human readable serial number
pico_unique_board_id_t id;
pico_get_unique_board_id(&id);
_idString[0] = 0;
for (auto i = 0; i < PICO_UNIQUE_BOARD_ID_SIZE_BYTES; i++) {
char hx[3];
sprintf(hx, "%02X", id.id[i]);
strcat(_idString, hx);
}
tusb_init();
irq_set_exclusive_handler(PICO_STDIO_USB_LOW_PRIORITY_IRQ, low_priority_worker_irq);
irq_set_enabled(PICO_STDIO_USB_LOW_PRIORITY_IRQ, true);
mutex_init(&usb_mutex);
add_alarm_in_us(PICO_STDIO_USB_TASK_INTERVAL_US, timer_task, NULL, true);
_running = true;
}
@@ -188,7 +64,7 @@ void SerialUSB::end() {
}
int SerialUSB::peek() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return 0;
}
@@ -198,7 +74,7 @@ int SerialUSB::peek() {
}
int SerialUSB::read() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return -1;
}
@@ -210,7 +86,7 @@ int SerialUSB::read() {
}
int SerialUSB::available() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return 0;
}
@@ -219,7 +95,7 @@ int SerialUSB::available() {
}
int SerialUSB::availableForWrite() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return 0;
}
@@ -228,7 +104,7 @@ int SerialUSB::availableForWrite() {
}
void SerialUSB::flush() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return;
}
@@ -241,7 +117,7 @@ size_t SerialUSB::write(uint8_t c) {
}
size_t SerialUSB::write(const uint8_t *buf, size_t length) {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return 0;
}
@@ -276,7 +152,7 @@ size_t SerialUSB::write(const uint8_t *buf, size_t length) {
}
SerialUSB::operator bool() {
CoreMutex m(&usb_mutex);
CoreMutex m(&__usb_mutex);
if (!_running || !m) {
return false;
}
@@ -315,3 +191,5 @@ void arduino::serialEventRun(void)
serialEvent();
}
}
#endif
+1 -1
View File
@@ -1 +1 @@
#include "api/String.h"
#include "api/Stream.h"
+90
View File
@@ -0,0 +1,90 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2018, hathach for Adafruit
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
#ifdef USE_TINYUSB
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE
#else
#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE
#endif
//#ifndef CFG_TUSB_MCU
// #define CFG_TUSB_MCU OPT_MCU_RP2040
//#endif
#define CFG_TUSB_OS OPT_OS_PICO
#define CFG_TUSB_DEBUG 0
//#if CFG_TUSB_DEBUG
// #define tu_printf serial1_printf
// extern int serial1_printf(const char *__restrict __format, ...);
//#endif
#define CFG_TUSB_MEM_SECTION
#define CFG_TUSB_MEM_ALIGN TU_ATTR_ALIGNED(4)
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
#define CFG_TUD_ENDOINT0_SIZE 64
//------------- CLASS -------------//
#define CFG_TUD_CDC 1
#define CFG_TUD_MSC 1
#define CFG_TUD_HID 1
#define CFG_TUD_MIDI 1
#define CFG_TUD_VENDOR 1
// CDC FIFO size of TX and RX
#define CFG_TUD_CDC_RX_BUFSIZE 256
#define CFG_TUD_CDC_TX_BUFSIZE 256
// MSC Buffer size of Device Mass storage
#define CFG_TUD_MSC_BUFSIZE 512
// HID buffer size Should be sufficient to hold ID (if any) + Data
#define CFG_TUD_HID_BUFSIZE 64
// MIDI FIFO size of TX and RX
#define CFG_TUD_MIDI_RX_BUFSIZE 128
#define CFG_TUD_MIDI_TX_BUFSIZE 128
// Vendor FIFO size of TX and RX
#define CFG_TUD_VENDOR_RX_BUFSIZE 64
#define CFG_TUD_VENDOR_TX_BUFSIZE 64
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CONFIG_H_ */
+1
View File
@@ -95,6 +95,7 @@ void noTone(uint8_t pin) {
if (entry != _toneMap.end()) {
pio_sm_set_enabled(entry->second->pio, entry->second->sm, false);
pio_sm_unclaim(entry->second->pio, entry->second->sm);
delete entry->second;
_toneMap.erase(entry);
pinMode(pin, OUTPUT);
digitalWrite(pin, LOW);
+18 -6
View File
@@ -21,7 +21,14 @@
#include <pico.h>
#include <pico/time.h>
extern "C" void delay( unsigned long ms ) {
#ifdef USE_TINYUSB
#include "Adafruit_TinyUSB_API.h"
#endif
extern "C"
{
void delay( unsigned long ms ) {
if (!ms) {
return;
}
@@ -29,22 +36,27 @@ extern "C" void delay( unsigned long ms ) {
sleep_ms(ms);
}
extern "C" void delayMicroseconds( unsigned int usec ) {
void delayMicroseconds( unsigned int usec ) {
if (!usec) {
return;
}
sleep_us(usec);
}
extern "C" void yield() {
// NOOP
void yield() {
#ifdef USE_TINYUSB
TinyUSB_Device_Task();
TinyUSB_Device_FlushCDC();
#endif
}
extern "C" uint32_t millis() {
uint32_t millis() {
return to_ms_since_boot(get_absolute_time());
}
extern "C" uint32_t micros() {
uint32_t micros() {
return to_us_since_boot(get_absolute_time());
}
} // extern C
+47 -128
View File
@@ -19,7 +19,15 @@
*/
#include <Arduino.h>
#include "RP2040USB.h"
#include <pico/stdlib.h>
#include <pico/multicore.h>
RP2040 rp2040;
volatile bool _MFIFO::_otherIdled = false;
mutex_t _pioMutex;
extern void setup();
extern void loop();
@@ -29,25 +37,62 @@ extern void loop();
void initVariant() __attribute__((weak));
void initVariant() { }
// Optional 2nd core setup and loop
extern void setup1() __attribute__((weak));
extern void loop1() __attribute__((weak));
static void main1() {
rp2040.fifo.registerCore();
if (setup1) {
setup1();
}
while (true) {
if (loop1) {
loop1();
}
}
}
extern "C" int main() {
#if F_CPU != 125000000
set_sys_clock_khz(F_CPU / 1000, true);
#endif
mutex_init(&_pioMutex);
initVariant();
#ifndef DISABLE_USB_SERIAL
#ifdef USE_TINYUSB
TinyUSB_Device_Init(0);
#else
__USBStart();
#ifndef DISABLE_USB_SERIAL
// Enable serial port for reset/upload always
Serial.begin();
#endif
#endif
#if defined DEBUG_RP2040_PORT
DEBUG_RP2040_PORT.begin();
#endif
if (setup1 || loop1) {
rp2040.fifo.begin(2);
multicore_launch_core1(main1);
} else {
rp2040.fifo.begin(1);
}
rp2040.fifo.registerCore();
setup();
while (1) {
while (true) {
loop();
#ifdef USE_TINYUSB
yield();
#endif
if (arduino::serialEventRun) {
arduino::serialEventRun();
}
@@ -60,129 +105,3 @@ extern "C" int main() {
}
return 0;
}
/* NEWLIB syscall overloads, so we can ::print() and ::getc() using our objects */
/* Placed here to ensure this compilation unit will be present when it's time */
/* to link newlib.a. */
#include <stdint.h>
#include <errno.h>
#include <_syslist.h>
#include <sys/times.h>
#include <bits/stdc++.h>
#undef errno
// TODO - check the fd, create a VFS, etc.
extern "C" int errno;
extern "C" ssize_t _write(int fd, const void *buf, size_t count) {
#if defined DEBUG_RP2040_PORT
return DEBUG_RP2040_PORT.write((const char *)buf, count);
#else
return 0;
#endif
}
extern "C" int _chown (const char *path, uid_t owner, gid_t group) {
errno = ENOSYS;
return -1;
}
extern "C" int _close (int fildes) {
errno = ENOSYS;
return -1;
}
extern "C" int _execve (char *name, char **argv, char **env) {
errno = ENOSYS;
return -1;
}
extern "C" int _fork (void) {
errno = ENOSYS;
return -1;
}
extern "C" int _fstat (int fildes, struct stat *st) {
errno = ENOSYS;
return -1;
}
extern "C" int _getpid (void) {
errno = ENOSYS;
return -1;
}
struct timeval;
extern "C" int _gettimeofday (struct timeval *ptimeval, void *ptimezone)
{
errno = ENOSYS;
return -1;
}
extern "C" int _isatty (int file) {
errno = ENOSYS;
return 0;
}
extern "C" int _kill (int pid, int sig) {
errno = ENOSYS;
return -1;
}
extern "C" int _link (char *existing, char *newlink) {
errno = ENOSYS;
return -1;
}
extern "C" int _lseek (int file, int ptr, int dir) {
errno = ENOSYS;
return -1;
}
extern "C" int _open (char *file, int flags, int mode) {
errno = ENOSYS;
return -1;
}
extern "C" int _read (int file, char *ptr, int len)
{
// return Serial.read(ptr, len);
return -1;
}
extern "C" int _readlink (const char *path, char *buf, size_t bufsize) {
errno = ENOSYS;
return -1;
}
extern "C" int _stat (const char *file, struct stat *st) {
errno = ENOSYS;
return -1;
}
extern "C" int _symlink (const char *path1, const char *path2) {
errno = ENOSYS;
return -1;
}
extern "C" clock_t _times (struct tms *buf) {
errno = ENOSYS;
return -1;
}
extern "C" int _unlink (char *name) {
errno = ENOSYS;
return -1;
}
extern "C" int _wait (int *status) {
errno = ENOSYS;
return -1;
}
extern "C" void __sync_synchronize() { /* noop */ }
+155
View File
@@ -0,0 +1,155 @@
/*
* NEWLIB syscall implementations
*
* Copyright (c) 2021 Earle F. Philhower, III <earlephilhower@yahoo.com>
*
* 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.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <Arduino.h>
#include <stdint.h>
#include <errno.h>
#include <_syslist.h>
#include <sys/times.h>
#include <pico/stdlib.h>
#include <pico/multicore.h>
#undef errno
// TODO - check the fd, create a VFS, etc.
extern "C" int errno;
extern "C" ssize_t _write(int fd, const void *buf, size_t count) {
#if defined DEBUG_RP2040_PORT
return DEBUG_RP2040_PORT.write((const char *)buf, count);
#else
return 0;
#endif
}
extern "C" int _chown (const char *path, uid_t owner, gid_t group) {
errno = ENOSYS;
return -1;
}
extern "C" int _close (int fildes) {
errno = ENOSYS;
return -1;
}
extern "C" int _execve (char *name, char **argv, char **env) {
errno = ENOSYS;
return -1;
}
extern "C" int _fork (void) {
errno = ENOSYS;
return -1;
}
extern "C" int _fstat (int fildes, struct stat *st) {
errno = ENOSYS;
return -1;
}
extern "C" int _getpid (void) {
errno = ENOSYS;
return -1;
}
static int64_t __timedelta_us = 0.0;
extern "C" int _gettimeofday (struct timeval *tv, void *tz) {
uint64_t now_us = to_us_since_boot(get_absolute_time()) + __timedelta_us;
if (tv) {
tv->tv_sec = now_us / 1000000L;
tv->tv_usec = now_us % 1000000L;
}
return 0;
}
extern "C" int settimeofday (const struct timeval *tv, const struct timezone *tz) {
uint64_t now_us = to_us_since_boot(get_absolute_time());
if (tv) {
uint64_t newnow_us;
newnow_us = tv->tv_sec * 1000000L;
newnow_us += tv->tv_usec;
__timedelta_us = newnow_us - now_us;
}
return 0;
}
extern "C" int _isatty (int file) {
errno = ENOSYS;
return 0;
}
extern "C" int _kill (int pid, int sig) {
errno = ENOSYS;
return -1;
}
extern "C" int _link (char *existing, char *newlink) {
errno = ENOSYS;
return -1;
}
extern "C" int _lseek (int file, int ptr, int dir) {
errno = ENOSYS;
return -1;
}
extern "C" int _open (char *file, int flags, int mode) {
errno = ENOSYS;
return -1;
}
extern "C" int _read (int file, char *ptr, int len)
{
// return Serial.read(ptr, len);
return -1;
}
extern "C" int _readlink (const char *path, char *buf, size_t bufsize) {
errno = ENOSYS;
return -1;
}
extern "C" int _stat (const char *file, struct stat *st) {
errno = ENOSYS;
return -1;
}
extern "C" int _symlink (const char *path1, const char *path2) {
errno = ENOSYS;
return -1;
}
extern "C" clock_t _times (struct tms *buf) {
errno = ENOSYS;
return -1;
}
extern "C" int _unlink (char *name) {
errno = ENOSYS;
return -1;
}
extern "C" int _wait (int *status) {
errno = ENOSYS;
return -1;
}
+2 -1
View File
@@ -33,8 +33,9 @@ extern "C" void interrupts() {
// ERROR
return;
}
restore_interrupts(_irqStack[get_core_num()].top());
auto oldIrqs = _irqStack[get_core_num()].top();
_irqStack[get_core_num()].pop();
restore_interrupts(oldIrqs);
}
extern "C" void noInterrupts() {
+1 -1
View File
@@ -1,4 +1,4 @@
## Welcome to Arduino-Pico
Please go to https://arduino-pico.readthedocs.io/en/latest/ for the
Please go to [https://arduino-pico.readthedocs.io/en/latest/](https://arduino-pico.readthedocs.io/en/latest/) for the
latest documentation.
+2 -1
View File
@@ -31,9 +31,10 @@ For the latest version, always check https://github.com/earlephilhower/arduino-p
SPI <spi>
Wire(I2C) <wire>
File Systems (SD, SDFS, LittleFS) <fs>
USB (Arduino and Adafruit_TinyUSB) <usb>
Multicore Processing <multicore>
Ported/Optimized Libraries <libraries>
Using Pico-SDK <sdk>
Licenses <license>
+24
View File
@@ -80,6 +80,30 @@ the ``USB Serial (CDC)`` driver.
.. image:: images/install_driver_old_win.png
Windows 7 Installation Problems
-------------------------------
When running MalwareBytes antivirus (or others) the scanner may lock the compiler or other toolchain executables, causing installation or build failures. (Thanks to @Andy2No)
Symptoms include:
*Access denied during update in the boards manager - affects the .exe files, because MalwareBytes has locked them.
* Access denied during compilation, to one of the .exe files - same reason.
* Can't delete the .exe files - they're locked by MalwareBytes.
A workaround is possible, involving setting the toolchain as an "excluded directory" and reinstalling.
1. In MalwareBytes Settings, click the Exclusions tab. Add an exclusion for the equivalent of this folder path:
``C:\Users{YOUR_USERNAME_HERE}\AppData\Local\Arduino15\packages\rp2040\tools\pqt-gcc\1.1.0-a-81a1771``
2. Reboot to unlock the files.
3. Do the boards manager installation / upgrade again.
4. Set the board type, e.g. to Raspberry Pi Pico and check it can compile.
Uploading Filesystem Images
---------------------------
The onboard flash filesystem for the Pico, LittleFS, lets you upload a filesystem image from the sketch directory for your sketch to use. Download the needed plugin from
+77
View File
@@ -0,0 +1,77 @@
Multicore Processing
====================
The RP2040 chip has 2 cores that can run independently of each other, sharing
peripherals and memory with each other. Arduino code will normally execute
only on core 0, with the 2nd core sitting idle in a low power state.
By adding a ``setup1()`` and ``loop1()`` function to your sketch you can make
use of the second core. Anything called from within the ``setup1()`` or
``loop1()`` routines will execute on the second core.
``setup()`` and ``setup1()`` will be called at the same time, and the ``loop()``
or ``loop1()`` will be started as soon as the core's ``setup()`` completes (i.e.
not necessarily simultaneously!).
See the ``Multicore.ino`` example in the ``rp2040`` example directory for a
quick introduction.
Pausing Cores
-------------
Sometimes an application needs to pause the other core on chip (i.e. it is
writing to flash or needs to stop processing while some other event occurs).
void rp2040.idleOtherCore()
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sends a message to stop the other core (i.e. when called from core 0 it
pauses core 1, and vice versa). Waits for the other core to acknowledge
before returning.
The other core will have its interrupts disabled and be busy-waiting in
an RAM-based routine, so flash and other peripherals can be accessed.
**NOTE** If you idle core 0 too long, then the USB port can become frozen.
This is because core 0 manages the USB and needs to service IRQs in a
timely manner (which it can't do when idled).
void rp2040.resumeOtherCore()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Resumes processing in the other core, where it left off.
Communicating Between Cores
---------------------------
The RP2040 provides a hardware FIFO for communicating between cores, but it
is used exclusively for the idle/resume calls described above. Instead, please
use the following functions to access a software-managed, multicore safe
FIFO.
void rp2040.fifo.push(uint32_t)
~~~~~~~~~~~~~~~~~~~~~~~~~~
Pushes a value to the other core. Will block if the FIFO is full.
bool rp2040.fifo.push_nb(uint32_t)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Pushes a value to the other core. If the FIFO is full, returns ``false``
immediately and doesn't block. If the push is successful, returns ``true``.
uint32_t rp2040.fifo.pop()
~~~~~~~~~~~~~~~~~~~~~
Reads a value from this core's FIFO. Blocks until one is available.
bool rp2040.fifo.pop_nb(uint32_t *dest)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Reads a value from this core's FIFO and places it in dest. Will return
``true`` if successful, or ``false`` if the pop would block.
int rp2040.fifo.available()
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Returns the number of values available in this core's FIFO.
+32
View File
@@ -0,0 +1,32 @@
USB (Arduino and Adafruit_TinyUSB)
==================================
Two USB stacks are present in the core. Users can choose the simpler
Pico-SDK version or the more powerful Adafruit TinyUSB library.
Use the ``Tools->USB Stack`` menu to select between the two.
Pico SDK USB Support
--------------------
This is the default mode and automatically includes a USB-based
serial port, ``Serial`` as well as supporting automatic reset-to-upload
from the IDE.
The Arduino-Pico core includes ported versions of the basic Arduino
``Keyboard`` and ``Mouse`` libraries. These libraries allow you to
emulate a keyboard or mouse with the Pico in your sketches.
See the examples and Arduino Reference at
https://www.arduino.cc/reference/en/language/functions/usb/keyboard/
and
https://www.arduino.cc/reference/en/language/functions/usb/mouse
Adafruit TinyUSB Arduino Support
--------------------------------
Examples are provided in the Adafruit_TinyUSB_Arduino for the more
advanced USB stack.
Please note that this stack requires sketches to manually call
``Serial.begin(115200)`` to enable the USB serial port and automatic
sketch upload from the IDE. If a sketch is run without this command
in ``setup()``, the user will need to use the standard "hold BOOTSEL
and plug in USB" method to enter program upload mode.
+20
View File
@@ -0,0 +1,20 @@
#######################################
# Syntax Coloring Map
#######################################
#######################################
# Datatypes (KEYWORD1)
#######################################
#######################################
# Methods and Functions (KEYWORD2)
#######################################
setup1 KEYWORD2
loop2 KEYWORD2
analogWriteFreq KEYWORD2
analogWriteRange KEYWORD2
analogWriteResolution KEYWORD2
######################################
# Constants (LITERAL1)
#######################################
BIN
View File
Binary file not shown.
@@ -13,7 +13,7 @@
#define PICO_SDK_VERSION_MAJOR 1
#define PICO_SDK_VERSION_MINOR 1
#define PICO_SDK_VERSION_REVISION 0
#define PICO_SDK_VERSION_STRING "1.1.0"
#define PICO_SDK_VERSION_REVISION 2
#define PICO_SDK_VERSION_STRING "1.1.2"
#endif
+57
View File
@@ -0,0 +1,57 @@
-iwithprefixbefore/cores/rp2040/api/deprecated-avr-comp/
-iwithprefixbefore/lib/pico_base/
-iwithprefixbefore/pico-examples/build/generated/pico_base
-iwithprefixbefore/pico-extras/src/common/pico_audio/include
-iwithprefixbefore/pico-extras/src/common/pico_util_buffer/include
-iwithprefixbefore/pico-extras/src/rp2_common/pico_audio_i2s/include
-iwithprefixbefore/pico-sdk/lib/tinyusb/src/
-iwithprefixbefore/pico-sdk/src/boards/include
-iwithprefixbefore/pico-sdk/src/common/pico_base/include
-iwithprefixbefore/pico-sdk/src/common/pico_base/include/
-iwithprefixbefore/pico-sdk/src/common/pico_binary_info/include
-iwithprefixbefore/pico-sdk/src/common/pico_bit_ops/include
-iwithprefixbefore/pico-sdk/src/common/pico_divider/include
-iwithprefixbefore/pico-sdk/src/common/pico_stdlib/include
-iwithprefixbefore/pico-sdk/src/common/pico_sync/include
-iwithprefixbefore/pico-sdk/src/common/pico_time/include
-iwithprefixbefore/pico-sdk/src/common/pico_util/include
-iwithprefixbefore/pico-sdk/src/rp2040/hardware_regs/include
-iwithprefixbefore/pico-sdk/src/rp2040/hardware_regs/include/
-iwithprefixbefore/pico-sdk/src/rp2040/hardware_regs/include/
-iwithprefixbefore/pico-sdk/src/rp2040/hardware_structs/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_adc/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_base/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_claim/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_clocks/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_divider/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_dma/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_flash/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_gpio/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_i2c/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_irq/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_pio/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_pll/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_pwm/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_resets/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_spi/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_sync/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_timer/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_timer/include/
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_uart/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_vreg/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_watchdog/include
-iwithprefixbefore/pico-sdk/src/rp2_common/hardware_xosc/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_bootrom/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_double/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_float/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_int64_ops/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_multicore/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_multicore/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform/include/
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_printf/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_runtime/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_stdio/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_stdio_uart/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_stdio_usb/include
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_unique_id/include
+149
View File
@@ -0,0 +1,149 @@
-Wl,--wrap=acos
-Wl,--wrap=acosf
-Wl,--wrap=acosh
-Wl,--wrap=acoshf
-Wl,--wrap=__aeabi_cdcmpeq
-Wl,--wrap=__aeabi_cdcmple
-Wl,--wrap=__aeabi_cdrcmple
-Wl,--wrap=__aeabi_cfcmpeq
-Wl,--wrap=__aeabi_cfcmple
-Wl,--wrap=__aeabi_cfrcmple
-Wl,--wrap=__aeabi_d2f
-Wl,--wrap=__aeabi_d2iz
-Wl,--wrap=__aeabi_d2lz
-Wl,--wrap=__aeabi_d2uiz
-Wl,--wrap=__aeabi_d2ulz
-Wl,--wrap=__aeabi_dadd
-Wl,--wrap=__aeabi_dcmpeq
-Wl,--wrap=__aeabi_dcmpge
-Wl,--wrap=__aeabi_dcmpgt
-Wl,--wrap=__aeabi_dcmple
-Wl,--wrap=__aeabi_dcmplt
-Wl,--wrap=__aeabi_dcmpun
-Wl,--wrap=__aeabi_ddiv
-Wl,--wrap=__aeabi_dmul
-Wl,--wrap=__aeabi_drsub
-Wl,--wrap=__aeabi_dsub
-Wl,--wrap=__aeabi_f2d
-Wl,--wrap=__aeabi_f2iz
-Wl,--wrap=__aeabi_f2lz
-Wl,--wrap=__aeabi_f2uiz
-Wl,--wrap=__aeabi_f2ulz
-Wl,--wrap=__aeabi_fadd
-Wl,--wrap=__aeabi_fcmpeq
-Wl,--wrap=__aeabi_fcmpge
-Wl,--wrap=__aeabi_fcmpgt
-Wl,--wrap=__aeabi_fcmple
-Wl,--wrap=__aeabi_fcmplt
-Wl,--wrap=__aeabi_fcmpun
-Wl,--wrap=__aeabi_fdiv
-Wl,--wrap=__aeabi_fmul
-Wl,--wrap=__aeabi_frsub
-Wl,--wrap=__aeabi_fsub
-Wl,--wrap=__aeabi_i2d
-Wl,--wrap=__aeabi_i2f
-Wl,--wrap=__aeabi_idiv
-Wl,--wrap=__aeabi_idivmod
-Wl,--wrap=__aeabi_l2d
-Wl,--wrap=__aeabi_l2f
-Wl,--wrap=__aeabi_ldivmod
-Wl,--wrap=__aeabi_lmul
-Wl,--wrap=__aeabi_memcpy
-Wl,--wrap=__aeabi_memcpy4
-Wl,--wrap=__aeabi_memcpy8
-Wl,--wrap=__aeabi_memset
-Wl,--wrap=__aeabi_memset4
-Wl,--wrap=__aeabi_memset8
-Wl,--wrap=__aeabi_ui2d
-Wl,--wrap=__aeabi_ui2f
-Wl,--wrap=__aeabi_uidiv
-Wl,--wrap=__aeabi_uidivmod
-Wl,--wrap=__aeabi_ul2d
-Wl,--wrap=__aeabi_ul2f
-Wl,--wrap=__aeabi_uldivmod
-Wl,--wrap=asin
-Wl,--wrap=asinf
-Wl,--wrap=asinh
-Wl,--wrap=asinhf
-Wl,--wrap=atan
-Wl,--wrap=atan2
-Wl,--wrap=atan2f
-Wl,--wrap=atanf
-Wl,--wrap=atanh
-Wl,--wrap=atanhf
-Wl,--wrap=calloc
-Wl,--wrap=cbrt
-Wl,--wrap=cbrtf
-Wl,--wrap=ceil
-Wl,--wrap=ceilf
-Wl,--wrap=__clz
-Wl,--wrap=__clzdi2
-Wl,--wrap=__clzl
-Wl,--wrap=__clzll
-Wl,--wrap=__clzsi2
-Wl,--wrap=copysign
-Wl,--wrap=copysignf
-Wl,--wrap=cos
-Wl,--wrap=cosf
-Wl,--wrap=cosh
-Wl,--wrap=coshf
-Wl,--wrap=__ctzdi2
-Wl,--wrap=__ctzsi2
-Wl,--wrap=drem
-Wl,--wrap=dremf
-Wl,--wrap=exp
-Wl,--wrap=exp10
-Wl,--wrap=exp10f
-Wl,--wrap=exp2
-Wl,--wrap=exp2f
-Wl,--wrap=expf
-Wl,--wrap=expm1
-Wl,--wrap=expm1f
-Wl,--wrap=floor
-Wl,--wrap=floorf
-Wl,--wrap=fma
-Wl,--wrap=fmaf
-Wl,--wrap=fmod
-Wl,--wrap=fmodf
-Wl,--wrap=free
-Wl,--wrap=hypot
-Wl,--wrap=hypotf
-Wl,--wrap=ldexp
-Wl,--wrap=ldexpf
-Wl,--wrap=log
-Wl,--wrap=log10
-Wl,--wrap=log10f
-Wl,--wrap=log1p
-Wl,--wrap=log1pf
-Wl,--wrap=log2
-Wl,--wrap=log2f
-Wl,--wrap=logf
-Wl,--wrap=malloc
-Wl,--wrap=memcpy
-Wl,--wrap=memset
-Wl,--wrap=__popcountdi2
-Wl,--wrap=__popcountsi2
-Wl,--wrap=pow
-Wl,--wrap=powf
-Wl,--wrap=powint
-Wl,--wrap=powintf
-Wl,--wrap=remainder
-Wl,--wrap=remainderf
-Wl,--wrap=remquo
-Wl,--wrap=remquof
-Wl,--wrap=round
-Wl,--wrap=roundf
-Wl,--wrap=sin
-Wl,--wrap=sincos
-Wl,--wrap=sincosf
-Wl,--wrap=sinf
-Wl,--wrap=sinh
-Wl,--wrap=sinhf
-Wl,--wrap=sqrt
-Wl,--wrap=sqrtf
-Wl,--wrap=tan
-Wl,--wrap=tanf
-Wl,--wrap=tanh
-Wl,--wrap=tanhf
-Wl,--wrap=trunc
-Wl,--wrap=truncf
+4 -3
View File
@@ -105,11 +105,12 @@ bool EEPROMClass::commit() {
if (!_data)
return false;
// TODO - this only stops IRQs on 1 core, need to do it on both
uint32_t save = save_and_disable_interrupts();
noInterrupts();
rp2040.idleOtherCore();
flash_range_erase((intptr_t)_sector - (intptr_t)XIP_BASE, 4096);
flash_range_program((intptr_t)_sector - (intptr_t)XIP_BASE, _data, _size);
restore_interrupts(save);
rp2040.resumeOtherCore();
interrupts();
return true;
}
Submodule libraries/Keyboard added at e8c1394e69
+8 -4
View File
@@ -173,10 +173,12 @@ int LittleFSImpl::lfs_flash_prog(const struct lfs_config *c,
lfs_block_t block, lfs_off_t off, const void *buffer, lfs_size_t size) {
LittleFSImpl *me = reinterpret_cast<LittleFSImpl*>(c->context);
uint8_t *addr = me->_start + (block * me->_blockSize) + off;
uint32_t save = save_and_disable_interrupts();
noInterrupts();
rp2040.idleOtherCore();
// Serial.printf("WRITE: %p, $d\n", (intptr_t)addr - (intptr_t)XIP_BASE, size);
flash_range_program((intptr_t)addr - (intptr_t)XIP_BASE, (const uint8_t *)buffer, size);
restore_interrupts(save);
rp2040.resumeOtherCore();
interrupts();
return 0;
}
@@ -184,9 +186,11 @@ int LittleFSImpl::lfs_flash_erase(const struct lfs_config *c, lfs_block_t block)
LittleFSImpl *me = reinterpret_cast<LittleFSImpl*>(c->context);
uint8_t *addr = me->_start + (block * me->_blockSize);
// Serial.printf("ERASE: %p, %d\n", (intptr_t)addr - (intptr_t)XIP_BASE, me->_blockSize);
uint32_t save = save_and_disable_interrupts();
noInterrupts();
rp2040.idleOtherCore();
flash_range_erase((intptr_t)addr - (intptr_t)XIP_BASE, me->_blockSize);
restore_interrupts(save);
rp2040.resumeOtherCore();
interrupts();
return 0;
}
+1
Submodule libraries/Mouse added at 1b39fd21e5
@@ -0,0 +1,40 @@
// Demonstrates a simple use of the setup1()/loop1() functions
// for a multiprocessor run.
// Will output something like, where C0 is running on core 0 and
// C1 is on core 1, in parallel.
// 11:23:07.507 -> C0: Blue leader standing by...
// 11:23:07.507 -> C1: Red leader standing by...
// 11:23:07.507 -> C1: Stay on target...
// 11:23:08.008 -> C1: Stay on target...
// 11:23:08.505 -> C0: Blue leader standing by...
// 11:23:08.505 -> C1: Stay on target...
// 11:23:09.007 -> C1: Stay on target...
// 11:23:09.511 -> C0: Blue leader standing by...
// 11:23:09.511 -> C1: Stay on target...
// 11:23:10.015 -> C1: Stay on target...
// Released to the public domain
// The normal, core0 setup
void setup() {
Serial.begin(115200);
delay(5000);
}
void loop() {
Serial.printf("C0: Blue leader standing by...\n");
delay(1000);
}
// Running on core1
void setup1() {
delay(5000);
Serial.printf("C1: Red leader standing by...\n");
}
void loop1() {
Serial.printf("C1: Stay on target...\n");
delay(500);
}
+28
View File
@@ -0,0 +1,28 @@
/* Simple demonstration of setting and printing the current time */
/* The initial time will need to come from an RTC, NTP, or user */
/* Released to the public domain by Earle F. Philhower, III <earlephilhower@yahoo.com> */
#include <time.h>
#include <sys/time.h>
void setup() {
Serial.begin(115200);
delay(5000);
struct timeval tv;
tv.tv_sec = 1611198855; // Jan 21, 2021 3:14:15AM ...RPi Pico Release;
tv.tv_usec = 0;
settimeofday(&tv, nullptr);
}
void loop() {
time_t now;
struct tm *info;
char buff[80];
time(&now);
strftime(buff, sizeof(buff), "%c", localtime(&now));
Serial.println(buff);
delay(1000);
}
+1 -1
View File
@@ -6,7 +6,7 @@
"websiteURL": "https://github.com/earlephilhower/arduino-pico",
"email": "earlephilhower@yahoo.com",
"help": {
"online": "https://github.com/earlephilhower/arduino-pico"
"online": "https://arduino-pico.readthedocs.io/en/latest/"
},
"platforms": [
{
-18
View File
@@ -1,18 +0,0 @@
mkdir -p pico
touch pico/config.h
for type in boot2_generic_03h boot2_is25lp080 boot2_w25q080 boot2_w25x10cl; do
for div in 2 4; do
../../system/arm-none-eabi/bin/arm-none-eabi-gcc -march=armv6-m -mcpu=cortex-m0plus -mthumb -O3 -DNDEBUG -DPICO_FLASH_SPI_CLKDIV=$div -c ../../pico-sdk/src/rp2_common/boot_stage2/$type.S -I ../../pico-sdk/src/rp2_common/pico_platform/include/ -I ../../pico-sdk/src/rp2040/hardware_regs/include/ -I../../pico-sdk/src/rp2_common/boot_stage2/asminclude/ -I.
../../system/arm-none-eabi/bin/arm-none-eabi-gcc -march=armv6-m -mcpu=cortex-m0plus -mthumb -O3 -DNDEBUG -Wl,--build-id=none --specs=nosys.specs -nostartfiles -Wl,--script=../../pico-sdk/src/rp2_common/boot_stage2/boot_stage2.ld -Wl,-Map=$type.$div.elf.map $type.o -o $type.$div.elf
../../system/arm-none-eabi/bin/arm-none-eabi-objdump -h $type.$div.elf > $type.$div.dis
../../system/arm-none-eabi/bin/arm-none-eabi-objdump -d $type.$div.elf >> $type.$div.dis
../../system/arm-none-eabi/bin/arm-none-eabi-objcopy -Obinary $type.$div.elf $type.$div.bin
python3 ../../pico-sdk/src/rp2_common/boot_stage2/pad_checksum -s 0xffffffff $type.$div.bin ${type}_${div}_padded_checksum.S
done
done
-17
View File
@@ -1,17 +0,0 @@
#!/bin/bash
rm -rf build
mkdir build
cd build
PICO_SDK_PATH=../../pico-sdk/ PATH="$(cd ../../system/arm-none-eabi/bin; pwd):$PATH" cmake ..
make -j32
cp libpico.a ../../lib/.
cp generated/pico_base/pico/version.h ../../pico_base/pico/.
cd ..
rm -rf boot
mkdir boot
cd boot
../boot.sh
cp *.S ../../assembly/.
cd ..
+18 -12
View File
@@ -38,20 +38,20 @@ compiler.warning_flags.default=
compiler.warning_flags.more=-Wall
compiler.warning_flags.all=-Wall -Wextra
compiler.defines={build.led}
compiler.includes="-I{runtime.platform.path}/pico_base/" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_unique_id/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_platform/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_base/include/" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_timer/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_stdlib/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_gpio/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_i2c/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_flash/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_base/include" "-I{runtime.platform.path}/pico-examples/build/generated/pico_base" "-I{runtime.platform.path}/pico-sdk/src/boards/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_platform/include" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_base/include" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_structs/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_claim/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_sync/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_uart/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_divider/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_time/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_timer/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_sync/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_util/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_runtime/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_clocks/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_resets/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_watchdog/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_xosc/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_pll/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_vreg/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_irq/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_printf/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_bootrom/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_bit_ops/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_divider/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_double/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_int64_ops/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_float/include" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_pio/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_stdio/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_dma/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_stdio_uart/include" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/lib/tinyusb/src/" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_stdio_usb/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_spi/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_pwm/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/hardware_adc/include" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_multicore/include" "-I{runtime.platform.path}/cores/rp2040/api/deprecated-avr-comp/" "-I{runtime.platform.path}/pico-sdk/src/rp2_common/pico_multicore/include" "-I{runtime.platform.path}/pico-extras/src/rp2_common/pico_audio_i2s/include" "-I{runtime.platform.path}/pico-extras/src/common/pico_audio/include" "-I{runtime.platform.path}/pico-extras/src/common/pico_util_buffer/include"
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections
compiler.wrap=-Wl,--wrap=acos -Wl,--wrap=acosf -Wl,--wrap=acosh -Wl,--wrap=acoshf -Wl,--wrap=__aeabi_cdcmpeq -Wl,--wrap=__aeabi_cdcmple -Wl,--wrap=__aeabi_cdrcmple -Wl,--wrap=__aeabi_cfcmpeq -Wl,--wrap=__aeabi_cfcmple -Wl,--wrap=__aeabi_cfrcmple -Wl,--wrap=__aeabi_d2f -Wl,--wrap=__aeabi_d2iz -Wl,--wrap=__aeabi_d2lz -Wl,--wrap=__aeabi_d2uiz -Wl,--wrap=__aeabi_d2ulz -Wl,--wrap=__aeabi_dadd -Wl,--wrap=__aeabi_dcmpeq -Wl,--wrap=__aeabi_dcmpge -Wl,--wrap=__aeabi_dcmpgt -Wl,--wrap=__aeabi_dcmple -Wl,--wrap=__aeabi_dcmplt -Wl,--wrap=__aeabi_dcmpun -Wl,--wrap=__aeabi_ddiv -Wl,--wrap=__aeabi_dmul -Wl,--wrap=__aeabi_drsub -Wl,--wrap=__aeabi_dsub -Wl,--wrap=__aeabi_f2d -Wl,--wrap=__aeabi_f2iz -Wl,--wrap=__aeabi_f2lz -Wl,--wrap=__aeabi_f2uiz -Wl,--wrap=__aeabi_f2ulz -Wl,--wrap=__aeabi_fadd -Wl,--wrap=__aeabi_fcmpeq -Wl,--wrap=__aeabi_fcmpge -Wl,--wrap=__aeabi_fcmpgt -Wl,--wrap=__aeabi_fcmple -Wl,--wrap=__aeabi_fcmplt -Wl,--wrap=__aeabi_fcmpun -Wl,--wrap=__aeabi_fdiv -Wl,--wrap=__aeabi_fmul -Wl,--wrap=__aeabi_frsub -Wl,--wrap=__aeabi_fsub -Wl,--wrap=__aeabi_i2d -Wl,--wrap=__aeabi_i2f -Wl,--wrap=__aeabi_idiv -Wl,--wrap=__aeabi_idivmod -Wl,--wrap=__aeabi_l2d -Wl,--wrap=__aeabi_l2f -Wl,--wrap=__aeabi_ldivmod -Wl,--wrap=__aeabi_lmul -Wl,--wrap=__aeabi_memcpy -Wl,--wrap=__aeabi_memcpy4 -Wl,--wrap=__aeabi_memcpy8 -Wl,--wrap=__aeabi_memset -Wl,--wrap=__aeabi_memset4 -Wl,--wrap=__aeabi_memset8 -Wl,--wrap=__aeabi_ui2d -Wl,--wrap=__aeabi_ui2f -Wl,--wrap=__aeabi_uidiv -Wl,--wrap=__aeabi_uidivmod -Wl,--wrap=__aeabi_ul2d -Wl,--wrap=__aeabi_ul2f -Wl,--wrap=__aeabi_uldivmod -Wl,--wrap=asin -Wl,--wrap=asinf -Wl,--wrap=asinh -Wl,--wrap=asinhf -Wl,--wrap=atan -Wl,--wrap=atan2 -Wl,--wrap=atan2f -Wl,--wrap=atanf -Wl,--wrap=atanh -Wl,--wrap=atanhf -Wl,--wrap=calloc -Wl,--wrap=cbrt -Wl,--wrap=cbrtf -Wl,--wrap=ceil -Wl,--wrap=ceilf -Wl,--wrap=__clz -Wl,--wrap=__clzdi2 -Wl,--wrap=__clzl -Wl,--wrap=__clzll -Wl,--wrap=__clzsi2 -Wl,--wrap=copysign -Wl,--wrap=copysignf -Wl,--wrap=cos -Wl,--wrap=cosf -Wl,--wrap=cosh -Wl,--wrap=coshf -Wl,--wrap=__ctzdi2 -Wl,--wrap=__ctzsi2 -Wl,--wrap=drem -Wl,--wrap=dremf -Wl,--wrap=exp -Wl,--wrap=exp10 -Wl,--wrap=exp10f -Wl,--wrap=exp2 -Wl,--wrap=exp2f -Wl,--wrap=expf -Wl,--wrap=expm1 -Wl,--wrap=expm1f -Wl,--wrap=floor -Wl,--wrap=floorf -Wl,--wrap=fma -Wl,--wrap=fmaf -Wl,--wrap=fmod -Wl,--wrap=fmodf -Wl,--wrap=free -Wl,--wrap=hypot -Wl,--wrap=hypotf -Wl,--wrap=ldexp -Wl,--wrap=ldexpf -Wl,--wrap=log -Wl,--wrap=log10 -Wl,--wrap=log10f -Wl,--wrap=log1p -Wl,--wrap=log1pf -Wl,--wrap=log2 -Wl,--wrap=log2f -Wl,--wrap=logf -Wl,--wrap=malloc -Wl,--wrap=memcpy -Wl,--wrap=memset -Wl,--wrap=__popcountdi2 -Wl,--wrap=__popcountsi2 -Wl,--wrap=pow -Wl,--wrap=powf -Wl,--wrap=powint -Wl,--wrap=powintf -Wl,--wrap=remainder -Wl,--wrap=remainderf -Wl,--wrap=remquo -Wl,--wrap=remquof -Wl,--wrap=round -Wl,--wrap=roundf -Wl,--wrap=sin -Wl,--wrap=sincos -Wl,--wrap=sincosf -Wl,--wrap=sinf -Wl,--wrap=sinh -Wl,--wrap=sinhf -Wl,--wrap=sqrt -Wl,--wrap=sqrtf -Wl,--wrap=tan -Wl,--wrap=tanf -Wl,--wrap=tanh -Wl,--wrap=tanhf -Wl,--wrap=trunc -Wl,--wrap=truncf
compiler.defines={build.led} {build.usbstack_flags} -DCFG_TUSB_MCU=OPT_MCU_RP2040 -DUSB_VID={build.vid} -DUSB_PID={build.pid} '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
compiler.includes="-iprefix{runtime.platform.path}/" "@{runtime.platform.path}/lib/platform_inc.txt"
compiler.flags=-Os -march=armv6-m -mcpu=cortex-m0plus -mthumb -ffunction-sections -fdata-sections -fno-exceptions
compiler.wrap="@{runtime.platform.path}/lib/platform_wrap.txt"
compiler.libpico="{runtime.platform.path}/lib/libpico.a"
compiler.c.cmd=arm-none-eabi-gcc
compiler.c.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu17 -g
compiler.c.elf.cmd=arm-none-eabi-g++
compiler.c.elf.flags={compiler.defines} {compiler.flags} -Wl,--gc-sections -u _printf_float -u _scanf_float
compiler.c.elf.flags={compiler.defines} {compiler.flags} -u _printf_float -u _scanf_float
compiler.S.cmd=arm-none-eabi-gcc
compiler.S.flags=-c -g -x assembler-with-cpp -MMD {compiler.includes} -g
compiler.cpp.cmd=arm-none-eabi-g++
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -std=gnu++17 -g
compiler.cpp.flags=-c {compiler.defines} {compiler.flags} {compiler.includes} -fno-rtti -std=gnu++17 -g
compiler.ar.cmd=arm-none-eabi-ar
compiler.ar.flags=rcs
@@ -81,6 +81,7 @@ build.flash_length=
build.eeprom_start=
build.fs_start=
build.fs_end=
build.usbstack_flags=
build.boot2=boot2_generic_03h_4_padded_checksum
@@ -92,22 +93,27 @@ discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.pl
# ----------------
## Compile c files
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.c.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
## Compile c++ files
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.cpp.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
## Compile S files
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} {build.usbpid} -DF_CPU={build.f_cpu} -DARDUINO={runtime.ide.version} -DARDUINO_{build.board} -DBOARD_NAME="{build.board}" -DARDUINO_ARCH_{build.arch} {compiler.S.extra_flags} {build.extra_flags} {build.debug_port} {build.debug_level} {includes} "{source_file}" -o "{object_file}"
## Create archives
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
archive_file_path={build.path}/{archive_file}
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
## Combine gc-sections, archives, and objects
## Generate the linker map with specific flash sizes/locations
recipe.hooks.linking.prelink.1.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/simplesub.py" --input "{runtime.platform.path}/lib/memmap_default.ld" --out "{build.path}/memmap_default.ld" --sub __FLASH_LENGTH__ {build.flash_length} --sub __EEPROM_START__ {build.eeprom_start} --sub __FS_START__ {build.fs_start} --sub __FS_END__ {build.fs_end}
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" --specs=nosys.specs -Wl,--start-group {compiler.ldflags} -o "{build.path}/{build.project_name}.elf" {object_files} "{build.path}/{archive_file}" "{runtime.platform.path}/lib/libpico.a" -lm "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" "{runtime.platform.path}/assembly/{build.boot2}.S" -lc -lstdc++ -Wl,--end-group
## Compile the boot stage 2 blob
recipe.hooks.linking.prelink.2.pattern="{compiler.path}{compiler.S.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -c "{runtime.platform.path}/assembly/{build.boot2}.S" "-I{runtime.platform.path}/pico-sdk/src/rp2040/hardware_regs/include/" "-I{runtime.platform.path}/pico-sdk/src/common/pico_binary_info/include" -o "{build.path}/boot2.o"
## Combine gc-sections, archives, and objects
recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" "-L{build.path}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} {compiler.ldflags} "-Wl,--script={build.path}/memmap_default.ld" "-Wl,-Map,{build.path}/{build.project_name}.map" -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" "{build.path}/boot2.o" {compiler.libpico} -lm -lc -lstdc++ -lc -Wl,--end-group
## Create output (UF2 file)
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"
+35
View File
@@ -0,0 +1,35 @@
# Tools directory for the RP2040 Arduino-Pico
## get.py
Downloads and installs the toolchain into a GIT clone of the repo. Run
once after the `git clone` and any time the toolchain JSON file updates.
The `dist` directory caches downloaded toolchain files.
## discovery.py
Run in the background by the IDE to scan for UF2 drives to show in the
menus. Normally not run manually by the user.
## uf2conv.py
Manages the upload of the UF2 formatted file to the board. Called as part
of the IDE upload process. Will optionally send the serial reset signal
to get the board into update mode (1200bps connection).
## simplesub.py
Very dumb `sed`-like tool used by the platform scripts to generate the
linker `.ld` file (replacing the EEPROM location, FS sizes, etc.).
Because we run on Windows, Mac, and Linux, need to provide this and not
rely on existance of `sed` command.
## pyserial
`git clone` of the PySerial Python3 library to be used by the IDE.
## makeboards.py
Generates `boards.txt` programmatically. Never edit the `boards.txt` file
manually, use `python3 tools/makeboards.py > boards.py`. Change the script
as necessary to add any add'l fields or menus required. Used because the
`boards.txt` file is very repetitive and it's safer to generate with code
than by hand.
## libpico/make-libpico.sh
Builds the libpico.a file as well as the bootloader stage2 binaries.
Run whenever the pico-sdk is updated.
@@ -18,6 +18,13 @@ target_compile_definitions(pico PUBLIC
PICO_FLASH_SIZE_BYTES=16777216
)
target_compile_options(pico PUBLIC
-fno-exceptions
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
)
include_directories(BEFORE ${PICO_SDK_PATH}/../tools/libpico)
target_link_libraries(pico
boot_stage2
hardware_adc
@@ -58,16 +65,16 @@ target_link_libraries(pico
pico_platform
pico_runtime
pico_standard_link
pico_stdio_usb
pico_stdlib
pico_unique_id
tinyusb
tinyusb_device_unmarked
pico_audio
pico_audio_i2s
)
add_custom_command(TARGET pico PRE_BUILD
COMMAND ../../system/arm-none-eabi/bin/arm-none-eabi-gcc -g -c ../../assembly/crt0.S -I ../../pico-sdk/src/rp2040/hardware_regs/include -I ../../pico-sdk/src/common/pico_binary_info/include/
COMMAND arm-none-eabi-gcc -g -c ../../../assembly/crt0.S -I "${PICO_SDK_PATH}/src/rp2040/hardware_regs/include" -I "${PICO_SDK_PATH}/src/common/pico_binary_info/include/"
)
add_custom_command(TARGET pico POST_BUILD
+45
View File
@@ -0,0 +1,45 @@
#!/bin/bash
set -e # Exit on error
export PICO_SDK_PATH="$(cd ../../pico-sdk/; pwd)"
export PATH="$(cd ../../system/arm-none-eabi/bin; pwd):$PATH"
rm -rf build
mkdir build
cd build
cmake ..
make -j
mv libpico.a ../../../lib/.
mv generated/pico_base/pico/version.h ../../../lib/pico_base/pico/.
rm -rf boot
mkdir boot
cd boot
mkdir -p pico
touch pico/config.h
for type in boot2_generic_03h boot2_is25lp080 boot2_w25q080 boot2_w25x10cl; do
for div in 2 4; do
arm-none-eabi-gcc -march=armv6-m -mcpu=cortex-m0plus -mthumb -O3 \
-DNDEBUG -DPICO_FLASH_SPI_CLKDIV=$div \
-c "$PICO_SDK_PATH/src/rp2_common/boot_stage2/$type.S" \
-I "$PICO_SDK_PATH/src/rp2040/hardware_regs/include/" \
-I "$PICO_SDK_PATH/src/rp2_common/pico_platform/include/" \
-I "$PICO_SDK_PATH/src/rp2_common/boot_stage2/asminclude/" \
-I .
arm-none-eabi-gcc -march=armv6-m -mcpu=cortex-m0plus -mthumb -O3 \
-DNDEBUG -Wl,--build-id=none --specs=nosys.specs -nostartfiles \
-Wl,--script="$PICO_SDK_PATH/src/rp2_common/boot_stage2/boot_stage2.ld" \
-Wl,-Map=$type.$div.elf.map $type.o -o $type.$div.elf
arm-none-eabi-objdump -h $type.$div.elf > $type.$div.dis
arm-none-eabi-objdump -d $type.$div.elf >> $type.$div.dis
arm-none-eabi-objcopy -Obinary $type.$div.elf $type.$div.bin
python3 "$PICO_SDK_PATH/src/rp2_common/boot_stage2/pad_checksum" \
-s 0xffffffff $type.$div.bin ${type}_${div}_padded_checksum.S
done
done
mv *.S ../../../../assembly/.
+116
View File
@@ -0,0 +1,116 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2019 Ha Thach (tinyusb.org)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/
#ifndef _TUSB_CONFIG_H_
#define _TUSB_CONFIG_H_
#ifdef __cplusplus
extern "C" {
#endif
//--------------------------------------------------------------------
// COMMON CONFIGURATION
//--------------------------------------------------------------------
// defined by board.mk
#ifndef CFG_TUSB_MCU
#error CFG_TUSB_MCU must be defined
#endif
// RHPort number used for device can be defined by board.mk, default to port 0
#ifndef BOARD_DEVICE_RHPORT_NUM
#define BOARD_DEVICE_RHPORT_NUM 0
#endif
// RHPort max operational speed can defined by board.mk
// Default to Highspeed for MCU with internal HighSpeed PHY (can be port specific), otherwise FullSpeed
#ifndef BOARD_DEVICE_RHPORT_SPEED
#if (CFG_TUSB_MCU == OPT_MCU_LPC18XX || CFG_TUSB_MCU == OPT_MCU_LPC43XX || CFG_TUSB_MCU == OPT_MCU_MIMXRT10XX || \
CFG_TUSB_MCU == OPT_MCU_NUC505 || CFG_TUSB_MCU == OPT_MCU_CXD56)
#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_HIGH_SPEED
#else
#define BOARD_DEVICE_RHPORT_SPEED OPT_MODE_FULL_SPEED
#endif
#endif
// Device mode with rhport and speed defined by board.mk
#if BOARD_DEVICE_RHPORT_NUM == 0
#define CFG_TUSB_RHPORT0_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
#elif BOARD_DEVICE_RHPORT_NUM == 1
#define CFG_TUSB_RHPORT1_MODE (OPT_MODE_DEVICE | BOARD_DEVICE_RHPORT_SPEED)
#else
#error "Incorrect RHPort configuration"
#endif
// This example doesn't use an RTOS
//#define CFG_TUSB_OS OPT_OS_NONE
// CFG_TUSB_DEBUG is defined by compiler in DEBUG build
// #define CFG_TUSB_DEBUG 0
/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment.
* Tinyusb use follows macros to declare transferring memory so that they can be put
* into those specific section.
* e.g
* - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") ))
* - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4)))
*/
#ifndef CFG_TUSB_MEM_SECTION
#define CFG_TUSB_MEM_SECTION
#endif
#ifndef CFG_TUSB_MEM_ALIGN
#define CFG_TUSB_MEM_ALIGN __attribute__ ((aligned(4)))
#endif
//--------------------------------------------------------------------
// DEVICE CONFIGURATION
//--------------------------------------------------------------------
#ifndef CFG_TUD_ENDPOINT0_SIZE
#define CFG_TUD_ENDPOINT0_SIZE 64
#endif
//------------- CLASS -------------//
#define CFG_TUD_HID (2)
#define CFG_TUD_CDC (1)
#define CFG_TUD_MSC (0)
#define CFG_TUD_MIDI (1)
#define CFG_TUD_VENDOR (0)
#define CFG_TUD_CDC_RX_BUFSIZE (256)
#define CFG_TUD_CDC_TX_BUFSIZE (256)
#define CFG_TUD_MIDI_RX_BUFSIZE (64)
#define CFG_TUD_MIDI_TX_BUFSIZE (64)
// HID buffer size Should be sufficient to hold ID (if any) + Data
#define CFG_TUD_HID_EP_BUFSIZE (64)
#ifdef __cplusplus
}
#endif
#endif /* _TUSB_CONFIG_H_ */
+27 -8
View File
@@ -44,9 +44,20 @@ def BuildBoot(name):
print("%s.menu.boot2.%s=%s" % (name, l[1], l[0]))
print("%s.menu.boot2.%s.build.boot2=%s" % (name, l[1], l[1]))
def BuildHeader(name, prettyname, pidtouse, pid, boarddefine, variant, uploadtool, flashsize, boot2):
def BuildUSBStack(name):
print("%s.menu.usbstack.picosdk=Pico SDK" % (name))
print("%s.menu.usbstack.picosdk.build.usbstack_flags=" % (name))
print("%s.menu.usbstack.tinyusb=Adafruit TinyUSB" % (name))
print('%s.menu.usbstack.tinyusb.build.usbstack_flags=-DUSE_TINYUSB "-I{build.core.path}/TinyUSB" "-I{runtime.platform.path}/libraries/Adafruit_TinyUSB_Arduino/src/arduino"' % (name))
def BuildHeader(name, vendor_name, product_name, pidtouse, vid, pid, boarddefine, variant, uploadtool, flashsize, boot2):
prettyname = vendor_name + " " + product_name
print()
print("# -----------------------------------")
print("# %s" % (prettyname))
print("# -----------------------------------")
print("%s.name=%s" % (name, prettyname))
print("%s.vid.0=0x2e8a" % (name))
print("%s.vid.0=%s" % (name, vid))
print("%s.pid.0=%s" % (name, pidtouse))
print("%s.build.usbpid=-DSERIALUSB_PID=%s" % (name, pid))
print("%s.build.board=%s" % (name, boarddefine))
@@ -65,6 +76,10 @@ def BuildHeader(name, prettyname, pidtouse, pid, boarddefine, variant, uploadtoo
print("%s.build.mcu=rp2040" % (name))
print("%s.build.ldscript=memmap_default.ld" % (name))
print("%s.build.boot2=%s" % (name, boot2))
print("%s.build.vid=%s" % (name, vid))
print("%s.build.pid=%s" % (name, pid))
print('%s.build.usb_manufacturer="%s"' % (name, vendor_name))
print('%s.build.usb_product="%s"' % (name, product_name))
def BuildGlobalMenuList():
print("menu.BoardModel=Model")
@@ -73,12 +88,13 @@ def BuildGlobalMenuList():
print("menu.dbgport=Debug Port")
print("menu.dbglvl=Debug Level")
print("menu.boot2=Boot Stage 2")
print("menu.usbstack=USB Stack")
def MakeBoard(name, prettyname, pid, boarddefine, flashsizemb, boot2):
def MakeBoard(name, vendor_name, product_name, vid, pid, boarddefine, flashsizemb, boot2):
for a, b, c in [ ["", "", "uf2conv"], ["picoprobe", " (Picoprobe)", "picoprobe"]]:
n = name + a
p = prettyname + b
p = product_name + b
fssizelist = [ 0, 64 * 1024, 128 * 1024, 256 * 1024, 512 * 1024 ]
for i in range(1, flashsizemb):
fssizelist.append(i * 1024 * 1024)
@@ -86,7 +102,7 @@ def MakeBoard(name, prettyname, pid, boarddefine, flashsizemb, boot2):
pidtouse = '0x0004'
else:
pidtouse = pid
BuildHeader(n, p, pidtouse, pid, boarddefine, name, c, flashsizemb * 1024 * 1024, boot2)
BuildHeader(n, vendor_name, p, pidtouse, vid, pid, boarddefine, name, c, flashsizemb * 1024 * 1024, boot2)
if name == "generic":
BuildFlashMenu(n, 2*1024*1024, [0, 1*1024*1024])
BuildFlashMenu(n, 4*1024*1024, [0, 2*1024*1024])
@@ -97,12 +113,15 @@ def MakeBoard(name, prettyname, pid, boarddefine, flashsizemb, boot2):
BuildFreq(n)
BuildDebugPort(n)
BuildDebugLevel(n)
BuildUSBStack(n)
if name == "generic":
BuildBoot(n)
BuildGlobalMenuList()
MakeBoard("rpipico", "Raspberry Pi Pico", "0x000a", "RASPBERRY_PI_PICO", 2, "boot2_w25q080_2_padded_checksum")
MakeBoard("adafruitfeather", "Adafruit Feather RP2040", "0x000b", "ADAFRUIT_FEATHER_RP2040", 8, "boot2_w25x10cl_4_padded_checksum")
MakeBoard("generic", "Generic RP2040", "0xf00a", "GENERIC_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
MakeBoard("rpipico", "Raspberry Pi", "Pico", "0x2e8a", "0x000a", "RASPBERRY_PI_PICO", 2, "boot2_w25q080_2_padded_checksum")
MakeBoard("adafruit_feather", "Adafruit", "Feather RP2040", "0x239a", "0x80f1", "ADAFRUIT_FEATHER_RP2040", 8, "boot2_w25x10cl_4_padded_checksum")
MakeBoard("adafruit_itsybitsy", "Adafruit", "ItsyBitsy RP2040", "0x239a", "0x80fd", "ADAFRUIT_ITSYBITSY_RP2040", 8, "boot2_w25q080_2_padded_checksum")
MakeBoard("adafruit_qtpy", "Adafruit", "QT Py RP2040", "0x239a", "0x80f7", "ADAFRUIT_QTPY_RP2040", 8, "boot2_generic_03h_4_padded_checksum")
MakeBoard("generic", "Generic", "RP2040", "0x2e8a", "0xf00a", "GENERIC_RP2040", 16, "boot2_generic_03h_4_padded_checksum")
+4
View File
@@ -236,6 +236,10 @@ def get_drives():
drives.append(words[0])
else:
rootpath = "/media"
if not os.path.isdir(rootpath):
rootpath = "/run/media"
if not os.path.isdir(rootpath):
rootpath = "/opt/media"
if sys.platform == "darwin":
rootpath = "/Volumes"
elif sys.platform == "linux":
@@ -0,0 +1,41 @@
#pragma once
// Pin definitions taken from:
// https://learn.adafruit.com/assets/100337
// LEDs
#define PIN_LED (11u)
// Serial
#define PIN_SERIAL1_TX (0u)
#define PIN_SERIAL1_RX (1u)
// Not pinned out
#define PIN_SERIAL2_TX (31u)
#define PIN_SERIAL2_RX (31u)
// SPI
#define PIN_SPI0_MISO (20u)
#define PIN_SPI0_MOSI (19u)
#define PIN_SPI0_SCK (18u)
#define PIN_SPI0_SS (31u) // not pinned out
// Not pinned out
#define PIN_SPI1_MISO (31u)
#define PIN_SPI1_MOSI (31u)
#define PIN_SPI1_SCK (31u)
#define PIN_SPI1_SS (31u)
// Wire
#define PIN_WIRE0_SDA (2u)
#define PIN_WIRE0_SCL (3u)
// Not pinned out
#define PIN_WIRE1_SDA (31u)
#define PIN_WIRE1_SCL (31u)
#define SERIAL_HOWMANY (2u)
#define SPI_HOWMANY (1u)
#define WIRE_HOWMANY (1u)
#include "../generic/common.h"
+41
View File
@@ -0,0 +1,41 @@
#pragma once
// Pin definitions taken from:
// https://learn.adafruit.com/assets/100337
// LEDs not pinned out
#define PIN_LED (31u)
// Serial
#define PIN_SERIAL1_TX (20u)
#define PIN_SERIAL1_RX (5u)
// Not pinned out
#define PIN_SERIAL2_TX (31u)
#define PIN_SERIAL2_RX (31u)
// SPI
#define PIN_SPI0_MISO (4u)
#define PIN_SPI0_MOSI (3u)
#define PIN_SPI0_SCK (6u)
#define PIN_SPI0_SS (31u) // not pinned out
// Not pinned out
#define PIN_SPI1_MISO (31u)
#define PIN_SPI1_MOSI (31u)
#define PIN_SPI1_SCK (31u)
#define PIN_SPI1_SS (31u)
// Wire
#define PIN_WIRE0_SDA (24u)
#define PIN_WIRE0_SCL (25u)
// Wire1 is connected to StemmaQT connector
#define PIN_WIRE1_SDA (22u)
#define PIN_WIRE1_SCL (23u)
#define SERIAL_HOWMANY (2u)
#define SPI_HOWMANY (1u)
#define WIRE_HOWMANY (2u)
#include "../generic/common.h"
+4 -4
View File
@@ -44,7 +44,7 @@ static const uint8_t A1 = (27u);
static const uint8_t A2 = (28u);
static const uint8_t A3 = (29u);
static const uint8_t SS = PIN_SPI1_SS;
static const uint8_t MOSI = PIN_SPI1_MOSI;
static const uint8_t MISO = PIN_SPI1_MISO;
static const uint8_t SCK = PIN_SPI1_SCK;
static const uint8_t SS = PIN_SPI0_SS;
static const uint8_t MOSI = PIN_SPI0_MOSI;
static const uint8_t MISO = PIN_SPI0_MISO;
static const uint8_t SCK = PIN_SPI0_SCK;