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.
This commit is contained in:
robert-hh 2022-06-05 08:55:27 +02:00 committed by Damien George
parent 4013577af2
commit 6c037af086
4 changed files with 300 additions and 5 deletions

View file

@ -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)

View file

@ -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()

View file

@ -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,
1 # The pin_cap_tables contain the information anbout pin mux set and pad
2 # for some of the peripheral devices with many possible assignments.
3 # The pin_cap_table is a subset from table 7-1 of the data sheet.
4 # It contain the information about pin mux set and pad
5 # The eic and adc columns contain the decimal numer for the respecitive
6 # quantity, the columns for sercom, tc and tcc have in each cell
7 # the device number in the upper nibble, and the pad number in the lower
8 # nibble. If a signal is not available, the cell in the csv table is left empty.
9 # The first column is the pin id, not the number of the board pin.
10 # Rows not starting with pa, pb, pc or pd are ignored.
11 # When editing the table with a spread sheet, take care to import the data as text.
12 #
13 # Pin,EIC,ADC,SERCOM1,SERCOM2,TC,TCC
14 pa00,0,,,10,20,
15 pa01,1,,,11,21,
16 pa02,2,0,,,,
17 pa03,3,1,,,,
18 pb04,4,12,,,,
19 pb05,5,13,,,,
20 pb06,6,14,,,,
21 pb07,7,15,,,,
22 pb08,8,2,,40,40,
23 pb09,9,3,,41,41,
24 pa04,4,4,,00,00,
25 pa05,5,5,,01,01,
26 pa06,6,6,,02,10,
27 pa07,7,7,,03,11,
28 pa08,,16,00,20,00,12
29 pa09,9,17,01,21,01,13
30 pa10,10,18,02,22,10,02
31 pa11,11,19,03,23,11,03
32 pb10,10,,,42,50,04
33 pb11,11,,,43,51,05
34 pb12,12,,40,,40,06
35 pb13,13,,41,,41,07
36 pb14,14,,42,,50,
37 pb15,15,,43,,51,
38 pa12,12,,20,40,20,06
39 pa13,13,,21,41,20,07
40 pa14,14,,22,42,30,04
41 pa15,15,,23,43,31,05
42 pa16,0,,10,30,20,06
43 pa17,1,,11,31,21,07
44 pa18,2,,12,32,30,02
45 pa19,3,,13,33,31,03
46 pb16,9,,50,,60,04
47 pb17,1,,51,,61,05
48 pa20,4,,52,32,70,04
49 pa21,5,,53,33,71,07
50 pa22,6,,30,50,40,04
51 pa23,7,,31,51,41,05
52 pa24,12,,32,52,50,12
53 pa25,13,,33,53,51,13
54 pb22,6,,,52,70,
55 pb23,7,,,53,71,
56 pa27,15,,,,,
57 pa28,8,,,,,
58 pa30,10,,,12,10,
59 pa31,11,,,13,11,
60 pb30,14,,,50,00,12
61 pb31,15,,,51,01,13
62 pb00,0,,,52,70,
63 pb01,1,,,53,71,
64 pb02,2,,,50,60,
65 pb03,3,,,51,61,

View file

@ -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,
1 # The pin_cap_table is a subset from table 6-1 of the data sheet.
2 # It contain the information about pin mux set and pad
3 # for some of the peripheral devices with many possible assignments.
4 # The colums represent the peripheral class, as defined in pin_cap_t. The
5 # column number is equivalent to the mux class.
6 # The eic and adc columns contain the decimal numer for the respecitive
7 # quantity, the columns for sercom, tc and tcc have in each cell
8 # the device number in the first, and the pad number in the second
9 # digit. If a signal is not available, the cell in the csv table is left empty.
10 # The first column is the pin id, not the number of the board pin.
11 # Rows not starting with pa, pb, pc or pd are ignored.
12 # When editing the table with a spread sheet, take care to import the data as text.
13 #
14 # Pin,EIC,ADC0,ADC1,SERCOM1,SERCOM2,TC,TCC1,TCC2
15 pb03,9,15,,,51,61,,
16 pa00,0,,,,10,20,,
17 pa01,1,,,,11,21,,
18 pc00,0,,10,,,,,
19 pc01,1,,11,,,,,
20 pc02,2,,4,,,,,
21 pc03,3,,5,,,,,
22 pa02,2,0,,,,,,
23 pa03,3,10,,,,,,
24 pb04,4,,6,,,,,
25 pb05,5,,7,,,,,
26 pd00,0,,14,,,,,
27 pd01,1,,15,,,,,
28 pb06,6,,8,,,,,
29 pb07,7,,9,,,,,
30 pb08,8,2,0,,40,40,,
31 pb09,9,3,1,,41,41,,
32 pa04,4,4,,,00,00,,
33 pa05,5,5,,,01,01,,
34 pa06,6,6,,,02,10,,
35 pa07,7,7,,,03,11,,
36 pc04,4,,,60,,,00,
37 pc05,5,,,61,,,,
38 pc06,6,,,62,,,,
39 pc07,9,,,63,,,,
40 pa08,,8,2,00,21,00,00,14
41 pa09,9,9,3,01,20,01,01,15
42 pa10,10,10,,02,22,10,02,16
43 pa11,11,11,,03,23,11,03,17
44 pb10,10,,,,42,50,04,10
45 pb11,12,,,,43,51,05,11
46 pb12,12,,,40,,40,30,00
47 pb13,13,,,41,,41,31,01
48 pb14,14,,,42,,50,40,02
49 pb15,15,,,43,,51,41,03
50 pd08,3,,,70,61,,01,
51 pd09,4,,,71,60,,02,
52 pd10,5,,,72,62,,03,
53 pd11,6,,,73,63,,04,
54 pd12,7,,,,,,05,
55 pc10,10,,,62,72,,00,14
56 pc11,11,,,63,73,,01,15
57 pc12,12,,,70,61,,02,16
58 pc13,13,,,71,60,,03,17
59 pc14,14,,,72,62,,04,10
60 pc15,15,,,73,63,,05,11
61 pa12,12,,,20,41,20,06,12
62 pa13,13,,,21,40,21,07,13
63 pa14,14,,,22,42,30,20,12
64 pa15,15,,,23,43,31,21,13
65 pa16,0,,,10,31,20,10,04
66 pa17,1,,,11,30,21,11,05
67 pa18,2,,,12,32,30,12,06
68 pa19,3,,,13,33,31,13,07
69 pc16,0,,,60,01,,00,
70 pc17,1,,,61,00,,01,
71 pc18,2,,,62,02,,02,
72 pc19,3,,,63,03,,03,
73 pc20,4,,,,,,04,
74 pc21,5,,,,,,05,
75 pc22,6,,,10,31,,05,
76 pc23,7,,,11,30,,07,
77 pd20,10,,,12,32,,10,
78 pd21,11,,,13,33,,11,
79 pb16,0,,,50,,60,30,04
80 pb17,1,,,51,,61,31,05
81 pb18,2,,,52,72,,10,
82 pb19,3,,,53,73,,11,
83 pb20,4,,,30,71,,12,
84 pb21,5,,,31,70,,13,
85 pa20,4,,,52,32,70,14,00
86 pa21,5,,,53,33,71,15,01
87 pa22,6,,,30,51,40,16,02
88 pa23,7,,,31,50,41,17,03
89 pa24,8,,,32,52,50,22,
90 pa25,9,,,33,53,51,,
91 pb22,22,,,12,52,70,,
92 pb23,7,,,13,53,71,,
93 pb24,8,,,00,21,,,
94 pb25,9,,,01,20,,,
95 pb26,12,,,20,41,,12,
96 pb27,13,,,21,40,,13,
97 pb28,14,,,22,42,,14,
98 pb29,15,,,23,43,,15,
99 pc24,8,,,02,22,,,
100 pc25,9,,,03,23,,,
101 pc26,10,,,,,,,
102 pc27,11,,,10,,,,
103 pc28,12,,,11,,,,
104 pa27,11,,,,,,,
105 pa30,14,,,72,12,60,20,
106 pa31,15,,,73,13,61,21,
107 pb30,14,,,70,51,00,40,06
108 pb31,15,,,71,50,01,41,07
109 pc30,14,,12,,,,,
110 pc31,15,,13,,,,,
111 pb00,9,12,,,52,70,,
112 pb01,1,13,,,53,71,,
113 pb02,2,14,,,50,60,22,