Skip to content

Adafruit Feather, overclocking, flash FS shims #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
324 changes: 297 additions & 27 deletions boards.txt

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion cores/rp2040/SerialUSB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ extern void serialEvent() __attribute__((weak));
#define PICO_STDIO_USB_LOW_PRIORITY_IRQ 31

#define USBD_VID (0x2E8A) // Raspberry Pi
#define USBD_PID (0x000a) // Raspberry Pi Pico SDK CDC

#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)
Expand Down
4 changes: 4 additions & 0 deletions cores/rp2040/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
*/

#include <Arduino.h>
#include <pico/stdlib.h>

extern void setup();
extern void loop();

extern "C" int main() {
#if F_CPU != 125000000
set_sys_clock_khz(F_CPU / 1000, true);
#endif
#if defined DEBUG_RP2040_PORT
DEBUG_RP2040_PORT.begin();
#endif
Expand Down
6 changes: 4 additions & 2 deletions variants/generic/memmap_default.ld → lib/memmap_default.ld
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@

MEMORY
{
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = 2044k /* 2048 - 4K for EEPROM */
FLASH(rx) : ORIGIN = 0x10000000, LENGTH = __FLASH_LENGTH__
RAM(rwx) : ORIGIN = 0x20000000, LENGTH = 256k
SCRATCH_X(rwx) : ORIGIN = 0x20040000, LENGTH = 4k
SCRATCH_Y(rwx) : ORIGIN = 0x20041000, LENGTH = 4k
}
PROVIDE ( _EEPROM_start = 0x101FF000 );
PROVIDE ( _EEPROM_start = __EEPROM_START__ );
PROVIDE ( _FS_start = __FS_START__ );
PROVIDE ( _FS_end = __FS_END__ );

ENTRY(_entry_point)

Expand Down
23 changes: 12 additions & 11 deletions platform.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,38 @@ compiler.S.extra_flags=
compiler.ar.extra_flags=
compiler.elf2hex.extra_flags=

# Board configuration, set in boards.txt. Present here to ensure substitution works
build.flash_length=
build.eeprom_start=
build.fs_start=
build.fs_end=



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

# USB Flags
# ---------
build.usb_flags=-DUSB_VID={build.vid} -DUSB_PID={build.pid} -DUSBCON '-DUSB_MANUFACTURER={build.usb_manufacturer}' '-DUSB_PRODUCT={build.usb_product}'

# Default usb manufacturer will be replaced at compile time using
# numeric vendor ID if available or by board's specific value.
build.usb_manufacturer="Unknown"

# Compile patterns
# ----------------

## Compile c files
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}"
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}"

## Compile c++ files
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}"
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}"

## Compile S files
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}"
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}"

## 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
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
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/bs2_default_padded_checksummed.S" -lc -lstdc++ -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"
Expand Down
85 changes: 85 additions & 0 deletions tools/makeboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3

def BuildFlashMenu(name, flashsize, fssizelist):
for fssize in fssizelist:
if fssize == 0:
fssizename = "no FS"
elif fssize < 1024 * 1024:
fssizename = "FS: %dKB" % (fssize / 1024)
else:
fssizename = "FS: %dMB" % (fssize / (1024 * 1024))
mn="%d_%d" % (flashsize, fssize)
print("%s.menu.flash.%s=%dMB (%s)" % (name, mn, flashsize / (1024 * 1024), fssizename))
print("%s.menu.flash.%s.upload.maximum_size=%d" % (name, mn, flashsize - 4096 - fssize))
print("%s.menu.flash.%s.build.flash_length=%d" % (name, mn, flashsize - 4096 - fssize))
print("%s.menu.flash.%s.build.eeprom_start=%d" % (name, mn, flashsize - 4096))
print("%s.menu.flash.%s.build.fs_start=%d" % (name, mn, flashsize - 4096 - fssize))
print("%s.menu.flash.%s.build.fs_end=%d" % (name, mn, flashsize - 4096))

def BuildDebugPort(name):
print("%s.menu.dbgport.Disabled=Disabled" % (name))
print("%s.menu.dbgport.Disabled.build.debug_port=" % (name))
for p in ["Serial", "Serial1", "Serial2"]:
print("%s.menu.dbgport.%s=%s" % (name, p, p))
print("%s.menu.dbgport.%s.build.debug_port=-DDEBUG_RP2040_PORT=%s" % (name, p, p))

def BuildDebugLevel(name):
for l in [ ("None", ""), ("Core", "-DDEBUG_RP2040_CORE"), ("SPI", "-DDEBUG_RP2040_SPI"), ("Wire", "DDEBUG_RP2040_WIRE"),
("All", "-DDEBUG_RP2040_WIRE -DDEBUG_RP2040_SPI -DDEBUG_RP2040_CORE"), ("NDEBUG", "-DNDEBUG") ]:
print("%s.menu.dbglvl.%s=%s" % (name, l[0], l[0]))
print("%s.menu.dbglvl.%s.build.debug_level=%s" % (name, l[0], l[1]))

def BuildFreq(name):
for f in [ 125, 50, 100, 133, 150, 175, 200, 225, 250, 275, 300]:
warn = ""
if f > 133: warn = " (Overclock)"
print("%s.menu.freq.%s=%s MHz%s" % (name, f, f, warn))
print("%s.menu.freq.%s.build.f_cpu=%dL" % (name, f, f * 1000000))

def BuildHeader(name, prettyname, pid, boarddefine, variant, uploadtool, flashsize):
print("%s.name=%s" % (name, prettyname))
print("%s.vid.0=0x2e8a" % (name))
print("%s.pid.0=%s" % (name, pid))
print("%s.build.usbpid=-DSERIALUSB_PID=%s" % (name, pid))
print("%s.build.board=%s" % (name, boarddefine))
print("%s.build.mcu=cortex-m0plus" % (name))
print("%s.build.variant=%s" % (name, variant))
print("%s.upload.tool=%s" % (name, uploadtool))
print("%s.upload.maximum_size=%d" % (name, flashsize))
print("%s.upload.maximum_data_size=262144" % (name))
print("%s.upload.wait_for_upload_port=true" % (name))
print("%s.upload.erase_cmd=" % (name))
print("%s.serial.disableDTR=false" % (name))
print("%s.serial.disableRTS=false" % (name))
print("%s.build.f_cpu=125000000" % (name))
print("%s.build.led=" % (name))
print("%s.build.core=rp2040" % (name))
print("%s.build.mcu=rp2040" % (name))
print("%s.build.ldscript=memmap_default.ld" % (name))

def BuildGlobalMenuList():
print("menu.BoardModel=Model")
print("menu.flash=Flash Size")
print("menu.freq=CPU Speed")
print("menu.dbgport=Debug Port")
print("menu.dbglvl=Debug Level")

BuildGlobalMenuList()

BuildHeader("rpipico", "Raspberry Pi Pico", "0x000a", "RASPBERRY_PI_PICO", "rpipico", "uf2conv", 2 * 1024*1024)
BuildFlashMenu("rpipico", 2 * 1024 * 1024, [ 0, 64 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024 ])
BuildFreq("rpipico")
BuildDebugPort("rpipico")
BuildDebugLevel("rpipico")

BuildHeader("adafruitfeather", "Adafruit Feather RP2040", "0x000b", "ADAFRUIT_FEATHER_RP2040", "adafruitfeather", "uf2conv", 8 *1024*1024)
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 ])
BuildFreq("adafruitfeather")
BuildDebugPort("adafruitfeather")
BuildDebugLevel("adafruitfeather")

BuildHeader("generic", "Generic RP2040", "0xf00a", "GENERIC_RP2040", "generif", "uf2conv", 2 * 1024*1024)
BuildFlashMenu("generic", 2 * 1024 * 1024, [ 0, 64 * 1024, 256 * 1024, 512 * 1024, 1024 * 1024 ])
BuildFreq("generic")
BuildDebugPort("generic")
BuildDebugLevel("generic")
28 changes: 28 additions & 0 deletions tools/simplesub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
import sys
import struct
import subprocess
import re
import os
import os.path
import argparse
import time

def main():
parser = argparse.ArgumentParser(description='Simple text substitution')
parser.add_argument('-i', '--input', action='store', required=True, help='Path to the source file')
parser.add_argument('-o', '--out', action='store', required=True, help='Path to the output file')
parser.add_argument('-s', '--sub', action='append', nargs=2, metavar=('find', 'replace'), required=True, help='Substition')
args = parser.parse_args()

with open(args.input, "r") as fin:
data = fin.read()

for f, r in args.sub:
data = re.sub(f, r, data)

with open(args.out, "w") as fout:
fout.write(data)


main()
8 changes: 8 additions & 0 deletions variants/adafruitfeather/pins_arduino.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef __rpipico_pins_arduino_h__
#define __rpipico_pins_arduino_h__

#define LED_BUILTIN 13

#include "../generic/common.h"

#endif
Loading