Skip to content

Conversation

@eltoozero
Copy link

@eltoozero eltoozero commented May 7, 2025

Tried to follow formatting guidelines as best as possible; I'm commissioning a build using this gear but everything seems to be there so far.

Please let me know if there are any issues with the naming conventions or any other assumptions I may have made.

Summary by CodeRabbit

  • New Features

    • Added support for the BTT SB2209 USB V1.0 RP2040 toolboard with detailed board definition and firmware configuration.
    • Included scripts to compile, flash, and automate firmware deployment for the toolboard.
    • Introduced configuration files defining pin aliases, sensor setups, and device-specific settings for improved hardware integration.
  • Chores

    • Added udev rules for consistent device naming and automated initialization upon device connection.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 7, 2025

Walkthrough

A new board configuration for the BTT SB2209 USB V1.0 RP2040 toolboard has been introduced. This includes board definition and hardware configuration files, firmware and toolboard configuration, udev rules for device handling, and shell scripts for compiling and flashing firmware. No existing exported or public entities were modified.

Changes

File(s) Change Summary
configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json Added board definition JSON for the SB2209 USB v1.0 RP2040, specifying metadata, hardware configuration, DFU instructions, and peripherals.
configuration/boards/btt-sb-2209-usb-10-rp2040/firmware.config Added firmware configuration for the RP2040 MCU, enabling board-specific options, USB support, sensor support, and pin assignments.
configuration/boards/btt-sb-2209-usb-10-rp2040/toolboard-config.cfg Added toolboard configuration file defining pin aliases, MCU serial, temperature sensor, and accelerometer SPI configuration.
configuration/boards/btt-sb-2209-usb-10-rp2040/98-btt-sb-2209-usb-10-rp.rules Added udev rules file to create a symlink and trigger a script when the device is connected.
configuration/boards/btt-sb-2209-usb-10-rp2040/compile.sh New script to compile firmware for the board, ensuring root permissions and managing file locations and ownership.
configuration/boards/btt-sb-2209-usb-10-rp2040/flash.sh New script to flash firmware to the board, checking for root permissions and invoking a higher-level flashing script with the correct device path.
configuration/boards/btt-sb-2209-usb-10-rp2040/make-and-flash-mcu.sh New wrapper script to automate the compile and flash process, ensuring root permissions and sequential execution of compile and flash scripts.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant make-and-flash-mcu.sh
    participant compile.sh
    participant flash.sh
    participant flash-path.sh

    User->>make-and-flash-mcu.sh: Run as root
    make-and-flash-mcu.sh->>compile.sh: Execute compile.sh
    compile.sh->>compile.sh: Compile firmware and copy binary
    make-and-flash-mcu.sh->>flash.sh: Execute flash.sh
    flash.sh->>flash-path.sh: Call flash-path.sh with device path
Loading
sequenceDiagram
    participant System
    participant USB Device
    participant udev
    participant klipper-mcu-added.sh

    USB Device->>System: Device plugged in
    System->>udev: Detect device (via rules)
    udev->>System: Create symlink
    udev->>klipper-mcu-added.sh: Execute script
Loading

Poem

🐰
New board arrives, a toolboard bright,
With scripts and configs, set up right.
Firmware compiled, then flashed with care,
Udev rules ensure it’s always there.
Pins and sensors, all defined—
In the warren, progress shines!

Tip

⚡️ Faster reviews with caching
  • CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.

Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d788bce and 9cb6c97.

