Skip to content

Commit

Permalink
target/cortex_m: allow poll quickly get out of TARGET_RESET state
Browse files Browse the repository at this point in the history
cortex_m_poll_one() detects reset testing S_RESET_ST sticky bit.
If the signal comes unexpectedly, poll must return TARGET_RESET state.

On the contrary in case of polling inside of an OpenOCD reset command,
TARGET_RESET has been has already been set and we need to get out of
it as quickly as possible.

The original code needs 2 polls: the first clears S_RESET_ST
and keeps TARGET_RESET state, the current TARGET_RUNNING or TARGET_HALTED
is reflected as late as the second poll is done.

Change the logic to keep in TARGET_RESET only when necessary.

See also [1]

Link: [1] 8284: tcl/target: ti_cc3220sf: Use halt for CC3320SF targets | https://review.openocd.org/c/openocd/+/8284
Fixes: https://sourceforge.net/p/openocd/tickets/360/
Signed-off-by: Tomas Vanek <[email protected]>
Change-Id: I759461e5f89ca48a6e16e4b4101570260421dba1
Reviewed-on: https://review.openocd.org/c/openocd/+/8285
Tested-by: jenkins
Reviewed-by: Dhruva Gole <[email protected]>
  • Loading branch information
tom-van committed Jun 17, 2024
1 parent bf4be56 commit 4892e32
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/target/cortex_m.c
Original file line number Diff line number Diff line change
Expand Up @@ -931,8 +931,12 @@ static int cortex_m_poll_one(struct target *target)
if (target->state != TARGET_RESET) {
target->state = TARGET_RESET;
LOG_TARGET_INFO(target, "external reset detected");
/* In case of an unexpected S_RESET_ST set TARGET_RESET state
* and keep it until the next poll to allow its detection */
return ERROR_OK;
}
return ERROR_OK;
/* S_RESET_ST was expected (in a reset command). Continue processing
* to quickly get out of TARGET_RESET state */
}

if (target->state == TARGET_RESET) {
Expand Down

0 comments on commit 4892e32

Please sign in to comment.