[genpinmap] Enhance path management

Use JSON configuration file

Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
This commit is contained in:
Frederic.Pillon 2018-04-30 15:57:17 +02:00
parent 88602c9d1a
commit da6cd5ab0e

View file

@ -2,6 +2,7 @@ import sys
import re import re
import os import os
import datetime import datetime
import json
from xml.dom import minidom from xml.dom import minidom
from xml.dom.minidom import parse, Node from xml.dom.minidom import parse, Node
io_list = [] #'PIN','name' io_list = [] #'PIN','name'
@ -543,6 +544,7 @@ def sort_my_lists():
# START MAIN PROGRAM # START MAIN PROGRAM
cur_dir = os.getcwd() cur_dir = os.getcwd()
out_filename = 'PeripheralPins.c' out_filename = 'PeripheralPins.c'
config_filename = 'config.json'
if len(sys.argv) < 3: if len(sys.argv) < 3:
print("Usage: " + sys.argv[0] + " <BOARD_NAME> <product xml file name>") print("Usage: " + sys.argv[0] + " <BOARD_NAME> <product xml file name>")
@ -561,47 +563,48 @@ if len(sys.argv) < 3:
print(" for instance)") print(" for instance)")
quit() quit()
if sys.platform.startswith('win32'): try:
#print ("Windows env") config_file = open(config_filename, "r")
cubemxdir = 'C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\db\mcu' except IOError:
cubemxdirIP = cubemxdir+"\\IP\\" print("Please set your configuration in %s file" % config_filename)
input_file_name = cubemxdir+"\\" + sys.argv[2] config_file = open(config_filename, "w")
out_path = cur_dir+'\\Arduino\\_'+sys.argv[1] if sys.platform.startswith('win32'):
output_filename = out_path+"\\"+out_filename print("Platform is Windows")
else: cubemxdir = 'C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeMX\\db\\mcu'
#print ("Linux env") elif sys.platform.startswith('linux'):
if sys.platform.startswith('linux'): print("Platform is Linux")
cubemxdir = os.getenv("HOME")+'/STM32CubeMX/db/mcu' cubemxdir = os.getenv("HOME")+'/STM32CubeMX/db/mcu'
cubemxdirIP = cubemxdir+"/IP/" elif sys.platform.startswith('darwin'):
input_file_name = cubemxdir+'/'+ sys.argv[2] print("Platform is Mac OSX")
out_path = cur_dir+'/Arduino/'+sys.argv[1] cubemxdir = '/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu'
output_filename = out_path+'/'+out_filename
else: else:
#print ("Darwin env") print("Platform unknown")
if sys.platform.startswith('darwin'): cubemxdir = '<Set CubeMX install directory>/db/mcu'
print("Platform is Mac OSX") config_file.write(json.dumps({"CUBEMX_DIRECTORY":cubemxdir}))
cubemxdir = '/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu' config_file.close()
cubemxdirIP = cubemxdir+"/IP/" exit(1)
input_file_name = cubemxdir+'/'+ sys.argv[2]
out_path = cur_dir+'/Arduino/'+sys.argv[1] config = json.load(config_file)
output_filename = out_path+'/'+out_filename config_file.close()
else: cubemxdir = config["CUBEMX_DIRECTORY"]
print ("Unsupported OS")
quit() cubemxdirIP = os.path.join(cubemxdir, 'IP')
input_file_name = os.path.join(cubemxdir, sys.argv[2])
out_path = os.path.join(cur_dir, 'Arduino', sys.argv[1])
output_filename = os.path.join(out_path, out_filename)
#open input file
#check input file exists #check input file exists
if not(os.path.isdir(cubemxdir)): if not(os.path.isdir(cubemxdir)):
print ("\n ! ! ! Cube Mx seems not to be installed or not at the requested location") print ("\n ! ! ! Cube Mx seems not to be installed or not at the requested location")
print ("\n ! ! ! please check the value you set for cubemxdir variable at the top of " + sys.argv[0] + " file") print ("\n ! ! ! please check the value you set for cubemxdir variable at the top of " + sys.argv[0] + " file")
quit() quit()
if not(os.path.isfile(input_file_name)): if not(os.path.isfile(input_file_name)):
print ('\n ! ! ! '+sys.argv[2] + ' file not found') print ('\n ! ! ! ' + sys.argv[2] + ' file not found')
print ("\n ! ! ! Check in " + cubemxdir + " the correct name of this file") print ("\n ! ! ! Check in " + cubemxdir + " the correct name of this file")
print ("\n ! ! ! You may use double quotes for this file if it contains special characters") print ("\n ! ! ! You may use double quotes for this file if it contains special characters")
quit() quit()
#open input file
print (" * * * Opening input file...") print (" * * * Opening input file...")
if not(os.path.isdir(out_path)): if not(os.path.isdir(out_path)):
os.makedirs(out_path) os.makedirs(out_path)
@ -614,11 +617,10 @@ if (os.path.isfile(output_filename)):
out_file = open(output_filename, 'w') out_file = open(output_filename, 'w')
gpiofile = find_gpio_file(xmldoc) gpiofile = find_gpio_file(xmldoc)
if gpiofile == 'ERROR': if gpiofile == 'ERROR':
quit() quit()
xml = parse(cubemxdirIP + 'GPIO-' + gpiofile + '_Modes.xml') xml = parse(os.path.join(cubemxdirIP, 'GPIO-' + gpiofile + '_Modes.xml'))
print (" * * * Getting pins and Ips for the xml file...") print (" * * * Getting pins and Ips for the xml file...")
pinregex=r'^(P[A-Z][0-9][0-5]?)' pinregex=r'^(P[A-Z][0-9][0-5]?)'
for s in itemlist: for s in itemlist:
@ -662,6 +664,7 @@ sort_my_lists()
print (" * * * Printing lists...") print (" * * * Printing lists...")
print_header() print_header()
print_all_lists() print_all_lists()
out_file.close()
nb_pin = (len(io_list)) nb_pin = (len(io_list))
print ("nb of I/O pins: %i" % nb_pin) print ("nb of I/O pins: %i" % nb_pin)