FlexRay Introduction - nanamiwang/openpilot GitHub Wiki

FlexRay Introduction

FlexRay Concepts

Node and Channel

The FlexRay system consists of a bus and several nodes, the node can be ECU on car, or MPC5748G board. nodes are connected via one or two channels.

Cluster

A communication system of multiple nodes connected via channels is called cluster.

Communication cycle and segments

  • FlexRay frame transmission is based on communication cycle, a cycle contains the static segment, the dynamic segment, the symbol window and the network idle time Apart from during startup the communication cycle is executed periodically with a period that consists of a constant number of macroticks. The macroticks is a fixed parameter for a cluster.
    • Transmission in static segment is TDMA based.
    • Within the dynamic segment a dynamic mini-slotting based scheme is used to arbitrate transmissions.
    • The symbol window is a communication period in which a symbol can be transmitted.
    • The network idle time is a communication-free period, no frame transmission occur within NIT.
  • The node maintain a cycle counter that contains the number of the current communication cycle

FlexRay frame

FlexRay transmission is frame based, at a given time, only one node can send frames.

  • Types of frame:
    • Sync frame, transmitted in static segment.
    • Startup frame, special type of sync frame, used by integrating node to get timing information of cluster.
    • Data frame, transmitted in static or dynamic segment.

Clock Synchronization and clock correction

  • FlexRay is distributed communication system, every node has its own clock.
  • FlexRay uses a distributed clock synchronization mechanism in which each node individually synchronizes itself to the cluster by observing the timing of transmitted sync frames from other node.
  • Sync frames is transmitted by sync node, for a cluster, at least three nodes shall be configured to be sync nodes. For example, on BMW 530i, there are 4 ECUs acting as sync nodes: ZGM, DSC, ICM and DME/DDE.
  • FlexRay node use the reception time of sync framed as a reference to check sync status and correct local clock settings.

FlexRay startup process

This is what will happen after connect MPC5748G to the car, and power on the car

  • Coldstart node

    • Coldstart nodes initiate the cluster start up. During start up, coldstart node will transmit startup frames on every cycle. For example, on BMW 530i, ZGM is a coldstart node.
  • Non-coldstart node

    • When a non-coldstart node enters startup, it listens to its attached channels and tries to receive FlexRay frames, integrate to a transmitting coldstart node. It tries to receive a valid pair of startup frames to derive its schedule and clock correction from the coldstart node. Drive assist camera or MPC5748G board should be this type of node.

FlexRay Configuration Parameters

  • Cluster parameters
    • Timing parameters, such as:
      • gMacroPerCycle defines the (integer) number of macroticks per cycle
      • pMicroPerCycle, the node specific number of microticks per cycle
      • gdCycle, the cluster wide duration of one communication cycle
      • pdMicrotick. the node specific duration of one microtick
    • Frame parameters
  • Node parameters, such as:
    • pKeySlotId, the slot used for sync frame transmission
    • pKeySlotUsedForSync, is true for sync node
    • pKeySlotUsedForStartup, is true for start node
  • Message buffer parameters(MPC5748G specific)
    • Rx Message Buffers
      • To demand the CC on MPC5748G board to receive a frame, a Rx message buffer must be added to FlexRay configuration.
    • Tx Message Buffers
      • To demand the CC on MPC5748G board to send a frame, a Tx message buffer must be added to FlexRay configuration and the app have to write data to this buffer.

FlexRay connection test on car

  • The MPC5748G board must join into cluster on car before sending and receiving frames, to ensure stable communication, the cluster parameters on board must be the same as other nodes on car.
  • Without knowing all parameters of the car, we have to configure the board using different sets of cluster parameters and try integrating into the FlexRay cluster on car, steps below:
    1. Open flexray_tool, Click "Join into FlexRay Network" button, edit configuration parameters.
    2. Shutdown the car.
    3. Pull out the stock LKAS camera
    4. Connect the board to FlexRay ports on car
    5. Power on the car.
    6. Power on the board.
    7. Open flexray_tool, click "Connect" button
    8. Check the POC status and sync frame table on flexray_tool GUI
      • If the parameters is incorrect, the board will not be able to receive any sync frame, POC status will be in startup for ever.
      • If the paramaters is almost correct, POC status will enter into normal active.
        • If the deviation property of sync frame is big, timing parameters need a correction

Make connection tests safer

  • To avoid interfering existing FlexRay communication on car, the MPC5748G board can be configured so that it will not send any data to FlexRay bus:
    • Make sure the board is configured as non-coldstart node, which ensure the board will not send startup/sync frames to the FlexRay bus during startup.
      • set pKeySlotUsedForSync to false
      • set pKeySlotUsedForStartup to false
    • Don't configure any Tx Message buffers, which ensure the board will not send data frames.
      • Remove all Tx message buffers on flexray_tools GUI.
  • To verify that the method above really works, connect the board to pico scope instead of connecting to car, if the scope doesn't capture any FlexRay traffic, the configuration works.