Friday, February 12, 2016

USB to SPI for .NET (performance)

USB to SPI performance

Getting good performance with a USB to SPI with a USB 2.0 full speed also depend also on what slave chip you are controlling, for example:
  • Let's pick the MAX7219 (10Mhz) an LED driver used to control 7-Segment display or 8x8 LED matrix.
    The communication protocol is :

        SELECT Byte0:Command, Byte1:Data, UNSELECT

    It does not really matter the speed at which the 2 bytes are transferred, after the 2 bytes, the MAX7219 required the UNSELECT. Most USB to SPI chip will therefore end the USB operation. With each USB operation there is a penalty at least of 1 Milli-second.
    If the USB to SPI chip (Software and hardware) allows to package multiple SELECT, Data, UNSELECT in one USB operation, then we will get good performance.
  • An EEPROM are generally more forgiving because we generally transfer pages of bytes. So for the cost of one USB operation we can transfer 64, 128, 256, ... bytes. But then it also depend on how much buffer the chip has.
  • A third case is for example the SPI OLED SH1106 or SSD1306 driver (128x64 monochrome pixel), which requires also extra GPIO named D/C (Data or Command).
    The communication protocol is :

    SELECT, DC=C, Cursor Position 3 bytes, UNSELECT, SELECT, DC=D, 128 data bytes, UNSELECT

    We need 8 times this sequence to send a full refresh of the display.
    If we cannot combine in one USB operation multiple sequences SELECT, DC, Data, UNSELECT. We will not get good performance even with a clock at 12Mhz.
    So it depends on the hardware and software feature of the chip.
    I am going to call this feature: USB to SPI Low Level Optimization.

    For example Nusbio G1 library (FT231X Chip) do support this mode and this allow to support the devices mentioned above with acceptable performance. That said the USB Buffer of the FT231X is 1k, so we can only package the bit banging in batch of 1024 and then we hit the USB operation penalty. That is why Nusbio G1 performance depending on the SPI slave device are between 10 K byte/s and 20 K byte/s.

    The FTDI FT232H is the only chip so I tested that support SPI Low Level Optimization.
    In FTDI world it is called MPSSE (Multi Protocol Synchronous Serial Engine). All FTDI chips supporting this mode can do SPI, I2C in very optimized way. This FT232H is High speed, the FT2232 is Full speed. More on the FT232H later.
  • USB 2.0 Highspeed. In Highspeed mode the cost (latency) of an USB operation is 100 nano second (I think). Therefore we can get better performance without SPI Low Level Optimization. Though it is preferable to have access to it.

No comments:

Post a Comment