From bcabd6bf702fac0fd95e89343cd7daa2499aa442 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Sat, 26 Oct 2019 12:53:41 +0300 Subject: [PATCH] Add Blue Pill --- platforms/README.md | 17 +++++++++ platforms/bluepill/.gitignore | 1 + platforms/bluepill/platformio.ini | 11 ++++++ platforms/bluepill/src/fib.wasm.h | 12 +++++++ platforms/bluepill/src/m3 | 1 + platforms/bluepill/src/main.cpp | 57 +++++++++++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 platforms/README.md create mode 100644 platforms/bluepill/.gitignore create mode 100644 platforms/bluepill/platformio.ini create mode 100644 platforms/bluepill/src/fib.wasm.h create mode 120000 platforms/bluepill/src/m3 create mode 100644 platforms/bluepill/src/main.cpp diff --git a/platforms/README.md b/platforms/README.md new file mode 100644 index 0000000..3cdb58d --- /dev/null +++ b/platforms/README.md @@ -0,0 +1,17 @@ +# Performance + +```log +Function: fib(24) fib64(24) comments +---------------------------------------------------------------------------------------------------- +ESP8266 LX106 @ 160MHz 288ms 299ms no TCO +ESP32 LX6 @ 240MHz 410ms 430ms no TCO +MXChip AZ3166 Arm M4 @ 100Mhz 651ms 713ms +WM W600 Arm M3 @ 80MHz 716ms 782ms stack used: 1952 +WM W600, TCO off Arm M3 @ 80MHz 846ms 914ms stack used: 8168 +BleNano2 (nRF52) Arm M4 @ 64MHz 1.19s 1.29s +Arduino MKR1000 Arm M0+ @ 48MHz 1.93s 2.06s no TCO +TinyBLE (nRF51) Arm M0 @ 16MHz 5.58s 5.93s no TCO, 16 Kb total RAM +BluePill Arm M3 @ 72MHz 7.62s 8.20s +HiFive1 (FE310) rv32imac @ 320MHz 9.10s 9.82s <- something wrong here? +Fomu rv32i @ 12MHz 25.2s 26.1s +``` diff --git a/platforms/bluepill/.gitignore b/platforms/bluepill/.gitignore new file mode 100644 index 0000000..03f4a3c --- /dev/null +++ b/platforms/bluepill/.gitignore @@ -0,0 +1 @@ +.pio diff --git a/platforms/bluepill/platformio.ini b/platforms/bluepill/platformio.ini new file mode 100644 index 0000000..b9138b9 --- /dev/null +++ b/platforms/bluepill/platformio.ini @@ -0,0 +1,11 @@ +[env:bluepill] +platform = ststm32 +board = bluepill_f103c8 +framework = stm32cube +upload_protocol = stlink +lib_deps = jeeh + +src_build_flags = + -Dd_m3FixedHeap=8192 -Dd_m3LogOutput=false + -Os -w -Wfatal-errors + -flto diff --git a/platforms/bluepill/src/fib.wasm.h b/platforms/bluepill/src/fib.wasm.h new file mode 100644 index 0000000..f621868 --- /dev/null +++ b/platforms/bluepill/src/fib.wasm.h @@ -0,0 +1,12 @@ +unsigned char fib_wasm[] = { + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0b, 0x02, 0x60, + 0x01, 0x7f, 0x01, 0x7f, 0x60, 0x01, 0x7e, 0x01, 0x7e, 0x03, 0x03, 0x02, + 0x00, 0x01, 0x07, 0x11, 0x02, 0x04, 0x5f, 0x66, 0x69, 0x62, 0x00, 0x00, + 0x06, 0x5f, 0x66, 0x69, 0x62, 0x36, 0x34, 0x00, 0x01, 0x0a, 0x3d, 0x02, + 0x1d, 0x00, 0x20, 0x00, 0x41, 0x02, 0x49, 0x04, 0x40, 0x20, 0x00, 0x0f, + 0x0b, 0x20, 0x00, 0x41, 0x02, 0x6b, 0x10, 0x00, 0x20, 0x00, 0x41, 0x01, + 0x6b, 0x10, 0x00, 0x6a, 0x0f, 0x0b, 0x1d, 0x00, 0x20, 0x00, 0x42, 0x02, + 0x54, 0x04, 0x40, 0x20, 0x00, 0x0f, 0x0b, 0x20, 0x00, 0x42, 0x02, 0x7d, + 0x10, 0x01, 0x20, 0x00, 0x42, 0x01, 0x7d, 0x10, 0x01, 0x7c, 0x0f, 0x0b +}; +unsigned int fib_wasm_len = 108; diff --git a/platforms/bluepill/src/m3 b/platforms/bluepill/src/m3 new file mode 120000 index 0000000..03cc5a6 --- /dev/null +++ b/platforms/bluepill/src/m3 @@ -0,0 +1 @@ +../../../source \ No newline at end of file diff --git a/platforms/bluepill/src/main.cpp b/platforms/bluepill/src/main.cpp new file mode 100644 index 0000000..f3288ec --- /dev/null +++ b/platforms/bluepill/src/main.cpp @@ -0,0 +1,57 @@ + +#include "m3/m3.hpp" + +#include "fib.wasm.h" + +#include + +#define FATAL(msg, ...) { puts("Fatal: " msg "\n"); return; } + +void run_wasm() +{ + M3Result result = c_m3Err_none; + + u8* wasm = (u8*)fib_wasm; + u32 fsize = fib_wasm_len-1; + + puts("Loading WebAssembly...\n"); + + IM3Module module; + result = m3_ParseModule (& module, wasm, fsize); + if (result) FATAL("m3_ParseModule: %s", result); + + IM3Runtime env = m3_NewRuntime (1024); + if (!env) FATAL("m3_NewRuntime"); + + result = m3_LoadModule (env, module); + if (result) FATAL("m3_LoadModule: %s", result); + + IM3Function f; + result = m3_FindFunction (&f, env, "_fib"); + if (result) FATAL("m3_FindFunction: %s", result); + + puts("Running...\n"); + + const char* i_argv[2] = { "24", NULL }; + result = m3_CallWithArgs (f, 1, i_argv); + + if (result) FATAL("m3_CallWithArgs: %s", result); +} + +PinC<13> led; + +int main() +{ + enableSysTick(); + led.mode(Pinmode::out); + + puts("wasm3 on Arduino, build " __DATE__ " " __TIME__ "\n"); + + led = 0; + run_wasm(); + led = 1; + + //Serial.print("Elapsed: "); + //Serial.print(end - start); + //Serial.println(" ms"); +}