Repository navigation
process-node 0.3.2: RS-485 mock (Modbus RTU device behind a transceiver model) - #13
Merged
Merged
Conversation
…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
force-pushed
the
process-node-rs485-mock
branch
from
November 18, 2026 17:00
7f60ed0 to
570df29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:modbus.c, host-tested intests/test_modbus.c):de on):undriven);collisions).de offmodels an automatic-direction transceiver.modbus statshows the counters;modbus regreads or sets a holding register.Tests
tests/modbus_master.pyis a Modbus RTU master over the pod.tests/test_rs485.py(markerrs485, needsBENCH_NEW_WIRING=1 BENCH_LA6_RESISTOR=1) runs it:read_holding_registershelper, unchanged;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.test_lifecycle,test_rs485,test_rl78,test_sensors_uartandtest_sensors_drdyin one run: 36 passed. The 9 skipped are RL78 tests, which need the unreleaseduart_hdfirmware.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.
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 onmode 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 withoutuart_de.🤖 Generated with Claude Code