Skip to content

Commit ba290e2

Browse files
authored
Merge pull request #1536 from luoliwoshang/feat/esp32c3-emulator-support
feat(esp32c3): QEMU emulator support
2 parents b03e16f + 9d6314c commit ba290e2

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

internal/firmware/esp.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@ func makeESPFirmareImage(infile, outfile, format string) error {
8484
}
8585

8686
if makeImage {
87-
// The bootloader starts at 0x1000, or 4096.
88-
// TinyGo doesn't use a separate bootloader and runs the entire
89-
// application in the bootloader location.
90-
outf.Write(make([]byte, 4096))
87+
// For QEMU emulation, we need to place the image at the correct offset.
88+
// ESP32 (Xtensa): bootloader starts at 0x1000, so we pad 4KB of zeros.
89+
// ESP32-C3 (RISC-V): bootloader starts at 0x0, so no padding needed.
90+
if chip == "esp32" {
91+
outf.Write(make([]byte, 4096))
92+
}
9193
}
9294

9395
// Chip IDs. Source:

targets/esp32c3-basic.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"inherits": [
3+
"riscv32-esp"
4+
],
5+
"features": "+32bit,+c,+m,+zmmul,-a,-b,-d,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-f,-h,-relax,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xesppie,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
6+
"build-tags": [
7+
"esp32c3",
8+
"esp"
9+
],
10+
"serial": "usb",
11+
"rtlib": "compiler-rt",
12+
"libc": "newlib-esp32",
13+
"linkerscript": "targets/esp32c3.memory.ld",
14+
"binary-format": "esp32c3",
15+
"flash-command": "esptool.py --chip=esp32c3 --port {port} write_flash 0x0 {bin}",
16+
"serial-port": [
17+
"303a:1001"
18+
],
19+
"openocd-interface": "esp_usb_jtag",
20+
"openocd-target": "esp32c3",
21+
"openocd-commands": [
22+
"gdb_memory_map disable"
23+
],
24+
"gdb": [
25+
"riscv32-esp-elf-gdb"
26+
],
27+
"emulator": "qemu-system-riscv32 -machine esp32c3 -nographic -drive file={img},if=mtd,format=raw -serial mon:stdio"
28+
}

targets/esp32c3.json

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,8 @@
11
{
22
"inherits": [
3-
"riscv32-esp"
3+
"esp32c3-basic"
44
],
5-
"features": "+32bit,+c,+m,+zmmul,-a,-b,-d,-e,-experimental-smmpm,-experimental-smnpm,-experimental-ssnpm,-experimental-sspm,-experimental-ssqosid,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-f,-h,-relax,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-v,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xesppie,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecdiscarddlone,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zicsr,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-ztso,-zvbb,-zvbc,-zve32f,-zve32x,-zve64d,-zve64f,-zve64x,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl128b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl32b,-zvl4096b,-zvl512b,-zvl64b,-zvl65536b,-zvl8192b",
6-
"build-tags": [
7-
"esp32c3",
8-
"esp"
9-
],
10-
"serial": "usb",
11-
"rtlib": "compiler-rt",
12-
"libc": "newlib-esp32",
13-
"linkerscript": "targets/esp32c3.memory.ld",
145
"extra-files": [
156
"targets/device/esp/esp32c3.c"
16-
],
17-
"binary-format": "esp32c3",
18-
"flash-command": "esptool.py --chip=esp32c3 --port {port} write_flash 0x0 {bin}",
19-
"serial-port": [
20-
"303a:1001"
21-
],
22-
"openocd-interface": "esp_usb_jtag",
23-
"openocd-target": "esp32c3",
24-
"openocd-commands": [
25-
"gdb_memory_map disable"
26-
],
27-
"gdb": [
28-
"riscv32-esp-elf-gdb"
297
]
308
}

0 commit comments

Comments
 (0)