Skip to content

Commit

Permalink
Fixes for mx2board.py
Browse files Browse the repository at this point in the history
  • Loading branch information
fpoussin committed May 11, 2017
1 parent a5c3ddb commit f6fb9f4
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tools/mx2board.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

from xml.etree import ElementTree as etree
from jinja2 import Template
from os.path import expanduser, sep, dirname
from os.path import expanduser, sep, dirname, abspath
from argparse import ArgumentParser
from traceback import print_exc
import re
import pprint

Expand Down Expand Up @@ -97,9 +98,6 @@ def get_gpio_file(proj_file, mx_path):
path = None
mcu_info = None

if not mx_path:
mx_path = '.'

print('Opening ' + proj_file)
with open(proj_file, 'r') as f:
proj_data = f.readlines()
Expand All @@ -113,14 +111,19 @@ def get_gpio_file(proj_file, mx_path):
print('Could not find MCU name in project file')
exit(1)

if "STM32F1" in mcu_name:
print('STM32F1xx are not compatible with this script. (old GPIO)')
exit(1)

found = False
for p in (mx_path,
'{0}{1}STM32CubeMX'.format(expanduser("~"), sep),
'C:{}STM32CubeMX'.format(sep)):
'C:{0}Program Files{0}STMicroelectronics{0}STM32Cube{0}STM32CubeMX'.format(sep)):

if not p:
continue
try:
path = '{1}{0}db{0}mcu{0}'.format(sep, p)
print('Trying ' + path)
mcu_info = open_xml(path + mcu_name)
found = True
break
Expand Down Expand Up @@ -182,9 +185,9 @@ def read_gpio(filename):
af = int(''.join(af.split('_')[1])[2:])
gpio['ports'][port][num][s.attrib['Name']] = af
except ValueError as e:
print(e)
print_exc(e)
except AttributeError as e:
print(e)
print_exc(e)

return gpio

Expand Down Expand Up @@ -317,6 +320,7 @@ def gen_ports(gpio, project):

if __name__ == '__main__':
args = parser.parse_args()
cur_path = dirname(abspath(__file__))

if args.gpio:
gpio = read_gpio(args.gpio)
Expand All @@ -328,7 +332,7 @@ def gen_ports(gpio, project):
defines = gen_defines(proj)
ports = gen_ports(gpio, proj)

with open(dirname(__file__) + '/board_gpio.tpl', 'r') as tpl_file:
with open(cur_path + '/board_gpio.tpl', 'r') as tpl_file:
tpl = tpl_file.read()
template = Template(tpl)

Expand Down

0 comments on commit f6fb9f4

Please sign in to comment.