Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
pguyot opened this issue Sep 3, 2023 · 1 comment
Open

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

pguyot opened this issue Sep 3, 2023 · 1 comment

Comments

@pguyot
Copy link
Contributor

pguyot commented Sep 3, 2023

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();
@coffeemakingtoaster
Copy link

coffeemakingtoaster commented Jan 23, 2024

Hey I just came across this. I don´t know if this solves your issue as well but I had to downgrade to the pico sdk 1.4.0 to get USB output working.

So my code looked like this in the end. Mind you: The sendByte calls are just implementation specific. They are used to ensure that the USB device will receive the output of the program running as the emulator tends to start running the compiled program before the USB device is connected and ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants