Skip to content
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

Add local reset via VECTRESET support for cortex-m device #114

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

windowsair
Copy link
Contributor

When use setTargetResetState method, apart from using external signals for a global reset through SYSRESETREQ, sometimes we prefer to trigger local reset, which is achieved through VECTRESET.

When use setTargetResetState method, apart from using external signals
for a global reset through SYSRESETREQ, sometimes we prefer to trigger
local reset, which is achieved through VECTRESET.
@thegecko
Copy link
Member

I'm not sure how I would test this. @jreineckearm does this look sensible?

* @returns Promise
*/
public async setTargetResetState(hardwareReset: boolean = true): Promise<void> {
public async setTargetResetState(hardwareReset: boolean = true, localReset: boolean = false, timeout: number = 1000): Promise<void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

  • Adding new parameters localReset and timeout has IMO potential for confusion. They get skipped if hardwareReset is true. Adding a new method with the enhanced functionality (and reset types as enums) might be a better approach. Alternatively, the dependencies between such parameters needs to be better documented in the API description.
  • Also, local/vector resets are only available for v7-M based CPUs, e.g. Cortex-M3/M4/M7. v6-M and v8-M based CPUs don't have that capability. Writes to the AIRCR.VECTRESET bit should be ignored by HW. But one could argue that it is the consumer's responsibility to check if a certain operation will succeed.
  • Adding timeout and checking for reset recovery is in general a good idea for all reset types (also the HW reset). But as done here, the changes significantly impact timings and functionality of this function. I am a little worried about the impact on other consumers of dapjs not expecting the newly introduced delays for SYSRESETREQ.
  • timeout isn't really a timeout here but a delay. For a timeout, it should regularly poll DHCSR and return early once the reset completed. Otherwise, this method is now delayed by 1 second by default. When polling, you need to make sure to handle target access errors. Depending on the reset implementation in HW, the DAP/CPU subsystem/CPU debug registers may be temporarily unavailable.
  • If going the route of checking for reset recovery you may want to indicate this via a return value of the method. This allows consumers handling of a the case where the reset does not recover (in time).

public async setTargetResetState(hardwareReset: boolean = true): Promise<void> {
public async setTargetResetState(hardwareReset: boolean = true, localReset: boolean = false, timeout: number = 1000): Promise<void> {
// Enable Reset Vector Catch
await this.halt();
Copy link
Contributor

@jreineckearm jreineckearm Jun 30, 2024

Choose a reason for hiding this comment

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

I would be careful with halting the CPU here unconditionally. This changes behavior of this method while strictly speaking writing AIRCR.SYSRESETREQ doesn't come with being unpredictable if the CPU is running before reset. On the other hand, the reset vector catch is always enabled in this method as well. So this probably only impacts corner cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense, maybe only halt when using VECTRESET?

@jreineckearm
Copy link
Contributor

jreineckearm commented Jun 30, 2024

I'm not sure how I would test this. @jreineckearm does this look sensible?

@thegecko , IIRC, the VECTRESET shouldn't affect parts of the CPU like SysTick or NVIC. It definitely is not supposed to affect device specific peripherals as they are considered part of the system, not the CPU. So, it may be worth to verify the behavior based on a device specific peripheral.

@windowsair
Copy link
Contributor Author

Here are two points:

  • The added VECTRESET only applies to armv7m, which only resets the CPU core, and we can determine the reset behavior based on the value of the CPU register file. I'm not sure it makes sense to add one of these more restricted features?
  • Perform reset detection, does this cover all scenarios due to the complexity of the hardware implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants