Reading FLASH arrays?

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

Reading FLASH arrays?

Postby scargill » Wed Jul 01, 2015 8:15 am

Does anyone have a simple example of reading data from a FLASH array - that is without having to hard code locations etc....

As a pseudo example (which clearly is fictional)

uint8_t fred[10]={ 1,2,3,4,5,6,7,8,9,10 }

a=fred[6];

but any array I've seen - event with CONST written all over it, still ends up using RAM! what C code would we need in order to create and access a similar array that never leaves FLASH and could hence be quite big.

??

Pete.

p.s. clarly it can be done - as there are routines in the SDK (and TUANPM wrote some) to store information in FLASH and bring it back... but it would be nice if somehow one could make something simple that doesn't involve knowing the exact location of the array in FLASH beforehand.

ESP8266Fan

Re: Reading FLASH arrays?

Postby ESP8266Fan » Wed Jul 01, 2015 10:31 am

You could try to define it like this

Code: Select all

static const char XXXX[] ICACHE_RODATA_ATTR = { ........ }


Flash is 4 bytes aligned, so your array has to be "uinit32" , read and write every 4 bytes.

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

Re: Reading FLASH arrays?

Postby scargill » Wed Jul 01, 2015 5:04 pm

Good idea ... but I think maybe you have to force the 4-byte alignment or something? It crashes the processor every time you try to access it..

static const uint32_t petes[] ICACHE_RODATA_ATTR = {
55,45,66,77,88,12,76,23,45,67,34,65,25,74,234,67,3,643,646,
55,45,66,77,88,12,76,23,45,67,34,65,25,74,234,67,3,643,646,
55,45,66,77,88,12,76,23,45,67,34,65,25,74,234,67,3,643,646};

iprintf is just a macro for a normal printf function...

iprintf("Data= %ld",petes[37]);

Immediate reboot....

Ideas?

scargill
Posts: 70
Joined: Sun Nov 02, 2014 8:09 pm

Re: Reading FLASH arrays?

Postby scargill » Sat Jul 04, 2015 3:06 pm

Well Well, it turns out after all of that - that it was just a silly typo - but here's the point, I've then gone on to do further tests with 8 bit arrays in FLASH and you can read individual bytes successfully - that came as a surprise. So now it would seem it is possible not only to move much of our code into FLASH without TOO bad an overhead but also lookup tables (I tried a very big table)! That should save some RAM.

eriksl
Posts: 157
Joined: Fri May 22, 2015 6:22 pm

Re: Reading FLASH arrays?

Postby eriksl » Sun Sep 13, 2015 6:01 pm

Please see my comments about character arrays in flash on your blog!

Who is online

Users browsing this forum: No registered users and 2 guests