Support erasing + flashing the User Information Configuration Registers (UICRs)

This commit is contained in:
Richard Eoin Meadows 2014-06-10 23:21:16 +01:00
parent 72ae78a185
commit 7dc18768c4
1 changed files with 15 additions and 3 deletions

View File

@ -49,6 +49,9 @@ static const char nrf51_xml_memory_map[] = "<?xml version=\"1.0\"?>"
" <memory type=\"flash\" start=\"0x0\" length=\"0x40000\">" " <memory type=\"flash\" start=\"0x0\" length=\"0x40000\">"
" <property name=\"blocksize\">0x400</property>" " <property name=\"blocksize\">0x400</property>"
" </memory>" " </memory>"
" <memory type=\"flash\" start=\"0x10001000\" length=\"0x100\">"
" <property name=\"blocksize\">0x400</property>"
" </memory>"
" <memory type=\"ram\" start=\"0x20000000\" length=\"0x4000\"/>" " <memory type=\"ram\" start=\"0x20000000\" length=\"0x4000\"/>"
"</memory-map>"; "</memory-map>";
@ -70,6 +73,9 @@ static const char nrf51_xml_memory_map[] = "<?xml version=\"1.0\"?>"
#define NRF51_FICR_CODESIZE (NRF51_FICR + 0x014) #define NRF51_FICR_CODESIZE (NRF51_FICR + 0x014)
#define NRF51_FICR_CONFIGID (NRF51_FICR + 0x05C) #define NRF51_FICR_CONFIGID (NRF51_FICR + 0x05C)
/* User Information Configuration Registers (UICR) */
#define NRF51_UICR 0x10001000
#define NRF51_PAGE_SIZE 1024 #define NRF51_PAGE_SIZE 1024
uint16_t nrf51_flash_write_stub[] = { 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; return -1;
while (len) { while (len) {
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 */ /* Write address of first word in page to erase it */
adiv5_ap_mem_write(ap, NRF51_NVMC_ERASEPAGE, addr); adiv5_ap_mem_write(ap, NRF51_NVMC_ERASEPAGE, addr);
}
/* Poll for NVMC_READY */ /* Poll for NVMC_READY */
while(adiv5_ap_mem_read(ap, NRF51_NVMC_READY) == 0) while(adiv5_ap_mem_read(ap, NRF51_NVMC_READY) == 0)