esp32sim [--chip esp32|s3|c3|c6] --boot rom --bootloader B.bin --ptable P.bin --app A.bin [--elf X.elf ...] [options]
esp32sim --flash-image flash.bin --boot rom ...
One binary for every chip; esp32sim-c3 is esp32sim --chip c3 and esp32sim-c6 is
esp32sim --chip c6. The RISC-V chips' defaults differ
where the chip does (--boot rom, --console uart0, --flash-mb 4) and they refuse the flags
their chip has nothing behind: PSRAM and register presets. Every chip runs on a bare module
(--board none, the default).
| Flag | Meaning |
|---|---|
--boot rom|app |
rom: start at the mask ROM reset vector (real boot chain). app: load the app image segments and jump to its entry |
--bootloader F, --ptable F, --app F |
written to flash at 0x0 / 0x8000 / 0x10000 |
--flash-image F |
whole flash dump written at 0 |
--chip esp32|s3|c3|c6 |
which chip (default s3; esp32 is the classic ESP32) |
--rom F |
mask ROM ELF (default: the chip's in ESP32SIM_ROM_DIR, then ~/.espressif/tools/esp-rom-elfs/*/) |
--mac xx:xx:xx:xx:xx:xx |
the station MAC the efuses report |
--serial TEXT |
bytes into the USB-Serial/JTAG console before the run |
--elf F (repeatable) |
symbols for logs/profiles (app ELF, bootloader ELF) |
--flash-mb N, --psram-mb N |
flash size (JEDEC follows it) and PSRAM size. S3 defaults: 8 / 2; octal MR2 density follows 4, 8, 16, 32 and 64 MiB. Classic ESP32 defaults: 4 / 0; --psram-mb 4 enables quad PSRAM, 0 disables it; other classic sizes are rejected. S31: 2 MiB by default (16 MiB with --board mosaico, which also has 16 MiB in-package PSRAM); 1, 2, 4, 8 or 16 |
--flash-octal |
octal SPI flash (ESP32-S3-WROOM-2): Macronix octal commands, JEDEC C2 80 xx, efuse FLASH_TYPE octal; S3 only. An --efuse-regs dump is loaded after it: a dump that includes RD_REPEAT_DATA3 (efuse +0x3c) replaces that word, FLASH_TYPE (bit 9) with it |
--sd IMAGE, --sd-rw IMAGE |
(S3) an SD card holding the image; on the P4 in the reference board's socket (CLK 43, CMD 44, D0-D3 39-42), on the S3 on whichever pins the firmware routes an SDMMC slot's clock to through the GPIO matrix (the first slot that has one). The card is a high capacity card of the image's size, rounded down to 512 KiB. --sd is copy-on-write: what the firmware writes stays in memory and the file is never modified. --sd-rw writes through to the file. See esp32p4.md, "SD card" |
--sd-prg-us N, --sd-serial HEX |
(S3) the card's programming time after a write or an erase, in microseconds of emulated time (default 0: instant), and its CID serial number (default: derived from the image size) |
--usb-host F |
(S3) a USB host on the USB-OTG port (high speed on the P4 and S31, full speed on the S3), running the commands in F (below) from power-up; the run then goes on to --max-seconds. On the S3 the host sees the device only once the firmware gives the internal PHY to USB-OTG (TinyUSB does). See esp32p4.md, "USB", and peripherals.md |
--board none|esp32dev|esp32dev-loopback|custom|socket:PATH|tcp:HOST:PORT |
board model (default none, a bare module, on every chip; esp32dev is an alias on the classic ESP32, esp32dev-loopback its SPI loopback fixture; on the S3: custom with --device; and on the classic ESP32 socket:PATH or tcp:HOST:PORT, a board in another process (socket-board.md)) |
--board custom, --device SPEC (repeatable) |
(S3) a bare board with nothing but the parts you wire on it, each on its real bus. SPEC is BUS:ADDR:MODEL for I2C (bus 0 or 1, address 0x08 to 0x77 in decimal or 0x hex), PIN:LEDS:ws2812, SCLK:MOSI:CS:DC:st7735, ili9341, ili9486 or ili9488, SCLK:MOSI:CS:RS:nt7534, HOST:WIDTH:HEIGHT:XOFF:co5300. Models: max30100, ms5611, ms5837, amg8833, ina226, bmp180, bmp280, bmp388, bmp390, bmi160, bma400, bmi270, bmm150, qmc5883l, qmc5883p, lis2mdl, lsm303dlhc-accel, lsm303dlhc-mag, ft5x06, aht10, aht20, aht21, lsm6ds3, mpu6500, mpu6886, mpu9250, lis3dh, lis2dw12, sh1106, tcs34725, htu21d, sht21, si7021, max30102. MPU-9250 includes a bypass-gated AK8963 at I2C 0x0c (INT_PIN_CFG bit 1); the auxiliary master is not modelled. One device per (bus, address) and one panel per kind, both refused otherwise. The ST7735, ILI9341 and NT7534 take software SPI or a GP-SPI host routed onto the same SCLK, MOSI and CS pins. See boards.md, "custom" |
--strap HEX, --reset-cause HEX, --efuse-regs F, --regs-init F |
reproduce a real chip's boot state (used by the differential tests) |
--no-reboot |
stop at the first chip reset instead of rebooting from ROM |
--flash-at OFFSET=FILE (repeatable) |
write a file into flash at a hex offset — a data partition's contents (the panel's demo partition takes energydata.json) |
--stub SYMBOL[=value] (repeatable) |
return value (default 0) immediately when execution reaches the function's entry; numeric function addresses require a 0x prefix; accepts decimal, 0x hex, true (1) or false (0); rejects invalid values |
--ble full |
experimental C3 register-level BLE controller; advertising, scanning and one virtual central; excludes --ble |
--ble-scan |
enable a virtual active scanner in C3 full mode; sends SCAN_REQ and observes guest-configured SCAN_RSP |
--ble-observe |
passive full-mode PDU log: half-microsecond timestamp, channel, type, AdvA, decoded AD and raw PDU |
--ble |
opt-in virtual BLE controller on S3/C3/C6; requires the matching application --elf |
--ble-nearby SPEC (repeatable) |
a Bluetooth LE device around the station, heard but not connectable: the guest's scans report it (ADV_SCAN_IND, plus SCAN_RSP for an active scan) next to the virtual peer — name=Thermo,rssi=-60 (name 1 to 26 bytes, a Complete Local Name after the Flags; adv / rsp the advertising data / scan response as hex, at most 31 bytes each, adv instead of name; addr aa:bb:cc:dd:ee:ff, default a random static address derived from the data, a random one not with the reserved top bits 10; type random (default) or public; rssi -127 to 20 dBm or 127 for not available, default -60; a name cannot hold ,, use adv for one that does); reported as scannable and not connectable (ADV_SCAN_IND); up to 32, each on an address of its own, needs --ble |
--wifi SPEC (repeatable) |
attach a virtual access point the WiFi blob hears, plus a virtual network (DHCP/ARP/ICMP/DNS/SNTP; station 10.0.2.15, gateway 10.0.2.2) — for example ssid=demo,chan=6,psk=demo-password,bssid=02:00:00:00:00:01. password and pass alias psk; unknown keys and invalid values are rejected. Open and WPA2-PSK networks both join end to end, on S3, C3, C6 and the classic ESP32 (docs/wifi-plan.md, docs/esp32c3.md, docs/wifi-c6-plan.md). --hostfwd publishes a guest TCP or UDP port on the host. Given several times, each spec is one more joinable access point (up to 8): every one beacons and answers probes, so a scan lists them all, and the station joins one at a time (associating with another leaves the first), e.g. --wifi ssid=guest --wifi ssid=home,psk=home-pass. Without bssid the first keeps 02:53:49:4d:00:01 and later ones derive a locally administered BSSID from their SSID; two access points may share neither SSID nor BSSID. All of them sit in front of the same virtual network, and the network's clock is the first spec's epoch (or --net's); epoch= in a later spec is an error. A station with another passphrase is turned away as hostapd turns it away: message 2 of the handshake does not verify, so the access point sends message 1 again every second. An ESP-IDF station gives up when the fourth message 1 arrives, about 3 s after association: it deauthenticates itself and reports reason 15, WIFI_REASON_4WAY_HANDSHAKE_TIMEOUT (a later attempt may report 205, CONNECTION_FAIL). A station that keeps waiting is deauthenticated by the access point with reason 15 (4-way handshake timeout) about 4 s after association (--debug wifi-frames shows "MISMATCH: dropped" for each message 2) |
--wifi-sta SPEC |
a virtual station that joins the guest's own access point (the guest in WIFI_MODE_AP, or WIFI_MODE_APSTA beside --wifi): ssid=NAME[,psk=PASSPHRASE][,mac=xx:xx:xx:xx:xx:xx] (password and pass alias psk, 8 to 63 characters; mac default 02:53:54:41:00:01). It follows the guest's beacons for that SSID, authenticates (open system), associates, takes the supplicant's side of the WPA2 four-way handshake when given a passphrase, then takes a lease from the guest's DHCP server and answers ARP for it. Joined, it sends a null data frame whenever it has sent the access point nothing for 8 s (or half the BSS Max Idle Period the access point gives, if that is shorter; a protected data frame if it requires protected keep-alives), so the guest does not disassociate it as inactive, and it renews its lease at T1 (unicast to the server), rebinds at T2 (broadcast) and starts again with DISCOVER at the lease's end. With the Ethernet relay on (set_ethernet_relay), a host program is that host instead, sending and taking the station's MAC; switched on while the station holds a lease, the station gives it up and does not renew it. The end-of-run line [emu] wifi-sta: gives its state, joins, lease and frame counts, and the keep-alives and lease renewals (rebinds among them) when there are any; the keep-alives are among the frames to the access point, so 87 frames to the access point, …, 81 keep-alives is 87 frames, 81 of them keep-alives; --debug wifi-frames logs each step. It leaves a network it cannot join alone and says why in that line: WEP and WPA, WPA3-SAE only, and protected management frames required. It takes the access point's group cipher (CCMP or TKIP) and needs CCMP pairwise. It listens again after a refusal, a deauthentication or disassociation (to it or to every station), 3 s without a beacon, or a beacon whose timestamp is lower than the last one's, and stops after three refusals in a row with the same authentication or association status, until the guest reboots. A wrong passphrase is not a refusal: message 3 of the handshake never comes, the station gives up after 1 s and tries again a second later, so every 2 s or so for the whole run, with "wrong passphrase?" in the end-of-run line. --wifi-sta can be given once; alone, it is refused with --net, which configures --wifi's network; and it is refused with a mac that is the BSSID of a --wifi access point. With the Ethernet relay on, frames the host program relayed that the station could not carry, because it left the access point after taking them, are counted in the end-of-run line. On the classic ESP32, S3, C3, C6 and S31 (each with examples/wifi-softap: joined, WPA2, a lease from the guest; not the P4, which has no WiFi of its own), open and WPA2-PSK networks. Beside --wifi (AP+STA) both are on the air: the guest's station joins --wifi's access points and the network behind them (--net configures it) while the virtual station joins the guest's access point, and --hostfwd goes through the virtual station (docs/wifi-plan.md; examples/wifi-apsta). --pcap captures the Ethernet frames the station and the guest's access point exchange (docs/wifi-plan.md) |
--wifi-nearby SPEC (repeatable) |
a network around the station, heard but not joinable: a scan lists it with its channel, signal and security, joining it fails as out of reach — ssid=Home,chan=1,rssi=-60,secure=1 (chan 1 through 14, default 1; rssi in dBm, default -60; secure 0 or 1, default 1; bssid optional, derived from the SSID otherwise); up to 32, each on a BSSID of its own, needs --wifi; one with an access point's SSID or BSSID is left out with a log line |
--net nat|none[,epoch=S] |
what the virtual network does with traffic it is not itself answering: nat (default; user is an alias) forwards TCP and UDP to the host's own network through ordinary sockets, none refuses it. epoch=S sets the network's clock at power-on (seconds since 1970, at most 4294967295): its SNTP answers are that plus emulated time, so a run that asks for the time is reproducible; without it the host's clock at the first answer fixes it. epoch= in the --wifi spec does the same |
--hostfwd tcp:HOST:HOSTPORT-GUEST:GUESTPORT, --hostfwd udp:HOST:HOSTPORT-GUEST:GUESTPORT |
(repeatable) listen on the host and deliver accepted TCP connections as SYNs to the station, or the datagrams arriving at a UDP port: each sender's come from a gateway port of its own (10.0.2.2, 50000 up), and what the guest sends back there goes to that sender from HOSTPORT. Empty HOST binds 127.0.0.1; empty GUEST is 10.0.2.15. Examples: tcp:127.0.0.1:8080-:80, udp::5353-:3333. Up to 8 listeners, TCP and UDP together. New UDP senders never push the guest's own UDP flows out of the NAT's table, and datagrams over 1472 bytes are dropped either way (docs/networking-howto.md). Requires --wifi and --net nat, or --wifi-sta (beside --wifi too, whatever --net says): then the forwards go to the guest's own access point from the virtual station's leased address (192.168.4.2 from ESP-IDF's SoftAP), once it has one, and an empty GUEST, or 0.0.0.0, is the DHCP server that leased it (192.168.4.1); a GUEST given is used as it is, so --wifi's 10.0.2.15 reaches nothing there; the guest's own connections and datagrams to the station are not relayed. Beside --wifi the virtual station's NAT has its own end-of-run line, [emu] nat (wifi-sta):, before [emu] net: and the [emu] nat: of --wifi's network |
--pcap FILE |
write every Ethernet frame the WiFi station sends and receives (what the virtual network, the NAT or the host relay sees, both directions) to a classic pcap: linktype 1 (Ethernet), microsecond timestamps in emulated time, flushed per frame so the file can be read during the run (tcpdump -r, Wireshark, dpkt-js). One capture of the station's traffic, however many --wifi access points; every chip with --wifi, and the co-processor's C6 on a P4 run. With --wifi-sta it holds what the guest's access point and the virtual station exchange, and beside --wifi the guest station's traffic too: both networks (10.0.2.0/24 and the guest's own) in one file, each frame from the guest or to it. The 4 bytes of the 802.11 FCS slot that end a frame the guest sends are left out, so both directions hold the Ethernet frame as it went on the wire. Requires --wifi or --wifi-sta |
--buslog FILE |
write the bus activity as text an LLM or a person can read without a waveform viewer: GPIO edges grouped per cycle with long idle gaps folded, the GP-SPI master transactions a panel driver sends, and one decoded run of bytes per CS pulse on a bit-banged panel (so a display's init sequence can be checked as text). Recording only happens with this flag, and is bounded: 200000 edges, 512 CS pulses, 4096 bytes, and the board's [buslog] report lines are printed only with it too. I2C stays on --debug i2c |
--trace-fn PREFIX (repeatable) |
log every call to functions whose name starts with PREFIX, with args and caller; append $ for an exact name |
--regstat FILE |
write per-register access statistics (count, pc, symbol) at exit — for reverse-engineering |
| Flag | Meaning |
|---|---|
--version, -V |
print esp32sim <version> and exit |
--help, -h |
print the usage line and exit |
--imu-motion N |
scripted IMU motion: 0 at rest, 1 the shared 30 s tilt, flip and shake script on guest time. Only --board custom on the S3 has IMU models (lsm6ds3, mpu6500/mpu6886/mpu9250, aht20 drift) |
--max-seconds S |
stop after this much emulated time, including all reboots |
--max-insns N |
cap scheduler work across all reboots (details below) |
--i2s-tone PORT:HZ:AMPLITUDE |
continuous RX sine on I2S controller 0 or 1; amplitude 0..1, for example 0:1000:0.5; repeat for multiple controllers |
--mic-wav [PORT:]FILE |
a host WAV file as the microphone on I2S controller PORT (default 0): 16-bit integer PCM, mono or stereo (mono goes to both slots), any rate from 1 to 192 kHz, resampled to the firmware's RX rate by zero-order hold (no filter); other formats are refused. Played once from the first frame the receiver takes, then silence; repeat for several controllers |
--script F |
host actions at emulated times (below) |
--exit-on TEXT |
end the run as soon as UART0 or the USB-Serial/JTAG console prints TEXT (also when it arrives in two pieces), with exit status 0. A run given --exit-on that ends any other way exits with status 1 (124 at --timeout). TEXT is taken as written, without the escapes --inject reads. The text is matched from the start of the run, and on UART0 also while --uart-tcp carries it |
--timeout DURATION |
end the run after this much wall-clock time — 500ms, 5s, 6.5s, 2m, 1h, a bare number is seconds — with exit status 124 (as coreutils timeout). The run stops as at --max-seconds, report included; --max-seconds counts emulated time instead |
--inject DATA, --inject-on TEXT (both repeatable) |
DATA into UART0's receive FIFO, with \n, \r, \t, \\ and \xNN (00 to 7f) for control characters. The first --inject-on pairs with the first --inject, and so on, and holds it back until UART0 has printed TEXT; an --inject left without a trigger goes in at the start. They are action-script steps (waituart0 without a timeout, then uart0), so the triggered pairs form one chain: each trigger is looked for after the previous payload went in, as the prompts of a dialogue come in turn. --inject-on is not available with --script, whose actions its waits would hold back: put waituart0 and uart0 lines in the script instead; a plain --inject goes in at the start alongside the script. TEXT is taken as written |
--uart-tcp HOST:PORT |
UART0's bytes both ways over a TCP socket, raw, to one client at a time: esptool and espefuse connect with --port socket://HOST:PORT (below). Port 0 picks a free port; the address is printed as [emu] UART0 on tcp .... A second client waits until the first closes; without a client UART0's output is dropped. UART0 no longer goes to stdout, the USB-Serial/JTAG console still does. Implies --realtime, whose pacing step polls the socket |
--uart1-tcp HOST:PORT |
the same for UART1: a host script plays a serial device (a GPS, a modem) wired to the firmware's UART1, while UART0 stays on stdout (checked with IDF's peripherals/uart/uart_echo on the C3) |
--console usb|uart0|both|all|none, --console-prefix |
which consoles to print |
--realtime |
pace to wall time without the UI |
--web PORT [--web-dir DIR] |
browser UI (implies real time). With --wifi the page gets a Network panel: the station's Ethernet frames live (time, ↑ sent / ↓ received, a dissection summary from dpkt-js 0.1.0, vendored under web/vendor/dpkt-js and loaded when the panel is first opened or a row clicked; until then, length and hex), a filter, pause, clear, the dissection tree of a clicked frame and a pcap download of the frames the page received. They arrive as binary WebSocket messages [5][dir: 0 sent, 1 received][emulated µs, u64 LE][frame], only while a page is connected; at most 512 frames or 1 MiB wait between pushes, the rest are dropped |
The legacy name --max-insns counts scheduler work, not total retired instructions. The
default scheduler charges one unit per core 0 instruction or idle cycle advanced; another
core does not add to that count. It checks the cap between scheduling rounds, so it may finish
the current round past the requested number. With an approximate cost model, it counts
scheduled events. Use --max-seconds for a predictable duration. The final execution report
separately lists the actual instruction count for each core.
--uart-tcp puts UART0 on a TCP port, and with the strapping pins set for download mode the mask
ROM's UART download protocol is on it: stock esptool and espefuse drive the emulator as they drive a
board on a serial port, through pyserial's socket:// (the QEMU-Espressif workflow). The socket is
raw: rfc2217:// would send its telnet negotiation to the ROM as data.
The --strap value is the chip's own GPIO_STRAP: download boot is bits [3:2] = 0 on the S3, C3, C6
and P4 and bits [4:3] = 0 on the classic ESP32 (components/soc/<chip>/include/soc/boot_mode.h, IDF
v5.5.4), so 0x2 on the S3, C3, C6 and P4 and 0x3 on the classic ESP32.
esp32sim-c3 --boot rom --flash-mb 4 --strap 0x2 --uart-tcp 127.0.0.1:5555
# in another shell
python -m esptool --port socket://127.0.0.1:5555 --chip esp32c3 --before no-reset --after no-reset flash-id
python -m esptool --port socket://127.0.0.1:5555 --chip esp32c3 --before no-reset --after no-reset write-flash 0x10000 app.bin
python -m esptool --port socket://127.0.0.1:5555 --chip esp32c3 --before no-reset --after no-reset read-flash 0x10000 0x1000 back.binA socket has no DTR and RTS, so esptool cannot reset the chip into the bootloader: pass
--before no-reset --after no-reset (no_reset in esptool 4.x). With esptool v5 the stub it uploads
keeps running between commands, and the next command finds it ("Stub flasher is already running"). The
emulator holds emulated time to wall time while the socket is open (as --realtime), so the
UART runs at its baud rate in real time. Flash written this way lasts as long as the run: nothing
writes it back to a file at exit.
Checked with stock esptool v5.6.0 on all five chips (chip-id, flash-id, write-flash of 8 KiB
of random data with its hash verified, verify-flash, read-flash compared byte for byte), and
espefuse v5.6.0 summary on the C3; idf.py flash with ESPPORT=socket://... runs the same esptool
but was not tried. esptool v4.12 (the one ESP-IDF 5.5 installs) works with --no-stub (checked on
the C3). Its default stub faults when it unlocks the flash, on the C3 in write_flash and in the
return to the ROM that ends each command, on the S3 in that return: it hands the ROM a flash-chip
pointer whose status mask lies at an address the emulator does not map (0x3fce0008 on the C3,
0x3ffae284 on the S3), and the emulator raises a load fault there.
Where esp32sim differs from Espressif's esp-emu, whose flag names these follow:
--strapis the chip's raw GPIO_STRAP value; esp-emu's--strap-mode 0x02means "UART download" on every chip and remaps it.--exit-onmatches UART0 and USB-Serial/JTAG output, whichever console the firmware uses;--inject-onmatches UART0 only and--injectwrites UART0 only, the console UART.- The
--inject-ontriggers are a chain, each looked for after the previous payload went in. --timeoutexits with status 124; a run given--exit-onthat never matched exits with 1.- There is no
--control-tcp(resets and flash operations over a second socket), and flash and eFuse changes are not saved back to a file at exit.
| Flag | Meaning |
|---|---|
--wav F |
audio captured from I2S (whichever controller played) |
--tft-png F, --gram-png F |
display frame (visible, scaled) / raw GRAM |
--no-dump |
skip the register dump at exit |
--adc PIN |
(repeatable) last completed ADC conversion on that GPIO: 12-bit raw count and generation |
--adc-raw PIN=COUNT |
(repeatable) a post-attenuation 12-bit count (0..4095) on that pad, before the first instruction |
--pwm PIN reports the GPIO-matrix PWM frequency in Hz and duty percentage when the run stops.
Repeat it to observe several pins. PIN is an unsigned 8-bit decimal number.
LEDC is supported on S3, C3, C6, P4 and the classic ESP32; MCPWM on S3, C6, P4 and the classic ESP32. During an LEDC hardware fade
it reports the duty in effect when the run stops.
A running timer with 0% or 100% duty still has a snapshot. "No supported running PWM" means
unrouted, disabled, paused or unsupported configuration; it does not imply a low GPIO level.
A paused hardware timer can hold its last level. This reports register-derived steady state,
not sampled edges. MCPWM dead time, carrier and extra generator actions are unsupported.
--adc PIN reports the last completed conversion on that pad when the run stops: the 12-bit
raw count and the generation (zero until the firmware samples, then one step per completed
conversion). Repeat it to observe several pads. PIN is an unsigned 8-bit decimal number.
--adc-raw PIN=COUNT puts a post-attenuation count on the pad before the first instruction;
unsupported pins and counts above 4095 are refused. Voltage scripts (adc, adcwave) still
set the transfer-curve input; a script on the same pin replaces the raw count at its timestamp.
Pads, units and the voltage curve are in peripherals.md.
"no ADC pad" means that GPIO is not an ADC input on this chip.
| Flag | Meaning |
|---|---|
--trace, --trace-from N |
per-instruction trace (from instruction N) |
--break PC (repeatable) |
stop at PC |
--watch ADDR |
stop when a word changes |
--peek ADDR,N, --disasm ADDR,N |
dump memory / disassemble at exit |
--profile |
top PCs by instruction count (single-steps, and keeps idle cores stepping: an idle core shows as a hot waiti) |
--profile-blocks |
time per function from the block path — full speed, no timing change; needs --elf for names |
--coverage, --coverage-file F |
block starts reached, per function; with a file, one addr symbol line each |
--irq-latency |
cycles from an interrupt line appearing at a core to the core taking it, per line; retains block execution |
--vcd F |
GPIO edges and interrupt lines as a VCD waveform (1 ps units); retains block execution |
--debug AREAS |
what the model prints: device names or prefixes (spi, usb, i2c, wifi, gdma, sha, rsa, lcd_cam, sdmmc, usb_otg for the USB-OTG core and the host's link; usb also takes USB-Serial/JTAG), net, wifi-frames, aes, rom, mmio, rt; also ESP_EMU_DEBUG=a,b |
--log-periph |
log the first access to every unknown peripheral register |
--no-jit |
run blocks through the interpreter instead of native code (aarch64 hosts compile blocks to machine code by default); the two must produce identical results, so this is the oracle when something looks wrong |
--stop-after-exceptions N |
stop after N exceptions |
--regtrace F, --regtrace-from-pc PC, --regtrace-max N |
register trace file for hw/compare.py |
Environment: ESP_EMU_DEBUG=wifi,spi,net is --debug for every run (the older
ESP_EMU_DEBUG_SPI, ESP_EMU_DEBUG_NET, ESP_EMU_LOG_ALL, ESP_EMU_RT_LOG... still work as aliases).
RV32_JIT=0 keeps the RISC-V chips' decoded blocks (C3, C6, P4 and S31) but runs them through the interpreter
(--no-jit runs no blocks either), and RV32_JIT_HOT=N compiles a block after N whole runs instead of 32.
Both are read once per process. The JIT has AArch64 and WebAssembly backends; on other hosts the blocks run
without it.
XTENSA_DIS_FILES=a.dis:b.dis feeds the decoder equivalence test.
One action per line, <seconds> <cmd> [args]; buttons/encoder are active low.
1.5 press btn1 150 # press for 150 ms (btn1, btn2, knob/sw, or a GPIO number)
2.0 release 16
2.5 gpio 17 0
3.0 knob cw 3 # 3 detents clockwise (ccw for the other way)
4.0 serial {"action":"set_note","value":"5"}
4.2 uart0 root # a line into UART0's receive FIFO (also `uart1`): a login on a Linux console
4.5 touch 450 30 1 # touch panel press at (450,30); `touch x y 0` releases
5.5 stop
hw/wsdrive.py [port] [seconds] drives the same inputs over the UI's WebSocket and reports
real-time keep-up (push gaps, lag, audio delivered); hw/wsaudio.py [port] [seconds] listens to the
UI's audio stream and reports sample counts/peak (how to check sound without listening).
Scripts accept adc <gpio> <volts> for a constant voltage and
adcwave <gpio> <file> <rate_hz> for voltage samples separated by whitespace or
commas. The waveform starts at the action's emulated time. A later input replaces
the previous source. S3 GPIO1–10 select ADC1 and GPIO11–20 select ADC2; C3 GPIO0–4
select ADC1 and GPIO5 selects ADC2; C6 GPIO0–6 select ADC1.
0 adc 1 0.5
0 waituart0 10 ADC READY
0 uart0 A
1 adc 1 1.0
1 uart0 C
2 adcwave 1 /tmp/adc-volts.txt 1000
waituart0 <timeout_s> <text> holds later actions until UART0 prints the text or
the timeout expires. Raw counts and completed-conversion observations are exposed
through the host ADC API. --adc PIN prints the last completed
sample at exit; --adc-raw PIN=COUNT injects a 12-bit count before the run.
--ble --elf firmware.elf substitutes the controller lifecycle and legacy VHCI
functions on S3 and C3, or the native NimBLE transport on C6. The guest host and sketch remain unchanged.
An emulator-created FreeRTOS task delivers controller packets through guest
callbacks. S3 uses the windowed Xtensa ABI; C3 uses RV32IMC. Unstripped controller,
VHCI, task and BSS symbols are required on S3/C3. C6 requires native transport,
NPL and mbuf allocator symbols; its board image needs --flash-mb 8.
C6 is ESP-IDF 5.5.x only. Enable reads esp_app_desc.idf_ver from the application
ELF and refuses missing, malformed or other versions before installing hooks.
Its native transport uses that version's os_mbuf layout and NPL initialization.
S3/C3 accept builds exposing the required VHCI/lifecycle symbols, controller BSS
and function sizes; there is no IDF version gate. Enable takes the mode of the
config given to init, as IDF does: BLE (1) on S3/C3, whose init takes nothing
else, and 1, 2 or 3 on the classic ESP32 (esp32.md). Arduino 3.3.8
with IDF 5.5.4 is validated. IDF 4.4 Bluedroid is unsupported and fails with a missing-symbol error.
Other IDF releases have not been validated.
VHCI transmit packets may also reside in mapped PSRAM: on the S3, as used by
StopWatch's ESP-IDF 6.1 build with external NimBLE allocation, and on the
classic ESP32 with --psram-mb 4, as Bluedroid built with
CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST sends them. Every page must map to
installed PSRAM, and on the classic ESP32 the cache must be able to read it;
flash, invalid mappings and out-of-range packets are rejected. The controller
task trampoline and its receive buffer still require internal controller BSS.
[ble] output reports advertising data and discovered GATT handles. Script commands
use seconds like the other script actions. For example:
0.5 ble connect
0.6 ble discover
1.0 ble read 0x0010
1.1 ble write 0x0010 68656c6c6f
Use handles reported by discovery. ble subscribe CCC_HANDLE writes notification
enable to a discovered client configuration descriptor. Commands are validated when
CLI arguments are parsed, before loading the ROM, and require --ble. connect waits for guest advertising;
ATT commands wait for the connection and run in order, with one request outstanding.
At exit, the CLI reports the number of queued or in-flight commands still pending.
Writes are limited to 20 bytes. A scanning guest sees a virtual
peripheral named esp32sim advertising the Battery Service.
This models one unencrypted LE link, legacy advertisements and ATT MTU 23. It does not model RF, pairing, physical connection timing or the controller's registers. Unsupported HCI commands return Unknown Command. The controller reports LL Privacy and keeps a 10-entry resolving list with an ESP32-S3 controller's statuses, so a host stack can set up controller privacy; it resolves no addresses and makes no resolvable private address. The callback task and its storage stay allocated until reboot. C6 initializes the guest NPL support and a heap-backed mbuf pool; it uses no controller BSS reservation. Cost-model execution does not support function substitutions; reported cycle time is not radio timing.
--ble full selects the experimental C3 link-controller register model and excludes
--ble HCI substitution. It runs the original guest controller without ELF hooks.
It implements initialization, clock capture, timer IRQs and legacy advertising on
channels 37–39. Completion IRQs let the guest schedule its next event. --ble-observe
logs to stderr emitted ADV_IND, ADV_NONCONN_IND or ADV_SCAN_IND packets as [ble-air] lines;
hus is modeled time in half-microseconds. [ble-config] reports configured
SCAN_RSP data separately; a passive observer cannot elicit that response. The queue
holds the latest 1024 observations and reports dropped entries when polled.
--ble-scan enables active SCAN_REQ/SCAN_RSP exchanges through guest RX descriptors.
Use script commands ble connect, ble read-uuid SERVICE CHARACTERISTIC,
ble central-stop, and ble disconnect. The last sends LL_TERMINATE_IND;
central-stop silences the central so the guest supervision timer can expire.
A read-uuid sent between central-stop and that timeout is queued on the
silent link and lost; send it after the next connect.
For example, pass this file with --ble full --script connection.txt:
0.5 ble connect
0.7 ble read-uuid 4fafc201-1fb5-459e-8fcc-c5c9c331914b beb5483e-36e1-4688-b7f5-ea07361b26a8
3.1 ble central-stop
The model supports one unencrypted 1M CSA#1 link, a fixed 30 ms interval and 2 s supervision timeout, default ATT MTU 23 and no L2CAP fragmentation. It replies to LL_VERSION_IND even without an ATT request. Pairing, CSA#2, PHY updates and optional LL procedures are unsupported. Register meanings and packet timing remain inferred/model choices. EX213 evidence separates the historical probe-b field checks from unvalidated RF timing.
Standard I2S RX supports 16/24/32-bit mono or stereo on S3 controllers 0/1,
C3/C6 controller 0 and S31 controllers 0/1 (through the AHB-GDMA, also as the
full-duplex slave RX that runs on the TX clock, as ESP-IDF sets it up when TX and
RX share a port). S3 controller 0 also accepts PDM-to-PCM RX at 16 bits.
--i2s-tone 0:1000:0.5 supplies a continuous 1 kHz sine at half full scale;
--mic-wav 0:speech.wav plays a recording once; omit both for silence. The
source survives software resets.
Rust hosts use SocBus::i2s_input(port) to access PcmInput. push(&[[left, right]])
queues signed 16-bit stereo frames at the firmware's programmed sample rate.
For mono input, duplicate each sample into both lanes. push returns the number
accepted, up to a queue limit of 65,536 frames; retry the remaining frames later.
clear() removes queued data and disables the tone. Empty queues read as zero.
Queued input pauses while RX or its DMA channel is stopped, including during reboot.
Each 16-bit input sample is the top 16 bits of the guest's sample, low bits zero.
32-bit RX writes 4 bytes per sample. 24-bit RX writes 3 bytes per sample, the size
ESP-IDF allocates, unless the firmware sets RX_24_FILL_EN (RX_CONF bit 16), which
pads each sample to 4 bytes. An unprogrammed RX_EOF_NUM uses the hardware reset value 0x40.
Input attaches to a controller at the PCM/DMA boundary. It does not simulate GPIO wiring, serial bit timing, or PDM filter response. Raw PDM, external slave clocks, more than two slots, companding, and reversed bit/byte order are unsupported. C3/C6 and S3 controller 1 have no hardware PDM-to-PCM converter, so their raw PDM mode does not consume this PCM source. Existing I2S TX capture is unchanged.
Rust hosts attach the shared source bank with SocBus::attach_pcm_sources() and
append PcmSource values to its inputs slot vector. Each source names PcmPins::I2s
with BCLK/WS/data pins, or PcmPins::Pdm with clock/data pins, and a rate from
8 to 96 kHz. Pushes retain the newest two seconds. Call attach_pcm_sources()
before each push or slot edit; it synchronizes the bank's clock (on S3 it also
flushes deferred ticks). SocBus::pcm_sources() is read-only: it returns the
attached bank as of its last synchronization, or None, and changes nothing.
Queues advance during RX/DMA stalls and survive resets. Matrix routes select the
lowest matching slot; a matched source that underruns produces silence. A receiver
whose route matches no slot keeps its per-controller input, so --i2s-tone and
i2s_input pushes keep working with a bank attached. tone() is rejected on a
routed source; push generated frames instead.
Routing matches the RX BCK/WS output signals only. In ESP-IDF full-duplex standard
mode the later-initialised channel becomes the slave and the BCK/WS pins usually carry
the TX output signals (IDF v5.5.5 esp_driver_i2s/i2s_std.c, lines 214–237 and
292–297). Such a duplex codec setup matches no routed source and reads its
per-controller input instead. This
models matrix selection and PCM samples, not IO_MUX, pad enable, serial edges or
PDM filtering.
For ADC audio, attach AnalogSource::Stream(stream.clone()) through analog_set.
Create AnalogStream::new(rate, bias_volts, cycles) and push finite f32 volts
with push(samples, cycles, CPU_HZ). For exact 12-bit counts, create
AnalogStream::new_raw(rate, bias_count, cycles), attach it as
AnalogSource::RawStream, and call push_raw(samples, cycles, CPU_HZ).
Stream rates are 1 Hz to 96 kHz, so slow sensor streams work too.
Invalid samples leave queue and time intact. Push between emulator runs at the
bus's current cycle count. Conversion uses AnalogInputs.cpu_hz. Buffers retain
two seconds, drop oldest samples on overflow, and hold the last value on
underrun. Both forms preserve main's completed-conversion observation counters.