Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【物联网设备端开发】ESP开发工具:QEMU如何模拟以太网口接入网络

【物联网设备端开发】ESP开发工具:QEMU如何模拟以太网口接入网络

作者头像
帐篷Li-物联网布道师
发布于 2024-08-17 00:25:42
发布于 2024-08-17 00:25:42
45700
代码可运行
举报
运行总次数:0
代码可运行

以太网口支持

ESP-IDF中添加了对Opencores以太网MAC的支持。

  • 运行以太网示例时,启用CONFIG_EXAMPLE_CONNECT_ETHERNETCONFIG_EXAMPLE_USE_OPENETH.。
  • 运行自定义应用程序时,启用CONFIG_ETH_USE_OPENETH 并初始化以太网驱动程序,如示例 /common_components/protocol_example.common/connect.c 中所示(查找 esp_eth_mac_new_openeth)。

启动QEMU时,使用open_eth网络设备。

用户模式网络

例如,要在用户模式下启动网络(仅TCP/UDP,模拟设备位于NAT之后),请在QEMU命令行中添加以下选项:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-nic user,model=open_eth

一些ESP项目(特别是运行TCP侦听器)可能需要设置端口转发,

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-nic user,model=open_eth,id=lo0,hostfwd=tcp:127.0.0.1:PORT_HOST-:PORT_GUEST

