Skip to content

Commit 10645bf

Browse files
authored
Merge pull request #5035 from tannewt/correct_a2040_flash
Fix Arduino RP2040 flash size
2 parents 8723a03 + 109bd28 commit 10645bf

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

ports/raspberrypi/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ $(BUILD)/stage2.c: stage2.c.jinja gen_stage2.py | $(BUILD)/
260260
$(STEPECHO) "GEN $<"
261261
$(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES)
262262

263+
$(HEADER_BUILD)/flash_info.h: flash_info.h.jinja gen_stage2.py | $(HEADER_BUILD)/
264+
$(STEPECHO) "GEN $<"
265+
$(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES)
266+
267+
$(BUILD)/supervisor/internal_flash.o: $(HEADER_BUILD)/flash_info.h
268+
263269
$(BUILD)/boot2.elf: $(BUILD)/stage2.c
264270
$(STEPECHO) "BOOT $<"
265271
$(Q)$(CC) $(CFLAGS) $(BOOT2_S_CFLAGS) -Os -ggdb3 -I. -fPIC --specs=nosys.specs -nostartfiles -Wl,-T,boot_stage2.ld -Wl,-Map=$@.map -o $@ $<

ports/raspberrypi/flash_info.h.jinja

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// This file is auto-generated using gen_stage2.py
2+
3+
#pragma once
4+
5+
#define FLASH_DEFAULT_POWER_OF_TWO {{ default_power_of_two }}

ports/raspberrypi/gen_stage2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import math
12
import sys
23
import cascadetoml
34
import pathlib
@@ -46,6 +47,18 @@ def all_match(nvms, key, default=None):
4647

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

50+
default_power_of_two = None
51+
for nvm in flashes["nvm"]:
52+
capacity = nvm.get("capacity", 0)
53+
if not 21 <= capacity < 30:
54+
power_of_two = int(math.log2(nvm["total_size"]))
55+
if not default_power_of_two:
56+
default_power_of_two = power_of_two
57+
else:
58+
default_power_of_two = min(power_of_two, default_power_of_two)
59+
if not default_power_of_two:
60+
default_power_of_two = 21
61+
4962
# Check that we have a consistent way to set quad enable.
5063
if continuous_status_write is None and split_status_write is None:
5164
print("quad not ok", continuous_status_write, split_status_write)
@@ -71,6 +84,7 @@ def all_match(nvms, key, default=None):
7184
"clock_divider": clock_divider,
7285
"read_command": read_command,
7386
"wait_cycles": wait_cycles,
87+
"default_power_of_two": default_power_of_two,
7488
}
7589

7690
template = Template(input_template.read_text())

ports/raspberrypi/supervisor/internal_flash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy