Hire Me

A J2534 driver for the candleLight FD

Mickey · · 9 min read

Top view of the candleLight FD circuit board with the USB-C socket on the left, the STM32G0B1 microcontroller in the middle, the NXP TJA1051 CAN transceiver below it and the CAN connector pads on the right.
The candleLight FD: USB-C on the left, the STM32G0B1 in the middle, the TJA1051 transceiver next to the CAN pads.

For the last two days a candleLight FD has been sitting on my Windows bench, plugged into a car’s CAN FD bus, and an ECU on that bus has just been flashed through it with the manufacturer’s own diagnostic tool. A 32-bit one, naturally. That sounds unspectacular until you know that this adapter has no J2534 driver. Nobody ever wrote one. So I did, and it’s called gs-usb-j2534.

Why a driver at all

Windows diagnostic and flash tools talk J2534. The tool looks into the registry for registered PassThru drivers, shows you a list, and loads whatever DLL you pick. That’s the whole plugin model, and it has been the plugin model for twenty years. The consequence is that hardware without such a DLL doesn’t exist for these tools, no matter how good it is. My PCAN-USB Pro FD works because PEAK ships a J2534 DLL. A candleLight FD doesn’t, even though it speaks CAN FD at 2 Mbit/s and costs a fraction of what the professional interfaces do.

The candleLight FD is, in my opinion, the nicest open USB-CAN-FD interface you can currently buy. It’s designed by Linux Automation, based on Hubert Denkmair’s original candleLight, and the hardware is open under the CERN OHL. An STM32G0B1 does the work, there’s a USB-C socket on one side and a DSUB-9 with the usual CAN pinout on the other, and an NXP TJA1051 transceiver sits in between. One CAN channel is populated out of the box; the footprints for a second one are there. The firmware (candleLight_fw) is open too and can be updated over USB with dfu-util. On Linux it simply shows up as can0, since the gs_usb driver learned CAN FD in kernel 5.18 — I’ve been living on that side for a while, see my little Linux CAN toolbox. You can order it directly from Linux Automation; the project page on GitHub has the schematics, and Pengutronix wrote it up when it came out.

On Windows, though, it’s just a WinUSB device with a protocol nobody speaks. I do have a j2534-bridge that already talks gs_usb natively, and that’s what CANcorder used so far. But a bridge is a client library: only programs that embed it benefit. The manufacturer’s flash tool doesn’t embed anything of mine. It wants a DLL in the registry. sigh

So the gap had to be closed from the other side: make the adapter a regular PassThru device.

What it is

A single Rust crate, built twice. A 64-bit DLL for 64-bit programs and a 32-bit DLL for the many diagnostic tools that are still 32-bit (the flash tool above is one, which I found out when it politely didn’t list my driver). The two live in different registry views, PassThruSupport.04.04 and its WOW6432Node twin, and the installer registers both.

Stack diagram: a 64-bit and a 32-bit J2534 application each find the driver through their own registry view and load the matching build of the same DLL. Inside the DLL four layers pass data down: the 14 exported PassThru functions, channels with filters and ISO-TP, a bus layer with one reader thread, ten hardware transmit slots behind a 4096-frame software queue, and the gs_usb protocol over WinUSB. Below the DLL the candleLightFD puts the frames on the CAN FD bus at 500 kbit/s and 2 Mbit/s.
One source tree, two DLLs; the transmit queue sits between the tool and the ten hardware slots.

It speaks J2534-1 04.04 with the four protocols you’d expect: CAN, ISO15765, and the two J2534-2 flavours for CAN FD, FD_CAN_PS and FD_ISO15765_PS. ISO-TP runs inside the driver in both directions, including flow control with block size and STmin, padding, extended addressing and the FD escape for frames longer than eight bytes. Applications get segmented messages the way the standard promises them, and the adapter gets plain frames. The USB side is rusb on top of WinUSB, so there’s no vendor driver and no Visual C++ redistributable to install.

Most of the real work was in the places the standard doesn’t talk about, and I’m happy to admit that an LLM did a good part of the typing, with me on the ECU side of the table making sure it was true. Two things stand out.

