From: Uwe Bonnes Date: Thu, 19 Jan 2012 13:17:22 +0000 (+0100) Subject: When loading a file to SRAM or Flash, set the Stack pointer with the initial X-Git-Url: https://git.gag.com/?p=fw%2Fstlink;a=commitdiff_plain;h=41e7c16cf2f9c6db6b4cc4d61af86a359646d6be;hp=4c206c3b7cb14bf29eb8ff23aa3c64e1cdab69db When loading a file to SRAM or Flash, set the Stack pointer with the initial SP value and the Program counter with the reset value from the Vector table. Then run reset function --- diff --git a/src/stlink-common.c b/src/stlink-common.c index 626c86d..87dfc02 100644 --- a/src/stlink-common.c +++ b/src/stlink-common.c @@ -799,6 +799,11 @@ int stlink_fwrite_sram /* success */ error = 0; + /* set stack*/ + stlink_write_reg(sl, stlink_read_debug32(sl, addr ),13); + /* Set PC to the reset routine*/ + stlink_write_reg(sl, stlink_read_debug32(sl, addr + 4),15); + stlink_run(sl); on_error: unmap_file(&mf); @@ -1514,6 +1519,11 @@ int stlink_fwrite_flash(stlink_t *sl, const char* path, stm32_addr_t addr) { mf.len -= num_empty; } err = stlink_write_flash(sl, addr, mf.base, mf.len); + /* set stack*/ + stlink_write_reg(sl, stlink_read_debug32(sl, addr ),13); + /* Set PC to the reset routine*/ + stlink_write_reg(sl, stlink_read_debug32(sl, addr + 4),15); + stlink_run(sl); unmap_file(&mf); return err; }