Skip to content

Commit 47d7d29

Browse files
committed
VM: add print and greeting, check for TinyGo entry function first
1 parent b2b7479 commit 47d7d29

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

examples_pio/Wasm_Advanced/wasm_vm/wasm_vm.ino

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#define NATIVE_STACK_SIZE (32*1024)
2323

2424
// For (most) devices that cannot allocate a 64KiB wasm page
25-
#define WASM_MEMORY_LIMIT 4096
25+
//#define WASM_MEMORY_LIMIT 4096
2626

2727
/*
2828
* WebAssembly app
@@ -105,34 +105,26 @@ m3ApiRawFunction(m3_arduino_getPinLED)
105105

106106
m3ApiRawFunction(m3_arduino_print)
107107
{
108-
m3ApiGetArgMem(const char *, buff)
108+
m3ApiGetArgMem (const uint8_t *, buf)
109+
m3ApiGetArg (uint32_t, len)
109110

110-
//printf("api: print %p\n", out);
111-
Serial.print(buff);
111+
//printf("api: print %p %d\n", buf, len);
112+
Serial.write(buf, len);
112113

113114
m3ApiSuccess();
114115
}
115116

116-
m3ApiRawFunction(m3_arduino_getString)
117+
m3ApiRawFunction(m3_arduino_getGreeting)
117118
{
118-
m3ApiGetArgMem(char *, out)
119-
m3ApiGetArg(int32_t, out_len)
119+
m3ApiGetArgMem (uint8_t *, out)
120+
m3ApiGetArg (int32_t, out_len)
120121

121-
const char buff[] = "Тест юнікоду!";
122+
const char buff[] = "Hello WASM world! 😊";
122123
memcpy(out, buff, min(sizeof(buff), out_len));
123124

124125
m3ApiSuccess();
125126
}
126127

127-
m3ApiRawFunction(m3_arduino_testCallback)
128-
{
129-
m3ApiGetArg(int32_t, func)
130-
131-
printf("api: testCallback %d\n", func);
132-
133-
m3ApiSuccess();
134-
}
135-
136128
m3ApiRawFunction(m3_dummy)
137129
{
138130
m3ApiSuccess();
@@ -148,13 +140,10 @@ M3Result LinkArduino (IM3Runtime runtime)
148140
m3_LinkRawFunction (module, arduino, "pinMode", "v(ii)", &m3_arduino_pinMode);
149141
m3_LinkRawFunction (module, arduino, "digitalWrite", "v(ii)", &m3_arduino_digitalWrite);
150142

151-
// Convenience functions
143+
// Test functions
152144
m3_LinkRawFunction (module, arduino, "getPinLED", "i()", &m3_arduino_getPinLED);
153-
m3_LinkRawFunction (module, arduino, "print", "v(*)", &m3_arduino_print);
154-
155-
// Tests
156-
m3_LinkRawFunction (module, arduino, "getString", "v(*i)", &m3_arduino_getString);
157-
m3_LinkRawFunction (module, arduino, "testCallback", "v(i)", &m3_arduino_testCallback);
145+
m3_LinkRawFunction (module, arduino, "getGreeting", "v(*i)", &m3_arduino_getGreeting);
146+
m3_LinkRawFunction (module, arduino, "print", "v(*i)", &m3_arduino_print);
158147

159148
// Dummy (for TinyGo)
160149
m3_LinkRawFunction (module, "env", "io_get_stdout", "i()", &m3_dummy);
@@ -193,7 +182,13 @@ void wasm_task(void*)
193182
if (result) FATAL("LinkArduino", result);
194183

195184
IM3Function f;
196-
result = m3_FindFunction (&f, runtime, "_start");
185+
// Check for TinyGo entry function first
186+
// See https://github.com/tinygo-org/tinygo/issues/866
187+
result = m3_FindFunction (&f, runtime, "cwa_main");
188+
if (result) {
189+
result = m3_FindFunction (&f, runtime, "_start");
190+
}
191+
197192
if (result) FATAL("FindFunction", result);
198193

199194
Serial.println("Running WebAssembly...");

src/m3_config_platforms.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ typedef int8_t i8;
240240
*/
241241

242242
# ifndef d_m3MaxFunctionStackHeight
243-
# if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AMEBA)
243+
# if defined(ESP8266) || defined(ESP32) || defined(ARDUINO_AMEBA) || defined(TEENSYDUINO)
244244
# define d_m3MaxFunctionStackHeight 128
245245
# endif
246246
# endif

0 commit comments

Comments
 (0)