Skip to content

Commit 1111f54

Browse files
Delete framework stm32xxx_hal_conf.h when custom_config_header=yes (#503)
There is a bug where a custom `stm32xxx_hal_conf.h` header (enabled by setting `build.stm32cube.custom_config_header=yes`) can't be used, as a copy exists in the downloaded framework, and this copy is first on the include path. To address this, when `build.stm32cube.custom_config_header=yes`, delete the framework copy of the header.
1 parent db138a2 commit 1111f54

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

builder/frameworks/stm32cube.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,21 +125,27 @@ def generate_hal_config_file():
125125
"Inc",
126126
)
127127

128-
if os.path.isfile(os.path.join(config_path, MCU_FAMILY + "xx_hal_conf.h")):
129-
return
128+
conf_h_path = os.path.join(config_path, MCU_FAMILY + "xx_hal_conf.h")
129+
template_h_path = os.path.join(config_path, MCU_FAMILY + "xx_hal_conf_template.h")
130130

131-
if not os.path.isfile(
132-
os.path.join(config_path, MCU_FAMILY + "xx_hal_conf_template.h")
133-
):
134-
sys.stderr.write(
135-
"Error: Cannot find peripheral template file to configure framework!\n"
136-
)
137-
env.Exit(1)
131+
if board.get("build.stm32cube.custom_config_header", "no") == "yes":
132+
if os.path.isfile(conf_h_path):
133+
sys.stderr.write(
134+
"Warning: '" + conf_h_path + "' exists, but custom_config_header=yes! Deleting...\n"
135+
)
136+
os.remove(conf_h_path)
137+
print("Using custom " + os.path.basename(conf_h_path) + "\n")
138+
else:
139+
if os.path.isfile(conf_h_path):
140+
return
138141

139-
shutil.copy(
140-
os.path.join(config_path, MCU_FAMILY + "xx_hal_conf_template.h"),
141-
os.path.join(config_path, MCU_FAMILY + "xx_hal_conf.h"),
142-
)
142+
if not os.path.isfile(template_h_path):
143+
sys.stderr.write(
144+
"Error: Cannot find peripheral template file to configure framework!\n"
145+
)
146+
env.Exit(1)
147+
148+
shutil.copy(template_h_path, conf_h_path)
143149

144150

145151
def build_custom_lib(lib_path, lib_manifest=None):
@@ -316,8 +322,7 @@ def build_usb_libs(usb_libs_root):
316322
#
317323

318324
# Generate a default stm32xxx_hal_conf.h
319-
if board.get("build.stm32cube.custom_config_header", "no") == "no":
320-
generate_hal_config_file()
325+
generate_hal_config_file()
321326

322327
env.BuildSources(
323328
os.path.join("$BUILD_DIR", "FrameworkHALDriver"),

0 commit comments

Comments
 (0)