From 3b15a27772b53f682d1c2f3866dbd6a9c204d9e6 Mon Sep 17 00:00:00 2001 From: ldursw <37294448+ldursw@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:38:26 -0300 Subject: [PATCH 1/4] Update stm32_serialbuffer.py --- .../PlatformIO/scripts/stm32_serialbuffer.py | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py index fecce47db307..1c6f64a69d87 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py +++ b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py @@ -15,14 +15,44 @@ # or the user-configured one, whichever is higher. # # Marlin has 128 and 32 as default values for RX_BUFFER_SIZE and -# TX_BUFFER_SIZE respectively. We use the highest value. +# TX_BUFFER_SIZE respectively. We use the highest value (128/64). +# +# If the specific flags SERIAL_*X_BUFFER_SIZE, USART_*X_BUF_SIZE, +# or MF_*X_BUFFER_SIZE are set, then the script will use these +# values as minimum. +build_flags = env.ParseFlags(env.get('BUILD_FLAGS'))["CPPDEFINES"] mf = env["MARLIN_FEATURES"] -rxBuf = str(max(128, int(mf["RX_BUFFER_SIZE"]) if "RX_BUFFER_SIZE" in mf else 0)) -txBuf = str(max(64, int(mf["TX_BUFFER_SIZE"]) if "TX_BUFFER_SIZE" in mf else 0)) - -build_flags = env.get('BUILD_FLAGS') -build_flags.append("-DSERIAL_RX_BUFFER_SIZE=" + rxBuf) -build_flags.append("-DSERIAL_TX_BUFFER_SIZE=" + txBuf) -build_flags.append("-DUSART_RX_BUF_SIZE=" + rxBuf) -build_flags.append("-DUSART_TX_BUF_SIZE=" + txBuf) -env.Replace(BUILD_FLAGS=build_flags) + +def getBuildFlagValue(name): + for flag in build_flags: + if isinstance(flag, list) and flag[0] == name: + return flag[1] + + return None + +def getInternalSize(side): + return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"USART_{side}_BUF_SIZE") + +def getBufferSize(side, default): + internal = int(getInternalSize(side) or default) + flag = side + "_BUFFER_SIZE" + if flag in mf: + return max(int(mf[flag]), internal) + else: + return internal + +def tryAddFlag(name, value): + if getBuildFlagValue(name) is not None: + return + + env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) + +rxBuf = getBufferSize("RX", 128) +txBuf = getBufferSize("TX", 64) + +tryAddFlag("SERIAL_RX_BUFFER_SIZE", rxBuf) +tryAddFlag("SERIAL_TX_BUFFER_SIZE", txBuf) +tryAddFlag("USART_RX_BUF_SIZE", rxBuf) +tryAddFlag("USART_TX_BUF_SIZE", txBuf) From 69c081d52d37b0801d9d44123100f55396fce869 Mon Sep 17 00:00:00 2001 From: ldursw <37294448+ldursw@users.noreply.github.com> Date: Fri, 30 Jul 2021 22:42:18 -0300 Subject: [PATCH 2/4] Update stm32f4.ini --- ini/stm32f4.ini | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ini/stm32f4.ini b/ini/stm32f4.ini index 2b77bf2e3c91..7cf40ebe1f2f 100644 --- a/ini/stm32f4.ini +++ b/ini/stm32f4.ini @@ -152,11 +152,10 @@ extends = stm32_variant board = marlin_STM32F407VGT6_CCM board_build.variant = MARLIN_BIGTREE_E3_RRF board_build.offset = 0x8000 -extra_scripts = ${common.extra_scripts} build_flags = ${stm32_variant.build_flags} -DSTM32F407_5VX - -DSERIAL_RX_BUFFER_SIZE=255 - -DSERIAL_TX_BUFFER_SIZE=255 + -DMF_RX_BUFFER_SIZE=255 + -DMF_TX_BUFFER_SIZE=255 # # Bigtreetech GTR V1.0 (STM32F407IGT6 ARM Cortex-M4) From c43bad054c30585dddecda6413a696befe19cb97 Mon Sep 17 00:00:00 2001 From: ldursw <37294448+ldursw@users.noreply.github.com> Date: Sat, 31 Jul 2021 11:57:33 -0300 Subject: [PATCH 3/4] Update stm32_serialbuffer.py --- buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py index 1c6f64a69d87..45eec8a5fc09 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py +++ b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py @@ -44,10 +44,8 @@ def getBufferSize(side, default): return internal def tryAddFlag(name, value): - if getBuildFlagValue(name) is not None: - return - - env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) + if getBuildFlagValue(name) is None: + env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) rxBuf = getBufferSize("RX", 128) txBuf = getBufferSize("TX", 64) From 26c8eb16db79decb7dc9750458ab286b7395ad17 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Sat, 31 Jul 2021 22:32:28 -0500 Subject: [PATCH 4/4] Update stm32_serialbuffer.py --- .../PlatformIO/scripts/stm32_serialbuffer.py | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py index 45eec8a5fc09..c3779289e0f3 100644 --- a/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py +++ b/buildroot/share/PlatformIO/scripts/stm32_serialbuffer.py @@ -3,26 +3,25 @@ # Import("env") -# Marlin has `RX_BUFFER_SIZE` and `TX_BUFFER_SIZE` to configure the -# buffer size for receiving and transmitting data respectively. -# Stm32duino uses another set of defines for the same purpose, -# so we get the values from the Marlin configuration and set -# them in `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE`. -# It is not possible to change the values at runtime, they must -# be set with build flags. +# Marlin uses the `RX_BUFFER_SIZE` \ `TX_BUFFER_SIZE` options to +# configure buffer sizes for receiving \ transmitting serial data. +# Stm32duino uses another set of defines for the same purpose, so this +# script gets the values from the configuration and uses them to define +# `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE` as global build +# flags so they are available for use by the platform. # # The script will set the value as the default one (64 bytes) # or the user-configured one, whichever is higher. # -# Marlin has 128 and 32 as default values for RX_BUFFER_SIZE and -# TX_BUFFER_SIZE respectively. We use the highest value (128/64). +# Marlin's default buffer sizes are 128 for RX and 32 for TX. +# The highest value is taken (128/64). # -# If the specific flags SERIAL_*X_BUFFER_SIZE, USART_*X_BUF_SIZE, -# or MF_*X_BUFFER_SIZE are set, then the script will use these -# values as minimum. +# If MF_*_BUFFER_SIZE, SERIAL_*_BUFFER_SIZE, USART_*_BUF_SIZE, are +# defined, the first of these values will be used as the minimum. build_flags = env.ParseFlags(env.get('BUILD_FLAGS'))["CPPDEFINES"] mf = env["MARLIN_FEATURES"] +# Get a build flag's value or None def getBuildFlagValue(name): for flag in build_flags: if isinstance(flag, list) and flag[0] == name: @@ -30,26 +29,30 @@ def getBuildFlagValue(name): return None +# Get an overriding buffer size for RX or TX from the build flags def getInternalSize(side): - return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \ - getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \ - getBuildFlagValue(f"USART_{side}_BUF_SIZE") + return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \ + getBuildFlagValue(f"USART_{side}_BUF_SIZE") +# Get the largest defined buffer size for RX or TX def getBufferSize(side, default): + # Get a build flag value or fall back to the given default internal = int(getInternalSize(side) or default) flag = side + "_BUFFER_SIZE" - if flag in mf: - return max(int(mf[flag]), internal) - else: - return internal + # Return the largest value + return max(int(mf[flag]), internal) if flag in mf else internal +# Add a build flag if it's not already defined def tryAddFlag(name, value): if getBuildFlagValue(name) is None: env.Append(BUILD_FLAGS=[f"-D{name}={value}"]) +# Get the largest defined buffer sizes for RX or TX, using defaults for undefined rxBuf = getBufferSize("RX", 128) -txBuf = getBufferSize("TX", 64) +txBuf = getBufferSize("TX", 64) +# Provide serial buffer sizes to the stm32duino platform tryAddFlag("SERIAL_RX_BUFFER_SIZE", rxBuf) tryAddFlag("SERIAL_TX_BUFFER_SIZE", txBuf) tryAddFlag("USART_RX_BUF_SIZE", rxBuf)