Skip to content

RFC, done by AI: hm2: add Fanuc alpha serial spindle link driver (fspd) - #4898

Open
0wn3r wants to merge 6 commits into
LinuxCNC:masterfrom
0wn3r:fanuc-serial-spindle
Open

0wn3r wants to merge 6 commits into
LinuxCNC:masterfrom
0wn3r:fanuc-serial-spindle

Conversation

@0wn3r

@0wn3r 0wn3r commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

I took a liberty to dump EPROM DSP firmware of the Alpha series SPM module A06B-6078-H206#H500, sniff data between 21-MB CNC control and this SPM, had a range of firmware dumps from CNC controls which I fed to Claude Code to search for protocol description.

This was tested only as a bench with feeding spindle parameters to SPM and waiting to get Alarm 11, mimicking control behavior when HV is not present. Sniffing/emulation was done with scope and later with Nucleo board and TTL RS422 transceiver.
Machine I took control off is already running set of STMBL V5.0 drives, so it's almost impossible for me to do live testing now.

VHDL part was done against 7i94T firmware.
fspd-hm2.zip
SPINDLE_LINK_PROTOCOL.md
SPINDLE_LINK_IMPLEMENTATION.md

CNC side of the Fanuc alpha serial spindle link (JA7A/JA7B) to an alpha
series spindle amplifier (SPM), for a hostmot2 firmware carrying the
FanucSpindle module (general function tag 0x5C, unofficial).

The FPGA does the line format: 1.5 Mbit/s, 40-bit units with CRC-5, two
9-unit blocks per 2 ms frame, new word content every 4th frame. This
driver runs the link in the servo thread:

- start-up as recorded from a Fanuc 21-MB: pre-frames, loopback pattern,
  0x6996 key, link start with the one-off 0xC000 word, data-select
  (ROM ID read, range select echoed before the download), sequential
  parameter download, wait for download complete
- run: speed command (Q14 of parameter 4020), direction through
  SFRA/SRVA, *ESPA/MRDYA, alarm reset, orientation request, torque limits
- feedback: speed meter, load meter, status words, alarm number,
  position from the per-update increments, linearly interpolated position
- index-enable through the SPM's one-rev synchronisation (w13 bit 8 arms,
  w12 bit 6 reports, w4 counts from the marker)
- faults: no loopback echo, no initialised bit, download not acknowledged,
  link lost, data-select not echoed, SPM link restart; a rising edge of
  alarm-reset restarts a faulted link

Config: num_fspds=N. Pins: hm2_<board>.fspd.NN.*

The start-up sequence, parameter channel and data-select were confirmed on
a real SPM (firmware 9D20) with a separate emulator; this driver has only
run against a software model of the FPGA and the SPM so far.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grandixximo

Copy link
Copy Markdown
Contributor

Thanks for the write-up; the notes on the test setup help. Before anyone reviews the code, I have a few questions about where some of the protocol knowledge comes from, so the maintainers have the full picture.

  1. The protocol doc tags some facts as read from the SPM 9D20 firmware and others from the 21i-B NC_BASIC. The SPM dump and the captures come from your own module and your 21-MB, if I read it right. Where does the 21i-B image come from? Is it a control you own or have worked on?

  2. Suppose only your own hardware were used: the SPM dump plus the 21-MB captures. Which parts of the doc would still stand? The [M] tags cover the start-up, the parameter download and the word map. Is anything the driver relies on backed only by the 21i-B code?

  3. The docs point to notes that aren't attached (notes/pseudo/06, ref_SPINDLE_LINK_21i_B_other_session.md). Are those decompiled listings? I'm not asking you to share them. I only want to know whether anything from them made its way into the driver, the VHDL or the attached docs beyond register numbers and bit meanings.

@0wn3r

0wn3r commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author
  1. I'm in process of acquiring SRAM card with CIS to dump 21-MB firmware. Sniffed command set was compared against 21i-B, 0i-B/C/D firmware dumps which a friend of mine acquired from machines he was working on using ATA PCMCIA cards.
  2. There was a crosscheck done also against Fanuc maintenance manuals
    SPINDLE_LINK_CROSS_CONTROL.md
  3. Answer from Fable 5.2 agent:
    It is a rewrite from the protocol description. No code from the SPM or CNC firmware was reused, translated or ported.

