Commit 760556fc authored by deroo's avatar deroo
Browse files

added flash array declaration macros

parent bb1389d2
name=Nano33BLE-flash
version=0.2
version=0.3
author=Roger De Roo
maintainer=Roger De Roo
sentence=Direct flash memory access
......
......@@ -9,6 +9,44 @@
#ifdef NRF52840_XXAA // this is defined iff Nano 33 BLE is selected
// the lowest flash address
#define _NANO33BLE_FLASH_BASE (0x0)
// set static unsigned int _flashAddr to one byte after the top of flash
#define NANO33BLE_FLASH_INIT() \
_flashAddr = (_NANO33BLE_FLASH_BASE + NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE);
// private macro: move _flashAddr down by the size of the array being declared
// cannot be done directly in NANO33BLE_FLASH macro
#define _NANO33BLE_FLASH_DECR_ADDR(_bytesInArray) \
_flashAddr -= (_bytesInArray);
// public macro: declare array in flash at highest flash addresses available
// first push _arrayAddr down by size of array in bytes,
// then use array - pointer equivalence to declare a pointer to that address
#define NANO33BLE_FLASH( _datatype, _arrayName, _numberOfArrayElements ) \
_NANO33BLE_FLASH_DECR_ADDR((sizeof(_datatype)) * (_numberOfArrayElements)) \
_datatype *_arrayName = (_datatype *)_flashAddr;
// public macro to be used after all the flash array declarations
// useful for looping over flash pages to initialize/erase them.
#define NANO33BLE_FLASH_LOWEST_PAGE \
((_flashAddr - _NANO33BLE_FLASH_BASE) / NRF_FICR->CODEPAGESIZE)
// test. result: don't do sizeof(#_datatype)
#define NANO33BLE_FLASH_SIZEOF(_datatype) \
(sizeof(_datatype))
/*
// these two defines below do work...
#define NANO33BLE_FLASH_INT(_arrayName) \
int *_arrayName = (int *)0x100000;
#define NANO33BLE_FLASH_DECL(TYPE,_arrayName) \
TYPE *_arrayName = (TYPE *)0x100000;
*/
static unsigned int _flashAddr = (_NANO33BLE_FLASH_BASE + NRF_FICR->CODESIZE * NRF_FICR->CODEPAGESIZE);
// Caution: these enums are the register settings for the given mode.
enum _flashModeEnum{
FLASH_READONLY = NVMC_CONFIG_WEN_Ren << NVMC_CONFIG_WEN_Pos, // 0,
......@@ -16,9 +54,9 @@ enum _flashModeEnum{
FLASH_ERASE = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos // 2
};
const int flashBytesPerPage = NRF_FICR->CODEPAGESIZE; // 4096 bytes
const int flashBytesPerWord = 4;
const int flashNumberOfPages = NRF_FICR->CODESIZE; // 256 pages
const unsigned int flashBytesPerPage = NRF_FICR->CODEPAGESIZE; // 4096 bytes
const unsigned int flashBytesPerWord = 4;
const unsigned int flashNumberOfPages = NRF_FICR->CODESIZE; // 256 pages
void flashMode(_flashModeEnum mode);
int flashErasePage(byte page);
......
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