From bedd9c5463b5eabcf586f08e9067e10d0aa3e458 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Sat, 18 Dec 2021 22:18:33 +0200 Subject: [PATCH] stm32/boards/make-pins.py: Generate empty ADC table if needed. If ADCx pins are hidden, print an empty table to prevent linker errors. --- ports/stm32/boards/make-pins.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/ports/stm32/boards/make-pins.py b/ports/stm32/boards/make-pins.py index b11f438aae3d..14c9e91097d2 100755 --- a/ports/stm32/boards/make-pins.py +++ b/ports/stm32/boards/make-pins.py @@ -426,16 +426,19 @@ def print_adc(self, adc_num): adc_pins[pin.adc_channel] = pin if adc_pins: table_size = max(adc_pins) + 1 - self.adc_table_size[adc_num] = table_size - print("") - print("const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size)) - for channel in range(table_size): - if channel in adc_pins: - obj = "&pin_{:s}_obj".format(adc_pins[channel].cpu_pin_name()) - else: - obj = "NULL" - print(" [{:d}] = {},".format(channel, obj)) - print("};") + else: + # If ADCx pins are hidden, print an empty table to prevent linker errors. + table_size = 0 + self.adc_table_size[adc_num] = table_size + print("") + print("const pin_obj_t * const pin_adc{:d}[{:d}] = {{".format(adc_num, table_size)) + for channel in range(table_size): + if channel in adc_pins: + obj = "&pin_{:s}_obj".format(adc_pins[channel].cpu_pin_name()) + else: + obj = "NULL" + print(" [{:d}] = {},".format(channel, obj)) + print("};") def print_header(self, hdr_filename, obj_decls): with open(hdr_filename, "wt") as hdr_file: