aboutsummaryrefslogtreecommitdiffstats
path: root/tools/mx2board.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mx2board.py')
-rwxr-xr-xtools/mx2board.py26
1 files changed, 19 insertions, 7 deletions
diff --git a/tools/mx2board.py b/tools/mx2board.py
index 8ab155d..a805e9f 100755
--- a/tools/mx2board.py
+++ b/tools/mx2board.py
@@ -35,11 +35,15 @@ PIN_PUPDR_FLOATING = "PIN_PUPDR_FLOATING({0})"
PIN_PUPDR_PULLUP = "PIN_PUPDR_PULLUP({0})"
PIN_PUPDR_PULLDOWN = "PIN_PUPDR_PULLDOWN({0})"
PIN_AFIO_AF = "PIN_AFIO_AF({0}, {1})"
+PIN_ASCR_DISABLED = "PIN_ASCR_DISABLED({0})"
+PIN_ASCR_ENABLED = "PIN_ASCR_ENABLED({0})"
+PIN_LOCKR_DISABLED = "PIN_LOCKR_DISABLED({0})"
+PIN_LOCKR_ENABLED = "PIN_LOCKR_ENABLED({0})"
FMT = '{0}'
FMT_DEF = '({0})'
-PIN_CONF_LIST = ['MODER', 'OTYPER', 'OSPEEDR', 'PUPDR', 'ODR']
+PIN_CONF_LIST = ['MODER', 'OTYPER', 'OSPEEDR', 'PUPDR', 'ODR', 'ASCR', 'LOCKR']
PIN_CONF_LIST_AF = ['AFRL', 'AFRH']
DEFAULT_PAD = {"SIGNAL": "UNUSED",
@@ -48,7 +52,9 @@ DEFAULT_PAD = {"SIGNAL": "UNUSED",
"OTYPER": PIN_OTYPE_PUSHPULL,
"OSPEEDR": PIN_OSPEED_VERYLOW,
"PUPDR": PIN_PUPDR_FLOATING,
- "ODR": PIN_ODR_LOW}
+ "ODR": PIN_ODR_LOW,
+ "ASCR": PIN_ASCR_DISABLED,
+ "LOCKR": PIN_LOCKR_DISABLED}
PIN_MODE_TRANSLATE = {"GPIO_MODE_AF_PP": PIN_MODE_ALTERNATE,
"GPIO_MODE_ANALOG": PIN_MODE_ANALOG,
@@ -207,8 +213,13 @@ def read_project(gpio, filename):
with open(filename, 'r') as mx_file:
tmp = mx_file.readlines()
pads = {}
+ mcu = 'Unknown'
+
+ for l in tmp:
+ if l.startswith('Mcu.Name'):
+ mcu = l.split('=')[-1].strip()
- # Default all pads to analog
+ # Default pad mode is analog, here we assign proper mode and speed.
for p in gpio['ports'].keys():
pads[p] = {}
for i in range(0, 16):
@@ -267,7 +278,7 @@ def read_project(gpio, filename):
pads[pad_port][pad_num]["OTYPER"] = PIN_OTYPE_OPENDRAIN
- return pads
+ return mcu, pads
# Add defines for all pins with labels
@@ -389,10 +400,11 @@ if __name__ == '__main__':
else:
gpio_file = get_gpio_file(args.project, args.mx)
gpio = read_gpio(gpio_file)
- proj = read_project(gpio, args.project)
+
+ mcu, proj = read_project(gpio, args.project)
defines = gen_defines(proj)
ports = gen_ports(gpio, proj)
-
+
with open(cur_path + '/templates/board_gpio.tpl', 'r') as tpl_file:
tpl = tpl_file.read()
template = Template(tpl)
@@ -405,6 +417,6 @@ if __name__ == '__main__':
for p in sorted(ports.keys()):
ports_sorted.append((p, ports[p]))
- template.stream(defines=defines_sorted, ports=ports_sorted).dump(args.output)
+ template.stream(defines=defines_sorted, ports=ports_sorted, ascr_lockr='L4' in mcu).dump(args.output)
print('File generated at ' + args.output)