esp32emu / tools /echo_test.mjs
HelloSun's picture
ESP32 emulator update
8d577f5 verified
Raw History Blame Contribute Delete
760 Bytes
import fs from 'fs';
import { createESP32 } from '../web/js/soc.js';
const romDir = new URL('../web/rom/', import.meta.url).pathname;
const wasmBytes = fs.readFileSync(new URL('../wasm/xtensa.wasm', import.meta.url));
const soc = await createESP32({ wasmBytes });
soc.loadRoms(fs.readFileSync(romDir + 'esp32-v3-rom.bin'), fs.readFileSync(romDir + 'esp32-v3-rom-app.bin'));
soc.setFlash(fs.readFileSync(process.argv[2])); soc.enablePsram(false);
soc.onUart = (n, b) => process.stdout.write(String.fromCharCode(b));
soc.reset('power');
let sent = false, led = [];
while (soc.timeNs < 4e9) {
soc.run(100000);
if (!sent && soc.timeNs > 1.7e9) { sent = true; soc.uart[0].rxPush(Buffer.from('hello esp32\n')); }
}
console.log('GPIO2 level', soc.gpio.level(2));