Skip to content

Commit

Permalink
[genpinmap] Add CubeMX database version and release
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Oct 27, 2020
1 parent 17f35a8 commit 10e65d0
Showing 1 changed file with 25 additions and 12 deletions.
37 changes: 25 additions & 12 deletions src/genpinmap/genpinmap_arduino.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def print_header():
*
*******************************************************************************
* Automatically generated from {}
* CubeMX DB version {} release {}
*/
#include "Arduino.h"
#include "{}.h"
Expand All @@ -313,6 +314,8 @@ def print_header():
""".format(
datetime.datetime.now().year,
os.path.basename(input_file_name),
cubemx_db_version,
cubemx_db_release,
re.sub("\\.c$", "", out_c_filename),
)
out_c_file.write(s)
Expand Down Expand Up @@ -970,20 +973,18 @@ def parse_pins():
config_file = open(config_filename, "w", newline="\n")
if sys.platform.startswith("win32"):
print("Platform is Windows")
cubemxdir = (
"C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeMX\\db\\mcu"
)
cubemxdir = "C:\\Program Files\\STMicroelectronics\\STM32Cube\\STM32CubeMX"
elif sys.platform.startswith("linux"):
print("Platform is Linux")
cubemxdir = os.getenv("HOME") + "/STM32CubeMX/db/mcu"
cubemxdir = os.getenv("HOME") + "/STM32CubeMX"
elif sys.platform.startswith("darwin"):
print("Platform is Mac OSX")
cubemxdir = (
"/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources/db/mcu"
"/Applications/STMicroelectronics/STM32CubeMX.app/Contents/Resources"
)
else:
print("Platform unknown")
cubemxdir = "<Set CubeMX install directory>/db/mcu"
cubemxdir = "<Set CubeMX install directory>"
config_file.write(json.dumps({"CUBEMX_DIRECTORY": cubemxdir}))
config_file.close()
exit(1)
Expand Down Expand Up @@ -1043,21 +1044,33 @@ def parse_pins():
)
quit()

cubemxdirIP = os.path.join(cubemxdir, "IP")
cubemxdirMCU = os.path.join(cubemxdir, "db", "mcu")
cubemxdirIP = os.path.join(cubemxdirMCU, "IP")
version_file = os.path.join(cubemxdir, "db", "package.xml")
cubemx_db_version = "Unknown"
cubemx_db_release = "Unknown"
xml_file = parse(version_file)
Package_item = xml_file.getElementsByTagName("Package")
for item in Package_item:
cubemx_db_version = item.attributes["DBVersion"].value
PackDescription_item = xml_file.getElementsByTagName("PackDescription")
for item in PackDescription_item:
cubemx_db_release = item.attributes["Release"].value
print("CubeMX DB version {} release {}\n".format(cubemx_db_version, cubemx_db_release))

if args.mcu:
# check input file exists
if not (os.path.isfile(os.path.join(cubemxdir, args.mcu))):
if not (os.path.isfile(os.path.join(cubemxdirMCU, args.mcu))):
print("\n" + args.mcu + " file not found")
print("\nCheck in " + cubemxdir + " the correct name of this file")
print("\nCheck in " + cubemxdirMCU + " the correct name of this file")
print("\nYou may use double quotes for file containing special characters")
quit()
mcu_list.append(args.mcu)
else:
mcu_list = fnmatch.filter(os.listdir(cubemxdir), "STM32*.xml")
mcu_list = fnmatch.filter(os.listdir(cubemxdirMCU), "STM32*.xml")

if args.list:
print("Available xml files description: {}".format(mcu_list))
print("Available xml files description:")
for f in mcu_list:
print(f)
quit()
Expand All @@ -1068,7 +1081,7 @@ def parse_pins():
out_c_filename, out_h_filename, mcu_file
)
)
input_file_name = os.path.join(cubemxdir, mcu_file)
input_file_name = os.path.join(cubemxdirMCU, mcu_file)
out_path = os.path.join(
cur_dir,
"Arduino",
Expand Down

0 comments on commit 10e65d0

Please sign in to comment.