What the implementation is made of

  • FPGA module (fanucspindle.vhd): written from scratch from the wire format measured with the scope and the Nucleo sniffer: bit rate, 40-bit unit, CRC-5, block and frame timing. In the real hardware this layer is a Fanuc gate array. We never had its design, so there was nothing to copy.
  • LinuxCNC driver (fanuc_spindle.c): a new state machine in the style of the other hostmot2 drivers. It plays the CNC's role, and its start-up sequence and timing follow the sniffed boot of Kira's own CNC.
  • Parameter values: from Kira's own parameter backup. They are not in the source; they come in through a HAL file.

What does come from the firmware analysis

  • Only facts about the interface: which link word means what, bit positions, and constants that appear on the wire anyway (the 0x55AA/0xAA55 test pattern, the 0x6996 key, the header bytes).
  • These are in the driver as plain numbers and names of my own. I checked the two source files today: neither contains firmware addresses, pseudocode or disassembly fragments.

Two caveats

  • This was not a clean-room process with separate teams. The same sessions that analysed the SPM firmware and read the CNC-side analysis also wrote the driver.
  • The project folder does hold pseudocode of the SPM firmware and the protocol documents with firmware addresses. Those are analysis notes, not part of the firmware or driver sources.

@grandixximo
grandixximo requested a review from pcw-mesa November 24, 2026 11:52
@0wn3r

0wn3r commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

kira_hal.zip
Forgot to include hal files.

@grandixximo

Copy link
Copy Markdown
Contributor

Thanks, that answers my questions.

One more, on testing: so far the link has only run against an SPM without a DC link, up to AL-11, and the index sync and rigid tap paths are not exercised at all. Would you be OK with the man page section for fspd saying it is experimental and untested on a running spindle, until someone with an alpha SPM on a machine reports back? The PR has no man page section yet, so it could go in when that is written.

@0wn3r

0wn3r commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Sure, I will start task on man page.

Adds a Fanuc serial spindle section and the num_fspds config option.
States that the driver has only run against a software model, and that
index-enable and rigid tapping in the amplifier are untested.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@grandixximo

Copy link
Copy Markdown
Contributor

Also please look at the review posted by @BsAtHome

@0wn3r

0wn3r commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Just to note the servo amplifier side - it's not feasible on anything that is not having the processing and protocol capabilities of something like STMBL. Fanuc uses a CNC side DSP which sends 3 PWM, reads two current feedbacks and passes processed encoder data. DSP computes current loop with a loop times of 250 us for HRV1, and up to 31.25 us for HRV4 for single drive. FSSB is serial link over fiber sending same data.
As a conclusion - if current is bearable for STMBL, it's better to use STMBL directly.

0wn3r and others added 2 commits November 24, 2026 14:45
- inline the small word helpers, clear the words with memset
- declare loop variables in their for statements
- check pin and parameter creation with a macro instead of summing results
- create integer pins and parameters with the 64-bit sint/uint calls
- set rom-id and rom-edition when they are read, not every cycle
- comment the word assignments of the running state

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
- limit the speed command in floating point before converting it; a very
  large speed-cmd-rpm was an out-of-range conversion
- drop the unused read of the received header register
- comments: no references to one machine, point at hostmot2(9), note that
  a watchdog bite stops the transmitter in the FPGA

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@0wn3r

0wn3r commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

VHDL code was replaced in main comment.

0wn3r and others added 2 commits November 24, 2026 17:23
- bool flags and typed enums for the link state, the fault code and the
  index state
- variables declared const at first use; no bare scoping blocks
- isnan/fmin/fmax/fabs from rtapi_math.h for the speed and position maths
- 64-bit rtapi types for the nanosecond counters

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Review comments: link word numbers, bit masks, header values, the
loopback pattern and its word range, start-up step counts and buffer
sizes are named constants now. The running state says what the words it
leaves at 0 are for.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@0wn3r
0wn3r force-pushed the fanuc-serial-spindle branch from 57f1195 to 9f9c564 Compare November 24, 2026 15:23
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.

3 participants