Configuration Guide

All config.h options, board selection, motion channels, encoder modes, PWM, and build-time flags.

Overview

Stepper-Ninja keeps matching configuration headers in two places:

In normal use, hal-driver/config.h should be a symlink to firmware/inc/config.h, not a separately maintained copy. If symlinks are missing, recreate them:

cd hal-driver
./make_symlinks.sh

Which File Should You Edit?

Edit firmware/inc/config.h for Pico firmware behaviour. hal-driver/config.h should point to it as a symlink. Some values in footer.h are overridden automatically when breakout_board is not 0.

Network Defaults

These define the startup network configuration stored in flash until changed via the serial terminal.

DefineMeaning
DEFAULT_MACDefault Ethernet MAC address
DEFAULT_IPDefault static IP address
DEFAULT_PORTUDP port used by the HAL driver
DEFAULT_GATEWAYDefault gateway
DEFAULT_SUBNETDefault subnet mask
DEFAULT_TIMEOUTCommunication timeout in microseconds

Board Selection

breakout_board selects the hardware layout.

ValueMeaning
0Custom pin mapping from config.h
1Stepper-Ninja breakout board
2IO-Ninja breakout board
3Analog-Ninja breakout board
100BreakoutBoard100

When breakout_board > 0, footer.h replaces custom pin definitions with board-specific values.

Motion Channels

DefineMeaning
stepgensNumber of step-generator channels
stepgen_stepsStep output pins
stepgen_dirsDirection output pins
step_invertInvert step outputs per channel
encodersNumber of encoder channels
enc_pinsFirst pin of each quadrature encoder pair (B is next GPIO)
enc_index_pinsIndex pins for encoders
enc_index_active_levelActive level of each index input
💡

Pins defined as gpio if only using numbers eg:22, or use real pico pcb pin numbers by "pin_12"

Encoder Mode

DefineMeaning
ENCODER_PIO_LEGACYOriginal quadrature counter PIO
ENCODER_PIO_SUBSTEPNewer substep-aware PIO (default)
encoder_pio_versionSelects which PIO is compiled
// Default — recommended
#define encoder_pio_version ENCODER_PIO_SUBSTEP

// Switch back to legacy
#define encoder_pio_version ENCODER_PIO_LEGACY

Override from the build command line:

CFLAGS='-Dencoder_pio_version=ENCODER_PIO_LEGACY' cmake -S firmware -B build -DWIZCHIP_TYPE=W5500
💡

Encoder velocity estimation is done in the HAL driver for legacy mode. In legacy mode, firmware sends per-cycle encoder count deltas; in substep mode, velocity calculated in pico and sent to HAL side.

Digital Inputs and Outputs

DefineMeaning
in_pinsInput GPIO list
in_pullupEnable pull-up per input
out_pinsOutput GPIO list

These are used only in custom mode or where the selected breakout board does not override them.

PWM Options

DefineMeaning
use_pwmEnables PWM support
pwm_countNumber of PWM outputs
pwm_pinPWM output pins
pwm_invertInvert PWM per channel
default_pwm_frequencyDefault PWM frequency
default_pwm_maxscaleHAL scaling limit
default_pwm_min_limitMinimum PWM output limit

Set use_pwm to 1 only when channel count and pins are valid for your board.

Raspberry Pi SPI Mode

DefineMeaning
raspberry_pi_spiUse SPI link to Raspberry Pi instead of Wiznet Ethernet
raspi_int_outInterrupt/status pin toward Raspberry Pi
raspi_inputsRaspberry Pi visible inputs
raspi_input_pullupsPull-up setting for those inputs
raspi_outputsRaspberry Pi controlled outputs

When raspberry_pi_spi is 0, the firmware uses the Wiznet Ethernet path.

Timing Defaults

DefineMeaning
default_pulse_widthDefault step pulse width in nanoseconds
default_step_scaleDefault steps per unit
use_timer_interruptEnables step command ring buffer and timer-driven step output
💡

use_timer_interrupt buffers step commands and can reduce visible PC-to-Pico jitter.

These live in footer.h and depend on the selected board or platform. Do not change casually.

DefineMeaning
use_stepcounterUses step counter instead of the quadrature encoder path
debug_modeExtra debug behaviour for Raspberry Pi communication
max_statemachinesDerived total PIO state machine count
pico_clockPico system clock used by the firmware

Build-Time Options (CMake)

OptionMeaning
-DWIZCHIP_TYPE=W5100SBuild for W5100S
-DWIZCHIP_TYPE=W5500Build for W5500
-DBOARD=picoBuild for Pico
-DBOARD=pico2Build for Pico2
-DSTEPPER_NINJA_RUN_FROM_RAM=ONCopy firmware to SRAM before execution

Full example:

cmake -S firmware -B build -DBOARD=pico2 -DWIZCHIP_TYPE=W5500 -DSTEPPER_NINJA_RUN_FROM_RAM=ON

Recommended Workflow

  1. Select the board with breakout_board.
  2. Set stepgens, encoders, and pin lists if using custom mode.
  3. Choose encoder_pio_version.
  4. Enable PWM only if your hardware uses it.
  5. Keep firmware and HAL driver config files aligned via the symlink.
  6. Build firmware and HAL driver after every meaningful config change.

For network settings changed at runtime, see the IP Configuration Guide.