Commit 9378cd70 authored by deroo's avatar deroo
Browse files

add NANO33BLE_DECLARE to initialize pointer safely

parent 22c39f58
......@@ -21,7 +21,8 @@ flashBytesPerWord
flashNumberOfPages
with the values of 4096, 4 and 256, respectively.
Finally, it declares 2 macros:
Finally, it declares 3 macros:
NANO33BLE_DECLARE( \<datatype\>, \<arrayName\> )
NANO33BLE_PUT_ARRAY_IN_FLASH( \<datatype\>, \<arrayName\>, \<numberOfArrayElements\> )
NANO33BLE_FLASH_LOWEST_PAGE
which are described below.
......@@ -51,11 +52,10 @@ Serial.print(arrayInFlash[index]);
Declare arrays in flash is a two-step process.
The first step is to declare the array data type, and specify its scope.
This is done with a statement with a format of
\<datatype\> *\<arrayName\>;
NANO33BLE(\<datatype\>,\<arrayName\>);
such as
double *arrayInFlash;
NANO33BLE(double,arrayInFlash);
to declare an array of doubles named "arrayInFlash".
The asterisk ( * ) before the array name is important.
The scope of the array is determined by where the declaration is made.
If outside of any function, the scope is global (all functions can see the array), while if it is inside a function, it will be seen only within that function , and others to which it is passed in function argument lists.
......
name=Nano33BLE-flash
version=0.4
version=0.6
author=Roger De Roo
maintainer=Roger De Roo
sentence=Direct flash memory access
paragraph=This library enables Arduino Nano 33 BLE to use its onboard flash memory for storage of arrays. Thanks to Frank Holtz of arduino-NVM for inspiration.
category=Data Storage
url=https://gitlab.eecs.umich.edu/deroo/nano33ble-flash
architectures=mbed, (nRF52840 specifically)
architectures=mbed, mbed_nano, (nRF52840 specifically)
......@@ -32,8 +32,9 @@ _NANO33BLE_FLASH_DECR_ADDR((sizeof(_datatype)) * (_numberOfArrayElements)) \
_datatype *_arrayName = (_datatype *)_flashAddr;
// sets the type and scope of the array in Flash, depending on where done.
// set to a default address just beyond flash in case PUT_ARRAY_IN_FLASH isn't called
#define NANO33BLE_DECLARE( _datatype, _arrayName) \
_datatype *_arrayName;
_datatype *_arrayName=(_datatype *)(_NANO33BLE_FLASH_BASE + NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE);
// move existing pointer _arrayName to next available spot in Flash
// macro includdes executable code, so call this in setup()
......
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