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
106106m3ApiRawFunction (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-
136128m3ApiRawFunction (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..." );
0 commit comments