esp32emu / tools /runw.mjs
HelloSun's picture
ESP32 emulator update
d8afd6f verified
Raw History Blame Contribute Delete
1.21 kB
// node runw.mjs flash.bin seconds [--js] [--psram] : run using wasm CPU (default) or JS CPU
import fs from 'fs';
import { ESP32, createESP32 } from '../web/js/soc.js';
const romDir = new URL('../web/rom/', import.meta.url).pathname;
const args = process.argv.slice(2);
const flash = args[0], secs = parseFloat(args[1] || '3');
const wasmBytes = fs.readFileSync(new URL('../wasm/xtensa.wasm', import.meta.url));
const sl = parseInt((args.find(a => a.startsWith("--slice=")) || "--slice=256").slice(8)); const soc = args.includes("--js") ? new ESP32({ slice: sl }) : await createESP32({ wasmBytes, slice: sl });
soc.loadRoms(fs.readFileSync(romDir + 'esp32-v3-rom.bin'), fs.readFileSync(romDir + 'esp32-v3-rom-app.bin'));
soc.setFlash(fs.readFileSync(flash)); soc.enablePsram(args.includes('--psram'));
soc.onUart = (n, b) => process.stdout.write(String.fromCharCode(b));
soc.reset('power');
const t0 = Date.now(); let instr = 0;
while (soc.timeNs < secs * 1e9) { instr += soc.run(200000); if (soc.idleForever) break; }
const dt = (Date.now() - t0) / 1000;
console.log(`\n[${soc.engine}] virtual ${(soc.timeNs / 1e9).toFixed(3)}s, ${instr} instr, wall ${dt.toFixed(2)}s, ${(instr / dt / 1e6).toFixed(1)} MIPS`);