(例如,asio-echo服务器默认在2222上设置服务器,因此hostfwd=tcp:127.0.0.1:22222-:2222 允许从主机访问 nc localhost 2222

指定引导模式

要指定所需的 strapping 模式, 在运行QEMU时需要添加以下参数:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-global driver=esp32.gpio,property=strap_mode,value=0x0f

这将设置 GPIO_STRAP 寄存器的值。

  • 使用 0x12 作为闪存启动模式(默认)
  • 0x0f 用于仅UART下载模式(因为SDIO部分未实现)

Specifying eFuse storage

Add extra arguments to the command line:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-drive file=qemu_efuse.bin,if=none,format=raw,id=efuse
-global driver=nvram.esp32.efuse,property=drive,value=efuse

The first argument creates a block device backed by qemu_efuse.bin file, with identifier efuse. The second line configures nvram.esp32.efuse device to use this block device for storage.

The file must be created before starting QEMU:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
dd if=/dev/zero bs=1 count=124 of=/tmp/qemu_efuse.bin

124 bytes is the total size of ESP32 eFuse blocks.

Note

Specifying eFuse storage is mandatory to test out any platform security features like “Secure Boot” or “Flash Encryption”.

Emulating ESP32 ECO3

For the application to detect the emulated chip as ESP32 ECO3, the following virtual efuses must be set:

  • CHIP_VER_REV1
  • CHIP_VER_REV2

Here is the corresponding efuse file (in hexadecimal, produced using xxd -p):

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
000000000000000000000000008000000000000000001000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000
00000000

To convert this (efuse.hex) back to binary, run xxd -r -p efuse.hex qemu_efuse.bin.

Alternatively, these bits can be set using espefuse:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
espefuse.py --port=socket://localhost:5555 burn_efuse CHIP_VER_REV1
espefuse.py --port=socket://localhost:5555 burn_efuse CHIP_VER_REV2

Disabling the watchdogs

By default, Timer Group watchdog timers are emulated, and TG0 WDT is enabled at reset. It is sometimes useful to disable these watchdog timers. This can be done by adding the following to the command line:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-global driver=timer.esp32.timg,property=wdt_disable,value=true

This disables the emulation of TG watchdog timers. Even if the application configures them, they will not fire.

The RTC watchdog timer is not emulated yet, so it doesn’t need to be disabled.

Using esptool.py and espefuse.py to interact with QEMU

Start QEMU:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
build/qemu-system-xtensa -nographic \
    -machine esp32 \
    -drive file=flash_image.bin,if=mtd,format=raw \
    -global driver=esp32.gpio,property=strap_mode,value=0x0f \
    -drive file=qemu_efuse.bin,if=none,format=raw,id=efuse \
    -global driver=nvram.esp32.efuse,property=drive,value=efuse \
    -serial tcp::5555,server,nowait

The final line redirects the emulated UART to TCP port 5555 (QEMU acts as a server).

Type q and press Enter at any time to quit.

Run esptool.py:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
esptool.py -p socket://localhost:5555 flash_id

Flashing with idf.py also works:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
export ESPPORT=socket://localhost:5555
idf.py flash

Or, run espefuse.py:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
espefuse.py --port socket://localhost:5555 --do-not-confirm burn_custom_mac 00:11:22:33:44:55

Note: esptool can not reset the emulated chip using the RTS signal, because the state of RTS is not transmitted over TCP to QEMU. To reset the emulated chip, run system_reset command in QEMU console (started at step 1).

Specifying ROM ELF file

If -kernel and -bios arguments are not given, ESP32 (rev. 3) ROM code will be loaded. This ROM code binary is included in the repository. To specify the ROM code ELF file to load, pass the filename with a -bios <filename> argument.

Using flash encryption

Self-encryption workflow

In the IDF application, enable CONFIG_SECURE_FLASH_ENC_ENABLED through menuconfig, and build it

Build the flash image as per the instructions from the Compiling the ESP-IDF program to emulate section.

Create qemu_efuse.bin as highlighted in the Specifying eFuse storage section.

Execute qemu-system-xtensa using the following command:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
build/qemu-system-xtensa -nographic -machine esp32 \
    -drive file=/path/to/qemu_efuse.bin,if=none,format=raw,id=efuse   \
    -global driver=nvram.esp32.efuse,property=drive,value=efuse       \
    -drive file=/path/to/flash_image.bin,if=mtd,format=raw            \
    -global driver=timer.esp32.timg,property=wdt_disable,value=true

Adding PSRAM

QEMU “memory size” option can be used to enable PSRAM emulation. By default, no PSRAM is added to the machine. You can add 2MB or 4MB PSRAM using -m 2M or -m 4M command line options, respectively.

Note that PSRAM MMU is not emulated yet, so things like bank switching (himem in IDF) do not work.

Using SD cards

QEMU emulates SD/MMC host controller used in ESP32. To add an SD card to the system, create an image and pass it to QEMU.

Create a raw image file, for example, 64 MB:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
$ dd if=/dev/zero bs=$((1024*1024)) count=64 of=sd_image.bin

Add the following argument when running QEMU:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
-drive file=sd_image.bin,if=sd,format=raw

If you need to create a large SD card image, it is recommended to use sparse cqow2 images instead of raw ones. Consult QEMU manual about qemu-img tool for details.

Only one SD card is supported at a time. You can use either slot 0 or slot 1 of the SD/MMC controller in the application code.

Enabling graphical user interface (GUI)

The ESP32 QEMU implementation implements a virtual RGB panel, absent on the real hardware, that can be used to show graphical interface. It is associated to a virtual frame buffer that can be used to populate the pixels to show. It is also possible to use the target internal RAM as a frame buffer.

To enable the graphical interface, while keeping the serial output in the console, use the following command line:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
build/qemu-system-xtensa \
    -machine esp32 \
    -drive file=flash_image.bin,if=mtd,format=raw
    -display sdl \
    -serial stdio

If gtk backend was enabled when compiling QEMU, it is possible to replace -display sdl with -display gtk

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-08-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
【物联网设备端开发】ESP开发工具:QEMU的使用方法
本文提供了一些运行QEMU的ESP特定说明。有关QEMU的一般使用问题,请参阅官方文档:https://www.qemu.org/documentation/.
帐篷Li-物联网布道师
2024/08/17
8540
如何利用ESP32-Cam制作个IP-Camera【microPython】
代码地址:https://github.com/ITJoker233/Esp32-Cam_IP_Camera
ITJoker
2022/08/30
1.7K0
Dji TT无人机扩展件ESP32芯片(D2WDQ5)
因为最近在做一个无人机辅助的操控装置,大的无人机不方便调试,就目光又转向了TT,所以需要不停的刷写程序,所以又燃起了对扩展件的研究欲望。上面的日志来自于烧录时,里面已经有了很多有趣的东西了,主要时芯片。
云深无际
2021/06/25
1.7K0
Dji TT无人机扩展件ESP32芯片(D2WDQ5)
【物联网设备端开发】Arduino快速上手esp32方案开发
ESP32是Espressif Systems推出的一款高性能、低功耗的Wi-Fi和蓝牙双模系统级芯片(SoC),广泛应用于物联网、智能家居、可穿戴设备等领域。它基于极低功耗的Tensilica Xtensa LX6微处理器,并集成了丰富的外设和传感器接口。以下是ESP32芯片的主要特性:
帐篷Li-物联网布道师
2024/03/20
1.2K0
【物联网设备端开发】Arduino快速上手esp32方案开发
【物联网设备端开发】使用QEMU模拟ESP硬件运行ESP-IDF
进入乐鑫 ESP-IDF Windows Installer Download 下载页面,选择ESP-IDF v4.4.8离线安装包,然后进行安装。
帐篷Li-物联网布道师
2024/08/09
7420
【物联网设备端开发】使用QEMU模拟ESP硬件运行ESP-IDF
VL53L0X激光测距传感器.ESP32使用篇
将ESP32与Arduino IDE搭配使用时,默认的I2C引脚为 GPIO 22 (SCL)和 GPIO 21 (SDA)
云深无际
2020/12/15
3.3K0
VL53L0X激光测距传感器.ESP32使用篇
esp32c3的系统底层启动分析
对于esp32的玩法,基本上定位都是做上层应用,乐鑫官方提供的ESP-IDF物联网开发框架已经十分的完善,做上层应用按照这套框架进行开发,完全不必了解底层的实现细节。作为一个深入研究riscv底层的爱好者来说,跳过ESP-IDF框架,直接像使用单片机一样去使用ESP32C3更加有意思。本文的目的就是理解ESP32C3的裸机开发流程,像玩单片机一样去使用这个riscv的mcu。
bigmagic
2021/07/23
3.8K0
【物联网设备端开发】ESP-IDF如何实现OTA升级
ESP-IDF(Espressif IoT Development Framework)是Espressif Systems为ESP32等芯片提供的官方开发框架,它支持多种功能,包括OTA(Over-The-Air)升级。OTA升级允许设备在运行时通过网络接收并安装新的固件,而无需物理连接。以下是使用ESP-IDF实现OTA升级的一般步骤:
帐篷Li-物联网布道师
2024/08/17
6050
esp32c3使用openocd调试程序
对于esp32c3裸机开发,用openocd结合gdb非常的有用,这是裸机开发的关键工具。
bigmagic
2021/08/20
3.7K0
ESP32 OTA详解-中文翻译版
ESP32应用程序可以在运行时通过Wi-Fi或以太网从特定的服务器下载新图像,然后将其闪存到某些分区中,从而进行升级。在ESP-IDF中有两种方式可以进行空中(OTA)升级:
小锋学长生活大爆炸
2020/08/13
4.5K0
ESP32 OTA详解-中文翻译版
ESP32 SPIFFS管理工具—spiffsgen.py
> 本文将介绍基于ESP32的SPIFFS文件系统制作工具的使用,以及烧录上传至开发板流程。
怪兽
2022/10/04
1.6K0
ESP32 SPIFFS管理工具—spiffsgen.py
【物联网设备端开发】ESP-IDF Modbus从站例子
此示例演示了使用FreeModbus协议栈来实现ESP32作为从站设备来进行通信, 该示例允许外部 Modbus主站使用 Modbus协议读取/写入的从站设备参数, “mb_example_common/modbus_params.h”头文件中,定义了可通过Modbus协议操作的参数,用户修改该文件来添加/删除自己的自定义参数。 这些在结构“holding_reg_params”、“input_reg_params”、“coil_reg_params”和“discrete_reg_params”中表示,分别用于保存寄存器、输入参数、线圈和离散输入。 app_main应用程序演示了如何启动Modbus协议,当参数发生变化时会通知主站设备。 FreeModbus 协议栈位于“components/freemodbus”文件夹中,包含“/port”文件夹,该文件夹中包含与 ESP32 连接的堆栈端口。 可以在 KConfig 文件中配置一些端口参数,以正确启动协议栈(有关详细信息,请参阅下面的说明)。
帐篷Li-物联网布道师
2024/03/20
4430
ESP32 DEVKILTv1(devkitv1)开发板全解析!!!(搭载芯片为ESP32D0WDQ6)
平时去淘宝买ESP32的开发板,20出头大概率是这个板子,那我们这篇就来完完整整的将芯片进行挖掘,解决我们的引脚配置,硬件设置等等相关的问题,以后不再纠缠相关的问题.
云深无际
2021/07/23
17.1K5
ESP32 DEVKILTv1(devkitv1)开发板全解析!!!(搭载芯片为ESP32D0WDQ6)
【物联网设备端开发】ESP-IDF设备自动配网方法和步骤
ESP-IDF设备自动配网是一个涉及ESP32芯片及其开发框架(ESP-IDF)的重要功能,它允许设备在没有用户干预的情况下自动连接到WiFi网络。以下是一个基于ESP-IDF的ESP32设备自动配网的示例,涵盖了主要步骤和概念。
帐篷Li-物联网布道师
2024/08/17
1.1K0
当DevOps撞上物联网
迄今为止,我们讨论的物联网的基础,基本上是寻常的互联网加上我们无法想象的节点数。我们也看到,在未来的几年中,能以各种形式联网的设备数量将继续呈指数增长。这一增长将是因特网的机器对机器部分。
博文视点Broadview
2020/06/12
9200
当DevOps撞上物联网
【物联网设备端开发】保姆级ESP-IDF开发环境搭建
进入乐鑫 ESP-IDF Windows Installer Download 下载页面,选择离线版本工具(网络原因,安装过程中使用github下载会出问题)。
帐篷Li-物联网布道师
2024/03/20
7460
【物联网设备端开发】保姆级ESP-IDF开发环境搭建
【物联网设备端开发】ESP-IDF Modbus 主站示例程序
这个示例展示了使用FreeModbus协议栈来实现ESP32作为主站设备来进行通信, 该示例能读取和写入连接到Modbus线路从站设备的属性值。所有需要访问的参数都在在Modbus主站示例源文件的数据字典中定义。 这些参数以属性的形式表示,每个属性都有其名称和属性ID ,这些属性与连接到Modbus线路的从站设备的寄存器相关联。 此外,该示例实现了一个简单的控制算法,用于检查从设备的参数。如果holding_data0参数的值超出限制,则会发出警报(在从设备中的继电器上)。 值得注意的是,modbus参数的实例对于主站和从站示例是通用的,它们都位于examples/protocols/modbus/mb_example_common文件夹中。
帐篷Li-物联网布道师
2024/03/20
5670
ESP32-I2C-Arduino
I2C (Inter-Integrated Circuit) 总线用于使 ESP32 和多个外部设备进行通信。多个外部设备可以共用一个 I 2C 总 线。
云深无际
2020/12/15
3K0
ESP32-I2C-Arduino
[ 物联网篇 ] ESP32 开发板 编译esp-avs
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/z2066411585/article/details/88955900
程序手艺人
2019/04/09
1.2K0
ESP32 DevKitC 编译烧写 AliOS Things
作者简介: 邵国际,计算机专业大四学生,擅长动手,热衷物联网。用技术表达自我,虽然是个玩过单片机的渣渣,但一直想做出好玩有趣的东西(软/硬件),并享受其中的乐趣。目前在深圳增长见识、学习嵌入式开发技术
刘盼
2018/03/16
6K1
ESP32 DevKitC 编译烧写 AliOS Things
推荐阅读
相关推荐
【物联网设备端开发】ESP开发工具:QEMU的使用方法
更多 >
交个朋友
加入腾讯云官网粉丝站
蹲全网底价单品 享第一手活动信息
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验