Skip to content

Commit 2e5b8a2

Browse files
authored
feat(demo): add "--image" and "--gdb" args (#116)
1 parent 3dd7ee8 commit 2e5b8a2

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

README.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,17 @@ npm install
3535
npm run start:micropython
3636
```
3737

38-
and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X.
38+
and enjoy the MicroPython REPL! Quit the REPL with Ctrl+X. A different UF2 image can be loaded by supplying the `--image` option:
3939

40-
You can replace rp2-pico-20210902-v1.17.uf2 with any recent MicroPython or CircuitPython release built for the RP2040.
40+
```
41+
npm run start:micropython -- --image=my_image.uf2
42+
```
43+
44+
A GDB server on port 3333 can be enabled by specifying the `--gdb` flag:
45+
46+
```
47+
npm run start:micropython -- --gdb
48+
```
4149

4250
With MicroPython – and probably also CircuitPython – you can use the filesystem on the Pico. This becomes useful as more than one script file is used in your code. Just put a [LittleFS](https://github.com/littlefs-project/littlefs) formatted filesystem image called `littlefs.img` into the rp2040js root directory, and your `main.py` will be automatically started from there.
4351

demo/micropython-run.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,31 @@ import { ConsoleLogger, LogLevel } from '../src/utils/logging';
55
import { bootromB1 } from './bootrom';
66
import { loadUF2, loadMicropythonFlashImage } from './load-flash';
77
import fs from 'fs';
8+
import minimist from 'minimist';
9+
10+
const args = minimist(process.argv.slice(2), {
11+
string: 'image', // UF2 image to load; defaults to "rp2-pico-20210902-v1.17.uf2"
12+
boolean: 'gdb', // start GDB server on 3333
13+
});
814

915
const mcu = new RP2040();
1016
mcu.loadBootrom(bootromB1);
1117
mcu.logger = new ConsoleLogger(LogLevel.Error);
12-
loadUF2('rp2-pico-20210902-v1.17.uf2', mcu);
18+
19+
const imageName = args.image ?? 'rp2-pico-20210902-v1.17.uf2';
20+
console.log(`Loading uf2 image ${imageName}`);
21+
loadUF2(imageName, mcu);
1322

1423
if (fs.existsSync('littlefs.img')) {
1524
loadMicropythonFlashImage('littlefs.img', mcu);
1625
// Instead of reading from file, it would also be possible to generate the LittleFS image on-the-fly here, e.g. using
1726
// https://github.com/wokwi/littlefs-wasm or https://github.com/littlefs-project/littlefs-js
1827
}
1928

20-
const gdbServer = new GDBTCPServer(mcu, 3333);
21-
console.log(`RP2040 GDB Server ready! Listening on port ${gdbServer.port}`);
29+
if (args.gdb) {
30+
const gdbServer = new GDBTCPServer(mcu, 3333);
31+
console.log(`RP2040 GDB Server ready! Listening on port ${gdbServer.port}`);
32+
}
2233

2334
const cdc = new USBCDC(mcu.usbCtrl);
2435
cdc.onDeviceConnected = () => {

package-lock.json

Lines changed: 24 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@
3939
},
4040
"devDependencies": {
4141
"@types/jest": "^27.4.1",
42+
"@types/minimist": "^1.2.2",
4243
"@types/node": "^14.14.22",
4344
"@typescript-eslint/eslint-plugin": "^4.22.1",
4445
"@typescript-eslint/parser": "^4.22.1",
4546
"eslint": "^7.26.0",
4647
"husky": "^6.0.0",
4748
"jest": "^27.5.1",
4849
"lint-staged": "^11.0.0",
50+
"minimist": "^1.2.7",
4951
"prettier": "^2.2.1",
5052
"rimraf": "^3.0.2",
5153
"ts-jest": "^27.1.3",

0 commit comments

Comments
 (0)