Any mJS code gives exception and followed by core dump on ESP8266 (release 2.20.0)

Something strange going on ESP8266 with new release Mongoose OS (2.20.0) while trying absolutely any mJS code. The same code listed below works on ESP32 without any issues. Also the same code works on ESP8266 using previous release Mongoose OS (2.19.1).

My actions:

  1. I’m using an empty skeleton (GitHub - mongoose-os-apps/empty);
  2. Add some additional libs to mos.yml (4 lines at the end), so my “libs” section looks like below:
libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - origin: https://github.com/mongoose-os-libs/rpc-service-config
  - origin: https://github.com/mongoose-os-libs/rpc-service-fs
  - origin: https://github.com/mongoose-os-libs/rpc-uart
  - origin: https://github.com/mongoose-os-libs/core
  - origin: https://github.com/mongoose-os-libs/wifi
  - origin: https://github.com/mongoose-os-libs/dash
  - origin: https://github.com/mongoose-os-libs/mjs
  1. Add minimal wifi and dash settings, plus credential info to mos.yml, so my “config_schema” section looks like below:
config_schema:
  - ["wifi.ap.enable", false]
  - ["wifi.sta.enable", true]
  - ["wifi.sta.ssid", "my_ssid"]
  - ["wifi.sta.pass", "my_secret"]
  - ["dash.enable", true]
  - ["dash.token", "mytoken"]
  1. Add simple mJS code on to init.js:
load('api_timer.js');

Timer.set(1000, true, function() {
  print('Hello from mJS:');
}, null);
  1. After building and flashing I’ve got this logs with errors:
