mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
cpu/nrf5x_common: add flashpage_raw_support
This commit is contained in:
parent
db08af4586
commit
254934dfa6
@ -49,6 +49,12 @@ extern "C" {
|
||||
#elif defined(CPU_MODEL_NRF51X22XXAB)
|
||||
#define FLASHPAGE_NUMOF (128U)
|
||||
#endif
|
||||
/* The minimum block size which can be written is 4B. However, the erase
|
||||
* block is always FLASHPAGE_SIZE.
|
||||
*/
|
||||
#define FLASHPAGE_RAW_BLOCKSIZE (4U)
|
||||
/* Writing should be always 4 bytes aligned */
|
||||
#define FLASHPAGE_RAW_ALIGNMENT (4U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -62,6 +62,13 @@ extern "C" {
|
||||
#elif defined(CPU_MODEL_NRF52840XXAA)
|
||||
#define FLASHPAGE_NUMOF (256U)
|
||||
#endif
|
||||
|
||||
/* The minimum block size which can be written is 4B. However, the erase
|
||||
* block is always FLASHPAGE_SIZE.
|
||||
*/
|
||||
#define FLASHPAGE_RAW_BLOCKSIZE (4U)
|
||||
/* Writing should be always 4 bytes aligned */
|
||||
#define FLASHPAGE_RAW_ALIGNMENT (4U)
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
# Put defined MCU peripherals here (in alphabetical order)
|
||||
FEATURES_PROVIDED += periph_cpuid
|
||||
FEATURES_PROVIDED += periph_flashpage
|
||||
FEATURES_PROVIDED += periph_flashpage_raw
|
||||
FEATURES_PROVIDED += periph_gpio periph_gpio_irq
|
||||
FEATURES_PROVIDED += periph_hwrng
|
||||
FEATURES_PROVIDED += periph_temperature
|
||||
|
@ -23,12 +23,37 @@
|
||||
#include "assert.h"
|
||||
#include "periph/flashpage.h"
|
||||
|
||||
void flashpage_write_raw(void *target_addr, const void *data, size_t len)
|
||||
{
|
||||
/* assert multiples of FLASHPAGE_RAW_BLOCKSIZE are written and no less of
|
||||
that length. */
|
||||
assert(!(len % FLASHPAGE_RAW_BLOCKSIZE));
|
||||
|
||||
/* ensure writes are aligned */
|
||||
assert(!(((unsigned)target_addr % FLASHPAGE_RAW_ALIGNMENT) ||
|
||||
((unsigned)data % FLASHPAGE_RAW_ALIGNMENT)));
|
||||
|
||||
/* ensure the length doesn't exceed the actual flash size */
|
||||
assert(((unsigned)target_addr + len) <
|
||||
(CPU_FLASH_BASE + (FLASHPAGE_SIZE * FLASHPAGE_NUMOF)) + 1);
|
||||
|
||||
uint32_t *page_addr = target_addr;
|
||||
const uint32_t *data_addr = data;
|
||||
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
|
||||
for (unsigned i = 0; i < (len / FLASHPAGE_RAW_BLOCKSIZE); i++) {
|
||||
*page_addr++ = data_addr[i];
|
||||
}
|
||||
|
||||
/* finish up */
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
}
|
||||
|
||||
void flashpage_write(int page, const void *data)
|
||||
{
|
||||
assert(page < (int)FLASHPAGE_NUMOF);
|
||||
|
||||
uint32_t *page_addr = (uint32_t *)flashpage_addr(page);
|
||||
const uint32_t *data_addr = data;
|
||||
|
||||
/* erase given page */
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
|
||||
@ -37,12 +62,6 @@ void flashpage_write(int page, const void *data)
|
||||
|
||||
/* write data to page */
|
||||
if (data != NULL) {
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Wen;
|
||||
for (unsigned i = 0; i < (FLASHPAGE_SIZE / 4); i++) {
|
||||
*page_addr++ = data_addr[i];
|
||||
}
|
||||
flashpage_write_raw(page_addr, data, FLASHPAGE_SIZE);
|
||||
}
|
||||
|
||||
/* finish up */
|
||||
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Ren;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user