Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
deroo
Nano33BLE-flash
Commits
760556fc
Commit
760556fc
authored
Aug 20, 2021
by
deroo
Browse files
added flash array declaration macros
parent
bb1389d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
library.properties
View file @
760556fc
name
=
Nano33BLE-flash
version
=
0.
2
version
=
0.
3
author
=
Roger De Roo
maintainer
=
Roger De Roo
sentence
=
Direct flash memory access
...
...
src/Nano33BLEflash.h
View file @
760556fc
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment