Skip to content

Commit f7440e5

Browse files
committed
[stm32variant] Add generic_clock.c generation
Signed-off-by: Frederic Pillon <[email protected]>
1 parent ce217eb commit f7440e5

File tree

3 files changed

+63
-13
lines changed

3 files changed

+63
-13
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ boards.local.txt
44
platform.local.txt
55
path_config.json
66
update_config.json
7+
variant_config.json
78

89
# Backup
910
*.bak
@@ -34,4 +35,4 @@ __pycache__/
3435
!.vscode/tasks.json
3536
!.vscode/launch.json
3637
!.vscode/extensions.json
37-
*.code-workspace
38+
*.code-workspace

CI/utils/stm32variant.py

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,16 @@ def print_boards_entry():
13851385
return generic_list
13861386

13871387

1388+
def print_general_clock(generic_list):
1389+
generic_clock_template = j2_env.get_template(generic_clock_filename)
1390+
generic_clock_file.write(
1391+
generic_clock_template.render(
1392+
year=datetime.datetime.now().year,
1393+
generic_list=generic_list,
1394+
)
1395+
)
1396+
1397+
13881398
# List management
13891399
tokenize = re.compile(r"(\d+)|(\D+)").findall
13901400

@@ -1713,6 +1723,7 @@ def manage_repo():
17131723
variant_h_filename = "variant.h"
17141724
variant_cpp_filename = "variant.cpp"
17151725
boards_entry_filename = "boards_entry.txt"
1726+
generic_clock_filename = "generic_clock.c"
17161727
repo_local_path = cur_dir / "repo"
17171728
cubemxdir = ""
17181729
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
@@ -1726,7 +1737,13 @@ def manage_repo():
17261737
parser = argparse.ArgumentParser(
17271738
description=textwrap.dedent(
17281739
"""\
1729-
By default, generate {}, {}, {}, {} and {}
1740+
By default, generates:
1741+
- {},
1742+
- {},
1743+
- {},
1744+
- {},
1745+
- {}
1746+
- {}
17301747
for all xml files description available in STM32CubeMX internal database.
17311748
Internal database path must be defined in {}.
17321749
It can be the one from STM32CubeMX directory if defined:
@@ -1740,6 +1757,7 @@ def manage_repo():
17401757
variant_cpp_filename,
17411758
variant_h_filename,
17421759
boards_entry_filename,
1760+
generic_clock_filename,
17431761
config_filename,
17441762
cubemxdir,
17451763
gh_url,
@@ -1766,15 +1784,10 @@ def manage_repo():
17661784
metavar="xml",
17671785
help=textwrap.dedent(
17681786
"""\
1769-
Generate {}, {}, {} and {}
1770-
for specified mcu xml file description in database.
1787+
Generate all files for specified mcu xml file description in database.
17711788
This xml file can contain non alpha characters in its name,
1772-
you should call it with double quotes""".format(
1773-
periph_c_filename,
1774-
pinvar_h_filename,
1775-
variant_cpp_filename,
1776-
variant_h_filename,
1777-
)
1789+
you should call it with double quotes.
1790+
"""
17781791
),
17791792
)
17801793

@@ -1892,6 +1905,7 @@ def manage_repo():
18921905
variant_cpp_filepath = out_temp_path / variant_cpp_filename
18931906
variant_h_filepath = out_temp_path / variant_h_filename
18941907
boards_entry_filepath = out_temp_path / boards_entry_filename
1908+
generic_clock_filepath = out_temp_path / generic_clock_filename
18951909
out_temp_path.mkdir(parents=True, exist_ok=True)
18961910

18971911
# open output file
@@ -1900,12 +1914,13 @@ def manage_repo():
19001914
variant_cpp_file = open(variant_cpp_filepath, "w", newline="\n")
19011915
variant_h_file = open(variant_h_filepath, "w", newline="\n")
19021916
boards_entry_file = open(boards_entry_filepath, "w", newline="\n")
1903-
1917+
generic_clock_file = open(generic_clock_filepath, "w", newline="\n")
19041918
parse_pins()
19051919
sort_my_lists()
19061920
manage_alternate()
19071921

19081922
generic_list = print_boards_entry()
1923+
print_general_clock(generic_list)
19091924
print_peripheral()
19101925
print_pinamevar()
19111926
print_variant(generic_list)
@@ -1932,6 +1947,7 @@ def manage_repo():
19321947
variant_h_file.close()
19331948
variant_cpp_file.close()
19341949
boards_entry_file.close()
1950+
generic_clock_file.close()
19351951
xml_mcu.unlink()
19361952
xml_gpio.unlink()
19371953

@@ -2062,7 +2078,7 @@ def manage_repo():
20622078
new_line_c += " || {}".format(pre)
20632079
new_line_h += " && !{}".format(pre)
20642080
update_file(mcu_dir / variant_cpp_filename, update_regex, new_line_c)
2065-
2081+
update_file(mcu_dir / generic_clock_filename, update_regex, new_line_c)
20662082
update_file(mcu_dir / variant_h_filename, update_regex, new_line_h)
20672083

20682084
# Appending to board_entry file
@@ -2077,8 +2093,12 @@ def manage_repo():
20772093

20782094
# Move to variants/ folder
20792095
out_path = out_family_path / mcu_dir.stem
2096+
generic_clock_filepath = out_path / generic_clock_filename
20802097
out_path.mkdir(parents=True, exist_ok=True)
20812098
for fname in mcu_dir.glob("*.*"):
2082-
fname.replace(out_path / fname.name)
2099+
if fname.name == generic_clock_filename and generic_clock_filepath.exists():
2100+
fname.unlink()
2101+
else:
2102+
fname.replace(out_path / fname.name)
20832103
# Clean temporary dir
20842104
rm_tree(tmp_dir)

CI/utils/templates/generic_clock.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2020-{{year}}, STMicroelectronics
4+
* All rights reserved.
5+
*
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
10+
*
11+
*******************************************************************************
12+
*/
13+
#if defined(ARDUINO_GENERIC_{{generic_list[0].board}}){% for name in generic_list[1:] %} || defined(ARDUINO_GENERIC_{{name.board}}){% endfor %}
14+
15+
#include "pins_arduino.h"
16+
17+
/**
18+
* @brief System Clock Configuration
19+
* @param None
20+
* @retval None
21+
*/
22+
WEAK void SystemClock_Config(void)
23+
{
24+
/* SystemClock_Config can be generated by STM32CubeMX */
25+
#warning "SystemClock_Config() is empty. Default clock at reset is used."
26+
}
27+
28+
#endif /* ARDUINO_GENERIC_* */
29+

0 commit comments

Comments
 (0)