|
@@ -3,26 +3,57 @@
|
3
|
3
|
#
|
4
|
4
|
Import("env")
|
5
|
5
|
|
6
|
|
-# Marlin has `RX_BUFFER_SIZE` and `TX_BUFFER_SIZE` to configure the
|
7
|
|
-# buffer size for receiving and transmitting data respectively.
|
8
|
|
-# Stm32duino uses another set of defines for the same purpose,
|
9
|
|
-# so we get the values from the Marlin configuration and set
|
10
|
|
-# them in `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE`.
|
11
|
|
-# It is not possible to change the values at runtime, they must
|
12
|
|
-# be set with build flags.
|
|
6
|
+# Marlin uses the `RX_BUFFER_SIZE` \ `TX_BUFFER_SIZE` options to
|
|
7
|
+# configure buffer sizes for receiving \ transmitting serial data.
|
|
8
|
+# Stm32duino uses another set of defines for the same purpose, so this
|
|
9
|
+# script gets the values from the configuration and uses them to define
|
|
10
|
+# `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE` as global build
|
|
11
|
+# flags so they are available for use by the platform.
|
13
|
12
|
#
|
14
|
13
|
# The script will set the value as the default one (64 bytes)
|
15
|
14
|
# or the user-configured one, whichever is higher.
|
16
|
15
|
#
|
17
|
|
-# Marlin has 128 and 32 as default values for RX_BUFFER_SIZE and
|
18
|
|
-# TX_BUFFER_SIZE respectively. We use the highest value.
|
|
16
|
+# Marlin's default buffer sizes are 128 for RX and 32 for TX.
|
|
17
|
+# The highest value is taken (128/64).
|
|
18
|
+#
|
|
19
|
+# If MF_*_BUFFER_SIZE, SERIAL_*_BUFFER_SIZE, USART_*_BUF_SIZE, are
|
|
20
|
+# defined, the first of these values will be used as the minimum.
|
|
21
|
+build_flags = env.ParseFlags(env.get('BUILD_FLAGS'))["CPPDEFINES"]
|
19
|
22
|
mf = env["MARLIN_FEATURES"]
|
20
|
|
-rxBuf = str(max(128, int(mf["RX_BUFFER_SIZE"]) if "RX_BUFFER_SIZE" in mf else 0))
|
21
|
|
-txBuf = str(max(64, int(mf["TX_BUFFER_SIZE"]) if "TX_BUFFER_SIZE" in mf else 0))
|
22
|
|
-
|
23
|
|
-build_flags = env.get('BUILD_FLAGS')
|
24
|
|
-build_flags.append("-DSERIAL_RX_BUFFER_SIZE=" + rxBuf)
|
25
|
|
-build_flags.append("-DSERIAL_TX_BUFFER_SIZE=" + txBuf)
|
26
|
|
-build_flags.append("-DUSART_RX_BUF_SIZE=" + rxBuf)
|
27
|
|
-build_flags.append("-DUSART_TX_BUF_SIZE=" + txBuf)
|
28
|
|
-env.Replace(BUILD_FLAGS=build_flags)
|
|
23
|
+
|
|
24
|
+# Get a build flag's value or None
|
|
25
|
+def getBuildFlagValue(name):
|
|
26
|
+ for flag in build_flags:
|
|
27
|
+ if isinstance(flag, list) and flag[0] == name:
|
|
28
|
+ return flag[1]
|
|
29
|
+
|
|
30
|
+ return None
|
|
31
|
+
|
|
32
|
+# Get an overriding buffer size for RX or TX from the build flags
|
|
33
|
+def getInternalSize(side):
|
|
34
|
+ return getBuildFlagValue(f"MF_{side}_BUFFER_SIZE") or \
|
|
35
|
+ getBuildFlagValue(f"SERIAL_{side}_BUFFER_SIZE") or \
|
|
36
|
+ getBuildFlagValue(f"USART_{side}_BUF_SIZE")
|
|
37
|
+
|
|
38
|
+# Get the largest defined buffer size for RX or TX
|
|
39
|
+def getBufferSize(side, default):
|
|
40
|
+ # Get a build flag value or fall back to the given default
|
|
41
|
+ internal = int(getInternalSize(side) or default)
|
|
42
|
+ flag = side + "_BUFFER_SIZE"
|
|
43
|
+ # Return the largest value
|
|
44
|
+ return max(int(mf[flag]), internal) if flag in mf else internal
|
|
45
|
+
|
|
46
|
+# Add a build flag if it's not already defined
|
|
47
|
+def tryAddFlag(name, value):
|
|
48
|
+ if getBuildFlagValue(name) is None:
|
|
49
|
+ env.Append(BUILD_FLAGS=[f"-D{name}={value}"])
|
|
50
|
+
|
|
51
|
+# Get the largest defined buffer sizes for RX or TX, using defaults for undefined
|
|
52
|
+rxBuf = getBufferSize("RX", 128)
|
|
53
|
+txBuf = getBufferSize("TX", 64)
|
|
54
|
+
|
|
55
|
+# Provide serial buffer sizes to the stm32duino platform
|
|
56
|
+tryAddFlag("SERIAL_RX_BUFFER_SIZE", rxBuf)
|
|
57
|
+tryAddFlag("SERIAL_TX_BUFFER_SIZE", txBuf)
|
|
58
|
+tryAddFlag("USART_RX_BUF_SIZE", rxBuf)
|
|
59
|
+tryAddFlag("USART_TX_BUF_SIZE", txBuf)
|