Welcome! Log In Create A New Profile

Advanced

PIC32 and flash memory map

Posted by damato68 
PIC32 and flash memory map
November 28, 2012 11:59AM
Hi, I'm trying to write two 256 bytes LUT (lookup table) from the SD file to the pic flash to avoid to keep these into the PIC ram.
The problem is that I don't know the flash mapping and how to reserve a memory block for this data from machineBasic (2.06).
Many thanks for any help.



Edited 1 time(s). Last edit at 11/28/2012 11:59AM by damato68.
Re: PIC32 and flash memory map
November 28, 2012 12:15PM
You can't dynamically write to flash but you can store tables to flash in the latest version 2.06-67 in a similar way that you can in C using the constant keyword. So a lookup table of bytes would be:

constant lut$ {1,2,3,0x55,77}

You can only have a line length of 80 characters and so a continue ‘\’ symbol can be used for larger tables thus:

constant lut$ {1,2,3,4,5,6,1,2,3,4,5,6,55,0xff,0xff,0xff,7,6,5,4 \
44,66,71,121,244 }

To store 32 bit integers leave off the $ thus:

constant lut{0xaabb1245, 5, 7877261 }

Full details are in the documentation, keywords, constant.
Re: PIC32 and flash memory map
November 28, 2012 12:28PM
many thanks!
Re: PIC32 and flash memory map
November 28, 2012 02:41PM
Hi,jimeer

I've implemented the method suggested to define LUT as constant. The problem is that the only way to extract data from variable is with peek calculating the right offset. "asc" function won't work. Is there a better way ?
Many regards
D.
Re: PIC32 and flash memory map
November 28, 2012 03:17PM
Peekc is the best way to do it, e.g.

value = peekc(?lut$+4+offset)
or if you prefer
data = ?lut$+4
value = peekc(data+offset)

When the constant is defined as a string, the first 4 bytes are the storage size so the actual data starts at byte 4 (5th one along from 0). peek(?lut$) will give you the size of the byte array. dump(?lut$,32) can also be quite useful for verification

Some points:
1) when accessing bytes use peekc(), 32 bit integers use peek() or @
2) ? is required because this is the address of the array and peek[c] uses an address
3) its not a good idea to use asc as that will return '.' if it is outside a printable range so only really works with text.
Re: PIC32 and flash memory map
November 29, 2012 09:30AM
Sorry, I've seen that exist but is undocumented.

>Hi jimer,
>peekc is ok, a function like "pokec" may be useful too :)-D



Edited 1 time(s). Last edit at 11/29/2012 10:04AM by damato68.
Re: PIC32 and flash memory map
November 29, 2012 03:31PM
Thats why there is one :-)
Sorry, only registered users may post in this forum.

Click here to login