Commit 83c87b2f authored by deroo's avatar deroo
Browse files

README update

parent 711e8aea
/*
*
*/
#ifndef Nano33BLEflash_h
#define Nano33BLEflash_h
#include "Arduino.h"
#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
// then make it start on a flash word boundary (the next lowest multiple of 4)
// cannot be done directly in NANO33BLE_FLASH macro
#define _NANO33BLE_FLASH_DECR_ADDR(_bytesInArray) \
_flashAddr -= (_bytesInArray); \
_flashAddr &= 0xFFFFC;
// 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,
FLASH_WRITE = NVMC_CONFIG_WEN_Wen << NVMC_CONFIG_WEN_Pos, // 1,
FLASH_ERASE = NVMC_CONFIG_WEN_Een << NVMC_CONFIG_WEN_Pos // 2
};
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(int page);
void _wait4flash2Bready(void);
/*
class Nano33BLEflash
{
public:
Nano33BLEflash();
enum Flash_mode{FLASH_READONLY=0, FLASH_WRITE=1, FLASH_ERASE=2};
const int bytesPerPage=NRF_FICR->CODEPAGESIZE; // 4096 bytes
void mode(Flash_mode mode);
int erase(byte page);
private:
void wait4flash2Bready(void);
};
*/
#endif
#endif
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