📒 Files selected for processing (2)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/toolboard-config.cfg (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/toolboard-config.cfg
  • configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (15)
configuration/boards/btt-sb-2209-usb-10-rp2040/make-and-flash-mcu.sh (3)

1-2: Add strict mode for safer failure handling
It’s best practice in Bash scripts to enable strict error handling to catch failures early. Consider adding at the top (immediately after the shebang) the following:

 #!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'

This will:

  • -e: exit on any command failure
  • -u: treat unset variables as errors
  • -o pipefail: catch failures in pipelines
  • IFS: avoid word-splitting pitfalls

3-6: Improve root-check and exit code
Currently exit without a code returns 0, which may mask failure in CI or wrappers. Also, error messages should go to stderr:

-if [ "$EUID" -ne 0 ]
-  then echo "ERROR: Please run as root"
-  exit
-fi
+if [[ $EUID -ne 0 ]]; then
+  echo "ERROR: Please run as root" >&2
+  exit 1
+fi

This ensures non-zero exit on permission issues.


8-11: Quote expansions and propagate errors
When invoking sub-scripts, wrap paths in quotes to handle whitelists or spaces, and rely on set -e to catch failures:

 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
 
-"$SCRIPT_DIR"/compile.sh
-"$SCRIPT_DIR"/flash.sh
+ "$SCRIPT_DIR"/compile.sh
+ "$SCRIPT_DIR"/flash.sh

Optionally, if you want the wrapper to return the exit status of flash.sh, you can use exec "$SCRIPT_DIR/flash.sh".

configuration/boards/btt-sb-2209-usb-10-rp2040/98-btt-sb-2209-usb-10-rp.rules (1)

2-2: Avoid hard-coded user paths in udev rule
Using /home/pi/printer_data/... in a udev rule is brittle and non-portable. Consider installing klipper-mcu-added.sh to a standard location (e.g., /usr/local/bin/klipper-mcu-added.sh) and referencing that path here. Alternatively, document that users must adjust this path if their config directory differs.

configuration/boards/btt-sb-2209-usb-10-rp2040/flash.sh (2)

1-6: Enable strict mode and fix root-check exit code
Apply the same strict flags as other scripts and ensure non-zero exit on root-check failure:

 #!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'
 MCU=/dev/btt-sb2209-usb-10
-if [ "$EUID" -ne 0 ]
-  then echo "ERROR: Please run as root"
-  exit
-fi
+if [[ $EUID -ne 0 ]]; then
+  echo "ERROR: Please run as root" >&2
+  exit 1
+fi

This also surface any missing commands (e.g. realpath) early.


7-9: Quote paths and verify helper exists
Ensure flash-path.sh is found and executable:

 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
-FLASH_SCRIPT=$(realpath "$SCRIPT_DIR/../../scripts/flash-path.sh")
-$FLASH_SCRIPT $MCU
+FLASH_SCRIPT="$(realpath "$SCRIPT_DIR"/../../scripts/flash-path.sh")"
+if [[ ! -x "$FLASH_SCRIPT" ]]; then
+  echo "ERROR: flash-path.sh not found or not executable at $FLASH_SCRIPT" >&2
+  exit 1
+fi
+exec "$FLASH_SCRIPT" "$MCU"

This adds robustness and proper hand-off.

configuration/boards/btt-sb-2209-usb-10-rp2040/compile.sh (3)

1-5: Add strict mode and fix root-check exit code
Apply strict flags and ensure an exit code on permission failure:

 #!/bin/bash
+set -euo pipefail
+IFS=$'\n\t'
 if [ "$EUID" -ne 0 ]
-  then echo "ERROR: Please run as root"
-  exit
+  then echo "ERROR: Please run as root" >&2
+  exit 1
 fi

12-16: Parameterize firmware output directory and user
Likewise, don’t hard-code /home/pi/printer_data/config/firmware_binaries—use an env var or derive from config. E.g.:

-if [ ! -d "/home/pi/printer_data/config/firmware_binaries" ]
+OUT_DIR="/home/pi/printer_data/config/firmware_binaries"
+if [[ ! -d "$OUT_DIR" ]]; then
     mkdir "$OUT_DIR"
-    chown pi:pi /home/pi/printer_data/config/firmware_binaries
+    chown "$(id -u):$(id -g)" "$OUT_DIR"
 fi

Ensures binary storage can be customized per user.


17-18: Use variables for clarity when copying UF2

