diff --git a/src/target/flashstub/Makefile b/src/target/flashstub/Makefile index abc03a4..4eb42a1 100644 --- a/src/target/flashstub/Makefile +++ b/src/target/flashstub/Makefile @@ -11,7 +11,7 @@ endif CFLAGS=-Os -std=gnu99 -mcpu=cortex-m0 -mthumb -I../../../libopencm3/include ASFLAGS=-mcpu=cortex-m3 -mthumb -all: lmi.stub stm32l4.stub nrf51.stub efm32.stub +all: lmi.stub stm32l4.stub efm32.stub %.o: %.c $(Q)echo " CC $<" diff --git a/src/target/flashstub/nrf51.c b/src/target/flashstub/nrf51.c deleted file mode 100644 index d291592..0000000 --- a/src/target/flashstub/nrf51.c +++ /dev/null @@ -1,37 +0,0 @@ -/* - * This file is part of the Black Magic Debug project. - * - * Copyright (C) 2017 Black Sphere Technologies Ltd. - * Written by Gareth McMullin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -#include -#include "stub.h" - -/* Non-Volatile Memory Controller (NVMC) Registers */ -#define NVMC ((volatile uint32_t *)0x4001E000) -#define NVMC_READY NVMC[0x100] - -void __attribute__((naked)) -nrf51_flash_write_stub(volatile uint32_t *dest, uint32_t *src, uint32_t size) -{ - for (int i; i < size; i += 4) { - *dest++ = *src++; - while (!(NVMC_READY & 1)) - ; - } - - stub_exit(0); -} diff --git a/src/target/nrf51.c b/src/target/nrf51.c index 4b5da81..1bbe034 100644 --- a/src/target/nrf51.c +++ b/src/target/nrf51.c @@ -83,13 +83,6 @@ const struct command_s nrf51_read_cmd_list[] = { #define NRF51_PAGE_SIZE 1024 #define NRF52_PAGE_SIZE 4096 -#define SRAM_BASE 0x20000000 -#define STUB_BUFFER_BASE ALIGN(SRAM_BASE + sizeof(nrf51_flash_write_stub), 4) - -static const uint16_t nrf51_flash_write_stub[] = { -#include "flashstub/nrf51.stub" -}; - static void nrf51_add_flash(target *t, uint32_t addr, size_t length, size_t erasesize) { @@ -192,22 +185,18 @@ static int nrf51_flash_write(struct target_flash *f, /* Enable write */ target_mem_write32(t, NRF51_NVMC_CONFIG, NRF51_NVMC_CONFIG_WEN); - /* Poll for NVMC_READY */ while (target_mem_read32(t, NRF51_NVMC_READY) == 0) if(target_check_error(t)) return -1; - - /* Write stub and data to target ram and call stub */ - target_mem_write(t, SRAM_BASE, nrf51_flash_write_stub, - sizeof(nrf51_flash_write_stub)); - target_mem_write(t, STUB_BUFFER_BASE, src, len); - int ret = cortexm_run_stub(t, SRAM_BASE, dest, - STUB_BUFFER_BASE, len, 0); + target_mem_write(t, dest, src, len); + /* Poll for NVMC_READY */ + while (target_mem_read32(t, NRF51_NVMC_READY) == 0) + if(target_check_error(t)) + return -1; /* Return to read-only */ target_mem_write32(t, NRF51_NVMC_CONFIG, NRF51_NVMC_CONFIG_REN); - - return ret; + return 0; } static bool nrf51_cmd_erase_all(target *t)