Skip to content

Commit 6a77b2d

Browse files
Merge pull request #44 from earlephilhower/feather
Adafruit Feather, overclocking, flash FS shims
2 parents 33dc16d + b2cef8d commit 6a77b2d

File tree

9 files changed

+444
-293
lines changed

9 files changed

+444
-293
lines changed

boards.txt

Lines changed: 297 additions & 27 deletions
Large diffs are not rendered by default.

cores/rp2040/SerialUSB.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,12 @@ extern void serialEvent() __attribute__((weak));
4343
#define PICO_STDIO_USB_LOW_PRIORITY_IRQ 31
4444

4545
#define USBD_VID (0x2E8A) // Raspberry Pi
46-
#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC
46+
47+
#ifdef SERIALUSB_PID
48+
#define USBD_PID (SERIALUSB_PID)
49+
#else
50+
#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC
51+
#endif
4752

4853
#define USBD_DESC_LEN (TUD_CONFIG_DESC_LEN + TUD_CDC_DESC_LEN)
4954
#define USBD_MAX_POWER_MA (250)

cores/rp2040/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@
1919
*/
2020

2121
#include <Arduino.h>
22+
#include <pico/stdlib.h>
2223

2324
extern void setup();
2425
extern void loop();
2526

2627
extern "C" int main() {
28+
#if F_CPU != 125000000
29+
set_sys_clock_khz(F_CPU / 1000, true);
30+
#endif
2731
#if defined DEBUG_RP2040_PORT
2832
DEBUG_RP2040_PORT.begin();
2933
#endif

variants/generic/memmap_default.ld renamed to lib/memmap_default.ld

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323

2424
MEMORY
2525
{
26-
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2044k /* 2048 - 4K for EEPROM */
26+
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = __FLASH_LENGTH__
2727
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
2828
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
2929
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
3030
}
31-
PROVIDE ( _EEPROM_start = 0x101FF000 );
31+
PROVIDE ( _EEPROM_start = __EEPROM_START__ );
32+
PROVIDE ( _FS_start = __FS_START__ );
33+
PROVIDE ( _FS_end = __FS_END__ );
3234

3335
ENTRY(_entry_point)
3436

platform.txt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,37 +76,38 @@ compiler.S.extra_flags=
7676
compiler.ar.extra_flags=
7777
compiler.elf2hex.extra_flags=
7878

79+
# Board configuration, set in boards.txt. Present here to ensure substitution works
80+
build.flash_length=
81+
build.eeprom_start=
82+
build.fs_start=
83+
build.fs_end=
84+
85+
7986

8087
# Allow Pico boards do be auto-discovered by the IDE
8188
discovery.rp2040.pattern="{runtime.tools.pqt-python3.path}/python3" "{runtime.platform.path}/tools/discovery.py"
8289

83-
# USB Flags
84-
# ---------
85-
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'
86-
87-
# Default usb manufacturer will be replaced at compile time using
88-
# numeric vendor ID if available or by board's specific value.
89-
build.usb_manufacturer="Unknown"
9090

9191
# Compile patterns
9292
# ----------------
9393

9494
## Compile c files
95-
recipe.c.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.c.flags} -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}"
95+
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}"
9696

9797
## Compile c++ files
98-
recipe.cpp.o.pattern="{compiler.path}{compiler.cpp.cmd}" {compiler.cpp.flags} -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}"
98+
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}"
9999

100100
## Compile S files
101-
recipe.S.o.pattern="{compiler.path}{compiler.S.cmd}" {compiler.S.flags} -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}"
101+
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}"
102102

103103
## Create archives
104104
# archive_file_path is needed for backwards compatibility with IDE 1.6.5 or older, IDE 1.6.6 or newer overrides this value
105105
archive_file_path={build.path}/{archive_file}
106106
recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{archive_file_path}" "{object_file}"
107107

108108
## Combine gc-sections, archives, and objects
109-
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.variant.path}/{build.ldscript}" "-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/bs2_default_padded_checksummed.S" -lc -lstdc++ -Wl,--end-group
109+
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}
110+
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/bs2_default_padded_checksummed.S" -lc -lstdc++ -Wl,--end-group
110111

111112
## Create output (UF2 file)
112113
recipe.objcopy.uf2.pattern="{runtime.tools.pqt-elf2uf2.path}/elf2uf2" "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.uf2"

tools/makeboards.py

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/usr/bin/env python3
2+
3+
def BuildFlashMenu(name, flashsize, fssizelist):
4+
for fssize in fssizelist:
5+
if fssize == 0:
6+
fssizename = "no FS"
7+
elif fssize < 1024 * 1024:
8+
fssizename = "FS: %dKB" % (fssize / 1024)
9+
else:
10+
fssizename = "FS: %dMB" % (fssize / (1024 * 1024))
11+
mn="%d_%d" % (flashsize, fssize)
12+
print("%s.menu.flash.%s=%dMB (%s)" % (name, mn, flashsize / (1024 * 1024), fssizename))
13+
print("%s.menu.flash.%s.upload.maximum_size=%d" % (name, mn, flashsize - 4096 - fssize))
14+
print("%s.menu.flash.%s.build.flash_length=%d" % (name, mn, flashsize - 4096 - fssize))
15+
print("%s.menu.flash.%s.build.eeprom_start=%d" % (name, mn, flashsize - 4096))
16+
print("%s.menu.flash.%s.build.fs_start=%d" % (name, mn, flashsize - 4096 - fssize))
17+
print("%s.menu.flash.%s.build.fs_end=%d" % (name, mn, flashsize - 4096))
18+
19+
def BuildDebugPort(name):
20+
print("%s.menu.dbgport.Disabled=Disabled" % (name))
21+
print("%s.menu.dbgport.Disabled.build.debug_port=" % (name))
22+
for p in ["Serial", "Serial1", "Serial2"]:
23+
print("%s.menu.dbgport.%s=%s" % (name, p, p))
24+
print("%s.menu.dbgport.%s.build.debug_port=-DDEBUG_RP2040_PORT=%s" % (name, p, p))
25+
26+
def BuildDebugLevel(name):
27+
for l in [ ("None", ""), ("Core", "-DDEBUG_RP2040_CORE"), ("SPI", "-DDEBUG_RP2040_SPI"), ("Wire", "DDEBUG_RP2040_WIRE"),
28+
("All", "-DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE"), ("NDEBUG", "-DNDEBUG") ]:
29+
print("%s.menu.dbglvl.%s=%s" % (name, l[0], l[0]))
30+
print("%s.menu.dbglvl.%s.build.debug_level=%s" % (name, l[0], l[1]))
31+
32+
def BuildFreq(name):
33+
for f in [ 125, 50, 100, 133, 150, 175, 200, 225, 250, 275, 300]:
34+
warn = ""
35+
if f > 133: warn = " (Overclock)"
36+
print("%s.menu.freq.%s=%s MHz%s" % (name, f, f, warn))
37+
print("%s.menu.freq.%s.build.f_cpu=%dL" % (name, f, f * 1000000))
38+
39+
def BuildHeader(name, prettyname, pid, boarddefine, variant, uploadtool, flashsize):
40+
print("%s.name=%s" % (name, prettyname))
41+
print("%s.vid.0=0x2e8a" % (name))
42+
print("%s.pid.0=%s" % (name, pid))
43+
print("%s.build.usbpid=-DSERIALUSB_PID=%s" % (name, pid))
44+
print("%s.build.board=%s" % (name, boarddefine))
45+
print("%s.build.mcu=cortex-m0plus" % (name))
46+
print("%s.build.variant=%s" % (name, variant))
47+
print("%s.upload.tool=%s" % (name, uploadtool))
48+
print("%s.upload.maximum_size=%d" % (name, flashsize))
49+
print("%s.upload.maximum_data_size=262144" % (name))
50+
print("%s.upload.wait_for_upload_port=true" % (name))
51+
print("%s.upload.erase_cmd=" % (name))
52+
print("%s.serial.disableDTR=false" % (name))
53+
print("%s.serial.disableRTS=false" % (name))
54+
print("%s.build.f_cpu=125000000" % (name))
55+
print("%s.build.led=" % (name))
56+
print("%s.build.core=rp2040" % (name))
57+
print("%s.build.mcu=rp2040" % (name))
58+
print("%s.build.ldscript=memmap_default.ld" % (name))
59+
60+
def BuildGlobalMenuList():
61+
print("menu.BoardModel=Model")
62+
print("menu.flash=Flash Size")
63+
print("menu.freq=CPU Speed")
64+
print("menu.dbgport=Debug Port")
65+
print("menu.dbglvl=Debug Level")
66+
67+
BuildGlobalMenuList()
68+
69+
BuildHeader("rpipico", "Raspberry Pi Pico", "0x000a", "RASPBERRY_PI_PICO", "rpipico", "uf2conv", 2 * 1024*1024)
70+
BuildFlashMenu("rpipico", 2 * 1024 * 1024, [ 0, 64 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024 ])
71+
BuildFreq("rpipico")
72+
BuildDebugPort("rpipico")
73+
BuildDebugLevel("rpipico")
74+
75+
BuildHeader("adafruitfeather", "Adafruit Feather RP2040", "0x000b", "ADAFRUIT_FEATHER_RP2040", "adafruitfeather", "uf2conv", 8 *1024*1024)
76+
BuildFlashMenu("adafruitfeather", 8 * 1024 * 1024, [ 0, 64 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024, 2 * 1024 * 1024, 3 * 1024 * 1024, 4 * 1024 *1024, 5 * 1024 *1024, 6 * 1024*1024, 7*1024*1024 ])
77+
BuildFreq("adafruitfeather")
78+
BuildDebugPort("adafruitfeather")
79+
BuildDebugLevel("adafruitfeather")
80+
81+
BuildHeader("generic", "Generic RP2040", "0xf00a", "GENERIC_RP2040", "generif", "uf2conv", 2 * 1024*1024)
82+
BuildFlashMenu("generic", 2 * 1024 * 1024, [ 0, 64 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024 ])
83+
BuildFreq("generic")
84+
BuildDebugPort("generic")
85+
BuildDebugLevel("generic")

tools/simplesub.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
import sys
3+
import struct
4+
import subprocess
5+
import re
6+
import os
7+
import os.path
8+
import argparse
9+
import time
10+
11+
def main():
12+
parser = argparse.ArgumentParser(description='Simple text substitution')
13+
parser.add_argument('-i', '--input', action='store', required=True, help='Path to the source file')
14+
parser.add_argument('-o', '--out', action='store', required=True, help='Path to the output file')
15+
parser.add_argument('-s', '--sub', action='append', nargs=2, metavar=('find', 'replace'), required=True, help='Substition')
16+
args = parser.parse_args()
17+
18+
with open(args.input, "r") as fin:
19+
data = fin.read()
20+
21+
for f, r in args.sub:
22+
data = re.sub(f, r, data)
23+
24+
with open(args.out, "w") as fout:
25+
fout.write(data)
26+
27+
28+
main()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef __rpipico_pins_arduino_h__
2+
#define __rpipico_pins_arduino_h__
3+
4+
#define LED_BUILTIN 13
5+
6+
#include "../generic/common.h"
7+
8+
#endif

0 commit comments

Comments
 (0)