Very slow SPI on ESP32?

Posted on
  • I'm playing around with one of the TTGO boards. It has an ILI9341 screen. But it looks like SPI is running at an extremely low rate. It takes several seconds just to clear the screen.

    SPI1.setup({sck:D18, miso:D12, mosi:D23, baud: 1000000});
    var g = require("ILI9341").connect(SPI1, D26, D27, D5, function() {
      g.clear();
      g.drawString("Hello",0,0);
      g.setFontVector(20);
      g.setColor(0,0.5,1);
      g.drawString("Espruino",0,10);
    });
    

    I found an old thread that mentioned ESP32 defaulting to 100kbs and ignoring the baud setting. Is that still true? Any way around it? Thanks.

  • I believe the ESP8266/ESP32 hardware SPI code isn't that speedy in general. Espruino expects to be able to queue a byte to send, then go away and work out the next byte while the first is sending. The ESPxx API doesn't let it do that so it has to send a byte, pause while it works out the next one, and so on.

    You could try software SPI? Not sure if that'll be faster, but it might be as it runs as fast as it can - especially if you don't specify a MISO pin, because you don't actually care about receiving data.

  • Thanks Gordon, I'll give that a try later.

  • About twice as fast in software. Bummer about the hardware speed.

    var spi = new SPI();
    spi.setup({sck:D18, mosi:D23, baud: 4000000});
    var g = require("ILI9341").connect(spi, D26, D27, D5, function() {
      g.clear();
      g.drawString("Hello",0,0);
      g.setFontVector(20);
      g.setColor(0,0.5,1);
      g.drawString("Espruino",0,10);
    });
    
  • The esp32 esp-idf allows a string to be sent - can you think of a way of keeping the existing code and also using the output as a string ? I suppose it could be done with the #ifdef but wondering if there is a cleaner way?

  • There's no easy way - in some cases the SPI could be sent a buffer, but for what the ILI9341 driver is doing here (sending a block of the same color) it's not going to work. Neither would it work for a bunch of other stuff.

    Basically we'd end up doing a massive hack and then maybe the ILI9341 would be twice as fast - but still too slow to be useful.

    Personally I'd like to sort out SPI properly so that it could work with buffers and DMA. That'd massively improve performance on all platforms.

  • I have just found out how slow it really is :(

  • Yeah I'm using it as well for a project and while the software SPI trick certainly sped it up (I was using hardware SPI), its still pretty glacial. Interestingly, here is a guy who's got a number of games, including DOOM, running on an ESP32 and an ILI9341.

    https://hackaday.io/project/163464-gamin­g-on-the-esp32-odroid-go

    Its PRETTY fast. So there is potential....

  • The issue is that the library esp provides takes a buffer - and the espruino calls send one byte at a time - so it's taking a buffer, and sending it a single byte - so it's really inefficient.

  • Oh I see. Thanks for the explanation! :)

  • There are some issues filed for it already:

    Basically rather than just hacking something in I'd like to get this fixed properly in a way that really improves all boards.

  • Thanks for the links Gordon, I checked them out, and you're right -- that for sure is the right approach. In my case I'm using it with something called the M5 Stack ( https://m5stack.com ), and thats a pretty neat little box, with lots of stackable options. Its totally usable as is, just not for making games or say, realtime UIs. Also, I know Jumjum and Wilberforce are working hard on the current challenges of integrating the latest versions of the ESP IDF.. . :)

  • I'd also love to see faster hardware SPI in Espruino

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Very slow SPI on ESP32?

Posted by Avatar for ConorONeill @ConorONeill

Actions