My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stm32_serialbuffer.py 2.1KB

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