The queue. The flash tool writes a whole ISO-TP block — 65 consecutive frames of 64 bytes — with timeout 0 and never retries a refused frame. The adapter has ten transmit slots. The first flash attempt ran for 199 blocks and then stopped, because PassThruWriteMsgs returned ERR_BUFFER_FULL in the middle of a burst and the tool took that as a reason to give up. The fix is a software queue of 4096 frames in front of the slots that feeds them strictly in order, so that “busy for a moment” never reaches the application. A little queue, and it was the difference between 199 blocks and all of them.

BRS, the bit rate switch. This one cost me most of a day. Early on, every frame I transmitted with BRS at 2 Mbit/s drove the controller into bus-off within milliseconds, and after a few rounds of that the adapter wouldn’t even answer PassThruOpen any more until I’d unplugged it. Receiving BRS frames was always fine. So the first working version quietly stripped the bit and sent everything at the nominal rate. The ECU accepted that, the flash completed, and it was slow.

To find out what was going on I put the candleLight and the PCAN-USB Pro FD on a bench bus with nobody else on it. Which comes with a rule I now know by heart: with no other node around, the other adapter has to be running and ACKing, otherwise the first frame already fails. On that bus BRS was flawless at 1 and 2 Mbit/s, 3000 frames, flooded and not. At 4 Mbit/s the default timing failed with the same bus-off-and-hang, and the cause turned out to be the sample point: the bit-timing calculation asked for 75 % and the controller’s time-quanta grid rounded that down to 70 %. With 80 % or 90 % the very same 4 Mbit/s run was clean; 5 Mbit/s wasn’t, whatever I did. That fits a transmitter without delay compensation (the gs_usb protocol has no field for it), but I’m hesitant to call it proven.

Back on the car, the original failure at 2 Mbit/s had gone. I can’t tell you which of the fixes in between cured it (waiting for the controller to sync to the bus after start, flow-control frames without BRS, the queue, …) and I don’t have the old driver’s transmit sequence around any more. What I have are numbers: three runs of 10,000 BRS frames on the live bus without a single error frame, and a complete ECU flash, 57,000 frames, with no bus-off and no lost confirmation. BRS is now on by default.

Bar chart of the total time of one complete ECU flash through the driver: 181 seconds when the bit rate switch is stripped from transmitted frames and 128 seconds when it is honored, about 29 percent faster for the same roughly 57,000 frames.
Total time of one complete flash from the driver trace, measured from the first to the last transmitted frame.

Using it

You don’t need a Rust toolchain. Download the zip from the releases page, extract it, and run install.cmd. Windows asks for administrator rights because the driver gets registered for all users; one package contains both the 64-bit and the 32-bit DLL and registers them in their respective registry views. Then start your J2534 application and pick candleLightFD J2534 (gs-usb-j2534) from its list of devices. For CAN FD choose the FD protocols and set the data rate (FD_CAN_DATA_PHASE_RATE, 2 Mbit/s if the tool doesn’t ask). If you’ve seen the list before, it looks like any other interface.

A few things worth knowing:

I’m also using it myself in CANcorder: it now reaches the adapter through the J2534 driver like any commercial tool would, which is the best test I could think of for a driver. If you build or test J2534 drivers, my little Jester tester is on the code page, next to the rest of the automotive tools.

What it can’t do yet

Version 0.9.0 means what it says. It has run on exactly one adapter (my candleLight FD, whose firmware is on the older side) with one ECU and one flash tool, plus the bench with the PCAN. Periodic messages and bit rates other than 500 kbit/s are unit-tested but haven’t seen real hardware. Not implemented: the 05.00 API variant, the GM flavour of the CAN FD protocol ID, battery voltage readout (the adapter can’t measure it) and the J1850 and K-line protocols, obviously. If your tool needs one of those, tell me which.

If you do try it with a different gs_usb adapter or a different flash tool — CANable, Cantact, something from the box of cheap STM32 boards — I’d like to hear how it went, especially if it doesn’t work. A trace file and the name of the tool is all I need. Stay tuned for 1.0 :)