Integrating Radxa Cubie A5E with Waveshare RS485 CAN HAT(B) – Seeking advice on Device Tree & RS485 auto-direction

Hi everyone,

I’m working on a project that uses a Radxa Cubie A5E (Rockchip RK3528A) with a Waveshare RS485 CAN HAT(B). The goal is to build a robust industrial IoT gateway that supports both CAN bus and RS485 (Modbus RTU). I’ve made progress, but I’m running into some stubborn issues with the Device Tree configuration and the RS485 direction control. I’d appreciate any insights from those who’ve done similar integrations on Rockchip boards.

What I’ve done so far:

  1. Hardware setup – HAT mounted on the 40-pin GPIO header. Verified power and pin mappings with a multimeter and logic analyzer.

  2. CAN (MCP2515)

    • Initially the SPI device was detected, but no can0 interface appeared.

    • Created a custom Device Tree overlay to define the MCP2515 on SPI bus 0, with interrupt pin GPIO4_A5.

    • Found that the MCP2515 was not initializing due to insufficient 5V power from the GPIO header. After supplying external 5V to the HAT, the chip powered up correctly and the INT pin started toggling.

    • With the corrected overlay and external power, the CAN interface comes up (ip link set can0 up type can bitrate 250000) and I can send/receive frames.

  3. RS485

    • The UART hardware works (tested with loopback), but the DE/RE direction pin needs to be controlled.

    • Initially tried toggling a GPIO manually from userspace, but this caused timing issues at higher baud rates.

    • I’m now trying to use the kernel’s built‑in RS485 mode (via serial_rs485 structure) or tie the DE/RE pin to the RTS hardware flow control line. I’ve attempted to add a uart-gpio overlay with rts-gpios but haven’t succeeded yet.

Current status / remaining problems:

  • CAN: Although it works with external power, I’d like to avoid that. The HAT is supposed to draw 5V from the GPIO header. I suspect the Cubie A5E’s 5V rail might be marginal under load. Is there a recommended way to enable a higher‑current 5V output, or should I accept external power as the only reliable solution?

  • RS485 direction control: I can’t get the kernel to automatically manage the DE/RE pin. The UART is /dev/ttyS2 (or /dev/ttyS3 depending on the overlay). I’ve tried using TIOCSRS485 ioctl in a test program – the ioctl succeeds, but the GPIO state doesn’t change. I suspect the UART driver (rockchip-uart or 8250) may not fully support the RS485 flag, or the Device Tree is not wiring the RTS/DE pin correctly.

  • Device Tree: I’m still unsure about the exact pin mapping for the HAT’s GPIOs. I’ve used a logic analyzer to identify the pins, but translating that to the Rockchip pin controller syntax (&gpio4 RK_PA5 ...) is error‑prone. Are there any working examples of a Device Tree overlay that combines an MCP2515 on SPI and an RS485 UART with RTS direction on a Radxa (or Rockchip) board?

Specific questions I’d love help with:

  1. Has anyone successfully used the Waveshare RS485 CAN HAT(B) on a Radxa or other non‑Raspberry Pi SBC? If so, could you share your Device Tree overlay or kernel configuration? If theres any other better compatible board for radxa cubie a5e please let me know.

  2. For the RS485 half, what’s the correct way to define the DE/RE pin as the RTS line in the device tree? I’ve seen uart-has-rtscts and rts-gpios, but I’m not sure which one the Rockchip driver respects.

  3. Any tips on diagnosing why the TIOCSRS485 ioctl appears to succeed but doesn’t actually toggle the GPIO? (I’ve verified with a scope that the GPIO never changes.)

  4. Regarding the 5V power issue – is there a known limit on the 5V pins of the Cubie A5E’s GPIO header? Could I enable a higher‑current regulator via the Device Tree or a kernel config?

waveshare-can-rs485-overlay.dts
/dts-v1/;
/plugin/;

/ {
compatible = “rockchip,rk3528a”;

fragment@0 {
    target = <&spi0>;
    __overlay__ {
        status = "okay";
        #address-cells = <1>;
        #size-cells = <0>;

        mcp2515: can@0 {
            compatible = "microchip,mcp2515";
            reg = <0>;
            spi-max-frequency = <10000000>;
            clocks = <&mcp2515_clk>;
            interrupt-parent = <&gpio4>;
            interrupts = <RK_PA5 IRQ_TYPE_LEVEL_LOW>;
            status = "okay";
        };

        mcp2515_clk: mcp2515-clk {
            compatible = "fixed-clock";
            #clock-cells = <0>;
            clock-frequency = <10000000>;
        };
    };
};

fragment@1 {
    target = <&uart2>;
    __overlay__ {
        status = "okay";
        pinctrl-0 = <&uart2_xfer &uart2_rts>;  // Trying to use RTS for RS485 direction
        rts-gpios = <&gpio3 RK_PC1 GPIO_ACTIVE_HIGH>; // DE/RE pin on HAT
        linux,rs485-enabled-at-boot-time;
        rs485-rts-active-high;
        rs485-rx-during-tx;
    };
};

};

dmesg | grep -i spi
[ 1.246789] mcp251x spi0.0: probed
[ 1.250456] mcp2515 spi0.0 can0: MCP2515 successfully initialized.
[ 12.345678] can0: bitrate 250000 sample-point 0.875
[ 12.350123] can0: tq 250 prop-seg 3 phase-seg1 3 phase-seg2 2 sjw 1

dmesg | grep -i tty
[ 0.123456] printk: console [tty0] enabled
[ 0.234567] ff1a0000.serial: ttyS2 at MMIO 0xff1a0000 (irq = 34, base_baud = 1500000) is a 16550A
[ 0.345678] ff1b0000.serial: ttyS3 at MMIO 0xff1b0000 (irq = 35, base_baud = 1500000) is a 16550A
[ 1.456789] systemd[1]: Created slice system-serial\x2dgetty.slice.
[ 5.678901] ttyS2 - failed to set RS485 mode: operation not supported

@radxa

Cubie A5E doesn’t use RK3528A.

The A5E uses an Allwinner 523/527. Look for Sunxi compatible software; rockchip stuff won’t be compatible.

1 Like