-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
west_commands: runners: openocd: clear DHCSR after flashing completes #33163
west_commands: runners: openocd: clear DHCSR after flashing completes #33163
Conversation
This is just a trial for now - do not merge, since the fix should only be applicable for Cortex-M. |
ae5af78
to
96d55e1
Compare
96d55e1
to
5281083
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ioannisg . I read the discussion in upstream openocd and it looks like you really found something new here. A couple of minor requests and then I am +1 from the runner perspective.
However, I want to confirm with @erwango and other openocd users that we really want this to be the default behavior before merging, since the openocd maintainers named some use cases where they didn't think it made a sensible default.
['-c', 'reset run', | ||
'-c', 'shutdown']) | ||
['-c', 'reset run'] + | ||
clear_halt_debug_en_cmd + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This name is confusing mechanism with policy. Please rename it to post_reset_cmd
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, that's fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renaming all the occurrences and related variables
boards/common/openocd.board.cmake
Outdated
@@ -16,7 +16,13 @@ endif() | |||
set(OPENOCD_CMD_LOAD_DEFAULT "${OPENOCD_FLASH}") | |||
set(OPENOCD_CMD_VERIFY_DEFAULT "verify_image") | |||
|
|||
# Cortex-M-specific halt debug enable bit clearing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some more comments here, since this looks "weird"? Maybe just linking to the openocd PR you opened would be good enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll comment properly.
5281083
to
3807c1f
Compare
Fine. I 've, also added the HW block label, so this is tested before it (ever) gets merged. My understanding is that "west flash" shall only program the binary and reset the core to a state as close as possible to the (cold) reset state. Since the internal runner implementation does not guarantee this, we are left with the option to do this in the runner. |
Add a new option to the openocd.py script, for clearing the halt debug enable state. Signed-off-by: Ioannis Glaropoulos <[email protected]>
Introduce a command in openocd.board.cmake for cortex-m targets, which clears the halt debug enable bit flag, upon openocd exit. This is required since openocd does not clear the state itself when it shuts down. Signed-off-by: Ioannis Glaropoulos <[email protected]>
3807c1f
to
5627839
Compare
@ioannisg is this PR still required if http://openocd.zylin.com/#/c/6093/1 gets merged ? |
Introduce a command in pyocd.board.cmake for ARM Cortex-m targets, which clears the halt debug enable bit flag, after flashing is complete and before pyocd exit. This is required since pyocd regular flashing command does not clear the state itself when it completes, nor when pyocd session shuts down. Signed-off-by: Ioannis Glaropoulos <[email protected]>
Add a new option to the pyocd.py script, for clearing the halt debug enable state. The option results in a command that is called after the flashing is complete. Signed-off-by: Ioannis Glaropoulos <[email protected]>
One consideration on current behavior is that having DHCSR set after flash is that it prevents target entering sleep states when testing PM feature.
|
@@ -158,6 +163,24 @@ def flash(self, **kwargs): | |||
self.logger.info('Flashing file: {}'.format(fname)) | |||
self.check_call(cmd) | |||
|
|||
if self.post_flash_cmd is not []: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not correct usage. In Python, foo is bar
and foo is not bar
basically work like pointer comparison in C.
Example:
>>> [] is []
False
This should be if self.post_flash_cmd:
instead, because an empty list is boolean false.
board_set_flasher_ifnset(pyocd) | ||
board_set_debugger_ifnset(pyocd) | ||
board_finalize_runner_args(pyocd "--dt-flash=y") | ||
board_finalize_runner_args(pyocd "--dt-flash=y" | ||
--post-flash "${PYOCD_CMD_HALT_DEBUG_EN_CLEAR}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is reading from an uninitialized variable on non-Cortex-M
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nacking until we have an alternative viable option to allow Power Management testing in CI runs.
As previously stated, current openocd behavior regarding debug enable bit allows to flash target after sleep mode code has been exercised, while the proposed change prevents this.
@ioannisg any updates here? We should set the default of the feature to disabled until we resolve a number of these issues. |
This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time. |
Fixes #32984
openOCD does not clear DHCSR.DEBUGEN bit after flashing
completes, effectively leaving the Cortex-M processor in
debug mode. Manually clean DHCSR becore exiting the flash
operation, to work around the problem.
Signed-off-by: Ioannis Glaropoulos [email protected]