|
@ -3,26 +3,57 @@ |
|
|
# |
|
|
# |
|
|
Import("env") |
|
|
Import("env") |
|
|
|
|
|
|
|
|
# Marlin has `RX_BUFFER_SIZE` and `TX_BUFFER_SIZE` to configure the |
|
|
# Marlin uses the `RX_BUFFER_SIZE` \ `TX_BUFFER_SIZE` options to |
|
|
# buffer size for receiving and transmitting data respectively. |
|
|
# configure buffer sizes for receiving \ transmitting serial data. |
|
|
# Stm32duino uses another set of defines for the same purpose, |
|
|
# Stm32duino uses another set of defines for the same purpose, so this |
|
|
# so we get the values from the Marlin configuration and set |
|
|
# script gets the values from the configuration and uses them to define |
|
|
# them in `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE`. |
|
|
# `SERIAL_RX_BUFFER_SIZE` and `SERIAL_TX_BUFFER_SIZE` as global build |
|
|
# It is not possible to change the values at runtime, they must |
|
|
# flags so they are available for use by the platform. |
|
|
# be set with build flags. |
|
|
|
|
|
# |
|
|
# |
|
|
# The script will set the value as the default one (64 bytes) |
|
|
# The script will set the value as the default one (64 bytes) |
|
|
# or the user-configured one, whichever is higher. |
|
|
# or the user-configured one, whichever is higher. |
|
|
# |
|
|
# |
|
|
# Marlin has 128 and 32 as default values for RX_BUFFER_SIZE and |
|
|
# Marlin's default buffer sizes are 128 for RX and 32 for TX. |
|
|
# TX_BUFFER_SIZE respectively. We use the highest value. |
|
|
# The highest value is taken (128/64). |
|
|
|
|
|
# |
|
|
|
|
|
# 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"] |
|
|
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)) |
|
|
# Get a build flag's value or None |
|
|
|
|
|
def getBuildFlagValue(name): |
|
|
build_flags = env.get('BUILD_FLAGS') |
|
|
for flag in build_flags: |
|
|
build_flags.append("-DSERIAL_RX_BUFFER_SIZE=" + rxBuf) |
|
|
if isinstance(flag, list) and flag[0] == name: |
|
|
build_flags.append("-DSERIAL_TX_BUFFER_SIZE=" + txBuf) |
|
|
return flag[1] |
|
|
build_flags.append("-DUSART_RX_BUF_SIZE=" + rxBuf) |
|
|
|
|
|
build_flags.append("-DUSART_TX_BUF_SIZE=" + txBuf) |
|
|
return None |
|
|
env.Replace(BUILD_FLAGS=build_flags) |
|
|
|
|
|
|
|
|
# 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") |
|
|
|
|
|
|
|
|
|
|
|
# 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" |
|
|
|
|
|
# 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) |
|
|
|
|
|
|
|
|
|
|
|
# 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) |
|
|
|
|
|
tryAddFlag("USART_TX_BUF_SIZE", txBuf) |
|
|