Skip to content

feature: add support for ESP32S3#19

Merged
deadprogram merged 8 commits intomainfrom
esp32s3-wifi
Apr 9, 2026
Merged

feature: add support for ESP32S3#19
deadprogram merged 8 commits intomainfrom
esp32s3-wifi

Conversation

@deadprogram
Copy link
Copy Markdown
Member

@deadprogram deadprogram commented Apr 7, 2026

This PR is to add support for the ESP32-S3 processor.

It required some changes to TinyGo from PR tinygo-org/tinygo#5283 which have been merged.

Works!

$ tinygo flash -target xiao-esp32s3 -ldflags="-X main.ssid=ssid -X main.password=passwordy" -size short -monitor ./examples/webserver/                                                                              
   code    data     bss |   flash     ram                                                                                                                                                                           
 870837   33584  348584 |  904421  382168
Connected to ESP32-S3                                                                                     
Flashing: 904528/904528 bytes (100%)
Connected to /dev/ttyACM0. Press Ctrl-C to exit.
load:0x4038a800,len:0xb360    
load:0x42038b34,len:0xa41ec                                                                               
SHA-256 comparison failed:                                                                                
Calculated: 6407b11582cb2b9d8c3fd675808d816c9521f18295da4b65f62ad262fbae02ee
Expected: 1821274ee9d7c1c5dada1c4df6b65dd961bda08c79acbcfd3b4ae47a2b838313
Attempting to boot anyway...                                                                              
entry 0x4038a88c                                                                                          
Connecting to WiFi...
HTTP server listening on http://192.168.1.241:80

Add ESP32-S3 (Xtensa LX7) WiFi blob libraries from esp-wifi and
platform-specific files:
- esp32s3/esp32s3.go: clock init, MAC read, PHY/WiFi isolation
- esp32s3/esp_phy_adapter.c: PHY calibration and register save/restore
- esp32s3/isr.c: interrupt vectoring for WiFi MAC
- radio_esp32s3.go: hardware init, ISR handler, per-target constants
- blobs/libs/esp32s3/: prebuilt WiFi/BT/PHY libraries

Remove .vscode/settings.json from version control.
Adapt shared radio, ISR, netif, and OSI code for both targets:
- radio.c: conditional phy_get_romfunc_addr (C3 only), manual
  wifi_init_config for Xtensa OR-offset workaround, WDT disable
  for both C3 (RISC-V registers) and S3 (Xtensa registers)
- radio.go: extract wifiISRHandler to per-target files, add arena
  pool init from Go heap, schedOnce with ROM pointer save/restore
- radio_esp32c3.go: direct ISR call, per-target arena pool size
- espradio.h: add espradio_arena_init declaration
- isr.c: support both RISC-V and Xtensa interrupt dispatch
- netif.c: ROM pointer save/restore, function table relocation
- osi.c: extended OSI function table for S3 blob compatibility
- examples/scan: minor adjustment for dual-target testing
Replace the static BSS arena with a proper allocator inside a pool
that Go allocates at startup (kept alive by a package-level variable
so the GC won't collect it).

The WiFi blob stores pointers in ROM BSS which is outside the GC's
scan range, so individual malloc'd objects get collected. A single
large pool kept reachable from Go avoids this.

Features:
- First-fit free-list with block splitting
- O(1) coalescing on free via boundary tags (header + footer)
- 8-byte aligned, min block 24 bytes
- realloc via alloc+memcpy+free with correct old-size tracking
- espradio_arena_stats walks all blocks for usage reporting
- __wrap_malloc/free/calloc/realloc on S3 route blob calls through arena
- Pool size: 32KB on C3 (limited DRAM), 80KB on S3
Add tools/patch_xtensa_literals.go to fix two Xtensa ELF relocation
issues that cause LLD to mislink WiFi blob .a libraries:

1. Propagate R_XTENSA_ASM_EXPAND addends to paired R_XTENSA_32
   literal pool entries (LLD ignores ASM_EXPAND relocations)
2. Move in-place addends into RELA r_addend fields for section-
   relative R_XTENSA_32 relocations (Xtensa GCC stores addends
   in-place; LLD expects them in r_addend per RELA convention)

Usage: go run tools/patch_xtensa_literals.go [-n] blobs/libs/esp32s3/*.a

Update Makefile with update-s3-blobs target.
Signed-off-by: deadprogram <ron@hybridgroup.com>
@dkegel-fastly
Copy link
Copy Markdown

What is the origin of those blobs? I always shudder when I see binary libraries checked into github.

Signed-off-by: deadprogram <ron@hybridgroup.com>
…omething happening

Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Copy Markdown
Member Author

What is the origin of those blobs? I always shudder when I see binary libraries checked into github.

I thought that was in the README, but it is https://github.com/esp-rs/esp-wifi-sys

Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Copy Markdown
Member Author

@deadprogram
Copy link
Copy Markdown
Member Author

Now merging, thanks everyone who helped with testing!

@deadprogram deadprogram merged commit a58e192 into main Apr 9, 2026
1 check passed
@deadprogram deadprogram deleted the esp32s3-wifi branch April 9, 2026 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants