Commit c6d7af3f authored by deroo's avatar deroo
Browse files

README updates

parent 967e53ad
......@@ -8,19 +8,24 @@ The Flash on the nRF52840 has 256 pages of 1024 words, each word is 4 bytes.
Each page is individually erasable; each word is individually writable.
This library defines 2 functions:
int flashErasePage(byte page);
int flashErasePage(int page);
void flashMode(_flashModeEnum mode);
where mode is one of
FLASH_READONLY
FLASH_WRITE
FLASH_ERASE
it also declares 3 constants
it also declares 3 int constants
flashBytesPerPage
flashBytesPerWord
flashNumberOfPages
with the values of 4096, 4 and 256, respectively.
Finally, it declares 2 macros:
NANO33BLE_FLASH( \<datatype\>, \<arrayName\>, \<numberOfArrayElements\> )<br>
NANO33BLE_FLASH_LOWEST_PAGE
which are described below.
This code is most useful for implementing non-volatile arrays,
particularly when the datatype is of the size of a flash word or larger
(eg. int, long, float, double).
......@@ -43,17 +48,6 @@ value = arrayInFlash[index];
or
Serial.print(arrayInFlash[index]);
The first 16 pages (0-15) are used for the bootloader.
<b>Do not corrupt the bootloader lest your Nano become useless!</b>
The next N pages (16-..) are used by the sketch.
Larger sketches may use more pages.
It seems the smallest sketches, like blink, take 19 pages.
To check how many pages your sketch uses,
watch the colored text as it uploads (hit the Arduino reset button to abort).
Or, compile and take the number of bytes
in "Sketch uses NNNN bytes (X%) of program storage space..."
and divide by 4096, rounding up.
Declare arrays in flash using a macro:<br>
NANO33BLE_FLASH( \<datatype\>, \<arrayName\>, \<numberOfArrayElements\> )<br>
such as<br>
......@@ -69,6 +63,10 @@ The macro sequentially packs the arrays in from the top of the available flash m
The lowest flash page that is partially or fully occupied with your arrays is given by the macro NANO33BLE_FLASH_LOWEST_PAGE.
Thus, if you need to erase all the pages your sketch is using in order to initialize them, loop with a for loop from NANO33BLE_FLASH_LOWEST_PAGE to flashNumberOfPages, erasing each page as you go.
Valid datatypes include structs and typedefs, in addition to the predefined C datatypes. Structs appear to default to multiples of flash words, so the programmer's attention to alignment issues does not appear to be neccessary.
Some limitations: the sizeof operator on any array declared in flash will always return 4 (=flashBytesPerWord). Also, C string functions like strcpy and strlen do not always work as one would expect to manipulate the arrays in flash, 'tho memcpy and strcpy do work to copy the contents out of flash, and memcpy does work to copy into flash, but the number of bytes should be a multple of flashBytesPerWord. I recommend using macros (ie. #define) or variables to declare the number of array elements as the sketch cannot figure out by itself how big a flash array has been declared after the declaration.
If you want more control over the details of the declarations in flash,
declare arrays in flash using pointers:<br>
\<datatype\> *\<arrayInFlash\> = ( \<datatype\> *)\<flashAddress\>;<br>
......@@ -83,3 +81,15 @@ the maximum index is the number of words on two pages, or 2048.
Note: you have to keep track of which array is where,
and take care not to walk off the end of your array into another one.
Fortunately, past the end of the sketch, it's all available to use.
The first 16 pages (0-15) are used for the bootloader.
<b>Do not corrupt the bootloader lest your Nano become useless!</b>
The next N pages (16-..) are used by the sketch.
Larger sketches may use more pages.
It seems the smallest sketches, like blink, take 19 pages.
To check how many pages your sketch uses,
watch the colored text as it uploads (hit the Arduino reset button to abort).
Or, compile and take the number of bytes
in "Sketch uses NNNN bytes (X%) of program storage space..."
and divide by 4096, rounding up.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment