Make Your Own Breakout Board

Design and integrate a custom breakout board — from hardware planning to firmware, HAL driver, and LinuxCNC bring-up.

1. What You Are Building

A custom board has two software sides:

Both sides are selected using breakout_board in firmware/inc/config.h and hal-driver/config.h.

2. Prerequisites

3. Hardware Planning Checklist

Lock down these items before writing any code:

4. Choose a New Board ID

Pick an unused integer ID — for example 42. You will use this same ID in:

5. Firmware Side Integration

5.1 Create the firmware module

cp firmware/modules/breakoutboard_user.c firmware/modules/breakoutboard_42.c

Change the guard:

#if breakout_board == 42   // was 255

Implement the required callbacks:

5.2 Add your module to the firmware build

Edit firmware/CMakeLists.txt and add your source file inside add_executable(...):

modules/breakoutboard_42.c

5.3 Define board macros in firmware config footer

Edit firmware/inc/footer.h and add a new block:

#if breakout_board == 42
    // #define I2C_SDA 26
    // #define I2C_SCK 27
    // #define I2C_PORT i2c1
    // #define MCP23017_ADDR 0x20
    // #define ANALOG_CH 2
    // #define MCP4725_BASE 0x60
    // override stepgen/encoder/in/out/pwm macros as needed
#endif

5.4 Select board in firmware config

#define breakout_board 42

6. HAL Driver Side Integration

6.1 Create HAL board module

cp hal-driver/modules/breakoutboard_hal_user.c hal-driver/modules/breakoutboard_hal_42.c

Change the guard:

#if breakout_board == 42   // was 255

Implement:

6.2 Register your HAL board include

Edit hal-driver/stepper-ninja.c in the board-selection include section:

#elif breakout_board == 42
#include "modules/breakoutboard_hal_42.c"

6.3 Select board ID in HAL config

#define breakout_board 42   // must match firmware

7. Packet Mapping Rules

Any mismatch between firmware and HAL packet mapping causes swapped pins or dead I/O. Keep a single mapping table in comments while developing.

8. Build and Flash Firmware

cd firmware
cmake -S . -B build -DBOARD=pico2 -DWIZCHIP_TYPE=W5500
cmake --build build -j"$(nproc)"
ls build/*.uf2

Use -DBOARD=pico for Pico v1. Flash by holding BOOTSEL, plugging USB, and copying the .uf2 to the RPI-RP2 drive. Open serial output to verify init logs.

9. Build and Install the LinuxCNC HAL Module

cd hal-driver
cmake -S . -B build-cmake
cmake --build build-cmake --target stepper-ninja
sudo cmake --install build-cmake --component stepper-ninja

This installs stepper-ninja.so into your LinuxCNC module directory.

10. LinuxCNC HAL Bring-Up (Minimal)

loadrt stepper-ninja ip_address="192.168.0.177:8888"
addf stepgen-ninja.0.watchdog-process servo-thread
addf stepgen-ninja.0.process-send     servo-thread
addf stepgen-ninja.0.process-recv     servo-thread

# board I/O nets (names depend on bb_hal_setup_pins implementation)
# net estop-in    stepgen-ninja.0.inputs.0  => some-signal
# net coolant-out some-command              => stepgen-ninja.0.outputs.0

Verify with halshow or:

halcmd show pin stepgen-ninja.0.*

11. Commissioning Procedure (Recommended Order)

  1. Power-only test — validate rails, no overheating, no excessive idle current.
  2. Bus discovery test — confirm expected I2C addresses are detected by firmware prints.
  3. Disconnect safety test — stop LinuxCNC; confirm outputs and analog channels go to safe state.
  4. Input polarity test — toggle each physical input and confirm matching HAL pin state.
  5. Output test — toggle each HAL output pin and verify physical output.
  6. Encoder test — rotate slowly and quickly, verify count direction and index handling.
  7. Motion test (motor disconnected) — validate step/dir polarity and pulse timing.
  8. Motion test (connected) — start with conservative velocity/acceleration.

12. Troubleshooting

No I/O response

Build succeeds but board callbacks not active

Inputs shifted / wrong bit order

Recheck bit packing/unpacking between breakoutboard_42.c and breakoutboard_hal_42.c.

Random disconnect behaviour

Analog output clipping / overflow

Clamp HAL values before packing DAC words. Confirm scaling against DAC resolution.

14. Quick File Checklist

All files below must be touched for a new board ID. If IDs are consistent, integration is usually straightforward.