Skip to content

How to do serial over USB with demo/emulator-run.ts? #133

@pguyot

Description

@pguyot

First, let me write this is very cool. I'd like to use @mingpepe 's core1 branch to run CI tests for AtomVM which extensively uses core1.

I got AtomVM's hello_pico sample to work but I had to alter compilation flags to use uart instead of usb for serial.

The demo/emulator-run.ts script works well with hello_uart.hex, but I can't seem to get it working with hello_usb.hex. I tried to adapt the code from demo/micropython-run.ts, but failed: nothing is being printed. What am I missing?

Also as a side note, why is demo/emulator-run.ts using a hex file instead of uf2 file(s)?

diff --git a/demo/emulator-run.ts b/demo/emulator-run.ts
index e18cc9f..c268dd8 100644
--- a/demo/emulator-run.ts
+++ b/demo/emulator-run.ts
@@ -3,10 +3,11 @@ import { RP2040 } from '../src';
 import { bootromB1 } from './bootrom';
 import { loadHex } from './intelhex';
 import { GDBTCPServer } from '../src/gdb/gdb-tcp-server';
+import { USBCDC } from '../src/usb/cdc';
 
 // Create an array with the compiled code of blink
 // Execute the instructions from this array, one by one.
-const hex = fs.readFileSync('hello_uart.hex', 'utf-8');
+const hex = fs.readFileSync('hello_usb.hex', 'utf-8');
 const mcu = new RP2040();
 mcu.loadBootrom(bootromB1);
 loadHex(hex, mcu.flash, 0x10000000);
@@ -18,5 +19,10 @@ mcu.uart[0].onByte = (value) => {
   process.stdout.write(new Uint8Array([value]));
 };
 
+const cdc = new USBCDC(mcu.usbCtrl);
+cdc.onSerialData = (value) => {
+  process.stdout.write(value);
+};
+
 mcu.core.PC = 0x10000000;
 mcu.execute();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions