summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-06-05 08:55:27 +0200
committerDamien George <damien@micropython.org>2022-10-06 22:38:45 +1100
commit6c037af086acd90755f93cd323a5114984885449 (patch)
tree823bda38e6d8db6b2b7208a391a0361154023757
parent4013577af2f530599db80a6696c23be2ed335bee (diff)
samd/boards: Create pin_af_table.c from pin_af_table_SAMDxx.csv files.
This step just creates the table. The firmware cannot be built at this commit. The next commit will complete the pin-af mechanism.
-rw-r--r--ports/samd/Makefile23
-rw-r--r--ports/samd/boards/make-pin-af.py104
-rw-r--r--ports/samd/boards/pin-af-table-SAMD21.csv65
-rw-r--r--ports/samd/boards/pin-af-table-SAMD51.csv113
4 files changed, 300 insertions, 5 deletions
diff --git a/ports/samd/Makefile b/ports/samd/Makefile
index ea71973bd..1556d8161 100644
--- a/ports/samd/Makefile
+++ b/ports/samd/Makefile
@@ -45,12 +45,22 @@ INC += -I$(TOP)/lib/asf4/$(MCU_SERIES_LOWER)/include
INC += -I$(TOP)/lib/asf4/$(MCU_SERIES_LOWER)/include/pio
INC += -I$(TOP)/lib/tinyusb/src
+MAKE_PIN_AF = boards/make-pin-af.py
+PIN_AF_TABLE_CSV = boards/pin-af-table-$(MCU_SERIES).csv
+GEN_PIN_AF = pin_af_table.c
+
+MAKE_PINS = boards/make-pins.py
+BOARD_PINS = $(BOARD_DIR)/pins.csv
+GEN_PINS_SRC = $(BUILD)/pins.c
+GEN_PINS_HDR = $(BUILD)/pins.h
+
CFLAGS_MCU_SAMD21 = -mtune=cortex-m0plus -mcpu=cortex-m0plus -msoft-float
CFLAGS_MCU_SAMD51 = -mtune=cortex-m4 -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS = $(INC) -Wall -Werror -std=c99 -nostdlib -mthumb $(CFLAGS_MCU_$(MCU_SERIES)) -fsingle-precision-constant -Wdouble-promotion
CFLAGS += -DMCU_$(MCU_SERIES) -D__$(CMSIS_MCU)__
CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA)
CFLAGS += -DMPCONFIG_MCU_H='<boards/mpconfig_$(MCU_SERIES_LOWER).h>'
+CFLAGS += -DPIN_AF_TABLE_C='<$(BUILD)/$(GEN_PIN_AF)>'
QSTR_GLOBAL_DEPENDENCIES += boards/mpconfig_$(MCU_SERIES_LOWER).h
@@ -59,11 +69,6 @@ LDFLAGS += $(LDFLAGS_MOD)
LIBS = $(shell $(CC) $(CFLAGS) -print-libgcc-file-name)
-MAKE_PINS = boards/make-pins.py
-BOARD_PINS = $(BOARD_DIR)/pins.csv
-GEN_PINS_SRC = $(BUILD)/pins.c
-GEN_PINS_HDR = $(BUILD)/pins.h
-
# Tune for Debugging or Optimization
CFLAGS += -g # always include debug info in the ELF
ifeq ($(DEBUG),1)
@@ -92,6 +97,7 @@ SRC_C = \
modmachine.c \
modsamd.c \
mphalport.c \
+ pin_af.c \
$(BUILD)/pins.c \
samd_flash.c \
samd_isr.c \
@@ -170,6 +176,13 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf
$(BUILD)/firmware.uf2: $(BUILD)/firmware.bin
$(Q)$(PYTHON) $(UF2CONV) -b $(TEXT0) -c -o $@ $<
+pin_af.c: $(BUILD)/$(GEN_PIN_AF)
+
+$(BUILD)/$(GEN_PIN_AF): $(PIN_AF_TABLE_CSV)
+ $(ECHO) "Create $@"
+ $(Q)$(PYTHON) $(MAKE_PIN_AF) --csv $(PIN_AF_TABLE_CSV) --table $(BUILD)/$(GEN_PIN_AF) --mcu $(MCU_SERIES)
+
+
$(GEN_PINS_SRC): $(BOARD_PINS)
$(ECHO) "Create $@"
$(Q)$(PYTHON) $(MAKE_PINS) --board $(BOARD_PINS) --pins $(GEN_PINS_SRC) --inc $(GEN_PINS_HDR)
diff --git a/ports/samd/boards/make-pin-af.py b/ports/samd/boards/make-pin-af.py
new file mode 100644
index 000000000..d895ef9dd
--- /dev/null
+++ b/ports/samd/boards/make-pin-af.py
@@ -0,0 +1,104 @@
+#!/usr/bin/env python
+"""Generates the pin_cap table file for the SAMD port."""
+
+from __future__ import print_function
+
+import argparse
+import sys
+import csv
+
+table_header = """// This file was automatically generated by make-pin-cap.py
+//
+
+"""
+
+
+class Pins:
+ def __init__(self):
+ self.board_pins = [] # list of pin objects
+
+ def parse_csv_file(self, filename):
+ with open(filename, "r") as csvfile:
+ rows = csv.reader(csvfile)
+ for row in rows:
+ # Pin numbers must start with "PA", "PB", "PC" or "PD"
+ if len(row) > 0 and row[0].strip().upper()[:2] in ("PA", "PB", "PC", "PD"):
+ self.board_pins.append(row)
+
+ def print_table(self, table_filename, mcu_name):
+ with open(table_filename, "wt") as table_file:
+ table_file.write(table_header)
+ table_file.write("const pin_af_t pin_af_table[] = {\n")
+ if mcu_name == "SAMD21":
+ for row in self.board_pins:
+ pin = "PIN_" + row[0].upper()
+ table_file.write(" #ifdef " + pin + "\n")
+ eic = row[1] if row[1] else "0xff"
+ adc = row[2] if row[2] else "0xff"
+ table_file.write(" {%s, %s, %s" % (pin, eic, adc))
+ for cell in row[3:]:
+ if cell:
+ table_file.write(
+ ", 0x%s" % cell if len(cell) == 2 else ", 0x0%s" % cell
+ )
+ else:
+ table_file.write(", 0xff")
+ table_file.write("},\n")
+ table_file.write(" #endif\n")
+ else:
+ for row in self.board_pins:
+ pin = "PIN_" + row[0].upper()
+ table_file.write(" #ifdef " + pin + "\n")
+ eic = row[1] if row[1] else "0xff"
+ adc0 = row[2] if row[2] else "0xff"
+ adc1 = row[3] if row[3] else "0xff"
+ table_file.write(" {%s, %s, %s, %s" % (pin, eic, adc0, adc1))
+ for cell in row[4:]:
+ if cell:
+ table_file.write(
+ ", 0x%s" % cell if len(cell) == 2 else ", 0x0%s" % cell
+ )
+ else:
+ table_file.write(", 0xff")
+ table_file.write("},\n")
+ table_file.write(" #endif\n")
+ table_file.write("};\n")
+
+
+def main():
+ parser = argparse.ArgumentParser(
+ prog="make-pin-cap.py",
+ usage="%(prog)s [options] [command]",
+ description="Generate MCU-specific pin cap table file",
+ )
+ parser.add_argument(
+ "-c",
+ "--csv",
+ dest="csv_filename",
+ help="Specifies the pin-mux-xxxx.csv filename",
+ )
+ parser.add_argument(
+ "-t",
+ "--table",
+ dest="table_filename",
+ help="Specifies the name of the generated pin cap table file",
+ )
+ parser.add_argument(
+ "-m",
+ "--mcu",
+ dest="mcu_name",
+ help="Specifies type of the MCU (SAMD21 or SAMD51)",
+ )
+ args = parser.parse_args(sys.argv[1:])
+
+ pins = Pins()
+
+ if args.csv_filename:
+ pins.parse_csv_file(args.csv_filename)
+
+ if args.table_filename:
+ pins.print_table(args.table_filename, args.mcu_name)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/ports/samd/boards/pin-af-table-SAMD21.csv b/ports/samd/boards/pin-af-table-SAMD21.csv
new file mode 100644
index 000000000..d8ab903c9
--- /dev/null
+++ b/ports/samd/boards/pin-af-table-SAMD21.csv
@@ -0,0 +1,65 @@
+# The pin_cap_tables contain the information anbout pin mux set and pad
+# for some of the peripheral devices with many possible assignments.
+# The pin_cap_table is a subset from table 7-1 of the data sheet.
+# It contain the information about pin mux set and pad
+# The eic and adc columns contain the decimal numer for the respecitive
+# quantity, the columns for sercom, tc and tcc have in each cell
+# the device number in the upper nibble, and the pad number in the lower
+# nibble. If a signal is not available, the cell in the csv table is left empty.
+# The first column is the pin id, not the number of the board pin.
+# Rows not starting with pa, pb, pc or pd are ignored.
+# When editing the table with a spread sheet, take care to import the data as text.
+#
+# Pin,EIC,ADC,SERCOM1,SERCOM2,TC,TCC
+pa00,0,,,10,20,
+pa01,1,,,11,21,
+pa02,2,0,,,,
+pa03,3,1,,,,
+pb04,4,12,,,,
+pb05,5,13,,,,
+pb06,6,14,,,,
+pb07,7,15,,,,
+pb08,8,2,,40,40,
+pb09,9,3,,41,41,
+pa04,4,4,,00,00,
+pa05,5,5,,01,01,
+pa06,6,6,,02,10,
+pa07,7,7,,03,11,
+pa08,,16,00,20,00,12
+pa09,9,17,01,21,01,13
+pa10,10,18,02,22,10,02
+pa11,11,19,03,23,11,03
+pb10,10,,,42,50,04
+pb11,11,,,43,51,05
+pb12,12,,40,,40,06
+pb13,13,,41,,41,07
+pb14,14,,42,,50,
+pb15,15,,43,,51,
+pa12,12,,20,40,20,06
+pa13,13,,21,41,20,07
+pa14,14,,22,42,30,04
+pa15,15,,23,43,31,05
+pa16,0,,10,30,20,06
+pa17,1,,11,31,21,07
+pa18,2,,12,32,30,02
+pa19,3,,13,33,31,03
+pb16,9,,50,,60,04
+pb17,1,,51,,61,05
+pa20,4,,52,32,70,04
+pa21,5,,53,33,71,07
+pa22,6,,30,50,40,04
+pa23,7,,31,51,41,05
+pa24,12,,32,52,50,12
+pa25,13,,33,53,51,13
+pb22,6,,,52,70,
+pb23,7,,,53,71,
+pa27,15,,,,,
+pa28,8,,,,,
+pa30,10,,,12,10,
+pa31,11,,,13,11,
+pb30,14,,,50,00,12
+pb31,15,,,51,01,13
+pb00,0,,,52,70,
+pb01,1,,,53,71,
+pb02,2,,,50,60,
+pb03,3,,,51,61,
diff --git a/ports/samd/boards/pin-af-table-SAMD51.csv b/ports/samd/boards/pin-af-table-SAMD51.csv
new file mode 100644
index 000000000..70a009ba5
--- /dev/null
+++ b/ports/samd/boards/pin-af-table-SAMD51.csv
@@ -0,0 +1,113 @@
+# The pin_cap_table is a subset from table 6-1 of the data sheet.
+# It contain the information about pin mux set and pad
+# for some of the peripheral devices with many possible assignments.
+# The colums represent the peripheral class, as defined in pin_cap_t. The
+# column number is equivalent to the mux class.
+# The eic and adc columns contain the decimal numer for the respecitive
+# quantity, the columns for sercom, tc and tcc have in each cell
+# the device number in the first, and the pad number in the second
+# digit. If a signal is not available, the cell in the csv table is left empty.
+# The first column is the pin id, not the number of the board pin.
+# Rows not starting with pa, pb, pc or pd are ignored.
+# When editing the table with a spread sheet, take care to import the data as text.
+#
+# Pin,EIC,ADC0,ADC1,SERCOM1,SERCOM2,TC,TCC1,TCC2
+pb03,9,15,,,51,61,,
+pa00,0,,,,10,20,,
+pa01,1,,,,11,21,,
+pc00,0,,10,,,,,
+pc01,1,,11,,,,,
+pc02,2,,4,,,,,
+pc03,3,,5,,,,,
+pa02,2,0,,,,,,
+pa03,3,10,,,,,,
+pb04,4,,6,,,,,
+pb05,5,,7,,,,,
+pd00,0,,14,,,,,
+pd01,1,,15,,,,,
+pb06,6,,8,,,,,
+pb07,7,,9,,,,,
+pb08,8,2,0,,40,40,,
+pb09,9,3,1,,41,41,,
+pa04,4,4,,,00,00,,
+pa05,5,5,,,01,01,,
+pa06,6,6,,,02,10,,
+pa07,7,7,,,03,11,,
+pc04,4,,,60,,,00,
+pc05,5,,,61,,,,
+pc06,6,,,62,,,,
+pc07,9,,,63,,,,
+pa08,,8,2,00,21,00,00,14
+pa09,9,9,3,01,20,01,01,15
+pa10,10,10,,02,22,10,02,16
+pa11,11,11,,03,23,11,03,17
+pb10,10,,,,42,50,04,10
+pb11,12,,,,43,51,05,11
+pb12,12,,,40,,40,30,00
+pb13,13,,,41,,41,31,01
+pb14,14,,,42,,50,40,02
+pb15,15,,,43,,51,41,03
+pd08,3,,,70,61,,01,
+pd09,4,,,71,60,,02,
+pd10,5,,,72,62,,03,
+pd11,6,,,73,63,,04,
+pd12,7,,,,,,05,
+pc10,10,,,62,72,,00,14
+pc11,11,,,63,73,,01,15
+pc12,12,,,70,61,,02,16
+pc13,13,,,71,60,,03,17
+pc14,14,,,72,62,,04,10
+pc15,15,,,73,63,,05,11
+pa12,12,,,20,41,20,06,12
+pa13,13,,,21,40,21,07,13
+pa14,14,,,22,42,30,20,12
+pa15,15,,,23,43,31,21,13
+pa16,0,,,10,31,20,10,04
+pa17,1,,,11,30,21,11,05
+pa18,2,,,12,32,30,12,06
+pa19,3,,,13,33,31,13,07
+pc16,0,,,60,01,,00,
+pc17,1,,,61,00,,01,
+pc18,2,,,62,02,,02,
+pc19,3,,,63,03,,03,
+pc20,4,,,,,,04,
+pc21,5,,,,,,05,
+pc22,6,,,10,31,,05,
+pc23,7,,,11,30,,07,
+pd20,10,,,12,32,,10,
+pd21,11,,,13,33,,11,
+pb16,0,,,50,,60,30,04
+pb17,1,,,51,,61,31,05
+pb18,2,,,52,72,,10,
+pb19,3,,,53,73,,11,
+pb20,4,,,30,71,,12,
+pb21,5,,,31,70,,13,
+pa20,4,,,52,32,70,14,00
+pa21,5,,,53,33,71,15,01
+pa22,6,,,30,51,40,16,02
+pa23,7,,,31,50,41,17,03
+pa24,8,,,32,52,50,22,
+pa25,9,,,33,53,51,,
+pb22,22,,,12,52,70,,
+pb23,7,,,13,53,71,,
+pb24,8,,,00,21,,,
+pb25,9,,,01,20,,,
+pb26,12,,,20,41,,12,
+pb27,13,,,21,40,,13,
+pb28,14,,,22,42,,14,
+pb29,15,,,23,43,,15,
+pc24,8,,,02,22,,,
+pc25,9,,,03,23,,,
+pc26,10,,,,,,,
+pc27,11,,,10,,,,
+pc28,12,,,11,,,,
+pa27,11,,,,,,,
+pa30,14,,,72,12,60,20,
+pa31,15,,,73,13,61,21,
+pb30,14,,,70,51,00,40,06
+pb31,15,,,71,50,01,41,07
+pc30,14,,12,,,,,
+pc31,15,,13,,,,,
+pb00,9,12,,,52,70,,
+pb01,1,13,,,53,71,,
+pb02,2,14,,,50,60,22,