Commit f7422e6c authored by deroo's avatar deroo
Browse files


parent 962596fb
# Nano33BLE-flash
Functions and constants for declaring arrays in the flash memory of an Arduino Nano 33 BLE and Arduino Nano 33 BLE Sense.
\ No newline at end of file
Functions and constants for declaring arrays in the flash memory
of an Arduino Nano 33 BLE and Arduino Nano 33 BLE Sense.
The Nano 33 BLE uses a nRF52840 microcontroller chip
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);
void flashMode(_flashModeEnum mode);
where mode is one of
it also declares 3 constants
with the values given above, or derived from it.
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).
Arrays of datatypes smaller than a flash word (eg. char, byte, short)
are awkward to implement, but doable.
Write data to a flash array with this motif:
and erase a page in flash with this motif:
The first 16 pages (0-15) are used for the bootloader.
Do not corrupt the bootloader lest your Nano become useless!
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 pointers:
datatype *arrayInFlash = (datatype *)flashAddress;
where the flashAddress is the number of bytes into the flash memory.
for example,
int *intsInFlash = (int *)(flashNumberOfPages-2)*flashBytesPerPage;
to use the last two flash pages as an array of ints.
Since the size of flash word is the same as sizeof(int) on the Nano 33 BLE,
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.
Supports Markdown
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