How to add custom peripherals to qemu-esp?
Posted: Wed Nov 05, 2025 2:56 pm
(Please note that English is not my native language)
Hi all! I am developing my own device with esp32 chip as CPU. This device has various peripherals on different buses such as i2c and spi. Some of the peripherals also have GPIO connections for interrupts.
I want to make an emulator of my device using QEMU. I am new to QEMU programming and have a vague understanding of the QEMU architecture and the ESP32 virtual machine in particular.
For example, I wrote a simple device for the i2c bus and connected it to an esp32 machine:
I added a call to this function from esp32_machine_init in /hw/xtensa/esp32.c. The device is successfully added to the i2c bus and I can work with it inside the virtual machine. But the interrupts aren't working. As I understand it, intmatrix isn't the place where I should be connecting the GPIO.
I also looked into the file /hw/gpio/esp32_gpio.c. Read and write functions do not appear to be implemented. https://github.com/espressif/qemu/blob/ ... gpio.c#L24 Now I'm completely confused and don't know which direction to go next. Ideally, I'd like to see documentation, but as far as I understand, there simply isn't any. If anyone has any information on how to properly connect devices to the machine using GPIO, i2c and SPI, please share the information. Ideally, I would like to be able to connect devices using qemu launch options.
Hi all! I am developing my own device with esp32 chip as CPU. This device has various peripherals on different buses such as i2c and spi. Some of the peripherals also have GPIO connections for interrupts.
I want to make an emulator of my device using QEMU. I am new to QEMU programming and have a vague understanding of the QEMU architecture and the ESP32 virtual machine in particular.
For example, I wrote a simple device for the i2c bus and connected it to an esp32 machine:
Code: Select all
static void esp32_machine_init_bic_peripherals( Esp32SocState* s ){
DeviceState* i2c_master = DEVICE(&s->i2c[0]);
I2CBus* i2c_bus = I2C_BUS( qdev_get_child_bus(i2c_master, "i2c") );
I2CSlave* bicPhoneKeyboard;
qemu_irq irq;
DeviceState* deviceState;
bicPhoneKeyboard = i2c_slave_create_simple( i2c_bus, "bic-phone-keyboard", 0x58 );
deviceState = DEVICE( bicPhoneKeyboard );
irq = qdev_get_gpio_in( DEVICE(&s->intmatrix), ETS_GPIO_INTR_SOURCE );
qdev_connect_gpio_out( deviceState, 0, irq );
}
I also looked into the file /hw/gpio/esp32_gpio.c. Read and write functions do not appear to be implemented. https://github.com/espressif/qemu/blob/ ... gpio.c#L24 Now I'm completely confused and don't know which direction to go next. Ideally, I'd like to see documentation, but as far as I understand, there simply isn't any. If anyone has any information on how to properly connect devices to the machine using GPIO, i2c and SPI, please share the information. Ideally, I would like to be able to connect devices using qemu launch options.