Skip to content

Commit 495e796

Browse files
jreineckearmthegecko
authored andcommitted
Added swjClock, swjPins, dapDelay. Allow bit granularity on swjSequence.
1 parent 001d266 commit 495e796

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

src/proxy/cmsis-dap.ts

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,8 @@ export class CmsisDAP extends EventEmitter implements Proxy {
256256
* @param sequence The sequence to send
257257
* @returns Promise
258258
*/
259-
public async swjSequence(sequence: BufferSource): Promise<void> {
260-
const bitLength = sequence.byteLength * 8;
259+
public async swjSequence(sequence: BufferSource, bitLength?: number): Promise<void> {
260+
bitLength = bitLength || sequence.byteLength * 8;
261261
const data = this.bufferSourceToUint8Array(bitLength, sequence);
262262

263263
try {
@@ -268,6 +268,69 @@ export class CmsisDAP extends EventEmitter implements Proxy {
268268
}
269269
}
270270

271+
/**
272+
* Send an SWJ Clock value
273+
* https://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__SWJ__Clock.html
274+
* @param clock The SWJ clock value to send
275+
* @returns Promise
276+
*/
277+
public async swjClock(clock: number): Promise<void> {
278+
try {
279+
await this.send(DAPCommand.DAP_SWJ_CLOCK, new Uint8Array([
280+
(clock & 0x000000FF),
281+
(clock & 0x0000FF00) >> 8,
282+
(clock & 0x00FF0000) >> 16,
283+
(clock & 0xFF000000) >> 24
284+
]));
285+
} catch (error) {
286+
await this.clearAbort();
287+
throw error;
288+
}
289+
}
290+
291+
/**
292+
* Read/Write SWJ Pins
293+
* https://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__SWJ__Pins.html
294+
* @param pinsOut Pin values to write
295+
* @param pinSelect Maske to select output pins to change
296+
* @param pinWait Time in microseconds to wait for output pin value to stabilize (0 - no wait, 1..3000000)
297+
* @returns Promise
298+
*/
299+
public async swjPins(pinsOut: number, pinSelect: number, pinWait: number): Promise<number> {
300+
try {
301+
const result = await this.send(DAPCommand.DAP_SWJ_PINS, new Uint8Array([
302+
pinsOut,
303+
pinSelect,
304+
(pinWait & 0x000000FF),
305+
(pinWait & 0x0000FF00) >> 8,
306+
(pinWait & 0x00FF0000) >> 16,
307+
(pinWait & 0xFF000000) >> 24
308+
]));
309+
return result.getUint8(1);
310+
} catch (error) {
311+
await this.clearAbort();
312+
throw error;
313+
}
314+
}
315+
316+
/**
317+
* Send Delay Command
318+
* https://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__Delay.html
319+
* @param delay Time to delay in microseconds
320+
* @returns Promise
321+
*/
322+
public async dapDelay(delay: number): Promise<void> {
323+
try {
324+
await this.send(DAPCommand.DAP_DELAY, new Uint8Array([
325+
(delay & 0x00FF),
326+
(delay & 0xFF00) >> 8
327+
]));
328+
} catch (error) {
329+
await this.clearAbort();
330+
throw error;
331+
}
332+
}
333+
271334
/**
272335
* Configure Transfer
273336
* https://www.keil.com/pack/doc/CMSIS/DAP/html/group__DAP__TransferConfigure.html

0 commit comments

Comments
 (0)