Skip to content

Commit

Permalink
Move check of current instruction mode to stlink_run
Browse files Browse the repository at this point in the history
  • Loading branch information
Ant-ON committed Nov 7, 2020
1 parent 4e58872 commit 277eee7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 7 additions & 1 deletion src/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1490,8 +1490,14 @@ int stlink_run(stlink_t *sl) {
struct stlink_reg rr;
DLOG("*** stlink_run ***\n");

/* Make sure we are in Thumb mode
* Cortex-M chips don't support ARM mode instructions
* xPSR may be incorrect if the vector table has invalid data */
stlink_read_reg(sl, 16, &rr);
DLOG("Run in %s mode\n", (rr.xpsr & (1 << 24))?"ARM":"THUMB");
if ((rr.xpsr & (1 << 24)) == 0) {
ILOG("Go to Thumb mode\n");
stlink_write_reg(sl, rr.xpsr | (1 << 24), 16);
}

return(sl->backend->run(sl));
}
Expand Down
7 changes: 0 additions & 7 deletions src/stlink-lib/flash_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,13 +356,6 @@ int stlink_flash_loader_run(stlink_t *sl, flash_loader_t* fl, stm32_addr_t targe
// only used on VL/F1_XL, but harmless for others
stlink_write_reg(sl, fl->loader_addr, 15); // pc register

/* Make sure we are in Thumb mode */
stlink_read_reg(sl, 16, &rr);
if ((rr.xpsr & (1 << 24)) == 0) {
ILOG("Go to Thumb mode\n");
stlink_write_reg(sl, rr.xpsr | (1 << 24), 16);
}

/* Run loader */
stlink_run(sl);

Expand Down

0 comments on commit 277eee7

Please sign in to comment.