[Jan  5 01:35:16.778]
[Jan  5 01:35:16.826] rBoot v1.2.1-cesanta1 - richardaburton@gmail.com
[Jan  5 01:35:16.826] Flash Size:   8 Mbit
[Jan  5 01:35:16.830] Flash Mode:   DIO
[Jan  5 01:35:16.830] Flash Speed:  80 MHz
[Jan  5 01:35:16.830] rBoot Option: Big flash
[Jan  5 01:35:16.831] 
[Jan  5 01:35:16.865] Booting rom 0 (0x8000).
[Jan  5 01:35:16.895] V2
[Jan  5 01:35:16.895] Mo
[Jan  5 01:35:17.040] ph����n��r��n|��l�prlb��|r�l�n��n�l`��r�l��rl��rl���b�b�brr��bl����llb��n�nn��l�p����ll��r��l�n����bl�brl
[Jan  5 01:35:17.106] esp_main.c:157          empty-master 1.0 (20220104-223418)
[Jan  5 01:35:17.111] esp_main.c:159          Mongoose OS 2.20.0 (20220104-223418/2.20.0-g1885c0f) sp 0x3fffff50
[Jan  5 01:35:17.119] esp_main.c:161          CPU: ESP8266EX, 160 MHz, RAM: 53992 total, 50996 free
[Jan  5 01:35:17.125] esp_main.c:165          SDK 3.0.5-dev(81bde69); flash: 1M
[Jan  5 01:35:17.130] esp_exc.c:236           Reset cause: 0 (power on)
[Jan  5 01:35:17.136] mongoose.c:15765        Mongoose 6.18, LwIP 1.4.0
[Jan  5 01:35:17.136] mongoose.c:4932         mbed TLS 2.16.11-cesanta1
[Jan  5 01:35:17.144] mgos_vfs_dev.c:72       sfl0: sysflash (), size 1048576
[Jan  5 01:35:17.151] mgos_vfs_dev.c:72       root: part ({"dev": "sfl0", "offset": 897024, "size": 131072}), size 131072
[Jan  5 01:35:17.161] mgos_vfs.c:173          /: SPIFFS @ root, opts {"bs":4096,"ps":256,"es":4096}
[Jan  5 01:35:17.190] mgos_vfs.c:344          /: size 113201, used: 92368, free: 20833
[Jan  5 01:35:17.248] mgos_sys_config.c:470   MAC: 11:22:33:44:55:66
[Jan  5 01:35:17.252] mgos_sys_config.c:478   WDT: 30 seconds
[Jan  5 01:35:17.256] mgos_ota_shadow_lib:116 OTA over shadow initialised
[Jan  5 01:35:17.264] mgos_dash.c:202         Dash init ok, server: wss://mdash.net/api/v2/rpc)
[Jan  5 01:35:17.269] mgos_rpc_channel_ua:320 0x3fff0bbc UART0
[Jan  5 01:35:17.273] esp_main.c:137          SDK: bcn 0
[Jan  5 01:35:17.280] esp_main.c:137          SDK: del if1
[Jan  5 01:35:17.280] esp_main.c:137          SDK: usl
[Jan  5 01:35:17.283] esp_main.c:137          SDK: mode : null
[Jan  5 01:35:17.287] mgos_wifi.c:325         WiFi mode: STA
[Jan  5 01:35:17.294] mgos_init.c:33          Init done, RAM: 53992 total, 46456 free, 44792 min free
[Jan  5 01:35:17.311] esp_main.c:210          Stack overflow! Tag 3,30,0x3ffef364 ptrs: 100:0x40295d92 36:0x402698e6 4:0x40295dbc -44:0x40295c4e -92:0x4029710f -124:0x4029646b -172:0x4029650f -204:0x402965b7 -236:0x40295e45 -252:0x402965b7 -284:0x40296085 -332:0x402953bf -348:0x402987
[Jan  5 01:35:17.336] esp_main.c:210          Stack overflow! Tag 3,45,0x3ffef364 ptrs: 84:0x402987e9 -12:0x40298f28 -60:0x402698e6 -92:0x40295c4e -140:0x40295e45 -188:0x4029710f -220:0x4029646b -252:0x402987e9 -268:0x4029650f -284:0x40296085 -300:0x402965b7 -332:0x40295e45 -380:0x402
[Jan  5 01:35:17.368] esp_main.c:210          Stack overflow! Tag 1,16,0x0 ptrs: 100:0x4021a048 84:0x4021a5da 20:0x402987e9 -12:0x4021fe48 -124:0x402698e6 -156:0x40295d92 -188:0x40226ba0 -204:0x402957e1 -252:0x40295dbc -300:0x4029710f -332:0x4029646b -380:0x402964ac -412:0x4026
[Jan  5 01:35:17.392] 
[Jan  5 01:35:17.392] Exception 9 @ 0x4021a0c1, vaddr 0x0000079b
[Jan  5 01:35:17.392]  A0: 0x4021fe80  A1: 0x3ffff000  A2: 0x00000777  A3: 0x3ffef844
[Jan  5 01:35:17.396]  A4: 0x3ffef844  A5: 0x3ffff018  A6: 0x3ffef855  A7: 0x00000008
[Jan  5 01:35:17.402]  A8: 0x001fffff  A9: 0x00000000 A10: 0x3ffef85c A11: 0x3fff2542
[Jan  5 01:35:17.407] A12: 0x00000001 A13: 0x3fff2540 A14: 0x00000777 A15: 0x00000001
[Jan  5 01:35:17.414] 
[Jan  5 01:35:17.414] (exc SP: 0x3fffee60)
[Jan  5 01:35:17.419] 
[Jan  5 01:35:17.419] --- BEGIN CORE DUMP ---
[Jan  5 01:35:17.419] mos: catching core dump
[Jan  5 01:35:20.262] ....
[Jan  5 01:35:28.901] ---- END CORE DUMP ----
  1. My goal: mJS code works as expected on ESP8266.
1 Like

Hi, I found a similar issue, however most of the mjs works for me but when I add api_timer.js the core dumps shows up.

Tested on a esp8266, as you mentioned it works in 2.19.1

Will test on a esp32!

2.19 did not have stack overflow check in mJS; 2.20 has it.
Either your code causes that or the amount of memory required is more than what your ESP8266 hardware can handle. Unfortunately I don’t have the official numbers for minimum memory needed.

It looks like there is no core dump anymore when building with latest.
Might be related to the updating of the sdk?

Does anyone happen to know if there is a way to downgrade on macOS using homebrew to work around this bug in V2.20?

No need to downgrade the mos tool.
One can specify the version to be used in mos.yml, e.g.

libs_version: 2.19.1 #${mos.version}
modules_version: 2.19.1 #${mos.version}
mongoose_os_version: 2.19.1 #${mos.version}
2 Likes

Nice, thanks for the tip @nliviu !

Edit: just tested this approach and fixed the issue for me.

The solution worked . Thanks a lot