Skip to content

Commit 080e1e7

Browse files
authored
Merge pull request stm32duino#2320 from fpistm/refactor_platform
refactor(platform): factorize using variables
2 parents 79579d7 + 79b6bdb commit 080e1e7

File tree

3 files changed

+64
-38
lines changed

3 files changed

+64
-38
lines changed

platform.txt

+35-27
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,33 @@
77
name=STM32 boards groups (Board to be selected from Tools submenu 'Board part number')
88
version=2.8.0-dev
99

10+
11+
# Define variables used multiple times in platform file
12+
# --------------------
13+
tool_suffix=
14+
tool_suffix.windows=.exe
15+
16+
busybox=
17+
busybox.windows={runtime.tools.STM32Tools.path}/win/busybox.exe
18+
19+
toolchain_dir={runtime.tools.xpack-arm-none-eabi-gcc-13.2.1-1.1.path}
20+
openocd_dir={runtime.tools.xpack-openocd-0.12.0-2.path}
21+
22+
tools_bin_path.windows={runtime.tools.STM32Tools.path}/win
23+
tools_bin_path.macosx={runtime.tools.STM32Tools.path}/macosx
24+
tools_bin_path.linux={runtime.tools.STM32Tools.path}/linux
25+
26+
core_stm32_dir={build.core.path}/stm32
27+
core_usb_dir={core_stm32_dir}/usb
28+
hal_dir={build.system.path}/Drivers/{build.series}_HAL_Driver
29+
cmsis_dir={runtime.tools.CMSIS-5.9.0.path}/CMSIS
30+
cmsis_dev_dir={build.system.path}/Drivers/CMSIS/Device/ST/{build.series}
31+
usbd_core_dir={build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core
32+
1033
# STM compile variables
1134
# ----------------------
12-
compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{build.core.path}/stm32" "-I{build.core.path}/stm32/LL" "-I{build.core.path}/stm32/usb" "-I{build.core.path}/stm32/OpenAMP" "-I{build.core.path}/stm32/usb/hid" "-I{build.core.path}/stm32/usb/cdc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Inc" "-I{build.system.path}/Drivers/{build.series}_HAL_Driver/Src" "-I{build.system.path}/{build.series}" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Inc" "-I{build.system.path}/Middlewares/ST/STM32_USB_Device_Library/Core/Src" {build.virtio_extra_include}
35+
compiler.stm.extra_include="-I{build.source.path}" "-I{build.core.path}/avr" "-I{core_stm32_dir}" "-I{core_stm32_dir}/LL" "-I{core_usb_dir}" "-I{core_stm32_dir}/OpenAMP" "-I{core_usb_dir}/hid" "-I{core_usb_dir}/cdc" "-I{hal_dir}/Inc" "-I{hal_dir}/Src" "-I{build.system.path}/{build.series}" "-I{usbd_core_dir}/Inc" "-I{usbd_core_dir}/Src" {build.virtio_extra_include}
36+
compiler.arm.cmsis.c.flags="-I{cmsis_dir}/Core/Include/" "-I{cmsis_dev_dir}/Include/" "-I{cmsis_dev_dir}/Source/Templates/gcc/" "-I{cmsis_dir}/DSP/Include" "-I{cmsis_dir}/DSP/PrivateInclude"
1337

1438
compiler.warning_flags=-w
1539
compiler.warning_flags.none=-w
@@ -23,7 +47,7 @@ compiler.optimization_flags={build.flags.optimize} {build.flags.debug}
2347
compiler.optimization_flags.release={build.flags.optimize} {build.flags.debug}
2448
compiler.optimization_flags.debug=-Og -g
2549

26-
compiler.path={runtime.tools.xpack-arm-none-eabi-gcc-13.2.1-1.1.path}/bin/
50+
compiler.path={toolchain_dir}/bin/
2751

2852
compiler.S.cmd=arm-none-eabi-gcc
2953
compiler.c.cmd=arm-none-eabi-gcc
@@ -75,8 +99,6 @@ compiler.ar.extra_flags=
7599
compiler.elf2bin.extra_flags=
76100
compiler.elf2hex.extra_flags=
77101

78-
compiler.arm.cmsis.c.flags="-I{runtime.tools.CMSIS-5.9.0.path}/CMSIS/Core/Include/" "-I{build.system.path}/Drivers/CMSIS/Device/ST/{build.series}/Include/" "-I{build.system.path}/Drivers/CMSIS/Device/ST/{build.series}/Source/Templates/gcc/" "-I{runtime.tools.CMSIS-5.9.0.path}/CMSIS/DSP/Include" "-I{runtime.tools.CMSIS-5.9.0.path}/CMSIS/DSP/PrivateInclude"
79-
80102
# USB Flags
81103
# ---------
82104
build.usb_flags=-DUSBCON {build.usb_speed} -DUSBD_VID={build.vid} -DUSBD_PID={build.pid} -DHAL_PCD_MODULE_ENABLED
@@ -122,10 +144,8 @@ build.opt.path={build.path}/sketch/{build.opt.name}
122144
extras.path={build.system.path}/extras
123145

124146
# Create {build.opt} if not exists in the output sketch dir and force include of SrcWrapper library
125-
recipe.hooks.prebuild.1.pattern="{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}"
126-
recipe.hooks.prebuild.1.pattern.windows="{runtime.tools.STM32Tools.path}/win/busybox.exe" sh "{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}"
127-
recipe.hooks.postbuild.1.pattern="{extras.path}/postbuild.sh" "{build.path}" "{build.series}" "{runtime.platform.path}"
128-
recipe.hooks.postbuild.1.pattern.windows="{runtime.tools.STM32Tools.path}/win/busybox.exe" sh "{extras.path}/postbuild.sh" "{build.path}" "{build.series}" "{runtime.platform.path}"
147+
recipe.hooks.prebuild.1.pattern="{busybox}" sh "{extras.path}/prebuild.sh" "{build.path}" "{build.source.path}" "{runtime.platform.path}"
148+
recipe.hooks.postbuild.1.pattern="{busybox}" sh "{extras.path}/postbuild.sh" "{build.path}" "{build.series}" "{runtime.platform.path}"
129149

130150
# compile patterns
131151
# ---------------------
@@ -149,7 +169,7 @@ recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.f
149169
recipe.objcopy.bin.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2bin.flags} {compiler.elf2bin.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.bin"
150170

151171
## Create output (.hex file)
152-
recipe.objcopy.hex.pattern="{compiler.path}{compiler.objcopy.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
172+
recipe.objcopy.hex.pattern="{compiler.path}{compiler.elf2hex.cmd}" {compiler.elf2hex.flags} {compiler.elf2hex.extra_flags} "{build.path}/{build.project_name}.elf" "{build.path}/{build.project_name}.hex"
153173

154174
build.preferred_out_format=bin
155175

@@ -170,25 +190,20 @@ recipe.size.regex.eeprom=^(?:\.eeprom)\s+([0-9]+).*
170190
# Upload to board via mass storage
171191
tools.massStorageCopy.cmd=massStorageCopy.sh
172192
tools.massStorageCopy.cmd.windows=massStorageCopy.bat
173-
tools.massStorageCopy.path={runtime.tools.STM32Tools.path}/win
174-
tools.massStorageCopy.path.macosx={runtime.tools.STM32Tools.path}/macosx
175-
tools.massStorageCopy.path.linux={runtime.tools.STM32Tools.path}/linux
176193
tools.massStorageCopy.upload.params.verbose=
177194
tools.massStorageCopy.upload.params.quiet=
178-
tools.massStorageCopy.upload.pattern="{path}/{cmd}" {upload.verbose} -I "{build.path}/{build.project_name}.bin" -O "{node}"
195+
tools.massStorageCopy.upload.pattern="{tools_bin_path}/{cmd}" {upload.verbose} -I "{build.path}/{build.project_name}.bin" -O "{node}"
179196

180197
# STM32CubeProgrammer upload
181198
tools.stm32CubeProg.path={runtime.tools.STM32Tools.path}
182-
tools.stm32CubeProg.busybox=
183-
tools.stm32CubeProg.busybox.windows={path}/win/busybox.exe
184199
tools.stm32CubeProg.cmd=stm32CubeProg.sh
185200
tools.stm32CubeProg.upload.params.verbose=
186201
tools.stm32CubeProg.upload.params.quiet=
187202
tools.stm32CubeProg.upload.pattern="{busybox}" sh "{path}/{cmd}" {upload.protocol} "{build.path}/{build.project_name}.bin" {build.flash_offset} {upload.options}
188203

189204
# blackmagic upload for generic STM32
190205
tools.bmp_upload.cmd=arm-none-eabi-gdb
191-
tools.bmp_upload.path={runtime.tools.xpack-arm-none-eabi-gcc.path}/bin
206+
tools.bmp_upload.path={toolchain_dir}/bin
192207
tools.bmp_upload.upload.speed=230400
193208
tools.bmp_upload.upload.params.verbose=-batch
194209
tools.bmp_upload.upload.params.quiet=--batch-silent
@@ -198,26 +213,19 @@ tools.bmp_upload.upload.pattern.windows="{path}/{cmd}" -nx -b {upload.speed} {up
198213
# HID flash 2.2 (HID bootloader v2.2 for STM32F1 and STM32F4 series)
199214
tools.hid_upload.cmd=hid-flash
200215
tools.hid_upload.cmd.windows=hid-flash.exe
201-
tools.hid_upload.path={runtime.tools.STM32Tools.path}/win
202-
tools.hid_upload.path.macosx={runtime.tools.STM32Tools.path}/macosx
203-
tools.hid_upload.path.linux={runtime.tools.STM32Tools.path}/linux
204216
tools.hid_upload.upload.params.verbose=-d
205217
tools.hid_upload.upload.params.quiet=n
206-
tools.hid_upload.upload.pattern="{path}/{cmd}" "{build.path}/{build.project_name}.bin" {serial.port.file}
218+
tools.hid_upload.upload.pattern="{tools_bin_path}/{cmd}" "{build.path}/{build.project_name}.bin" {serial.port.file}
207219

208220
# Upload using Maple bootloader over DFU
209221
tools.maple_upload.script=maple_upload.sh
210-
tools.maple_upload.busybox=
211-
tools.maple_upload.busybox.windows={path}/win/busybox.exe
212222
tools.maple_upload.path={runtime.tools.STM32Tools.path}
213223
tools.maple_upload.upload.params.verbose=-d
214224
tools.maple_upload.upload.params.quiet=n
215225
tools.maple_upload.upload.pattern="{busybox}" sh "{path}/{script}" {serial.port.file} {upload.altID} {upload.usbID} "{build.path}/{build.project_name}.bin"
216226

217227
# STM32MP1 self-contained shell script
218228
tools.remoteproc_gen.path={runtime.tools.STM32Tools.path}
219-
tools.remoteproc_gen.busybox=
220-
tools.remoteproc_gen.busybox.windows={path}/win/busybox.exe
221229
tools.remoteproc_gen.script=run_arduino_gen.sh
222230
tools.remoteproc_gen.upload.params.verbose=
223231
tools.remoteproc_gen.upload.params.quiet=
@@ -229,9 +237,9 @@ tools.remoteproc_gen.upload.pattern="{busybox}" sh "{path}/{script}" generate "{
229237
# - this is alpha and may be subject to change without notice
230238
debug.executable={build.path}/{build.project_name}.elf
231239
debug.toolchain=gcc
232-
debug.toolchain.path={compiler.path}
240+
debug.toolchain.path={toolchain_dir.path}/bin
233241
debug.toolchain.prefix=arm-none-eabi-
234242
debug.server=openocd
235-
debug.server.openocd.path={runtime.tools.xpack-openocd-0.12.0-2.path}/bin/openocd
236-
debug.server.openocd.scripts_dir={runtime.tools.xpack-openocd-0.12.0-2.path}/openocd/scripts
243+
debug.server.openocd.path={openocd_dir}/bin/openocd
244+
debug.server.openocd.scripts_dir={openocd_dir}/openocd/scripts
237245
debug.server.openocd.script={build.path}/openocd.cfg

system/extras/postbuild.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh -
22

33
BUILD_PATH="$1"
44
BUILD_SERIE="$2"

system/extras/prebuild.sh

+28-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash
1+
#!/bin/sh -
22

33
BUILD_PATH="$1"
44
BUILD_SOURCE_PATH="$2"
@@ -9,20 +9,38 @@ if [ ! -f "$BUILD_PATH/sketch" ]; then
99
mkdir -p "$BUILD_PATH/sketch"
1010
fi
1111

12-
# Create empty build.opt if build_opt.h does not exists in the original sketch dir
13-
# Then add or append -fmacro-prefix-map option to change __FILE__ absolute path of
14-
# the board platform folder to a relative path by using '.'.
15-
# (i.e. the folder containing boards.txt)
12+
# Create empty build.opt or clear it if build_opt.h does not exists in the original sketch dir
1613
if [ ! -f "$BUILD_SOURCE_PATH/build_opt.h" ]; then
17-
printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" > "$BUILD_PATH/sketch/build.opt"
14+
true >"$BUILD_PATH/sketch/build.opt"
1815
else
1916
# Else copy the build_opt.h as build.opt
2017
# Workaround to the header file preprocessing done by arduino-cli
2118
# See https://github.com/arduino/arduino-cli/issues/1338
22-
cp "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt"
23-
printf '\n-fmacro-prefix-map="%s"=.' "${BOARD_PLATFORM_PATH//\\/\\\\}" >> "$BUILD_PATH/sketch/build.opt"
19+
cp -f "$BUILD_SOURCE_PATH/build_opt.h" "$BUILD_PATH/sketch/build.opt"
2420
fi
25-
21+
# On Windows, need to protect '\' in path
22+
UNAME_OS="$(uname -s)"
23+
case "${UNAME_OS}" in
24+
Windows*)
25+
i=1
26+
prefix=""
27+
while [ "$i" -le "${#BOARD_PLATFORM_PATH}" ]; do
28+
c=$(printf '%s' "$BOARD_PLATFORM_PATH" | cut -c $i)
29+
prefix=${prefix}${c}
30+
if [ "${c}" = "\\" ]; then
31+
prefix=${prefix}"\\"
32+
fi
33+
i="$((i + 1))"
34+
done
35+
;;
36+
*)
37+
prefix=${BOARD_PLATFORM_PATH}
38+
;;
39+
esac
40+
# Then append -fmacro-prefix-map option to change __FILE__ absolute path of
41+
# the board platform folder to a relative path by using '.'.
42+
# (i.e. the folder containing boards.txt)
43+
printf '\n-fmacro-prefix-map="%s"=.' "${prefix}" >>"$BUILD_PATH/sketch/build.opt"
2644

2745
# Force include of SrcWrapper library
28-
echo "#include <SrcWrapper.h>" > "$BUILD_PATH/sketch/SrcWrapper.cpp"
46+
echo "#include <SrcWrapper.h>" >"$BUILD_PATH/sketch/SrcWrapper.cpp"

0 commit comments

Comments
 (0)