Commit Graph

4831 Commits

Author SHA1 Message Date
Pavel Burgr b420a8be17 Puya PY32F MCU support (#5106)
* pinout yamls removed

* machine: implement default UART pin configuration for Embedfire boards

* flash command moved to chip level so VS Code plugin can select bare chip

* machine: add support for alternate pin mode configuration

* add build targets for embedfire on py32

* add support for embedfire target in GNUmakefile for py32

* lib/py32-svd: remove duplicate DBGMCU.IDCODE CODE field

Update submodule to fix duplicate SetIDCODE/GetIDCODE method
declarations in the generated py32f002bxx.go device file.

* update subproject commit reference in py32-svd

* refactor: update CPU frequency handling in machine and runtime packages

* refactor: replace ConfigureUARTPin function with direct pin configuration in UART setup

* SetAltFunc documentation for GPIO pin alternate functions

* refactor: improve UART write and flush error handling with timeout

* machine/py32: generalize UART driver to any USART

Add a per-instance setup func to the UART type so the driver is no longer
hardwired to USART1. DefaultUART stays USART1; add UART2 (USART2) in a
separately build-tagged file since py32f002x parts lack USART2. RX IRQ
handlers reference runtime-assigned vars to break the init cycle, and setup
is assigned in the var initializer so it runs before InitSerial.

Add the py32f003_32k_4k target (32K flash / 4K RAM).

* Add canonical PY32F002, F003, and F030 density targets

Use CMSIS/pyocd device names for target files and build tags. Add all F003 and F030 densities plus F002A/B, correct F002B to 24K flash and its own startup file, fix the F030x8 pyocd target, and update Embedfire inheritance.

* Add targets for all PY32 CMSIS devices

* Support all PY32 register layout variants

* machine/py32: use generated register definitions

* machine/py32: fix alternate-function documentation

* machine/py32: report the configured CPU frequency

* machine/py32: use unsafe.Add for GPIO ports

* machine/py32: bound and yield UART polling

* machine/py32: configure UART pins from UARTConfig

* build: use the current PY32 SVD repository URL

* test: cover PY32 UART register layouts

* machine/py32: restore dynamic CPU frequency tracking

* machine/py32: share the USART TX-ready bit

* targets/py32: scale system stacks with RAM

* machine/py32: keep clock state internal

* targets/py32: normalize generated metadata

* machine/py32: normalize GPIO configuration

* machine/py32: fix T020 UART setup

* machine/py32: reduce clock variant files

* machine/py32: clean up UART variants

* machine/py32: decouple UART clock capability

* lib/py32-svd: use organization repository

* runtime/py32: name 24MHz HSI encodings

* machine/py32: derive startup clock from capability

* machine/py32: use generated USART clock mask

* machine/py32: name T020 8-bit UART mode

* ci: include PY32 in sharded smoke tests

* runtime: remove PY32 HSI frequency workaround
2026-08-29 08:41:43 +02:00
Matthew Hiles f6e502e121 UEFI: add support for tasks scheduler and make it default (#5553)
* add support for UEFI time and UEFI events; fix STOP \n -> \r\n conversion

* make it so both scheduler=none and scheduler=tasks works

* address pr comments
  - Renamed/shared the amd64 Win64 ABI task stack Go file for both Windows and UEFI.
  - Deleted the duplicate UEFI task stack Go file and old Windows-suffixed Go file.
  - Added task_stack_amd64_windows.S unconditionally to targets/uefi-amd64.json.
  - Removed the UEFI ExtraFiles() special case from compileopts/config.go.
  - Added a scheduler.none tinygo_task_exit stub.
  - Removed the custom UEFI sleep override so normal scheduler sleep queue is used.

* revert back to simpler return value for ExtraFiles()

* create uefi specific tasks_none file

* remove unused sleepSchedulerCustom stuff

* add back the uefi tag

* lib: restore macos-minimal-sdk pointer
2026-08-28 19:48:48 +02:00
Pat Whittingslow f924a9e3ea Add agents.md guideline for using ASD-STE100 in documentation and discourse (#5566)
* Add agents.md guideline for using ASD-STE100 in documentation

* @deadprogram success story

* Rename agents.md to AGENTS.md
2026-08-28 17:42:58 +02:00
deadprogram b9577ac8aa net: update net submodule from latest changes
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-28 11:27:07 +02:00
Ron Evans a213d9ae46 ci: run the full smoke test once, and split the GNUmakefile (#5616)
* GNUmakefile: split into topic files in make/

The GNUmakefile had 1295 lines and mixed build configuration, LLVM
bootstrapping, device generation, four test suites, the smoke tests,
release packaging, and lint tools. The smoke tests alone were 500 lines.

Move each part into its own file in make/ and include them from
GNUmakefile. config.mk must be included first because the other files
use its variables in immediate assignments and conditionals.

There is no change in behavior. The parsed make database is identical
for the default build and for ASSERT=1, STATIC=1, XTENSA=0, STM32=0,
WASM=0, and CROSS=aarch64-linux-gnu, except for MAKEFILE_LIST and the
.PHONY list, which now also includes targets that were phony but not
declared.

The Dockerfile copies GNUmakefile alone before it builds LLVM, to keep
that layer independent of the source tree. It must copy make/ too.

* make/smoketest.mk: split into groups and add smoketest-quick

The smoke test was one recipe of about 500 lines with 236 builds that
always ran in sequence. Split it at the group boundaries that were
already there, so that:

- `make -j smoketest` builds the groups in parallel. A full run goes
  from 325 to 91 seconds on a 32 core machine.
- CI can shard the groups across runners.

Each group writes to its own name in build/smoke/, because all builds
wrote to test.hex before and would overwrite each other in a parallel
build. The output extension selects the format, so it stays per line.

Add smoketest-quick, which builds one board for each processor
architecture. The full smoke test answers "can TinyGo build for every
board", which does not depend on the host OS, so it only needs to run
on one OS. The other jobs use smoketest-quick.

The comment above the esp32c3 group had 4 spaces of indentation instead
of a tab. That was harmless in the middle of a recipe, but it is now the
first line of a group, where it would stop the recipe from starting.

The set of build commands is unchanged for the default flags and for
XTENSA=0, STM32=0, and WASM=0. All 226 checksums are the same as before,
for a sequential build and for `make -j16`.

* ci: run the full smoke test once, on Linux only

The smoke test ran six times for each push: twice on Linux, twice on
macOS, once on Windows, and once in the compatibility test. Together
that was about 97 minutes of the CI time.

The smoke test checks that TinyGo can build a binary for each board.
That does not depend on the host OS. The only part that does is one
build behind a Windows check.

Add a smoketest-linux job that runs the full set, split across four
runners that use the tarball from the build-linux job. The groups are
balanced with the measured build time of each group. Remove the full
smoke test from test-linux-build, which the new job replaces, and use
smoketest-quick for the other four jobs.

Expected result: about 55 to 39 minutes for the slowest workflow, and
about 97 to 35 minutes of total smoke test time.

* make/smoketest.mk: build nintendoswitch in smoketest-quick

It is the only target that uses the aarch64 LLVM triple. With it,
smoketest-quick covers all 13 triples that the full smoke test uses.
2026-08-28 09:08:26 +02:00
Patricio Whittingslow ac98a3df85 targets:wasm_exec.js set _pendingEvent to null 2026-08-27 20:32:13 +02:00
deadprogram 86d58db1af lib: update macos-minimal-sdk to v0.1.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-27 09:09:19 +02:00
Felipe Gené 31fff2c9a3 runtime: run syscall/js finalizers on wasm without a manual GC (#5545)
* runtime: run syscall/js finalizers on wasm without a manual GC

* runtime: address review feedback on finalizer idle GC

* runtime: clear a finished task's args pointer so its arguments are collectable

* runtime: skip the finalizer scan with a per-block registration bit

* runtime: guard the finalizer registration bitmap with gcLock

* testdata: cover finalizer invariants on every scheduler

* main_test: limit the finalizer scheduler variants to linux and darwin

* testdata: wait for the finalizer queue to drain before asserting

* testdata: make the finalizer counters atomic and wait for a known drain count

* runtime: add finalizer bookkeeping asserts under runtime_asserts

* runtime: address finalizer GC review feedback

* testdata: strengthen blocked stack finalizer test

* runtime: fix finalizer cleanup edge cases

* runtime: decouple wasm export scheduling from finalizers

* runtime: avoid redundant wakeups for re-entrant wasm exports

* runtime: simplify finalizer comments
2026-08-26 20:03:44 +02:00
deadprogram 8d6240a5e6 modules: update espflasher with version including fixes for esp32c3/esp32s3
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-26 15:37:27 +02:00
Jake Bailey 8f8ce06594 builder: convert TestBinarySize to a golden file test 2026-08-26 13:00:31 +02:00
V 840af7a842 machine/esp32: add ADC driver (#5595)
* machine/esp32: add ADC driver

Implements ADC1 on the Xtensa ESP32: InitADC, Configure and Get for
GPIO36, GPIO37, GPIO38, GPIO39, GPIO32, GPIO33, GPIO34 and GPIO35
(channels 0-7). The ADC pins are not contiguous on this chip, so the
pin to channel mapping is a lookup rather than arithmetic as on the
ESP32-S3.

Conversions are driven by the RTC controller under software control,
and Get returns the 12-bit sample scaled to 0..65520 to match the
other ESP ADC drivers.

The analog pads are spread over three unrelated RTC_IO registers
(SENSOR_PADS, XTAL_32K_PAD and ADC_PAD), so pad setup is kept local to
this file rather than adding a PinAnalog mode to machine_esp32.go.
That keeps the change to a single file.

Values are raw and uncalibrated. Unlike the ESP32-C3, S3 and C6
drivers there is no eFuse or self-calibration step; accurate voltage
mapping should be done with a two-point calibration in user code.

ADC2 is not implemented. On the ESP32 it is shared with the Wi-Fi
radio and cannot be used reliably while the radio is active.

Tested on an ESP32 Coreboard V2 with a photoresistor divider on
GPIO36. Readings swept 5056..59824 over the light range, all eight
channels returned independent values, and an invalid pin returned an
error from Configure and 0 from Get.

Signed-off-by: zombieleet <osikwemhev@gmail.com>

* fix: use package level err definiition and return (uint32, bool) from adcRTCGPIO

---------

Signed-off-by: zombieleet <osikwemhev@gmail.com>
2026-08-25 13:24:05 +02:00
deadprogram 242f34d71a esp32s3: fix register-window corruption under interrupt load
Remove the C3 bluetooth hook addresses from esp32s3.ld (on the S3 they
point into the ROM md5/crc thunk table, and being bare assignments they
also shadowed the blob's own definitions), keep the interrupt frame clear
of the 16-byte windowed-ABI save area below SP, and make tinygo_swapTask
hold INTLEVEL across the stack switch while keeping the running frame's
WINDOWSTART bit set.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-23 21:29:21 +02:00
Moses Narrow f71b63053c reflect: skip the MakeChan panic cases on every wasm target, not just wasip1
The guard was on runtime.GOOS == "wasip1", so under wasip2 the three cases that
rely on recover ran anyway. recover does not work on wasm yet, so the panic
escaped and trapped the test binary — which is the tinygo-test-wasip2-fast
failure on this PR.

Checked on runtime.GOARCH instead, since the limitation is wasm's rather than
any one platform's. wasip1, wasip2 and js/wasm all set the tinygo.wasm build
tag, and arch_tinygowasm.go defines GOARCH as wasm for it, so one condition
covers all three of the wasm test targets.

Worth noting for anyone reading targets/wasip2.json: the goarch there is arm,
but that is what is handed to the Go toolchain for package selection —
runtime.GOARCH is the one above.
2026-08-20 17:11:24 -07:00
Moses Narrow 1579b235e8 reflect: implement MakeChan
TinyGo had MakeMap/MakeSlice but not MakeChan. Implement it via the runtime
chanMake primitive (mirroring MakeMap), so packages that call reflect.MakeChan
(e.g. github.com/ugorji/go/codec used by gin) compile and work.
2026-08-20 17:11:24 -07:00
rdon-key af429a597b interp: mark pointers in aggregate call operands as external 2026-08-20 19:01:03 +02:00
sago35 93bc65479f machine: add USBDevice.Attach and USBDevice.Detach (#5563)
* machine: add USBDevice.Attach and USBDevice.Detach

The USB device is attached to the bus automatically during startup,
before user code has a chance to finish its USB configuration (device
identifiers, extra HID interfaces, ...). Composite devices such as
keyboards may therefore be enumerated by the host with an incomplete
configuration.

Attach and Detach expose the soft-connect control (DP pull-up) so that
an application or library can detach in an init function, complete its
configuration, and attach again to let the host enumerate the finished
device. They can also be used to force re-enumeration without
replugging the cable.

Implemented for atsamd21, atsamd51, nrf52840, rp2040 and rp2350.

* machine: make USB Detach sticky on nrf52840

The USB IRQ handler re-enables the DP pull-up on every power-ready
event, silently undoing an earlier Detach. Guard the pull-up write with
a detached flag so the device stays off the bus until Attach is called.

* machine: add USB Attach and Detach to stm32 and esp32 targets

- stm32f4, stm32f7, stm32h7: implement Attach and Detach using the
  DCTL soft-disconnect bit that Configure already toggles.
- esp32c3, esp32c6, esp32s3: add no-op stubs to keep user code
  portable; the fixed-function USB Serial/JTAG controller has no
  software-controlled soft-connect.

* machine: use Attach and Detach in USB Configure

Replace the direct soft-connect register writes in Configure with the
equivalent Attach and Detach calls on atsamd21, atsamd51, rp2040,
rp2350, stm32f4, stm32f7 and stm32h7.
2026-08-20 17:17:33 +02:00
Jake Bailey 1958d6ff9d test: run ESP32 programs in QEMU 2026-08-20 16:07:13 +02:00
Jake Bailey 1991b00395 builder: fix ESP32 QEMU XIP image offsets 2026-08-20 16:07:13 +02:00
deadprogram ada22bc691 all: build/test using Go 1.27.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-20 14:27:13 +02:00
deadprogram e3bf9306b3 Revert "chore: copy fix to esp32xx"
This reverts commit 6cd0c00060.
2026-08-20 12:53:31 +02:00
Navendu Pottekkat 6cd0c00060 chore: copy fix to esp32xx
Signed-off-by: Navendu Pottekkat <navendu@apache.org>
2026-08-20 10:20:11 +02:00
Navendu Pottekkat dc97300c2e fix: remove incorrect !readLast check
Signed-off-by: Navendu Pottekkat <navendu@apache.org>
2026-08-20 10:20:11 +02:00
deadprogram 6136fb7b95 test: skip asn1 nesting-limit tests, and BoundarySlices crypto tests
Skip TestUnmarshalNestingLimitSlice/Struct, which fails due to the nesting limit
added in golang/go@6a6d115f9a.

Since Go 1.27 the crypto hash tests go through cryptotest.TestHash, which
calls cryptotest.BoundarySlices. Targets reporting GOOS=linux build
boundary.go (//go:build linux || darwin) instead of boundary_compat.go, and
that needs a working syscall.Mmap/syscall.Mprotect:

* baremetal fails to compile: undefined: syscall.Mprotect
* wasip2 gets ENOSYS from syscall.Mmap, and since t.Fatalf cannot Goexit on
  wasm the test falls through and panics with "slice out of range"

Exclude crypto/md5, crypto/sha1, crypto/sha256 and crypto/sha512 from both.
wasip1 reports GOOS=wasip1, gets the boundary_compat.go fallback, and keeps
testing all four.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-19 08:39:13 -07:00
deadprogram f21e027b5c all: build/test using Go 1.27-rc3
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-08-19 08:39:13 -07:00
Moses Narrow ac45c35924 os: add File.Chown on the unix path
file_unix.go (darwin/linux/wasip) was missing the exported (*File).Chown method
that file_other.go (baremetal/wasm) already has, so callers requiring the full
os.File surface — e.g. github.com/pkg/sftp — failed to compile for the
linux/amd64 TinyGo target. Delegates to the package-level Chown, mirroring
(*File).Truncate.
2026-08-18 14:18:42 -07:00
Moses Narrow 338af91ae6 runtime: implement MemStats.NumGC
Reading runtime.MemStats.NumGC is common enough in dependency code that its
absence is a compile error for programs that never look at the value. Rather
than add the field as a constant zero, track it:

- gc_blocks: count completed cycles in runGC, so collections triggered by an
  allocation are counted as well as explicit runtime.GC() calls. The counter is
  read and written under gcLock, like the other counters beside it.
- gc_boehm: report bdwgc's own gc_no from the prof_stats struct.
- gc_leaking: always 0, since that collector never completes a cycle.
2026-08-18 14:18:29 -07:00
v1rtl d74f70bdd0 os, syscall: add Statfs/Fstatfs stubs and Getpagesize for non-hosted targets 2026-08-18 14:18:19 -07:00
Navendu Pottekkat 80506a9cea esp32: fix pullup/pulldown on RTC GPIO pins
Signed-off-by: Navendu Pottekkat <navendu@apache.org>
2026-08-16 06:45:06 -07:00
Jake Bailey c33682cf00 builder: build SSA before compiling packages 2026-08-14 11:56:40 -07:00
Jake Bailey 570a3deac2 tests: normalize LLVM IR when updating goldens 2026-08-14 11:56:25 -07:00
Damian Gryski c4219439eb runtime: make arrays and struct field hashes order dependent 2026-08-12 12:08:52 -07:00
Konstantin Sharlaimov 7a9c649268 fix(gc): pause all cores before scanning stack and globals.
In gcMarkReachable, busy-wait for other cores to enter the interrupt handler and pause before scanning the GC core's stack or globals. Prevents data race where a running core relocates heap references to globals during mark phase.
2026-08-09 12:11:59 -07:00
Konstantin Sharlaimov 213d10838f fix(gc): correct leaking allocator bounds and overflow checks.
Change heap-end comparison to > to prevent spurious OOM when heapptr exactly matches heapEnd. Add overflow check to prevent heap wrapping.
2026-08-09 12:11:59 -07:00
Konstantin Sharlaimov b573ef3813 fix(gc): correct old size calculation in block realloc.
Using blocksPerStateByte instead of bytesPerBlock caused the old size to be underestimated for multi-block allocations, leading to data truncation on growing reallocations.
2026-08-09 12:11:59 -07:00
Mohammed-Asad-Khan 854f91ecf2 Fix to allow -o flag to point to a directory
Previously, running 'tinygo build -o dist/ file.go' where dist/ already
exists as a directory failed with 'open dist/: is a directory', because
Build() only auto-derived a binary name when outpath was empty, not when
it pointed to an existing directory. This adds that check, matching the
behavior of 'go build -o dir/' with a package.

Note: only handles the case where the directory already exists; if the
directory doesn't exist yet, behavior is unchanged.
2026-08-05 07:17:00 -07:00
deadprogram c2346570fb targets/esp32*: add espradio tag for convenience
This add the `espradio` build tag to all ESP32C3,
ESP32S3, and ESP32 boards, since they all have support
for wireless communication using espradio. This
just makes it to people do not have to remember to use
the build tag, the same as we have done with both
`ninafw` and `cyw43439` build tags.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-07-30 02:03:13 +02:00
deadprogram 169daed2a1 main: update to espflasher 0.8.0
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-07-28 13:57:25 +02:00
deadprogram cd5e2580c1 targets/esp32c3: add remaining required BT ROM functions to linker
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-07-28 12:11:11 +02:00
deadprogram 8b3200cec8 targets/esp32c3: add BT ROM functions to linker
Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-07-27 17:34:22 +02:00
deadprogram b0298c6a69 targets/esp32: add .rxring and .wifibss sections to DRAM1
Place espradio's RX ring buffer and WiFi-only BSS (ISR tables,
timer slots, ISR ring) in SRAM1 pool 7/6 ahead of the arena.
Frees ~14 KB of SRAM2 for the Go GC heap. The arena assertion
still guarantees ≥32 KB remains for WiFi DMA buffers.

Signed-off-by: deadprogram <ron@hybridgroup.com>
2026-07-25 17:42:01 +02:00
rdon-key 0fe4c619eb runtime: prevent timer starvation in cores scheduler 2026-07-25 10:02:09 +02:00
Jake Bailey 16fc1ea2bb runtime: make fatal failures unrecoverable
Match the Go runtime by terminating for deadlocks, stack overflows,
runtime and GC invariants, invalid lock operations, and platform
initialization failures instead of routing them through panic/recover.

Keep language-level runtime errors and unsupported user operations
recoverable. Add crash coverage that verifies fatal errors bypass deferred
recover calls.
2026-07-25 07:14:00 +02:00
Jake Bailey 9105cce340 runtime: make out-of-memory failures fatal
Match the Go runtime by terminating instead of unwinding when an
allocator exhausts the heap. Recovering an OOM can leave allocator locks
held and cannot safely continue when the panic path itself needs memory.
2026-07-25 07:14:00 +02:00
Jake Bailey 7756941f39 main_test: skip flaky goroutines test on threaded schedulers 2026-07-24 20:50:26 +02:00
Matthew Hiles 259842dc2e UEFI: Add support for UEFI time and UEFI events; fix STOP \n -> \r\n conversion (#5549)
* add support for UEFI time and UEFI events; fix STOP \n -> \r\n conversion

* apply EFI timezone offset
2026-07-24 19:29:42 +02:00
Jake Bailey 528476f2b3 compiler, runtime: support recover on riscv64 2026-07-24 08:55:49 +02:00
rdon-key 0c68e1215e runtime: add critical-section fallbacks for atomic And and Or 2026-07-23 18:53:35 +02:00
Matthew Hiles 9c2eafce6f targets: minimal uefi target support (#5452)
* runtime: split baremetal memory setup

* runtime: extract Windows PE globals scan helper

* compileopts,builder: add target linker flavor override

* machine,runtime,targets: add minimal uefi-amd64 target

* runtime,examples: add clean UEFI exit path test

* machine,x86: fix amd64 ABI stack handling

* machine/uefi: add CHAR16 conversion helpers

* machine/uefi: add loaded image protocol support

* runtime: add UEFI PE globals support

* machine,runtime,x86: add UEFI time and text output support

* machine,runtime,x86: add UEFI text and time support

* machine,runtime,examples: add UEFI text input support

* machine,examples: add UEFI graphics output support

* add rest of STOP methods (direct UEFI ABI only)

* runtime: fix UEFI sleep tick conversion

* machine/uefi: make text input waits cooperative

* address TestClangAttributes/uefi-amd64 failure

* address TestConfigLinkerFlavor bug

* uefi: move raw bindings to device package

* strip down implementation to bare minimum

* amd64: rename x86 package

* do git restore upstream/dev for src/net

* add smoketest for uefi-amd64; add required zeroSizeAllocPtr constant

* address PR issues: remove unused files; make putchar() insert '\r' before '\n'

* swap lines around
2026-07-23 14:34:18 +02:00
Konstantin Sharlaimov 3797e89600 feat(machine/stm32): add STM32H7 and NUCLEO-H753ZI support 2026-07-23 12:29:44 +02:00
Konstantin Sharlaimov 40ed956d6c src/device/arm: add ARM v7-M MPU support 2026-07-23 12:29:44 +02:00