OBD-II and ELM327 (9), MITM Failure Analysis 3, the CAN Bus Requires At Least Two Devices

A House to The Development kit

I have to say, keep the things neat is profession. I seek expert (my wife) to improve my equipment
  • The pins of the development board are inserted into the foam as the base, and the base is attached to the box with hot melt glue
    • Expert: Hot melt glue is your friend
  • The DuPont wire is fixed to the edge of the box with strap
    • Expert: With strap, I can adjust wires if desired
  • Dig a hole in the box to fix the OBD-II head (fixed with hot melt glue), 
  • Dig another hold to route USB cable
    • USB1: Powering MCU board, and programming it
    • USB2: Get 5V power source, and a 5v-to-12v DC-to-DC coverter to power devices (HUD)
    • USB3: Powering Raspberry Pi







Datasheet is good friend to play with MCU

The advantage of changing to STM32 is that environment is simple. Reading datasheet about CAN bus makes me understand more. The text below is some note for me as reading the datasheet
  • STM32 by default doesn't enable CAN re-transmission
    • As the packet from HUD forwards to CAR, it might be dropped because the CAN bus is busy. So we need to turn-on re-transmission
    • If the packet is dropped, HUD will be unhappy (it thinks car doesn't respond)
    • STM register naming is quite bad: NART, No Auto ReTransmission
      • The good naming style is positive-list
        • 0: disable
        • 1: enable
        • Match human intuition
      • ENART(Enable Auto ReTransmission) is much better, really
  • STM32 CAN-TX is quite strong, it had 3x mailbox allowing queues up to 3 messages
    • So I can send the packet directly (assume the buffer never full)
  • STM32 CAN-RX is also strong, which had two FIFO, and each FIFO can store up to 3 messages
    • Don't need to worry buffer overflow
  • STM32 CAN1/CAN2 shares resource
    • I shall configure CAN2::filter by CAN1
    • That's the way STM32 designs their HW, read book !!

    Inspiration

    I think the real problem is: what's the difference between car and desktop. Why it's OK on the desktop but failure on the car. HUD expects to attach to live network, which includes a lot of devices; But my desktop is very quiet. As the MITM working, there's two CAN networks
    • CAN1
      • CAR or Pi-CAR
      • RPi-MITM
    • CAN2
      • HUD
      • RPi-MITM
    As connecting RPi-MITM to the car, the packets forward from CAN1 to CAN2. If HUD is NOT powered, there would be single devices on CAN2

    In CAN network, there's an *ack* field which all nodes shall respond. If there's only one node in CAN bus transmitting packet (but no ack), the TEC (Transmit Error Count) in CAN controller will keep rising. As reaching 255, the CAN controller mutes itself and entering bus-off status

    In the car, CAN1 keeps receiving packets and forward to CAN2. Before the HUD connecting to the network, RPi-MITM::CAN2 is in bus-off state (TEC reachs 255), and no longer response. Now as HUD powers up, nobody would ack to HUD's packet. Finally HUD also thinks the network is DEAD. This is why HUD doesn't work

    So the correct solution is: there's at least two devices in the CAN-bus
    • CAN1
      • CAR or Pi-CAR
      • STM32-CAN1 (package forwarding)
      • RPi-CAN0 (dummy client/ sniffer)
    • CAN2
      • HUD or VIDA-DICE
      • STM32-CAN2 (package forwarding)
      • SRPi-CAN1 (dummy client/ sniffer)
    In my final configuration, STM32 is in charged of packet-forwarding while RPi acks as dummy devices or sniffer. Before HUD powering up, both CAN bus contains at least two devices and we can send/receive packets without trouble (no entering bus-off state now)

    Use STM32 to forward CAN bus, it's the fastest way to forward packets within MCU; RPi can sniffer data and store them to SD cards. We can use WiFi to send command and retrieve data from RPi


    With the configuration above, I can finally light up HUD in the car with MITM. A long long way to struggle...


    STM32 Development Environemnt

    Since this is engineer's note, here's the tools I used, and why I picked them
    最後我想聊一下開發環境,底下是我用的工具和挑選的理由
    • STM32 CUBEMX
      • STM provided boot code generator. Easy to use, and quite handy
      • It also includes USB example
    • Atollic True Studio
      • Well develop GCC development environment, I can compile code easily
        • Avoid to use Keil ARM (the license is quite expensive)
    • Sublime text 3
      • The text editor I used in recent years, cross platform in Windows/Linux
    • Convert ST-Link on-board into a J-Link
      • Thanks to SEGGER, it converts ST-Link on Nucleo board to J-Link
      • I love J-Link

    • Segger OZone Debugger
      • Professional, free, and cross-platform (Windows/ Mac/ Linux) debugger
        • I didn't use Keil ARM, which had very handy debugger as well
        • Attolic True Studio also had gdb-based debugger, but not easy to use
    • Amazon FreeRTOS

    Comments

    Popular posts from this blog

    OBD-II and ELM327 (1)

    OBD-II and ELM327 (3), try to decode CAN package recorded by ELM327

    OBD-II and ELM327 (2), the underlying interface of ELM327