From 41e7c16cf2f9c6db6b4cc4d61af86a359646d6be Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Thu, 19 Jan 2012 14:17:22 +0100 Subject: [PATCH] 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 --- src/stlink-common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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; } -- 2.30.2