Repository navigation
Commit adeb496
authored
examples/arduino: write the platform layer against Arduino, not Zephyr (pytorch#21992)
## Summary
The library shipped `runtime/platform/default/zephyr.cpp`, which calls
`k_uptime_ticks` and `k_malloc`. That pinned it to the one Arduino core
built on Zephyr, for seven functions that all have Arduino equivalents.
`arduino_pal.cpp` uses `micros()`, `malloc()` and `free()` instead, and
routes logging through the weak `et_arduino_log` hook the examples
already implement. Both upstream backends are dropped so link order
cannot pick one.
It also corrects a timestamp bug: `zephyr.cpp` returned a tick ratio of
`{1, 1}` with a comment admitting it did not know the units. `micros()`
is microseconds, so `{1000, 1}` is right, and profiling numbers now mean
something.
Two things had to be fixed before another core could work at all. The
Renesas cores define `abs` as a macro in `Arduino.h`, which turns c10's
`inline T abs(T a)` into a syntax error and takes `<complex>` with it —
the Zephyr core happens not to, which is the only reason this was
invisible. And those cores ship `arm-none-eabi-gcc 7.2.1` from 2017,
which cannot resolve `EValue::to()`'s overload set. Nothing in the
library fixes that, so it now fails with one line naming the toolchain
rather than pages of template errors:
```
error: #error "ExecuTorch needs GCC 9 or newer. This board core ships an older
arm-none-eabi-gcc (Renesas cores are on 7.2.1 from 2017). Nothing in the
library can work around it; the core's toolchain has to be updated."
```
`architectures` stays `zephyr`. Every other Arduino core ships
`arm-none-eabi-gcc 7` -- mbed_nano, renesas_uno and renesas_portenta all
do -- so opening it up would advertise the library to boards that would
every one of them stop at the `#error`, trading a clear message for a
wasted install. Zephyr's SDK 0.16.8 is the only Arduino toolchain new
enough today. It becomes `*` when that changes, and the guard is what
makes that safe to do.
To be clear about what this does and does not do: **it adds no new
board**. What it buys is the `abs` fix, the corrected tick ratio, one
platform layer instead of two, and the blocker moving off our side and
onto Arduino's toolchain.
GCC 12.2 is verified working and 7.2.1 verified failing. The floor of 9
is conservative rather than measured; 8 through 11 are untested.
## Test plan
Arduino Uno Q, core 0.90.0, `link_mode=static`:
```
HelloExecuTorch 473,368 flash (60%) 3,060 RAM (1%)
AddModel 508,556 flash (64%) 12,276 RAM (4%)
KeywordSpotting 564,352 flash (71%) 47,092 RAM (17%)
```
All three flashed and run. KeywordSpotting still detects every class,
with scores identical to the `zephyr.cpp` build, so the swap is
behaviourally inert:
```
yes 8.95 no -2.16 up -8.49 down -6.48 left -0.77 right -9.26
on -14.81 off -0.46 stop -5.40 go -7.10 -> Detected: yes CORRECT!
```
Compiler guard checked in both directions — Uno Q (GCC 12.2) compiles;
Portenta C33 (GCC 7.2.1) stops at the `#error` above rather than
emitting template failures.
`lintrunner` clean.
Authored with Claude Code (Opus 5).1 parent 1d4df21 commit adeb496
4 files changed
Lines changed: 126 additions & 41 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
25 | 56 | | |
26 | 57 | | |
27 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
429 | | - | |
430 | | - | |
431 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
432 | 435 | | |
433 | | - | |
434 | | - | |
435 | | - | |
436 | | - | |
437 | | - | |
438 | | - | |
439 | | - | |
440 | | - | |
441 | | - | |
442 | | - | |
443 | | - | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
464 | | - | |
465 | | - | |
466 | | - | |
467 | | - | |
468 | | - | |
469 | | - | |
470 | | - | |
| 436 | + | |
| 437 | + | |
471 | 438 | | |
472 | 439 | | |
473 | 440 | | |
| |||
0 commit comments