Skip to content

process-node 0.3.2: RS-485 mock (Modbus RTU device behind a transceiver model) - #13

Merged
wardviaene merged 3 commits into
mainfrom
process-node-rs485-mock
Nov 18, 2026
Merged

wardviaene merged 3 commits into
mainfrom
process-node-rs485-mock

Conversation

@wardviaene

@wardviaene wardviaene commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

An RS-485 mock in process-node, so Modbus RTU through a transceiver (the 5 V and RS-485 docs page) can be tested on the bench without a transceiver or a Modbus device.

Stacked on #12 (the RL78 emulator); its two commits show here until that one merges.

What it does

modbus start <addr> <baud> [8E1|8N2|...] [delay <us>] [de on|off] turns USART3 into an RS-485 bus with one Modbus RTU device on it. It uses the bench wires the UART sensors already use, with LA6 as the transceiver's DE:

Transceiver Pod Node
DI LA8 PC11 (USART3 RX)
RO LA7 PC10 (USART3 TX)
DE + /RE LA6 (GPIO) PA8, through 1 kOhm
  • The device (modbus.c, host-tested in tests/test_modbus.c):
    • functions 01, 03, 04, 05, 06, 08 (return query data), 0F and 10;
    • exceptions 01 to 03;
    • broadcasts are carried out and not answered;
    • a bad CRC or another address gets no answer.
  • Framing: frames end after 3.5 characters of silence. A frame is dropped on a gap of more than 1.5 characters, or on a framing or parity error.
  • The transceiver rules (de on):
    • a byte the pod sends while DE is low never reaches the device (counted as undriven);
    • a reply byte while DE is still high never reaches the pod (counted as collisions).
    • de off models an automatic-direction transceiver.
  • Console: modbus stat shows the counters; modbus reg reads or sets a holding register.

Tests

tests/modbus_master.py is a Modbus RTU master over the pod. tests/test_rs485.py (marker rs485, needs BENCH_NEW_WIRING=1 BENCH_LA6_RESISTOR=1) runs it:

  • registers, coils and echo;
  • the four exceptions;
  • the silent cases (bad CRC, another slave, broadcast);
  • 9600 8N2, 19200 8E1, 38400 8O1 and 115200 8N1;
  • a parity mismatch;
  • DE never raised, raised correctly, released too early, released too late;
  • the docs page's read_holding_registers helper, unchanged;
  • a turnaround sweep.

The pod runs one UART session at a time, so the master and the node's console take turns. Neither the node nor the mock is reset in between.

Hardware results

On benchpod-30a9f1 (release firmware 3.10.10, no pod changes needed):

  • test_rs485.py --soak 2: 43/44 passed. The one failure was the report-only turnaround case at 20 ms, which raised on a half-collided reply instead of counting it; fixed.
  • Then test_lifecycle, test_rs485, test_rl78, test_sensors_uart and test_sensors_drdy in one run: 36 passed. The 9 skipped are RL78 tests, which need the unreleased uart_hd firmware.

These runs used the build just before the README and version bump; the code is the same.

Finding: host-switched DE is slow

Measured with the pod's logic analyzer: a GPIO command from the host takes about 27 ms over LAN, so DE drops about 25 ms after the request's last byte.

Device answers after Replies
30 ms or more 10/10
20 ms 2/10
5 ms 0/10

So the docs page's example works only with devices that answer slowly. Many real Modbus devices answer within a few milliseconds and need an automatic-direction transceiver today. The mock's de on mode can verify a pod-side automatic DE once one exists.

Update: the pod drives DE itself (embeddedci-com/benchpod-firmware#163)

  • test_pod_de: open_uart(de=6), with no DE handling on the host, at 9600 8N2, 19200 8E1 and 115200 8N1. The device answers after 3.5 characters, 1 ms and 5 ms. Every reply arrives, with 0 undriven bytes and 0 collisions. It skips on pods without uart_de.
  • Mock fix: DE's falling edge is now timed with EXTI line 8 on PA8, and a byte counts as driven when DE fell within its stop bit. Sampling DE in the receive interrupt counted the last byte as undriven at one stop bit, because a correct DE drops at the end of the stop bit, often before that interrupt runs.
  • Hardware, gateware v58:
    • RS-485 suite, soak 2: 62/62, with the pod-DE subset also on the loop and emulation images;
    • the lifecycle, rl78, sensors_uart, drdy, analog_in and bus_master suites: 43/43;
    • on release 3.10.10 the pod-DE tests skip.

🤖 Generated with Claude Code

wardviaene and others added 3 commits November 18, 2026 11:00
…iver model

`modbus start <addr> <baud> [fmt] [delay <us>] [de on|off]` turns USART3
(LA8 -> PC11 as DI, PC10 -> LA7 as RO) into an RS-485 bus with one Modbus
RTU device, with the LA6 wire into PA8 as the transceiver's DE + /RE. With
DE honored, a byte the pod sends while DE is low never reaches the device
and a reply byte while DE is high never reaches the pod, so a master's
direction handling is tested as on a real bus; `de off` models an
automatic-direction transceiver.

modbus.c: functions 01/03/04/05/06/08/0F/10, exceptions 01-03, broadcast,
CRC; frames by t3.5 silence, dropped on a t1.5 gap or a framing / parity
error. Host-tested in tests/test_modbus.c.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/modbus_master.py and tests/test_rs485.py (marker rs485): registers,
coils, exceptions, silent cases, four frame formats, a parity mismatch, DE
never raised / released too early / too late, the docs page's example, and
the turnaround a host-switched DE allows (measured: ~25 ms DE release lag on
LAN; devices answering after >= 30 ms work, 20 ms 2/10, 5 ms never).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s own DE

The mock sampled DE when a byte's receive interrupt ran, around the middle
of its stop bit or later; the pod's DE (gateware v58) drops at the end of
the last stop bit, so at one stop bit the last byte counted as undriven.
EXTI line 8 now times DE's falling edge on PA8, and a byte counts as driven
when DE fell within its stop bit. test_pod_de: open_uart(de=6), 9600 8N2 /
19200 8E1 / 115200 8N1, the device answering after 3.5 characters, 1 ms and
5 ms, every reply, 0 undriven, 0 collisions (skips without uart_de).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@wardviaene
wardviaene force-pushed the process-node-rs485-mock branch from 7f60ed0 to 570df29 Compare November 18, 2026 17:00
@wardviaene
wardviaene merged commit f05fadc into main Nov 18, 2026
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