E.memoryArea not working on ESP8266 (due to char-iterator ?) #5268
Replies: 1 comment
-
Posted at 2016-01-04 by @gfwilliams Yes - I think this is something we'd have to look into. It might be worth seeing if you could just tweak jsvStringIterator to read 32 bits at a time and see if that fixes it? (you'd have to change jslex.c too) I guess seeing if you could use Posted at 2016-01-04 by JumJum peek32 works fine on flash Sorry my knowledge is too poor to make the changes by myself :-( Posted at 2016-01-04 by tve Out of curiosity, what are you trying to do with E.memoryArea? And where is it documented, I don't see it in http://www.espruino.com/Reference ? Posted at 2016-01-05 by @gfwilliams I think The idea is that you can put strings/arrays into flash, and can even execute code direct from it - I think this was something you'd actually asked for at some point? Potential uses:
Posted at 2016-01-05 by JumJum In jswrap_espruino.c line 700 and following is a description for E.memoryArea. Posted at 2016-01-05 by JumJum Based on a lot of copy/paste, trial and error, E.memoryArea works for strings.
In next step function jslNextCh in jslex.c is extended too and first test calling a simple function works fine.
Pretty sure there is a nicer way doing this, and we will see this in next version. Posted at 2016-01-05 by @gfwilliams That's great! So that works for you on ESP8266? Personally I'd just Posted at 2016-01-06 by @gfwilliams @tve I know you're doing some benchmarking at the moment? Please could you try:
And see if it hurts performance much? My hope is that actually it won't have that much of an effect at all. If not, it'd be great to get it in as it could really help with the low RAM situation... Posted at 2016-01-06 by tve OK. This week looks very busy for me, so it will have to wait a few days. Posted at 2016-01-11 by JumJum I did some testing with new function to use strings in flash.
Next testcase has SHA1-function and server-object in Flash.
Result from this test(IMHO) is:
Posted at 2016-01-11 by JumJum One more test.
Posted at 2016-01-12 by tve Interesting tests, but a bit difficult to follow without any code snippets. For example, I don't know what you mean by "This time the SHA1 was copied to flash without function body." If you didn't put the SHA1 function body in flash, then what did you put in flash? I can see how to execute code from a memory area, what I'm not yet seeing is how to put it all together. One option could be to have a special method to load a bunch of source code into a flash area and tell the interpreter: here, load this. But that now creates a completely separate path from the way the IDE or command line tool work to load code. Or we could modify some stuff in jsinteractive that puts code into a memory area by default. But now we need to create a memory allocator for the flash area that can also deal with code being replaced, i.e. areas being freed, etc. On top of that then comes Posted at 2016-01-12 by JumJum Let me try to give a better explanation. Its more or less a proof of concept.
Posted at 2016-01-26 by @gfwilliams I've just added some code to handle this here I'm not able to test on my ESP8266 for some reason so it'd be great if someone could take a look at the builds and see if they still work ok. Posted at 2016-02-11 by Wilberforce Hi Gordon, Posted at 2016-02-11 by @gfwilliams You could look at the ChangeLog on @tve's GitHub and figure out which commits have the changes in (if any). Otherwise the main travis builds for Espruino are auto-built and should be usable. According to the comments on this bug it may not work though. I'd kind of assumed that after all the requests someone might have tested it, but it seems not :( Posted at 2016-02-11 by Wilberforce Ah - I'll try one of the auto builds this weekend and report back if it works. Posted at 2016-02-12 by JumJum Just tested with sources from github, for me it works fine.
Posted at 2016-02-12 by @gfwilliams That's awesome - thanks for checking! Nice to know it is all working properly, at least in some builds :) Posted at 2016-02-14 by Wilberforce I can confirm the peek stuff above works, however I get a reset with E.memoryArea trying to read the Esp8266 flash:
It works with the 0x3ff00054 address:
So this seems to be associated with the address.... https://github.com/espruino/Espruino/wiki/ESP8266-Design-Notes Posted at 2016-02-14 by JumJum Flash in ESP8266 is mirrored (windowed?) to 0x40200000.
if this returns 255 for all fields, usually this is available flash Posted at 2016-02-15 by @gfwilliams hmm, so could it be that the READ_UINT8 macro won't work graphics (As in @MaBecker's bug) because the address used is wrong? That could complicate things :( I guess we'd need a second Macro with Posted at 2016-02-15 by Wilberforce Thanks. Using the offset works ok- I'm wondering if there is a way of hiding this transparently like Flash() lib does? I was expecting the esp8266.getFlash() to return these larger regions, it doesn't look like this is implemented yet. I also believe these is a restriction of 1mb max, and that this is in the espurino core rather than the esp8266 implementation. Does anyone know why this is the case? Posted at 2016-02-15 by Wilberforce
That makes sense, and would explain it. Posted at 2016-02-15 by @gfwilliams
Well, it's not a restriction in Espruino itself - maybe just something about Posted at 2016-02-16 by Wilberforce
I was going by this comment: The restriction seems to be here:
#define FLASH_MAX (1024*1024) Looking at the fetch:
So really #define FLASH_MAX (1024*1024) should be determined by the type of Flash chip in the esp8266 board. https://github.com/espruino/Espruino/blob/master/targets/esp8266/jswrap_esp8266.c
So this could be used rather than the #define: Posted at 2016-02-16 by tve Maybe E.memoryArea should use flash addresses (starting at 0) instead of memory mapped addresses? Posted at 2016-02-16 by @gfwilliams
I guess we'd need some ESP8266-specific tweaks in there for that, but it could be a plan.
@wilberforce So Posted at 2016-02-16 by JumJum Would it be possible/an option to move the defines from jsutils to jshardware ? Posted at 2016-02-16 by @gfwilliams At the moment there's no per-platform I agree it's a shame to have loads of ESP8266 ifdefs in Posted at 2016-03-07 by Wilberforce Does using the api get around the memory mapped limitation of accessing > 1mb memory for flash? For writing the api call is used,but for reading it is just accessing memory. If the Api was used for the reading could we using the flash module for accessing > 1 mb? Posted at 2016-03-07 by @gfwilliams I would imagine so, but there might be some gotchas. @tve might know? Posted at 2016-03-16 by tve Speed is the main gotcha, IIRC. Espruino uses 4-byte flash reads when loading stuff like the saved code from flash, so if each one turns into an SDK call which has to tweak the HW memory map back and forth to access the rest of flash it's gonna be real slow. Posted at 2016-03-16 by tve Or perhaps a better option: if the flash region accessed is in the lower 1MB use the existing memory-mapped code, if it's higher use the SDK calls... Posted at 2016-03-17 by @gfwilliams I think you'd be fine using the API calls for As @tve says, I wouldn't start changing internal stuff (eg. E.memoryArea) to use it, or performance will really suffer. Posted at 2016-03-17 by Wilberforce Looks like the conditional if < 1mb direct read otherwise api is the way to go. Now that the flash module returns available flash should the esp8266 call be depreciated? If I manage to get this stuff working, I'll have to extend the free areas to return the new available space too Posted at 2016-03-17 by @gfwilliams The esp8266 call is deprecated - it'll say so in the documentation when the next version is released (the online documentation matches the current release). Posted at 2016-03-30 by Wilberforce The code compiles, but I've not had a chance to test yet: Posted at 2016-03-31 by Wilberforce Tested ok on 4mb board. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-01-04 by JumJum
Tested this command on actual Esp8266 firmware.
Going down to assembler listing it breaks using an 8 bit instruction in iterator.
There could be a problem in reading bytes from Flash, reading works fine for aligned 32bits only (afaik).
Beta Was this translation helpful? Give feedback.
All reactions