Skip to content

dist/tools/openocd: use reset halt command for board using stlink#8976

Closed
aabadie wants to merge 3 commits intoRIOT-OS:masterfrom
aabadie:pr/stlink_debug_fix
Closed

dist/tools/openocd: use reset halt command for board using stlink#8976
aabadie wants to merge 3 commits intoRIOT-OS:masterfrom
aabadie:pr/stlink_debug_fix

Conversation

@aabadie
Copy link
Copy Markdown
Contributor

@aabadie aabadie commented Apr 18, 2018

Contribution description

Based on #8856 and #8475, this PR uses the reset halt command of openocd for all board using an stlink adapter.

It might not be the best solution and has side effects: after starting the debug session the program is always halted in the entry point (for ARM) otherwise it can be at any position which might be something expected (but doesn't work after).

Issues/PRs references

Fixes #8975, based on #8856 and #8475

@aabadie aabadie added Area: tools Area: Supplementary tools Area: boards Area: Board ports labels Apr 18, 2018
@aabadie aabadie requested a review from cladmi April 18, 2018 16:05
@aabadie aabadie added State: waiting for other PR State: The PR requires another PR to be merged first Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) labels Apr 18, 2018
Copy link
Copy Markdown
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good idea to refactor this, but still a bit messy and not sure all changes are valid. See details inline.


export DEBUG_ADAPTER ?= stlink
export STLINK_VERSION ?= 2
export OPENOCD_CONFIG := $(RIOTBOARD)/$(BOARD)/dist/openocd.cfg
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not like that you need here to set it to the default openocd value.
I would prefer it handled in the stlink-adapter, see below.

export OPENOCD_DBG_START_CMD = -c 'reset halt'

# select OpenOCD configuration depending on CPU type
ifeq (,$(OPENOCD_CONFIG))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up to setting to the default value in boards:

You could add another check if $(RIOTBOARD)/$(BOARD)/dist/openocd.cfg does not exist before using the st configuration.

@@ -1,3 +1,3 @@
source [find target/stm32l0.cfg]
reset_config srst_only
reset_config srst_only connect_assert_srst
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you change the reset_config configurations in a "boards/common/stm32-link: add common place for stlink" commit ?
If it it necessary, it should be another properly justified commit.

# this board has an on-board ST-link adapter
export DEBUG_ADAPTER ?= stlink

# call a 'reset halt' command before starting the debugger
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not call this commit "revert" as it is not reverting the change, only using the now common definition.

@@ -1,3 +0,0 @@
source [find target/stm32l0.cfg]

reset_config trst_and_srst srst_nogate connect_assert_srst
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reset configuration is different from the common one in st/configs/stm32l0.cfg

I think this file should be kept.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this file should be kept

It could but it makes no difference if using the common one (with the connect_assert_srst). I checked on other L0 based boards (nucleo-l053/nucleo-l073) and the openocd configuration file provided by this PR works for all of them.

@@ -1 +0,0 @@
source [find target/stm32f7x.cfg]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does not match the st/configs/stm32f7.cfg configuration.

endif

# this board uses openocd
# include openocd
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous comment before was better than repeating what the next line does.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 24, 2018

@cladmi, maybe you missed the fact that this PR is based on #8475 and most of your comments are related to this one.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Apr 24, 2018

Oh absolutely right. Should I re-do them there then ?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 24, 2018

Should I re-do them there then ?

Not needed, both PRs are linked. But I'll apply the requested changes in #8475

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Apr 24, 2018

Rebased on top of latest #8475, not dependent of #8856 anymore.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Jun 29, 2018

I think you can now rebase again.

@aabadie aabadie removed the State: waiting for other PR State: The PR requires another PR to be merged first label Jul 1, 2018
@aabadie aabadie force-pushed the pr/stlink_debug_fix branch from 5d85034 to b9a33ff Compare July 1, 2018 12:35
@aabadie aabadie added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jul 1, 2018
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Jul 2, 2018

@cladmi, rebased and comments addressed.

Copy link
Copy Markdown
Contributor

@cladmi cladmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK changes looks good for me.

I trust you that it is necessary for all stlink boards.

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Jul 6, 2018

Merge now if you want, or ask if you want someone else testing.

@kaspar030
Copy link
Copy Markdown
Contributor

This implies that it is now not possible anymore to "attach" to a running node, right?

Please wait a bit before merging, I'd like to get some opinions over lunch.

@kYc0o
Copy link
Copy Markdown
Contributor

kYc0o commented Jul 18, 2018

Please wait a bit before merging, I'd like to get some opinions over lunch.

/edit, it was for @kaspar030 not for @smlng
@kaspar030 did you? I'm asking because this is marked as a bugfix, which would be good to have for the release.

@miri64
Copy link
Copy Markdown
Member

miri64 commented Aug 24, 2018

Ping?

@miri64 miri64 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Aug 24, 2018
@aabadie aabadie force-pushed the pr/stlink_debug_fix branch from b1c2d2a to 84b6ca6 Compare September 18, 2018 15:08
@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Sep 18, 2018

After discussing briefly about this PR with @cladmi at the summit, it seems that the best solution is:

  • to keep a configuration that works most of the time: when one wants to start a gdb debug session on the board, gdb should always be able to attach the gdb server, even if the CPU is in sleep mode. This is what this PR does, by forcing a reset
  • for other not so common cases, e.g. attach to a running application or a crashed application to see it's current state, that were raised by @kaspar030, it's highly possible that the debug target fails with stlink. But we should still provide this possibility: I pushed a fixup commit to address this point. Using
OPENOCD_DBG_START_CMD= make BOARD=<any stlink board> debug

will put -c halt (default value in openocd) in OPENOCD_DBG_START_CMD.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Oct 12, 2018

@cladmi, what's your opinion about my latest comment ?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Oct 23, 2018

@cladmi ?

@jnohlgard
Copy link
Copy Markdown
Member

jnohlgard commented Nov 28, 2018

After discussing briefly about this PR with @cladmi at the summit, it seems that the best solution is:

  • to keep a configuration that works most of the time: when one wants to start a gdb debug session on the board, gdb should always be able to attach the gdb server, even if the CPU is in sleep mode. This is what this PR does, by forcing a reset

I agree completely with this. It is incredibly annoying to have the debug or flash commands fail because the CPU happened to be in a low power mode at the time that the tool tried to connect. This is going to become more common now that the boards are getting more low power support fixes and applications will begin using low power modes to a greater extent.

  • for other not so common cases, e.g. attach to a running application or a crashed application to see it's current state, that were raised by @kaspar030, it's highly possible that the debug target fails with stlink. But we should still provide this possibility: I pushed a fixup commit to address this point.

It would be useful to have a command which tries to attach to the running system, and if that fails fall back to a connect under reset configuration, but someone would need to implement this as a shell script since OpenOCD needs a restart after a failed init AFAIK. I have experimented with various combinations of catch statements in the OpenOCD TCL scripts, but so far have not found a configuration which can recover from a failed connection attempt.

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Nov 29, 2018

It is incredibly annoying to have the debug or flash commands fail because the CPU happened to be in a low power mode at the time that the tool tried to connect. This is going to become more common now that the boards are getting more low power support fixes and applications will begin using low power modes to a greater extent.

@gebart, I'm happy we are on the same line about this. I'm +1 for merging #10479 since it does the same thing but globally. What would be great is to add some documentation somewhere about how to attach a crashed/running application without resetting it all. I'm thinking of this kind of thing:

OPENOCD_DBG_START_CMD="-c halt" make BOARD=<any openocd programmed board> debug

@cladmi
Copy link
Copy Markdown
Contributor

cladmi commented Dec 6, 2018

Sorry I missed the ping, I agree that having reliable flash is better.

I think #10479 only takes care on the debug-server though, am I right ?

@aabadie
Copy link
Copy Markdown
Contributor Author

aabadie commented Dec 6, 2018

I think #10479 only takes care on the debug-server though, am I right ?

Not really. In the current state, #10479 applies '-c reset halt' by default to all debug sessions using OpenOCD, see here.
But it will still be possible to override OPENOCD_DBG_START_CMD as described in #8976 (comment).

@stale
Copy link
Copy Markdown

stale bot commented Aug 10, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Aug 10, 2019
@stale stale bot closed this Sep 10, 2019
@aabadie aabadie deleted the pr/stlink_debug_fix branch June 24, 2020 06:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: boards Area: Board ports Area: tools Area: Supplementary tools CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR State: stale State: The issue / PR has no activity for >185 days Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dist/tools/openocd: cannot debug some stlink based boards

6 participants