From 7dc18768c4bfc949c8fc1f12c753a1e0df7ee0cc Mon Sep 17 00:00:00 2001 From: Richard Eoin Meadows Date: Tue, 10 Jun 2014 23:21:16 +0100 Subject: Support erasing + flashing the User Information Configuration Registers (UICRs) --- src/nrf51.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/nrf51.c') diff --git a/src/nrf51.c b/src/nrf51.c index 7a9d136..08dcdb9 100644 --- a/src/nrf51.c +++ b/src/nrf51.c @@ -49,6 +49,9 @@ static const char nrf51_xml_memory_map[] = "" " " " 0x400" " " + " " + " 0x400" + " " " " ""; @@ -70,6 +73,9 @@ static const char nrf51_xml_memory_map[] = "" #define NRF51_FICR_CODESIZE (NRF51_FICR + 0x014) #define NRF51_FICR_CONFIGID (NRF51_FICR + 0x05C) +/* User Information Configuration Registers (UICR) */ +#define NRF51_UICR 0x10001000 + #define NRF51_PAGE_SIZE 1024 uint16_t nrf51_flash_write_stub[] = { @@ -157,8 +163,14 @@ static int nrf51_flash_erase(struct target_s *target, uint32_t addr, int len) return -1; while (len) { - /* Write address of first word in page to erase it */ - adiv5_ap_mem_write(ap, NRF51_NVMC_ERASEPAGE, addr); + if (addr == NRF51_UICR) { // Special Case + /* Write to the ERASE_UICR register to erase */ + adiv5_ap_mem_write(ap, NRF51_NVMC_ERASEUICR, 0x1); + + } else { // Standard Flash Page + /* Write address of first word in page to erase it */ + adiv5_ap_mem_write(ap, NRF51_NVMC_ERASEPAGE, addr); + } /* Poll for NVMC_READY */ while(adiv5_ap_mem_read(ap, NRF51_NVMC_READY) == 0) @@ -241,4 +253,4 @@ static bool nrf51_cmd_erase_all(target *t) return false; return true; -} \ No newline at end of file +} -- cgit v1.2.3