-
Notifications
You must be signed in to change notification settings - Fork 53
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,18 +259,33 @@ export class CortexM extends ADI implements Processor { | |
/** | ||
* set the target to reset state | ||
* @param hardwareReset use hardware reset pin or software reset | ||
* @param localReset true: Requests a local CPU reset using VECTRESET, false: Requests a reset by an external system resource using SYSRESETREQ | ||
* @param timeout Milliseconds to wait before aborting wait | ||
* @returns Promise | ||
*/ | ||
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense, maybe only halt when using VECTRESET? |
||
await this.writeMem32(DebugRegister.DEMCR, DemcrMask.CORERESET); | ||
|
||
// Clear S_RESET_ST | ||
await this.readMem32(DebugRegister.DHCSR); | ||
|
||
if (hardwareReset === true) { | ||
await this.reset(); | ||
} else { | ||
const value = await this.readMem32(NvicRegister.AIRCR); | ||
await this.writeMem32(NvicRegister.AIRCR, AircrMask.VECTKEY | value | AircrMask.SYSRESETREQ); | ||
await this.writeMem32(DebugRegister.DEMCR, 0); | ||
return; | ||
} | ||
|
||
const value = localReset ? AircrMask.VECTRESET : AircrMask.SYSRESETREQ; | ||
await this.writeMem32(NvicRegister.AIRCR, AircrMask.VECTKEY | value); | ||
|
||
const waitReset = async (): Promise<boolean> => { | ||
const ret = await this.readMem32(DebugRegister.DHCSR); | ||
return !!(ret & DhcsrMask.S_RESET_ST); // Wait for S_RESET_ST bit set | ||
}; | ||
|
||
await this.waitDelay(waitReset, timeout); | ||
await this.writeMem32(DebugRegister.DEMCR, 0); | ||
} | ||
} |
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.
localReset
andtimeout
has IMO potential for confusion. They get skipped ifhardwareReset
istrue
. 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.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.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 ofdapjs
not expecting the newly introduced delays forSYSRESETREQ
.timeout
isn't really a timeout here but a delay. For a timeout, it should regularly pollDHCSR
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.