From 8f7c2d187bbb02915f44b926c7aa02185402aef7 Mon Sep 17 00:00:00 2001 From: Fabien Poussin Date: Thu, 19 Sep 2019 19:46:06 +0200 Subject: Adding support for STM32L4 in mx2board --- tools/mx2board.py | 26 +++++++++++++++++++------- tools/templates/board_gpio.tpl | 15 ++++++++++++++- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'tools') 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) diff --git a/tools/templates/board_gpio.tpl b/tools/templates/board_gpio.tpl index 07a316d..1e770f1 100644 --- a/tools/templates/board_gpio.tpl +++ b/tools/templates/board_gpio.tpl @@ -50,6 +50,19 @@ {{ i }} | \ {%- endfor %} 0) +{% if ascr_lockr %} +#define VAL_GPIO{{p}}_ASCR ( \ + {%- for i in v.ASCR %} + {{ i }} | \ + {%- endfor %} + 0) + +#define VAL_GPIO{{p}}_LOCKR ( \ + {%- for i in v.LOCKR %} + {{ i }} | \ + {%- endfor %} + 0) +{% endif %} {% endfor %} -#endif \ No newline at end of file +#endif -- cgit v1.2.3