2016-04-20 11:03:18 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Freie Universität Berlin
|
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser
|
|
|
|
* General Public License v2.1. See the file LICENSE in the top level
|
|
|
|
* directory for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup cpu_nrf5x_common
|
2017-06-22 15:43:17 +02:00
|
|
|
* @ingroup drivers_periph_flashpage
|
2016-04-20 11:03:18 +02:00
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Low-level flash page driver implementation
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "assert.h"
|
|
|
|
#include "periph/flashpage.h"
|
|
|
|
|
2019-08-04 10:52:26 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-03-13 14:47:11 +01:00
|
|
|
void flashpage_write(int page, const void *data)
|
2016-04-20 11:03:18 +02:00
|
|
|
{
|
make: fix sign-compare errors
cpu, nrf5x_common: fix sign-compare in periph/flashpage
drivers, periph_common: fix sign-compare in flashpage
cpu, sam0_common: fix sign-compare error in periph/gpio
cpu, cc2538: fix sign-compare in periph/timer
cpu, sam3: fix sign-compare in periph/gpio
cpu, stm32_common: fix sign-compare in periph/pwm
cpu, stm32_common: fix sign-compare in periph/timer
cpu, stm32_common: fix sign-compare in periph/flashpage
cpu, nrf5x_common: fix sign-compare in radio/nrfmin
cpu, samd21: fix sign-compare in periph/pwm
cpu, ezr32wg: fix sign-compare in periph/gpio
cpu, ezr32wg: fix sign-compare in periph/timer
drivers, ethos: fix sign-compare
sys, net: fix sign-compare
cpu, atmega_common: fix sign-compare error
cpu, msp430fxyz: fix sign-compare in periph/gpio
boards, msb-430-common: fix sign-compare in board_init
driver, cc2420: fix sign-compared
sys/net: fix sign-compare in gnrc_tftp
driver, pcd8544: fix sign-compare
driver, pn532: fix sign-compare
driver, sdcard_spi: fix sign-compare
tests: fix sign_compare
sys/net, lwmac: fix sign_compare
pkg, lwip: fix sign-compare
boards, waspmote: make CORECLOCK unsigned long to fix sign_compare error
tests, sock_ip: fix sign compare
tests, msg_avail: fix sign compare
tests, sock_udp: fix sign compare
boards: fix sign-compare for calliope and microbit matrix
2017-10-31 11:57:40 +01:00
|
|
|
assert(page < (int)FLASHPAGE_NUMOF);
|
2016-04-20 11:03:18 +02:00
|
|
|
|
|
|
|
uint32_t *page_addr = (uint32_t *)flashpage_addr(page);
|
|
|
|
|
|
|
|
/* erase given page */
|
|
|
|
NRF_NVMC->CONFIG = NVMC_CONFIG_WEN_Een;
|
|
|
|
NRF_NVMC->ERASEPAGE = (uint32_t)page_addr;
|
|
|
|
while (NRF_NVMC->READY == 0) {}
|
|
|
|
|
|
|
|
/* write data to page */
|
|
|
|
if (data != NULL) {
|
2019-08-04 10:52:26 +02:00
|
|
|
flashpage_write_raw(page_addr, data, FLASHPAGE_SIZE);
|
2016-04-20 11:03:18 +02:00
|
|
|
}
|
|
|
|
}
|