From 4c6c1a93d288c66f4902dff33b5e4c93d42939e7 Mon Sep 17 00:00:00 2001 From: Andrew Scheller Date: Wed, 6 May 2026 10:28:58 +0100 Subject: [PATCH] Tweak check_board_header.py to also validate the PSRAM settings --- src/rp2350/rp2350a_interface_pins.json | 7 ++++ src/rp2350/rp2350b_interface_pins.json | 7 ++++ tools/check_board_header.py | 47 +++++++++++++++++++++++--- 3 files changed, 56 insertions(+), 5 deletions(-) diff --git a/src/rp2350/rp2350a_interface_pins.json b/src/rp2350/rp2350a_interface_pins.json index 7869d2aad..1a75f607d 100644 --- a/src/rp2350/rp2350a_interface_pins.json +++ b/src/rp2350/rp2350a_interface_pins.json @@ -89,6 +89,13 @@ "B": [15] } } + }, + "QMI": { + "instances": { + "0": { + "CS1N": [0, 8, 19] + } + } } }, "pins": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29] diff --git a/src/rp2350/rp2350b_interface_pins.json b/src/rp2350/rp2350b_interface_pins.json index ee90ad27f..c8ed6bb85 100644 --- a/src/rp2350/rp2350b_interface_pins.json +++ b/src/rp2350/rp2350b_interface_pins.json @@ -105,6 +105,13 @@ "B": [39, 47] } } + }, + "QMI": { + "instances": { + "0": { + "CS1N": [0, 8, 19, 47] + } + } } }, "pins": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47] diff --git a/tools/check_board_header.py b/tools/check_board_header.py index 5a5c84e63..f835beadb 100755 --- a/tools/check_board_header.py +++ b/tools/check_board_header.py @@ -37,10 +37,24 @@ def __init__(self, message, errors): 'RP2350B': "src/rp2350/rp2350b_interface_pins.json", } -compulsory_cmake_settings = set(['PICO_PLATFORM']) -compulsory_cmake_default_settings = set(['PICO_FLASH_SIZE_BYTES']) -matching_cmake_default_settings = set(['PICO_FLASH_SIZE_BYTES', 'PICO_RP2350_A2_SUPPORTED']) -compulsory_defines = set(['PICO_FLASH_SIZE_BYTES']) +# names for which we MUST have a pico_board_cmake_set +compulsory_cmake_settings = frozenset(['PICO_PLATFORM']) + +# names for which we MUST have a pico_board_cmake_set_default +compulsory_cmake_default_settings = frozenset(['PICO_FLASH_SIZE_BYTES']) + +# names for which pico_board_cmake_set_default (if present) needs a matching #define (and vice-versa) +matching_cmake_default_settings = frozenset(['PICO_FLASH_SIZE_BYTES', 'PICO_RP2350_A2_SUPPORTED', 'PICO_PSRAM_SIZE_BYTES']) + +# names for which we MUST have a #define +compulsory_defines = frozenset(['PICO_FLASH_SIZE_BYTES']) + +# names where the presence of one #define requires other #defines to be present too +# (this is one-way and not bidirectional, so you'll need multiple entries for mutually-dependent #defines) +linked_defines = { + 'PICO_PSRAM_SIZE_BYTES': frozenset(['PICO_PSRAM_CS_PIN']), + 'PICO_AUTO_DETECT_PSRAM_SIZE': frozenset(['PICO_PSRAM_CS_PIN']), +} DefineType = namedtuple("DefineType", ["name", "value", "resolved_value", "lineno"]) @@ -456,6 +470,11 @@ def read_defines_from(header_file, defines_dict): for setting in compulsory_defines: if setting not in defines: errors.append(Exception("{} is missing a #define {}".format(board_header, setting))) + for setting in linked_defines: + if setting in defines: + for linked_define in linked_defines[setting]: + if linked_define not in defines: + errors.append(Exception("{} defines {} but is missing a corresponding #define {}".format(board_header, setting, linked_define))) if chip is None: errors.append(Exception("Couldn't determine chip for {}".format(board_header))) @@ -471,7 +490,7 @@ def read_defines_from(header_file, defines_dict): with open(interfaces_json) as interfaces_fh: interface_pins = json.load(interfaces_fh) allowed_interfaces = interface_pins["interfaces"] - allowed_pins = set(interface_pins["pins"]) + allowed_pins = frozenset(interface_pins["pins"]) # convert instance-keys to integers (allowed by Python but not by JSON) for interface in allowed_interfaces: instances = allowed_interfaces[interface]["instances"] @@ -549,6 +568,24 @@ def read_defines_from(header_file, defines_dict): if not any(func_pin in defines for func_pin in expected_function_pins): errors.append(Exception("{}:{} {} is defined but none of {} are defined".format(board_header, define.lineno, name, list_to_string_with(expected_function_pins, "or")))) + # check for invalid PSRAM CS pin + if name == "PICO_PSRAM_CS_PIN": + interface = "QMI" + instance_num = 0 + function = "CS1N" + if interface not in allowed_interfaces: + errors.append(Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json))) + continue + if instance_num not in allowed_interfaces[interface]["instances"]: + errors.append(Exception("{}:{} {} is set to an invalid instance {}".format(board_header, instance_define.lineno, instance_define, instance_num))) + continue + interface_instance = allowed_interfaces[interface]["instances"][instance_num] + if function not in interface_instance: + errors.append(Exception("{}:{} {} is defined but {} isn't a valid function for {}".format(board_header, define.lineno, name, function, instance_define))) + continue + if define.resolved_value not in interface_instance[function]: + errors.append(Exception("{}:{} {} is set to {} which isn't a valid pin for {} on {} {}".format(board_header, define.lineno, name, define.resolved_value, function, interface, instance_num))) + if not has_include_guard: errors.append(Exception("{} has no include-guard (expected {})".format(board_header, expected_include_guard))) if not has_board_detection and expected_board_detection != "NONE":