* Migrate RP2040-specific bits to separate dirs * Add chip to boards.txt, isolate RP2040-specifics * Add RP2350 boot2, bearssl, and libraries * Platform.IO adjust to new paths * Add RPIPICO2 JSON for P.IO * Add RP2350 to Platform.io * Update Picotool and OpenOCD for all hosts * Use picotool to generate UF2s * Build separate libpico blobs serially Thanks for the review, @aarturo182 ! * Add RP2350 to CI * Allow Ethernet/WiFi building for RP2350 * Update Adafruit TinyUSB to latest * Test skip fix * Make RP2350 Picotool work. update USB ID * Fix EEPROM/FS flash locations RP2350 adds a 4K header sector to the UF2, meaning we have 4K less total flash to work with. Adjust all constants appropriately on the RP2350. * Adds ilabs board and PSRAM support. (#2342) * Adds iLabs boards and basic PSRAM support. * Make PSRAM come up as part of chip init Uses SparkFun psram.cpp to set timings on clocks which are defined in the variant file. Prefix things with RP2350_PSRAM_xxx for sanity. Users don't need to call anything, PSRAM "just appears". Still need to add in malloc-type allocation. * Add board SparkFun ProMicro RP2350 Same pinout as the SparkFun ProMicro RP2040 with 8MB PSRAM and RP2350 * Add TLSF library for use w/PSRAM Fork of upstream to include add'l C++ warning fixes. * Add pmalloc/pcalloc to use PSRAM memory free() and realloc() all look at the pointer passed in and jump to the appropriate handler. Also takes care of stopping IRQs and taking the malloc mutex to support multicore and FreeRTOS (when that workd) * Fix BOOTSEL for RP2350 * Add simple rp2040.idleOtherCore test * Add Generic RP2350 and clean up PSRAM menus Commercial boards now only have 1 size PSRAM, no need to have menu for them. * Add Solder Party RP2350 Stamp boards (#2352) * Add PSRAM heap info helpers, mutex lock mallinfo * Add RP2350 docs * FreeRTOS and OTA unsupported warnings for RP2350
90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
/*
|
|
RP2040 PIO utility class
|
|
|
|
Copyright (c) 2023 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 "PIOProgram.h"
|
|
#include <map>
|
|
|
|
#if defined(PICO_RP2350)
|
|
#define PIOS pio0, pio1, pio2
|
|
#define PIOCNT 3
|
|
#elif defined(PICO_RP2040)
|
|
#define PIOS pio0, pio1
|
|
#define PIOCNT 2
|
|
#endif
|
|
|
|
static std::map<const pio_program_t *, int> __pioMap[PIOCNT];
|
|
auto_init_mutex(_pioMutex);
|
|
|
|
PIOProgram::PIOProgram(const pio_program_t *pgm) {
|
|
_pgm = pgm;
|
|
_pio = nullptr;
|
|
_sm = -1;
|
|
}
|
|
|
|
// We leave the INSN loaded in INSN RAM
|
|
PIOProgram::~PIOProgram() {
|
|
if (_pio) {
|
|
pio_sm_unclaim(_pio, _sm);
|
|
}
|
|
}
|
|
|
|
// Possibly load into a PIO and allocate a SM
|
|
bool PIOProgram::prepare(PIO *pio, int *sm, int *offset) {
|
|
CoreMutex m(&_pioMutex);
|
|
PIO pi[PIOCNT] = { PIOS };
|
|
|
|
// If it's already loaded into PIO IRAM, try and allocate in that specific PIO
|
|
for (int o = 0; o < PIOCNT; o++) {
|
|
auto p = __pioMap[o].find(_pgm);
|
|
if (p != __pioMap[o].end()) {
|
|
int idx = pio_claim_unused_sm(pi[o], false);
|
|
if (idx >= 0) {
|
|
_pio = pi[o];
|
|
_sm = idx;
|
|
*pio = pi[o];
|
|
*sm = idx;
|
|
*offset = p->second;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Not in any PIO IRAM, so try and add
|
|
for (int o = 0; o < PIOCNT; o++) {
|
|
if (pio_can_add_program(pi[o], _pgm)) {
|
|
int idx = pio_claim_unused_sm(pi[o], false);
|
|
if (idx >= 0) {
|
|
int off = pio_add_program(pi[o], _pgm);
|
|
__pioMap[o].insert({_pgm, off});
|
|
_pio = pi[o];
|
|
_sm = idx;
|
|
*pio = pi[o];
|
|
*sm = idx;
|
|
*offset = off;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Nope, no room either for SMs or INSNs
|
|
return false;
|
|
}
|