Skip to content

Commit

Permalink
STM32_gen_PeripheralPins script update
Browse files Browse the repository at this point in the history
- add CMakeLists.txt
- patch for STM32U5 boards
  • Loading branch information
jeromecoutant committed Aug 16, 2021
1 parent df00ed4 commit 79d403a
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions targets/TARGET_STM/tools/STM32_gen_PeripheralPins.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from argparse import RawTextHelpFormatter
import subprocess

GENPINMAP_VERSION = "1.20.2"
GENPINMAP_VERSION = "1.20.3"

ADD_DEVICE_IF = 0
ADD_GPIO_PINMAP = 0
Expand Down Expand Up @@ -388,9 +388,36 @@ def store_osc(pin, name, signal):

# function to store SYS pins
def store_sys(pin, name, signal):
if 'PWR_WKUP' in signal:
signal = "SYS_" + signal
sys_list.append([pin, name, signal])



def make_cmakelist():
mbed_target = "mbed-" + TARGET_NAME.replace("_", "-").lower()
mbed_family = "mbed-" + TARGET_SUBFAMILY.lower()

line_to_write = ("""# Copyright (c) %i ARM Limited. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
add_library(%s INTERFACE)
target_sources(%s
INTERFACE
PeripheralPins.c
)
target_include_directories(%s
INTERFACE
.
)
target_link_libraries(%s INTERFACE %s)
""" % (datetime.datetime.now().year, mbed_target, mbed_target, mbed_target, mbed_target, mbed_family))
cmake_file.write(line_to_write)


def print_header():
global ALTERNATE_DEFINITION
date_year = datetime.datetime.now().year
Expand Down Expand Up @@ -501,7 +528,8 @@ def print_footer():
LED_list.append("Pxx")
StandardLED = {}
for EachLED in LED_list:
PinLabel[EachLED] = "TODO"
if EachLED not in PinLabel:
PinLabel[EachLED] = "TODO"
StandardLED[PinLabel[EachLED]] = EachLED

for EachLED in sorted(StandardLED):
Expand Down Expand Up @@ -1567,9 +1595,13 @@ def parse_board_file(file_name):
parser.add_argument("-g", "--gpio", help="Add GPIO PinMap table", action="store_true")
parser.add_argument("-n", "--nopull", help="Avoid STM32_open_pin_data git pull", action="store_true")
parser.add_argument("-f", "--flat", help="All targets stored in targets_custom/TARGET_STM/", action="store_true")
parser.add_argument("-d", "--debug", help="Few debug info in console", action="store_true")

args = parser.parse_args()

if args.debug:
DEBUG_PRINT = 1

print ("\nChecking STM32_open_pin_data repo...")
if not os.path.exists("STM32_open_pin_data"):
print("*** git clone https://github.com/STMicroelectronics/STM32_open_pin_data.git ***")
Expand Down Expand Up @@ -1652,6 +1684,9 @@ def parse_board_file(file_name):
board_file_name = os.path.join(cubemxdirBOARDS, args.target)
if not(os.path.isfile(board_file_name)):
board_list = fnmatch.filter(os.listdir(cubemxdirBOARDS), '*%s*AllConfig.ioc' % args.target)
for item in list(board_list):
if "TrustZone" in item:
board_list.remove(item)
if len(board_list) == 0:
print (" ! ! ! No file contains " + args.target)
print (" ! ! ! Check in " + cubemxdirBOARDS + " the correct filter to apply")
Expand Down Expand Up @@ -1698,12 +1733,12 @@ def parse_board_file(file_name):

parse_board_file(board_file_name)
if "Nucleo" in board_file_name:
TARGET_NAME += "NUCLEO_"
TARGET_NAME = "NUCLEO_"
elif "Discovery" in board_file_name:
TARGET_NAME += "DISCO_"
TARGET_NAME = "DISCO_"
elif "Evaluation" in board_file_name:
TARGET_NAME += "EVAL_"
m = re.search(r'STM32([MFLGWH][\w]*)_Board', board_file_name)
TARGET_NAME = "EVAL_"
m = re.search(r'STM32([MFLGWHU][\w]*)_Board', board_file_name)
if m:
TARGET_NAME += "%s" % m.group(1)
# specific case
Expand All @@ -1718,6 +1753,7 @@ def parse_board_file(file_name):
"DISCO_L4S5V": "B_L4S5I_IOT01A",
"DISCO_G071RBT": "DISCO_G071RB",
"DISCO_L4R9A": "DISCO_L4R9I",
"DISCO_U585AI": "B_U585I_IOT02A",
"NUCLEO_WB55R": "NUCLEO_WB55RG",
"NUCLEO_WL55JCI": "NUCLEO_WL55JC",
"NUCLEO_H743ZIT": "NUCLEO_H743ZI2",
Expand Down Expand Up @@ -1845,12 +1881,14 @@ def parse_board_file(file_name):
print(" * Generating %s and %s with '%s'" % (PeripheralPins_c_filename, PinNames_h_filename, input_file_name))
output_cfilename = os.path.join(out_path, PeripheralPins_c_filename)
output_hfilename = os.path.join(out_path, PinNames_h_filename)
cmake_filename = os.path.join(out_path, "CMakeLists.txt")

if os.path.isfile(output_cfilename):
print_debug(" * Requested %s file already exists and will be overwritten" % PeripheralPins_c_filename)
os.remove(output_cfilename)
out_c_file = open(output_cfilename, 'w')
out_h_file = open(output_hfilename, 'w')
cmake_file = open(cmake_filename, 'w')

#open input file
try:
Expand Down Expand Up @@ -1897,6 +1935,7 @@ def parse_board_file(file_name):
print_header()
print_all_lists()
print_footer()
make_cmakelist()

nb_pin = (len(gpio_list))
nb_connected_pin = len(PinLabel)
Expand All @@ -1905,3 +1944,4 @@ def parse_board_file(file_name):

out_c_file.close()
out_h_file.close()
cmake_file.close()

0 comments on commit 79d403a

Please sign in to comment.