QEMU Testing
Mainline QEMU does not support ESP32. Use Espressif’s fork, which ships with ESP-IDF.
Prerequisites
Section titled “Prerequisites”- ESP-IDF v5.x installed and sourced (
. $HOME/esp/esp-idf/export.sh) - Espressif QEMU at:
~/.espressif/tools/qemu-xtensa/esp_develop_9.0.0_20240606/qemu/bin/qemu-system-xtensa
Build for QEMU
Section titled “Build for QEMU”# Use the QEMU sdkconfig defaultscp sdkconfig.defaults.qemu sdkconfig.defaultsidf.py set-target esp32idf.py buildThe QEMU config disables WiFi/BLE, enables the custom OTA partition table, and defines CONFIG_QEMU_TEST_MODE.
Create the flash image
Section titled “Create the flash image”cd buildesptool.py --chip esp32 merge_bin --output flash_image.bin \ --flash_mode dio --flash_freq 40m --flash_size 4MB \ 0x1000 bootloader/bootloader.bin \ 0x8000 partition_table/partition-table.bin \ 0xd000 ota_data_initial.bin \ 0x10000 esp32cam_qemu_test.binRun in QEMU
Section titled “Run in QEMU”~/.espressif/tools/qemu-xtensa/esp_develop_9.0.0_20240606/qemu/bin/qemu-system-xtensa \ -nographic \ -machine esp32 \ -drive file=build/flash_image.bin,if=mtd,format=raw \ -m 4MPress Ctrl+A then X to exit QEMU.
What the loopback test does
Section titled “What the loopback test does”On startup in QEMU mode, main.c runs test_loopback_transfer():
- Loads the embedded 64×64 JPEG test image (1365 bytes).
- Computes CRC16 over the image data.
- Fragments the image and sends each fragment via
lora_send()— which writes to a FreeRTOS queue instead of UART. - Reads each fragment back from the queue via
lora_receive(). - Feeds fragments through
xfer_rx_process()for reassembly. - After all fragments arrive, verifies the reassembled image matches the original byte-for-byte.
Expected output:
=== Loopback Transfer Test ===Test image: 1365 bytes, 9 frags, CRC=XXXXLoopback received header: H:1:9:1365:64:64:XXXX...Image fully reassembled via loopback!Loopback verify: PASS=== Loopback Test Complete ===QEMU limitations
Section titled “QEMU limitations”| Feature | Status |
|---|---|
| Camera | Emulated via fake_camera component |
| LoRa UART | FreeRTOS queue loopback (no real UART) |
| PSRAM | Not emulated by default |
| WiFi / Bluetooth | Not emulated |
| NVS | Works (flash image includes NVS partition) |
| OTA partitions | Present in partition table |