esp32emu / tools /clk.mjs
HelloSun's picture
ESP32 emulator update
d8afd6f verified
Raw History Blame Contribute Delete
945 Bytes
import fs from 'fs';
import { ESP32 } from '../web/js/soc.js';
const romDir = new URL('../web/rom/', import.meta.url).pathname;
const soc = new ESP32({});
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(true);
soc.reset('power');
const oc = soc.setClocks.bind(soc);
soc.setClocks = (c, a) => { console.log('setClocks', c, a, 'at', soc.timeNs / 1e6, 'ms'); return oc(c, a); };
const ow = soc.rtc.write.bind(soc.rtc);
soc.rtc.write = (off, v) => { if (off === 0x70) console.log('RTC CLK_CONF', (v>>>0).toString(16)); return ow(off, v); };
const odw = soc.dportWrite.bind(soc);
soc.dportWrite = (c, a, s, v) => { if ((a - 0x3ff00000) === 0x3c) console.log('DPORT 3c', v); return odw(c, a, s, v); };
while (soc.timeNs < 6e9) soc.run(100000);
console.log('cpuHz', soc.cpuHz, 'socClk', soc.rtc.socClk, 'per', soc.cpuPerSel);