Skip to content

Commit 7e8bb10

Browse files
committed
Tweak check_board_header.py to also validate the PSRAM settings
1 parent 25bd5b7 commit 7e8bb10

3 files changed

Lines changed: 55 additions & 5 deletions

File tree

src/rp2350/rp2350a_interface_pins.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@
8989
"B": [15]
9090
}
9191
}
92+
},
93+
"QMI": {
94+
"instances": {
95+
"0": {
96+
"CS1N": [0, 8, 19]
97+
}
98+
}
9299
}
93100
},
94101
"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]

src/rp2350/rp2350b_interface_pins.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@
105105
"B": [39, 47]
106106
}
107107
}
108+
},
109+
"QMI": {
110+
"instances": {
111+
"0": {
112+
"CS1N": [0, 8, 19, 47]
113+
}
114+
}
108115
}
109116
},
110117
"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]

tools/check_board_header.py

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,23 @@ def __init__(self, message, errors):
3737
'RP2350B': "src/rp2350/rp2350b_interface_pins.json",
3838
}
3939

40-
compulsory_cmake_settings = set(['PICO_PLATFORM'])
41-
compulsory_cmake_default_settings = set(['PICO_FLASH_SIZE_BYTES'])
42-
matching_cmake_default_settings = set(['PICO_FLASH_SIZE_BYTES', 'PICO_RP2350_A2_SUPPORTED'])
43-
compulsory_defines = set(['PICO_FLASH_SIZE_BYTES'])
40+
# names for which we MUST have a pico_board_cmake_set
41+
compulsory_cmake_settings = frozenset(['PICO_PLATFORM'])
42+
43+
# names for which we MUST have a pico_board_cmake_set_default
44+
compulsory_cmake_default_settings = frozenset(['PICO_FLASH_SIZE_BYTES'])
45+
46+
# names for which pico_board_cmake_set_default (if present) needs a matching #define (and vice-versa)
47+
matching_cmake_default_settings = frozenset(['PICO_FLASH_SIZE_BYTES', 'PICO_RP2350_A2_SUPPORTED', 'PICO_PSRAM_SIZE_BYTES'])
48+
49+
# names for which we MUST have a #define
50+
compulsory_defines = frozenset(['PICO_FLASH_SIZE_BYTES'])
51+
52+
# names where the presence of one #define requires other #defines to be present too
53+
# (this is one-way and not bidirectional, so you'll need multiple entries for mutually-dependent #defines)
54+
linked_defines = {
55+
'PICO_PSRAM_SIZE_BYTES': frozenset(['PICO_PSRAM_CS_PIN'])
56+
}
4457

4558
DefineType = namedtuple("DefineType", ["name", "value", "resolved_value", "lineno"])
4659

@@ -456,6 +469,11 @@ def read_defines_from(header_file, defines_dict):
456469
for setting in compulsory_defines:
457470
if setting not in defines:
458471
errors.append(Exception("{} is missing a #define {}".format(board_header, setting)))
472+
for setting in linked_defines:
473+
if setting in defines:
474+
for linked_define in linked_defines[setting]:
475+
if linked_define not in defines:
476+
errors.append(Exception("{} defines {} but is missing a corresponding #define {}".format(board_header, setting, linked_define)))
459477

460478
if chip is None:
461479
errors.append(Exception("Couldn't determine chip for {}".format(board_header)))
@@ -471,7 +489,7 @@ def read_defines_from(header_file, defines_dict):
471489
with open(interfaces_json) as interfaces_fh:
472490
interface_pins = json.load(interfaces_fh)
473491
allowed_interfaces = interface_pins["interfaces"]
474-
allowed_pins = set(interface_pins["pins"])
492+
allowed_pins = frozenset(interface_pins["pins"])
475493
# convert instance-keys to integers (allowed by Python but not by JSON)
476494
for interface in allowed_interfaces:
477495
instances = allowed_interfaces[interface]["instances"]
@@ -549,6 +567,24 @@ def read_defines_from(header_file, defines_dict):
549567
if not any(func_pin in defines for func_pin in expected_function_pins):
550568
errors.append(Exception("{}:{} {} is defined but none of {} are defined".format(board_header, define.lineno, name, list_to_string_with(expected_function_pins, "or"))))
551569

570+
# check for invalid PSRAM CS pin
571+
if name == "PICO_PSRAM_CS_PIN":
572+
interface = "QMI"
573+
instance_num = 0
574+
function = "CS1N"
575+
if interface not in allowed_interfaces:
576+
errors.append(Exception("{}:{} {} is defined but {} isn't in {}".format(board_header, define.lineno, name, interface, interfaces_json)))
577+
continue
578+
if instance_num not in allowed_interfaces[interface]["instances"]:
579+
errors.append(Exception("{}:{} {} is set to an invalid instance {}".format(board_header, instance_define.lineno, instance_define, instance_num)))
580+
continue
581+
interface_instance = allowed_interfaces[interface]["instances"][instance_num]
582+
if function not in interface_instance:
583+
errors.append(Exception("{}:{} {} is defined but {} isn't a valid function for {}".format(board_header, define.lineno, name, function, instance_define)))
584+
continue
585+
if define.resolved_value not in interface_instance[function]:
586+
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)))
587+
552588
if not has_include_guard:
553589
errors.append(Exception("{} has no include-guard (expected {})".format(board_header, expected_include_guard)))
554590
if not has_board_detection and expected_board_detection != "NONE":

0 commit comments

Comments
 (0)