Skip to content

Commit 66d6408

Browse files
committed
[stm32variant] Add generic_clock.c generation
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent e6ac2bd commit 66d6408

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
@@ -1393,6 +1393,16 @@ def print_boards_entry():
13931393
return generic_list
13941394

13951395

1396+
def print_general_clock(generic_list):
1397+
generic_clock_template = j2_env.get_template(generic_clock_filename)
1398+
generic_clock_file.write(
1399+
generic_clock_template.render(
1400+
year=datetime.datetime.now().year,
1401+
generic_list=generic_list,
1402+
)
1403+
)
1404+
1405+
13961406
# List management
13971407
tokenize = re.compile(r"(\d+)|(\D+)").findall
13981408

@@ -1721,6 +1731,7 @@ def manage_repo():
17211731
variant_h_filename = "variant.h"
17221732
variant_cpp_filename = "variant.cpp"
17231733
boards_entry_filename = "boards_entry.txt"
1734+
generic_clock_filename = "generic_clock.c"
17241735
repo_local_path = cur_dir / "repo"
17251736
cubemxdir = ""
17261737
gh_url = "https://github.com/STMicroelectronics/STM32_open_pin_data"
@@ -1734,7 +1745,13 @@ def manage_repo():
17341745
parser = argparse.ArgumentParser(
17351746
description=textwrap.dedent(
17361747
"""\
1737-
By default, generate {}, {}, {}, {} and {}
1748+
By default, generates:
1749+
- {},
1750+
- {},
1751+
- {},
1752+
- {},
1753+
- {}
1754+
- {}
17381755
for all xml files description available in STM32CubeMX internal database.
17391756
Internal database path must be defined in {}.
17401757
It can be the one from STM32CubeMX directory if defined:
@@ -1748,6 +1765,7 @@ def manage_repo():
17481765
variant_cpp_filename,
17491766
variant_h_filename,
17501767
boards_entry_filename,
1768+
generic_clock_filename,
17511769
config_filename,
17521770
cubemxdir,
17531771
gh_url,
@@ -1774,15 +1792,10 @@ def manage_repo():
17741792
metavar="xml",
17751793
help=textwrap.dedent(
17761794
"""\
1777-
Generate {}, {}, {} and {}
1778-
for specified mcu xml file description in database.
1795+
Generate all files for specified mcu xml file description in database.
17791796
This xml file can contain non alpha characters in its name,
1780-
you should call it with double quotes""".format(
1781-
periph_c_filename,
1782-
pinvar_h_filename,
1783-
variant_cpp_filename,
1784-
variant_h_filename,
1785-
)
1797+
you should call it with double quotes.
1798+
"""
17861799
),
17871800
)
17881801

@@ -1902,6 +1915,7 @@ def manage_repo():
19021915
variant_cpp_filepath = out_temp_path / variant_cpp_filename
19031916
variant_h_filepath = out_temp_path / variant_h_filename
19041917
boards_entry_filepath = out_temp_path / boards_entry_filename
1918+
generic_clock_filepath = out_temp_path / generic_clock_filename
19051919
out_temp_path.mkdir(parents=True, exist_ok=True)
19061920

19071921
# open output file
@@ -1910,12 +1924,13 @@ def manage_repo():
19101924
variant_cpp_file = open(variant_cpp_filepath, "w", newline="\n")
19111925
variant_h_file = open(variant_h_filepath, "w", newline="\n")
19121926
boards_entry_file = open(boards_entry_filepath, "w", newline="\n")
1913-
1927+
generic_clock_file = open(generic_clock_filepath, "w", newline="\n")
19141928
parse_pins()
19151929
sort_my_lists()
19161930
manage_alternate()
19171931

19181932
generic_list = print_boards_entry()
1933+
print_general_clock(generic_list)
19191934
print_peripheral()
19201935
print_pinamevar()
19211936
print_variant(generic_list)
@@ -1942,6 +1957,7 @@ def manage_repo():
19421957
variant_h_file.close()
19431958
variant_cpp_file.close()
19441959
boards_entry_file.close()
1960+
generic_clock_file.close()
19451961
xml_mcu.unlink()
19461962
xml_gpio.unlink()
19471963

@@ -2089,7 +2105,7 @@ def manage_repo():
20892105
new_line_c += " || {}".format(pre)
20902106
new_line_h += " && !{}".format(pre)
20912107
update_file(mcu_dir / variant_cpp_filename, update_regex, new_line_c)
2092-
2108+
update_file(mcu_dir / generic_clock_filename, update_regex, new_line_c)
20932109
update_file(mcu_dir / variant_h_filename, update_regex, new_line_h)
20942110

20952111
# Appending to board_entry file
@@ -2104,8 +2120,12 @@ def manage_repo():
21042120

21052121
# Move to variants/ folder
21062122
out_path = out_family_path / mcu_dir.stem
2123+
generic_clock_filepath = out_path / generic_clock_filename
21072124
out_path.mkdir(parents=True, exist_ok=True)
21082125
for fname in mcu_dir.glob("*.*"):
2109-
fname.replace(out_path / fname.name)
2126+
if fname.name == generic_clock_filename and generic_clock_filepath.exists():
2127+
fname.unlink()
2128+
else:
2129+
fname.replace(out_path / fname.name)
21102130
# Clean temporary dir
21112131
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)