-cp -f /home/pi/klipper/out/klipper.uf2 /home/pi/printer_data/config/firmware_binaries/firmware-btt-sb-2209-usb-10-rp.uf2
-chown pi:pi /home/pi/printer_data/config/firmware_binaries/firmware-btt-sb-2209-usb-10-rp.uf2
+UF2_SRC="$KLIPPER_DIR/out/klipper.uf2"
+UF2_DST="$OUT_DIR/firmware-btt-sb-2209-usb-10-rp.uf2"
+cp -f "$UF2_SRC" "$UF2_DST"
+chown "$(id -u):$(id -g)" "$UF2_DST"

This reduces duplication and makes maintenance easier.

configuration/boards/btt-sb-2209-usb-10-rp2040/toolboard-config.cfg (3)

11-15: Remove duplicate/ambiguous aliases
You’ve defined both lis2dw_cs_pin=gpio1 and adxl345_cs_pin=gpio1 under the same alias block. If only the LIS2DW is used, drop the ADXL345 line to avoid confusion. Also, consider using the lis2dw_cs_pin alias in the [lis2dw] section rather than raw gpio values.


17-19: Clarify probe vs. BLTouch pins
You’ve set bltouch_sensor_pin=gpio21 and then probe_pin=gpio21. If your BLTouch inverts the sensor/trigger behavior, this may be intentional, but please confirm that the same GPIO isn’t conflicting. Consider adding a comment explaining reuse.


31-35: Use consistent lowercase instance names
Your [temperature_sensor Toolboard] block uses an uppercase “Toolboard,” which differs from the lowercase “toolboard” instance elsewhere. Klipper’s config is case‐sensitive; use a matching lowercase name:

-[temperature_sensor Toolboard]
+ [temperature_sensor toolboard]
configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json (1)

39-44: Align sensor block key casing
The key "LIS2DW" is in uppercase, while other top-level keys use camelCase. To maintain consistency (and satisfy most JSON schemas), consider renaming this block to "lis2dw" or "LIS2DW_sensor".

configuration/boards/btt-sb-2209-usb-10-rp2040/firmware.config (2)

57-63: Review sensor support modules
Currently you’ve enabled WANT_LIS2DW, WANT_LDC1612, WANT_HX71X, and WANT_ADS1220. The board only integrates the LIS2DW accelerometer. Unless there are external connectors for the other sensors, consider disabling LDC1612, HX71X, and ADS1220 to reduce firmware footprint.


67-67: Remove unused CANBUS_FREQUENCY
CONFIG_RPXXXX_CANBUS is not set, yet CONFIG_CANBUS_FREQUENCY=1000000 remains. To avoid confusion, remove the CANBUS_FREQUENCY setting if CANBUS isn’t used on this board.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1322e24 and 965a8b0.

