Skip to content

Commit cee3cb5

Browse files
authored
Merge pull request #29 from ARMmbed/f/rework
Rework
2 parents c7e16b3 + 697b5af commit cee3cb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+4704
-22817
lines changed

README.md

Lines changed: 194 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,92 +3,222 @@
33
[![Circle CI](https://circleci.com/gh/ARMmbed/dapjs.svg?style=shield&circle-token=d37ef109d0134f6f8e4eb12a65214a8b159f77d8)](https://circleci.com/gh/ARMmbed/dapjs/)
44
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://spdx.org/licenses/MIT.html)
55

6-
DAP.js is a JavaScript interface to CMSIS-DAP, aiming to implement a subset of
7-
the functionality provided by [pyOCD](https://github.com/mbedmicro/pyOCD), enabling
8-
debugging of Arm Cortex-M devices in Node.js and in the browser using [WebUSB](https://developers.google.com/web/updates/2016/03/access-usb-devices-on-the-web).
9-
10-
## Features
11-
12-
- General
13-
- Read core registers
14-
- Run arbitrary assembled Arm machine code
15-
- Debugging
16-
- Set hardware and software breakpoints
17-
- Step (instruction level)
18-
- Memory
19-
- Read blocks from memory:
20-
- 16-bit reads/writes
21-
- 32-bit reads/writes
22-
- Word-aligned mass reads and writes
23-
- Flashing
24-
- Full-chip erase
25-
- Flash binary files and intel hex files
26-
- Support for the NRF51 (including the micro:bit) and NXP's FRDM-K64F.
27-
- Performance
28-
- Support for batched commands to improve HID report utilisation
29-
- Flashing at ~10-20 kB/s, comparable with PyOCD and OpenOCD
6+
DAP.js is a JavaScript interface to [CMSIS-DAP](https://www.keil.com/pack/doc/CMSIS/DAP/html/index.html), enabling access to Arm Microcontrollers using [Node.js](https://nodejs.org/) or in the browser using [WebUSB](https://wicg.github.io/webusb/).
307

318
## Prerequisites
329

33-
[Node.js > v8.9.0](https://nodejs.org), which includes `npm 5`.
10+
[Node.js > v6.10.0](https://nodejs.org), which includes `npm`.
3411

3512
## Installation
3613

37-
The SDK is distributed using npm. To install the package in your project:
14+
The package is distributed using npm. To install the package in your project:
3815

39-
$ npm install dapjs
16+
```bash
17+
$ npm install dapjs
18+
```
19+
20+
## Getting Started
21+
22+
Decide on a transport layer to use (see below) and refer to the [examples folder](https://github.com/ARMmbed/dapjs/tree/master/examples/) to get started.
23+
24+
The web example can be seen running at:
25+
26+
https://armmbed.github.io/dapjs/examples/daplink-flash/web.html
27+
28+
Refer to the [DAPjs API Documentation](https://armmbed.github.io/dapjs/) for more information.
29+
30+
## Choosing a Transport
31+
32+
In order to use DAPjs, you need to install support for one of the transports. Use the following information to help you choose which to use:
33+
34+
### WebUSB
4035

41-
## Development setup
36+
If you wish to use DAPjs in a browser environment, you must use WebUSB. Please refer to the [implementation status](https://github.com/WICG/webusb#implementation-status) of WebUSB to understand browser support for this technology.
4237

43-
After cloning this repository:
38+
__Note:__ WebUSB in the browser doesn't require any further libraries to be installed.
4439

45-
$ npm install
40+
If you also want your program to work in a Node.js environment a [WebUSB library](https://github.com/thegecko/webusb) exists to allow your program to be ported to Node.js.
4641

47-
Then run one of the gulp commands:
42+
To install the library for Node.js, use:
4843

49-
$ gulp
50-
$ gulp watch
51-
$ npm run gulp
44+
```bash
45+
$ npm install webusb
46+
```
47+
48+
#### Example
5249

53-
## Examples
50+
In the browser, require the library:
5451

55-
For more full-featured examples, please refer to the [examples](https://github.com/ARMmbed/dapjs/tree/master/examples) folder and see the web example running at:
52+
```html
53+
<script type="text/javascript" src="bundles/dap.bundle.js"></script>
54+
```
5655

57-
https://armmbed.github.io/dapjs/
56+
In Node.js Require the libraries:
5857

5958
```javascript
60-
device = await navigator.usb.requestDevice({
61-
filters: [{vendorId: 0x0d28}]
59+
const usb = require("webusb").usb;
60+
const DAPjs = require("dapjs");
61+
```
62+
63+
Then in either environment:
64+
65+
```javascript
66+
<navigator>.usb.requestDevice({
67+
filters: [{vendorId: 0xD28}]
68+
})
69+
.then(device => {
70+
const transport = new DAPjs.WebUSB(device);
71+
const daplink = new DAPjs.DAPLink(transport);
72+
73+
return daplink.connect()
74+
.then(() => daplink.disconnect())
75+
.then(() => process.exit());
76+
})
77+
.catch(error => {
78+
console.error(error.message || error);
79+
process.exit();
6280
});
81+
```
82+
83+
#### Pros
84+
- Works in the browser
85+
- Programs are portable to Node.js environments
6386

64-
this.deviceCode = device.serialNumber.slice(0, 4);
65-
selector = new DAPjs.PlatformSelector();
66-
const info = await selector.lookupDevice(this.deviceCode);
67-
this.hid = new DAPjs.HID(device);
68-
69-
// open hid device
70-
await this.hid.open();
71-
dapDevice = new DAPjs.DAP(this.hid);
72-
// contains flash algorithms data and memory map
73-
let flashAlgorithmsData = {};
74-
let flashAlgorithm = new DAPjs.FlashAlgorithm(flashAlgorithmsData, this.deviceCode);
75-
this.target = new DAPjs.FlashTarget(dapDevice, flashAlgorithm);
76-
77-
// init and halt target
78-
await this.target.init();
79-
await this.target.halt();
80-
81-
// program_data contains binary data
82-
program_data = DAPjs.FlashProgram.fromBinary(0, program_data);
83-
await this.target.program(program_data, (progress) => {
84-
console.log(progress);
87+
#### Cons
88+
- Requires a recent version of [DAPLink](https://armmbed.github.io/DAPLink/) to be installed on your target device.
89+
90+
### HID
91+
92+
For the highest level of firmware compatibility in a Node.js environment, the HID transport is recommended. This utilises the `node-hid` library and is installed as follows:
93+
94+
```bash
95+
$ npm install node-hid
96+
```
97+
98+
#### Example
99+
100+
```javascript
101+
const hid = require("node-hid");
102+
const DAPjs = require("dapjs");
103+
104+
let devices = hid.devices();
105+
devices = devices.filter(device => device.vendorId === 0xD28);
106+
107+
const transport = new DAPjs.HID(devices[0]);
108+
const daplink = new DAPjs.DAPLink(transport);
109+
110+
daplink.connect()
111+
.then(() => daplink.disconnect())
112+
.then(() => process.exit())
113+
.catch(error => {
114+
console.error(error.message || error);
115+
process.exit();
85116
});
117+
```
118+
119+
#### Pros
120+
- Compatible with older CMSIS-DAP firmware.
121+
122+
#### Cons
123+
- Requires HID access to JavaScript in your OS.
124+
125+
### USB
86126

87-
await this.target.reset();
127+
A "pure" USB transport exists which bypasses requiring `WebUSB` and `HID`.
128+
This utilises the `usb` library and is installed as follows:
129+
130+
```bash
131+
$ npm install usb
88132
```
89133

90-
## Documentation
134+
#### Example
135+
136+
```javascript
137+
const usb = require("usb");
138+
const DAPjs = require("dapjs");
139+
140+
let devices = usb.getDeviceList();
141+
devices = devices.filter(device => device.deviceDescriptor.idVendor === 0xD28);
91142

92-
API documentation can be viewed at:
143+
const transport = new DAPjs.USB(devices[0]);
144+
const daplink = new DAPjs.DAPLink(transport);
93145

94-
https://armmbed.github.io/dapjs/docs/
146+
daplink.connect()
147+
.then(() => daplink.disconnect())
148+
.then(() => process.exit())
149+
.catch(error => {
150+
console.error(error.message || error);
151+
process.exit();
152+
});
153+
```
154+
155+
#### Pros
156+
- Doesn't require HID access to JavaScript in your OS.
157+
158+
#### Cons
159+
- Requires a recent version of [DAPLink](https://armmbed.github.io/DAPLink/) to be installed on your target device.
160+
161+
## Architecture
162+
163+
The architecture of this project is built up in layers as follows:
164+
165+
### Transport
166+
167+
The `Transport` layer offers access to the USB device plugged into the host. Different transports are available based on user needs (see above).
168+
169+
### Proxy
170+
171+
The `Proxy` layer uses the transport layer to expose low-level `CMSIS-DAP` commands to the next layer. A common use for the proxy is as a debug chip attached to the main processor accessed over USB.
172+
173+
A CMSIS-DAP implementation is included, however a network proxy or similar could be introduced at this layer in order to remote commands.
174+
175+
### DAPLink
176+
177+
The `DAPLink` layer is a special derived implementation of the `CMSIS-DAP` proxy implementation. It adds DAPLink vendor specific functionality such as Mass Storage Device `firmware flashing` and `serial control`.
178+
179+
### DAP
180+
181+
The `DAP` (Debug Access Port) layer exposes low-level access to ports, registers and memory. An implementation exists for `ADI` (Arm Debug Interface).
182+
183+
### Processor
184+
185+
The `Processor` layer exposes access to the core processor registers.
186+
187+
## Development
188+
189+
After cloning this repository, install the development dependencies:
190+
191+
```bash
192+
$ npm install
193+
```
194+
195+
### Building
196+
197+
[Gulp](https://gulpjs.com/) is used as a task runner to build the project.
198+
To build the project, simply run `gulp` or to continually build as source changes, run `gulp watch`:
199+
200+
```bash
201+
$ gulp
202+
$ gulp watch
203+
```
204+
205+
A `package.json script` exists to run gulp if you don't have it installed globally:
206+
207+
```bash
208+
$ npm run gulp
209+
$ npm run gulp watch
210+
```
211+
212+
### Running
213+
214+
A local [express](https://expressjs.com/) server is included to run the web example locally:
215+
216+
```bash
217+
$ node server.js
218+
```
219+
220+
The latest build of master is always available to be installed from the `gh-pages` branch:
221+
222+
```bash
223+
$ npm install ARMmbed/dapjs#gh-pages
224+
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

circle.yml

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
1-
machine:
2-
node:
3-
version: 6.10.0
4-
environment:
5-
LIVE_BRANCH: gh-pages
1+
version: 2
62

7-
dependencies:
8-
pre:
9-
- sudo apt-get update
10-
- sudo apt-get install libudev-dev
3+
jobs:
4+
build:
5+
docker:
6+
- image: circleci/node:6
7+
steps:
8+
- run: sudo apt-get update
9+
- run: sudo apt-get install libudev-dev
10+
- run: sudo apt-get install libusb-1.0-0-dev
11+
- checkout
12+
- run: npm install
13+
- run: npm run gulp
14+
- persist_to_workspace:
15+
root: ../
16+
paths:
17+
- project
1118

12-
compile:
13-
override:
14-
- npm run gulp
19+
deploy:
20+
docker:
21+
- image: circleci/node:6
22+
steps:
23+
- attach_workspace:
24+
at: ../
25+
- run: mkdir ~/.ssh/ && echo -e "Host github.com\n\tStrictHostKeyChecking no\n" > ~/.ssh/config
26+
- run: git config --global user.name thegecko
27+
- run: git config --global user.email [email protected]
28+
- run: git add --force bundles lib types docs
29+
- run: git stash save
30+
- run: git checkout gh-pages
31+
- run: git merge master --no-commit
32+
- run: git checkout stash -- .
33+
- run: git commit --allow-empty --message "Automatic Deployment [skip ci]"
34+
- run: git push
1535

16-
test:
17-
override:
18-
- exit 0
19-
20-
deployment:
21-
staging:
22-
branch: master
23-
commands:
24-
- echo Syncing to $LIVE_BRANCH on GitHub...
25-
- git config --global user.name thegecko
26-
- git config --global user.email [email protected]
27-
- git add --force bundles lib types docs
28-
- git stash save
29-
- git checkout $LIVE_BRANCH
30-
- git merge master --no-commit
31-
- git checkout stash -- .
32-
- git commit --allow-empty --message "Automatic Deployment [skip ci]"
33-
- git push
36+
workflows:
37+
version: 2
38+
commit:
39+
jobs:
40+
- build
41+
- deploy:
42+
requires:
43+
- build
44+
filters:
45+
branches:
46+
only: master
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)