8000 Fix Arduino RP2040 flash size by tannewt · Pull Request #5035 · adafruit/circuitpython · GitHub
[go: up one dir, main page]

Skip to content

Fix Arduino RP2040 flash size #5035

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
Jul 21, 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
6 changes: 6 additions & 0 deletions ports/raspberrypi/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ $(BUILD)/stage2.c: stage2.c.jinja gen_stage2.py | $(BUILD)/
$(STEPECHO) "GEN $<"
$(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES)

$(HEADER_BUILD)/flash_info.h: flash_info.h.jinja gen_stage2.py | $(HEADER_BUILD)/
$(STEPECHO) "GEN $<"
$(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES)

$(BUILD)/supervisor/internal_flash.o: $(HEADER_BUILD)/flash_info.h

$(BUILD)/boot2.elf: $(BUILD)/stage2.c
$(STEPECHO) "BOOT $<"
$(Q)$(CC) $(CFLAGS) $(BOOT2_S_CFLAGS) -Os -ggdb3 -I. -fPIC --specs=nosys.specs -nostartfiles -Wl,-T,boot_stage2.ld -Wl,-Map=$@.map -o $@ $<
Expand Down
5 changes: 5 additions & 0 deletions ports/raspberrypi/flash_info.h.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// This file is auto-generated using gen_stage2.py

#pragma once

#define FLASH_DEFAULT_POWER_OF_TWO {{ default_power_of_two }}
14 changes: 14 additions & 0 deletions ports/raspberrypi/gen_stage2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import math
import sys
import cascadetoml
import pathlib
Expand Down Expand Up @@ -46,6 +47,18 @@ def all_match(nvms, key, default=None):

max_clock_speed_mhz = min((x.get("max_clock_speed_mhz", 1000) for x in flashes["nvm"]))

default_power_of_two = None
for nvm in flashes["nvm"]:
capacity = nvm.get("capacity", 0)
if not 21 <= capacity < 30:
power_of_two = int(math.log2(nvm["total_size"]))
if not default_power_of_two:
default_power_of_two = power_of_two< 8000 /td>
else:
default_power_of_two = min(power_of_two, default_power_of_two)
if not default_power_of_two:
default_power_of_two = 21

# Check that we have a consistent way to set quad enable.
if continuous_status_write is None and split_status_write is None:
print("quad not ok", continuous_status_write, split_status_write)
Expand All @@ -71,6 +84,7 @@ def all_match(nvms, key, default=None):
"clock_divider": clock_divider,
"read_command": read_command,
"wait_cycles": wait_cycles,
"default_power_of_two": default_power_of_two,
}

template = Template(input_template.read_text())
Expand Down
3 changes: 2 additions & 1 deletion ports/raspberrypi/supervisor/internal_flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "extmod/vfs.h"
#include "extmod/vfs_fat.h"
#include "genhdr/flash_info.h"
#include "py/mphal.h"
#include "py/obj.h"
#include "py/runtime.h"
Expand Down Expand Up @@ -68,7 +69,7 @@ void supervisor_flash_init(void) {
uint8_t cmd[] = {0x9f, 0, 0, 0};
uint8_t data[4];
flash_do_cmd(cmd, data, 4);
uint8_t power_of_two = 21;
uint8_t power_of_two = FLASH_DEFAULT_POWER_OF_TWO;
// Flash must be at least 2MB (1 << 21) because we use the first 1MB for the
// CircuitPython core. We validate the range because Adesto Tech flash chips
// don't return the correct value. So, we default to 2MB which will work for
Expand Down
0