• Hi all,

    This looks like a great piece of work, and I am migrating some personal project to Espruino with my ESP cards.

    For everything to work fine, I needed some enhancements, so I have done them (on v91), and I think it woud be worth sharing so that these can be merged into the public version:

    • Resizable vars : the code is there, for the Linux version. Just patched a bit to enable it in ESP (should also work for other cards now) and fixed also some minor bugs on the save to / load from flash code (as it was, I think it would also fail on Linux, as with RESIZABLE_JSVARS the vars are stored in blocks, while the compress functions, as they were, read and wrote a full contiguous block of memory)

    • 1024Kb + 1024Kb memory map : Added few lines to the Makefile to create a new target for the ESP 4Mbyte cards. With this layout, now we have 1024KB for firmware and stored vars and functions. Still neeeded to check where to fix some address mapping for the second image, as in this mode the bootloader maps 0x4020000 to either the first or second Mb of flash, and the image itself is exactly identical for user1 and user2. Just need to check in existing code if there is something harcoded around flash address and fix it.

    So now, I get:

    reset();
    =undefined
    ... [ Espruino boot banner ] ...
    Flash map 4MB:1024/1024, manuf 0xe0 chip 0x4016
    Flash code area: 0x76000 (565248 bytes)

    process.memory();
    ={ "free": 106, "usage": 22, "total": 128, "history": 0 }

    require("ESP8266").getState();
    ={
    "sdkVersion": "2.0.0(5a875ba)",
    "cpuFrequency": 160, "freeHeap": 34232, "maxCon": 10,
    "flashMap": "4MB:1024/1024",
    "flashKB": 4096,
    "flashChip": "0xe0 0x4016"
    }

    var tester = [];
    =[ ]

    for(var i=0 ; i < 900 ; i++) tester[i] = i;
    =undefined

    process.memory();
    ={ "free": 88, "usage": 936, "total": 1024, "history": 6 }

    var more = [];
    =[ ]

    for(var i=0 ; i < 900 ; i++) more[i] = 2*i;
    =undefined

    process.memory();
    ={ "free": 210, "usage": 1838, "total": 2048, "history": 6 }

    require("ESP8266").getState();
    ={
    "sdkVersion": "2.0.0(5a875ba)",
    "cpuFrequency": 160, "freeHeap": 3344, "maxCon": 10,
    "flashMap": "4MB:1024/1024",
    "flashKB": 4096,
    "flashChip": "0xe0 0x4016"
    }

    require("ESP8266").reboot();
    =undefined
    ... [ ESP boot info and some garbage :) ] ...
    Loading 2048 jsvars from flash...

    dump();
    var tester = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,;
    var i = 900;
    var more = [ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, ;
    pinMode(D0, "input_pullup", true);
    pinMode(D4, "input_pullup", true);
    pinMode(D5, "input_pullup", true);
    pinMode(D12, "input_pullup", true);
    pinMode(D13, "input_pullup", true);
    pinMode(D14, "input_pullup", true);
    pinMode(D15, "input_pullup", true);
    =undefined

    TO DO:

    • More testing
    • Take benefit of this extra memory (make sure we can access code directly on it)

    For the second part, what I use is as small piece of code based on something I found a couple of years ago in Internet and which I enhanced bit, so that ESP can access directly the flash mapped memory independently of alignment, or size (1, 2, 4 bytes) with no further modification to the user code. This is possible because ESP8266 is a bit of a monster, and allows virtualizing memory access through HW catchable exceptions for this kind of memory access errors, so a trap function can directly see the failing opcode and target address, access flash with the right alignment, simulate the opcode and put the result on the right register, and return control to the program (at assembler opcode level) after the offending opcode address.

    This is seamless to your code, that can now access memory mapped flash as if it was in the rodata area. Of course, there is an impact in speed, which I have not benchmarked, but not noticed either, as we are not using our ESP8266s to do math intensive calculations (are we?)

    Will work on other improvements.

    So, if there is interest on it, I have a bunch of ".patch" files I will be happy to submit, or share, or whatever is the best way to get these into the main build.

About

Avatar for Pedro @Pedro started