From f4b8921e61eabd63872ad5aec25f173b1e4ee618 Mon Sep 17 00:00:00 2001 From: Uri Shaked Date: Thu, 27 May 2021 13:03:43 +0300 Subject: [PATCH] feat(demo): MicroPython REPL works! update README with relevant instructions --- README.md | 15 +++++++++++++-- demo/emulator-run.ts | 2 +- demo/micropython-run.ts | 9 +++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 638f31c..fa6536d 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,25 @@ # rp2040js -A Raspberry Pi Pico Emulator (WiP). It (almost) blinks! +A Raspberry Pi Pico Emulator (WiP). It blinks, runs Arduino code, and even the MicroPython REPL! -## Enjoy the wonders +## Run the demo project + +You'd need to get `hello_uart.hex` by building it from the [pico-examples repo](https://github.com/raspberrypi/pico-examples/tree/master/uart/hello_uart), then copy it to the rp2040js root directory and run: ``` npm install npm start ``` +To run the micropython demo, first download [rp2040-micropython-uart-47e6c52f0c.hex](https://raw.githubusercontent.com/wokwi/firmware-assets/gh-pages/rp2040-micropython-uart-47e6c52f0c.hex), rename it to `micropython.hex` and place it in the rp2040js root directory, then run: + +``` +npm install +npm run start:micropython +``` + +and enjoy the MicroPython REPL! Quit the REPL with Ctrl+D. + ## Learn more - [Live-coding stream playlist](https://www.youtube.com/playlist?list=PLLomdjsHtJTxT-vdJHwa3z62dFXZnzYBm) diff --git a/demo/emulator-run.ts b/demo/emulator-run.ts index b35f07c..6f5190a 100644 --- a/demo/emulator-run.ts +++ b/demo/emulator-run.ts @@ -15,7 +15,7 @@ const gdbServer = new GDBTCPServer(mcu, 3333); console.log(`RP2040 GDB Server ready! Listening on port ${gdbServer.port}`); mcu.uart[0].onByte = (value) => { - console.log('UART sent: ', String.fromCharCode(value)); + process.stdout.write(new Uint8Array([value])); }; mcu.PC = 0x10000000; diff --git a/demo/micropython-run.ts b/demo/micropython-run.ts index fcde8d2..9f49700 100644 --- a/demo/micropython-run.ts +++ b/demo/micropython-run.ts @@ -18,6 +18,15 @@ console.log(`RP2040 GDB Server ready! Listening on port ${gdbServer.port}`); mcu.uart[0].onByte = (value) => { process.stdout.write(new Uint8Array([value])); }; +process.stdin.setRawMode(true); +process.stdin.on('data', (chunk) => { + if (chunk[0] === 4) { + process.exit(0); + } + for (const byte of chunk) { + mcu.uart[0].feedByte(byte); + } +}); mcu.PC = 0x10000000; mcu.execute();