⛔ Files ignored due to path filters (3)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/board.png is excluded by !**/*.png
  • configuration/boards/btt-sb-2209-usb-10-rp2040/dfubooting.png is excluded by !**/*.png
  • configuration/boards/btt-sb-2209-usb-10-rp2040/manual.pdf is excluded by !**/*.pdf
📒 Files selected for processing (7)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/98-btt-sb-2209-usb-10-rp.rules (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/compile.sh (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/firmware.config (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/flash.sh (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/make-and-flash-mcu.sh (1 hunks)
  • configuration/boards/btt-sb-2209-usb-10-rp2040/toolboard-config.cfg (1 hunks)
🔇 Additional comments (8)
configuration/boards/btt-sb-2209-usb-10-rp2040/board-definition.json (4)

1-2: Verify schema reference path
Ensure the "$schema": "../board-definition.schema.json" path correctly resolves to the shared schema file in the repo. If the schema is located elsewhere (e.g., at configuration/board-definition.schema.json), update this relative path accordingly.


6-12: Check metadata naming conventions

  • Confirm that the "id" ("btt-sb-2209-usb-10-rp") and "firmwareBinaryName" ("firmware-btt-sb-2209-usb-10-rp.uf2") adhere to the project’s kebab-case guidelines and do not conflict with existing IDs.
  • Verify that "manufacturer" and "name" reflect the exact branding/casing preferred by BIGTREETECH.

13-22: Validate power and fan connector settings

  • Ensure "fourPinFanConnectorCount": 1 matches the actual hardware (does the board provide exactly one 4-pin connector?).
  • Verify "driverVoltages": [24] and the "outputPins" mapping for "part_fan_power" (GPIO14) align with the electrical design, including default "value": 0.

27-36: Verify DFU section details

  • Confirm that "flashDevice": "2e8a:0003" is the correct DFU vendor:product ID for the RP2040 bootloader.
  • Check that the "instructions" accurately describe the button sequence to enter DFU mode, and that "hasBoot0Jumper": false matches the hardware.
  • Ensure dfubooting.png is versioned in the repo and referenced in documentation.
configuration/boards/btt-sb-2209-usb-10-rp2040/firmware.config (4)

13-15: Confirm CONFIG_BOARD_DIRECTORY value
CONFIG_BOARD_DIRECTORY="rp2040" selects the generic RP2040 board directory. Verify that this matches the physical directory structure and the build system’s expectation for locating the board files.


16-23: Validate USB serial and memory layout

  • Check that CONFIG_USBSERIAL=y and the chosen USB serial number (CONFIG_USB_SERIAL_NUMBER) reflect the intended endpoints.
  • Ensure flash (CONFIG_FLASH_SIZE, CONFIG_FLASH_BOOT_ADDRESS, CONFIG_FLASH_APPLICATION_ADDRESS) and RAM (CONFIG_RAM_START, CONFIG_RAM_SIZE) settings match the RP2040 2 MB flash, on-chip RAM specs, and any reserved bootloader area.

26-33: Verify stage2 bootloader configuration

  • Confirm that CONFIG_RP2040_STAGE2_FILE="boot2_w25q080.S" exists in the source tree and is built correctly.
  • Ensure CONFIG_RP2040_FLASH_W25Q080 aligns with the actual flash chip on the board.

46-50: Cross-check USB vendor/device IDs
The firmware uses CONFIG_USB_VENDOR_ID=0x1d50 and CONFIG_USB_DEVICE_ID=0x614e. Make sure these match the IDs specified in the board-definition JSON and in the udev rules.

Comment on lines +6 to +11
cp -f /home/pi/printer_data/config/RatOS/boards/btt-sb-2209-usb-10-rp2040/firmware.config /home/pi/klipper/.config
pushd /home/pi/klipper || exit
make olddefconfig
make clean
make

Copy link
Contributor

@coderabbitai coderabbitai bot May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid absolute /home/pi paths—use script location
Hard-coding /home/pi/... prevents reuse. Instead derive the repo root from SCRIPT_DIR and reference relative paths:

-cp -f /home/pi/printer_data/config/RatOS/boards/btt-sb-2209-usb-10-rp2040/firmware.config /home/pi/klipper/.config
-pushd /home/pi/klipper || exit
+SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
+CONFIG_DIR="/home/pi/printer_data/config/RatOS/boards/btt-sb-2209-usb-10-rp2040"
+KLIPPER_DIR="/home/pi/klipper"
+cp -f "$CONFIG_DIR/firmware.config" "$KLIPPER_DIR/.config"
+pushd "$KLIPPER_DIR" || exit

Optionally, expose KLIPPER_DIR and CONFIG_DIR as environment variables for flexibility.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
cp -f /home/pi/printer_data/config/RatOS/boards/btt-sb-2209-usb-10-rp2040/firmware.config /home/pi/klipper/.config
pushd /home/pi/klipper || exit
make olddefconfig
make clean
make
SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
CONFIG_DIR="/home/pi/printer_data/config/RatOS/boards/btt-sb-2209-usb-10-rp2040"
KLIPPER_DIR="/home/pi/klipper"
cp -f "$CONFIG_DIR/firmware.config" "$KLIPPER_DIR/.config"
pushd "$KLIPPER_DIR" || exit
make olddefconfig
make clean
make

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@miklschmidt I thought removing the reliance on /home/pi was planned for another major refactoring, I'm just going off status-quo "templates". Should I make this edit?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Milkman Dan and others added 5 commits May 7, 2025 16:13
…r in Wizard "Confirm Configuration":

Error
[
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "undefined",
    "path": [
      "adxl345_cs_pin"
    ],
    "message": "Required"
  }
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant