Espruino on ESP32

Posted on
Page
of 3
Prev
/ 3
Next
  • @Kolban
    My adafruit dev esp32 board has arrived. Before I test a build is there firmware I can flash stored anywhere?

    Ideally it would be great to get the Esp32 built automatically with the Travis builds - to do this for the esp8266 @tve has hosted the toolchan.tar file on his server - we would need to do something similar for esp32...

    Or are things still a little unstable to do this?

  • for first testing you can download from here Its latest version from my "playing with the chip". Source is available on github, pull request to Espruino is created and open for discussion. Stability(?), at least it starts and runs commands, http, pin, .... but its more or less a proof of concept.
    I would recommend to build your own development area. Neil Kolban added some helpful docu under targets/ESP32/docu
    flashing:
    bootloader.bin to 0x1000
    partitions_singleapp.bin to 0x4000
    espruino_ESP32.bin to 0x10000

  • Thanks @JumJum
    I'll test first with the binary you have built - thanks.

    I've been reading up on the tools chain etc - I'll document how to build under windows 10 with the bash/Linux subsystem when I get around to installing.

  • I have a compiled version on Windows 10 working. This also works out of the box which looks promising:
    make USE_CRYPTO=1 USE_TLS=1 USE_GRAPHICS=1 USE_AES=1

    This means potentially we will be able to use https:// to hit other sites.

    This is working:

    require("http").get("http://www.google.c­om", function(res) {
      res.on('data', function(data) { console.log(data);    });
    });
    
    ={ "type": 1,
      "#onconnect": function (res) { ... },
      "res": {  },
      "opt": {
        "protocol": "http:",
        "method": "GET",
        "host": "http://www.google.com",
        "path": "/",
        "pathname": "/",
        "search": null, "port": null, "query": null },
      "dSnd": "GET / HTTP/1.0\r\nU" ... "ww.google.com\r\n\r\n",
      "sckt": 3 }
    <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
    <TITLE>302 Moved</TITLE></HEAD><BODY>
    <H1>302 Moved</H1>
    The document has moved
    <A HREF="http://www.google.co.nz/?gfe_rd=cr­&amp;ei=HtMvWK6XD9TN8genzLygCQ">here</A>­.
    </BODY></HTML>
    

    however this errors:

    require("http").get("https://www.google.­com", function(res) {
    :  res.on('data', function(data) { console.log(data);    });
    :});
    
    Connecting with TLS...
    ERROR: Unable to create socket
    ={ "type": 5,
      "#onconnect": function (res) { ... },
      "res": {  },
      "opt": {
        "protocol": "https:",
        "method": "GET",
        "host": "http://www.google.com",
        "path": "/",
        "pathname": "/",
        "search": null, "port": null, "query": null },
      "dSnd": "GET / HTTP/1.0\r\nU" ... "ww.google.com\r\n\r\n",
      "closeNow": true }
    

    I've also got issues with save() - if you do this it appears to corrupt the flash memory and the board won't boot on reset and needs to be re-flashed. I've put more detail on the gitter.im feed

  • @tve are you likely to get an ESP32 board?

  • I've had some problems with saved code after reflashing.
    Fixed it with flashing last page of saved area with an empty.bin.
    As far as I can see, there are 2 parts of saved data.
    First part gives an error message if data is corrupted, but 2nd part does not test this and crashes at least on ESP32.

  • @JumJum
    Where did you save the empty bin to was it 0x100000. ?

    Have you had a sucesssful save the works on power up?

  • I came across this. It seems there are some hardware issues that cannot be bypassed by firmware, and another revision of the board will be released next year. Maybe nothing that will impact the ESP32 port, but maybe worth bearing in mind if trying to get hold of an ESP32 now.

    http://espressif.com/sites/default/files­/documentation/eco_and_workarounds_for_b­ugs_in_esp32_en.pdf

  • @Wilberforce, 0x100000 is start of save area, which is 16 pages, each 4096 bytes.
    So startadresse is end of flash area (0x110000) minus size of your empty file.

  • BTW, adress in flash will change soon. Espressif uses a grown boot area.
    I'm wondering if there is a way to automate calculation of save area.

  • Further progress made:

    1. save() works - and on reboot loads saved code
    2. wifi.save() saves the current connects and reloads on reboot

    So after wifi connect and save, here is a example using websockets:

    function onInit() {
      
      console.log('on init...');
    
    var wifi=require("Wifi");
    //wifi.connect(ssid, {password: password}, function() {
    
    wifi.on('connected', function(details) { 
      console.log("Connected to access point, listening for clients",details);
    
      var http = require("http");
      
      
     function onPageRequest(req, res) {
        //console.log(req);
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.end(page);
     }
    
      var page=`
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scal­e=1">
        <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/boo­tstrap/3.3.5/css/bootstrap.min.css">
      </head>
      <body>
        <div class="well well-lgt">
          <div class="panel-heading">
            <h3>Websockets</h3>
          </div>
          <button class="btn btn-warning" id="send" onclick="ws.send(JSON.stringify({click:{­count:count}}));;count=count+1;this.inne­rHTML='Send '+count">Send to Espruino</button>
          <ul id="list" class="list-group"></ul>
        </div>
        <script>
        var ws, count = 1;
      setTimeout(function () {
    
      ws = new WebSocket("ws://" + location.host + "/my_websocket", "protocolOne");
        ws.jsend=function(o) {
       this.send(JSON.stringify(o));
        };
      ws.onmessage = function (event) {
        console.log({
          msg : event.data
        });
        var ul = document.getElementById("list");
        var li = document.createElement("li");
        li.className = "list-group-item";
        li.appendChild(document.createTextNode(e­vent.data));
        ul.appendChild(li);
      };
      setTimeout(function () {
        //ws.send(JSON.stringify({click:{count:c­ount}}));
        //ws.send(JSON.stringify({info:{value:'H­ello to Espruino!'}}));
        //ws.send(JSON.stringify({date:{date : new Date()}}));
        ws.jsend({info:{value:'Hello to Espruino!'}});
        ws.jsend({date:{date : new Date()}});
      }, 1000);
    }, 1000);
    </script>
      </body>
    </html>
    `;
    
    var ws_outer;
      
      function sendTime() {
        ws_outer.send(JSON.stringify({data:new Date().ms}));
      }
    
    
     var server = require('ws').createServer(onPageRequest­);
     server.listen(80);
     server.on("websocket", function(ws) {
       ws_outer=ws;
        ws.on('message',function(msg) { console.log((msg)); });
        ws.send("Hello from Espruino!");
        sendTime();
     });
    
    
    });
    };
    

    open a browser with the address echoed:

    Connected to access point, listening for clients {
      "ip": "192.168.15.11",
      "netmask": "255.255.255.0",
      "gw": "192.168.15.1"
     }
    

    Still lots of vars free:

    >process.memory();
    ={ "free": 3858, "usage": 1142, "total": 5000, "history": 528 }
    >ESP32.getState();
    ={
      "sdkVersion": "1.0.0(c418d6b)",
      "freeHeap": 97864 }
    > 
    
  • Some great progress here. Has anyone make and arbitrary tests with > 5000 JSvars, to get a feel for what might be possible whilst keeping everything stable?

  • Not yet, still getting everything stable. How many vars are you thinking of?

    I think we would need to reserve more than 12k of flash for the save code area. There is still plenty heap space.

  • Don't have a number in mind. I'm just intrigued at what applications might be possible on ESP32 given there's so many GPIO pins. My inference is that programs which orchestrate all of those pins will need more memory to run and flash in which to save the code. I recall the ESP8266 port moving up/down a few times as things progressed through the porting process, and finally exceeding all (certainly my own) expectations at 1700 JSvars.

    So just interested to know if the upper memory (and save) space limits of ESp32 have been "prodded " yet and how realistic those limits might be.

  • Given there is 3mb of flash free, and js code can be run from flash - I'm not sure if there will be any practical limits!

    I tried to look up to see how many vars the Linux port uses - however there is nothing in the Linux.py file for variables

  • Just fyi - the Linux port uses a slightly different method of variable storage that lets it dynamically grow the memory it uses (the MCU versions needs to allocate it up front)

    Even if you store code in flash, each function will use 2 or 3 vars to store the pointer to the code. But still - it's a big improvement.

  • @ollie - 8000 vars is too much.

    Still seems to boot with 6000 vars. - and 7000!

    >ESP32.getState();
    ={
      "sdkVersion": "1.0.0(c418d6b)",
      "freeHeap": 69312 }
    >process.env
    ={
      "VERSION": "1v87.132",
      "BUILD_DATE": "Nov 28 2016",
      "BUILD_TIME": "20:47:04",
      "GIT_COMMIT": "114743c748dec1b9bc9b85fdd20ac7ccd300f5b­b",
      "BOARD": "ESP32",
      "CHIP": "ESP32",
      "CHIP_FAMILY": "ESP32",
      "FLASH": 0, "RAM": 524288,
      "SERIAL": "240ac400-2f90",
      "CONSOLE": "Serial1",
      "EXPORTS": { "jsvLock": 1074612384, "jsvLockAgainSafe": 1074612520, "jsvUnLock": 1074615156, "jsvSkipName": 1074635332,
        "jsvMathsOp": 1074646944, "jsvMathsOpSkipNames": 1074650168, "jsvNewFromFloat": 1074629948, "jsvNewFromInteger": 1074629860, "jsvNewFromString": 1074628356,
        "jsvNewFromBool": 1074629920, "jsvGetFloat": 1074640852, "jsvGetInteger": 1074634132, "jsvGetBool": 1074641544, "jspeiFindInScopes": 1074661088,
        "jspReplaceWith": 1074660836, "jspeFunctionCall": 1074671164, "jspGetNamedVariable": 1074662684, "jspGetNamedField": 1074663072, "jspGetVarNamedField": 1074663180,
        "jsvNewWithFlags": 1074627972 }
     }
    >process.memory();
    ={ "free": 6968, "usage": 32, "total": 7000, "history": 13 }
    > 
    
  • @Wilberforce at 7000 that's comparable to Espruino Wifi, but i imagine there is a lot of work to do yet, before can know if that's realistically attainable. Anyway thanks for the update :)

  • I am amazed at how well this is progressing. I can't wait to try it out - haven't had time for any "for fun" projects like Espruino. I've been so busy lately, I haven't even had a chance to fire up my Espruino WiFi's yet

  • @DrAzzy

    What the amazing thing is is how little code has been written. Look in the esp32 branch under targets. So far there is about 3 files!

    For graphics and crypto - its all compiling cleanly and we don't need to do all the tricks like for the esp8266.

    There is an sdk update due at the end of the month tht will give us spi and i2c, however @jumjum has found issues with the Uart.

    I've got the telnet module linked in, however the connection from Uart to sockets needs sorting - not sure where to start yet..l

  • I've managed to get i2c working on the ESP32 - using parts of the arduino library.

    The device supports 2 i2c devices - at this stage it's only one supported ( The version 1.0 sdk did not contain the spi and i2c api's as expected)

    The bitrate seemed to default to 50000, so I needed to set to 100000 for it to work.

    The esp32 needed to be powered up with the display Vcc left off and then turned on, otherwise the board would not intialise properly - it seem to be better feeding the display 5V directly.

    I2C1.setup({"scl":D17,"sda":D16,bitrate:­100000});
    var lcd = require("HD44780").connectI2C(I2C1);
    lcd.print("Hello ESP32!!");
    
    
  • image:


    1 Attachment

    • IMG_0827.JPG
  • update the COM3 to whatever port you use.
    esptool.py --chip esp32 --port COM3 --baud 921600 write_flash --flash_mode dio --flash_freq 40m --flash_size 16MB 0x1000 .bootloader.bin 0x10000 espruino_esp32.bin 0x8000 partitions_singleapp.bin


    1 Attachment

  • Great work! Though I only loosely understand what was involved, I did infer the lack of these features in the SDK release might have been a showstopper for you and @JumJum.

    Little did I know!

  • esptool doesn't recognise the --chip esp32 option, have I got the wrong tool?

    EDIT: yep with this tool it's looking good. Thanks Wilberforce!

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

Espruino on ESP32

Posted by Avatar for Kolban @Kolban

Actions