Modbus Master Crashes: assert failed: xMBMasterRTUReceiveFSM mbrtu_m.c:235

User avatar
Michael.Uray
Posts: 7
Joined: Sat Nov 05, 2022 3:13 pm

Modbus Master Crashes: assert failed: xMBMasterRTUReceiveFSM mbrtu_m.c:235

Postby Michael.Uray » Sat Nov 05, 2022 3:32 pm

I am run after some time of operation into the problem, that my ESP32 restarts with the above mentioned error.
The Modbus master code is pretty much the same as the example which is included in the ESP IDF, i just changed a few minor things.
  1. I (1911922) count_task: RAM left 123264; mb_master_hwm: 1508, count_task_hwm: 20, mqtt_ssl_main_hwm: 6276
  2. I (1912262) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  3. I (1912762) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  4. I (1913262) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  5. I (1913762) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  6. I (1914262) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  7. I (1914762) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  8. I (1914922) count_task: RAM left 123640; mb_master_hwm: 1508, count_task_hwm: 20, mqtt_ssl_main_hwm: 6276
  9. I (1915262) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  10. I (1915762) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  11. I (1916262) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  12. I (1916762) MASTER_TEST: Characteristic #0 Data_channel_0 (kW) value = 4531.000000 (0x458d9800) read successful. Restarted: 0
  13.  
  14. assert failed: xMBMasterRTUReceiveFSM mbrtu_m.c:235 (( eSndState == STATE_M_TX_IDLE ) || ( eSndState == STATE_M_TX_XFWR ))
  15.  
  16.  
  17. Backtrace:0x40081c02:0x3ffd00700x40089559:0x3ffd0090 0x400909b5:0x3ffd00b0 0x400e0751:0x3ffd01d0 0x400e1545:0x3ffd0200 0x400e15b4:0x3ffd0230 0x4008cdad:0x3ffd0260
  18. 0x40081c02: panic_abort at C:/Users/Michael.Uray/esp/esp-idf/components/esp_system/panic.c:402
  19.  
  20. 0x40089559: esp_system_abort at C:/Users/Michael.Uray/esp/esp-idf/components/esp_system/esp_system.c:128
  21.  
  22. 0x400909b5: __assert_func at C:/Users/Michael.Uray/esp/esp-idf/components/newlib/assert.c:85
  23.  
  24. 0x400e0751: xMBMasterRTUReceiveFSM at C:/Users/Michael.Uray/esp/esp-idf/components/freemodbus/modbus/rtu/mbrtu_m.c:235 (discriminator 2)
  25.  
  26. 0x400e1545: usMBMasterPortSerialRxPoll at C:/Users/Michael.Uray/esp/esp-idf/components/freemodbus/port/portserial_m.c:94
  27.  
  28. 0x400e15b4: vUartTask at C:/Users/Michael.Uray/esp/esp-idf/components/freemodbus/port/portserial_m.c:142
  29.  
  30. 0x4008cdad: vPortTaskWrapper at C:/Users/Michael.Uray/esp/esp-idf/components/freertos/port/xtensa/port.c:131
  31.  
  32.  
  33.  
  34.  
  35.  
  36. ELF file SHA256: 375376b08aba9e70
  37.  
  38. Rebooting...
  39. ets Jul 29 2019 12:21:46

My application runs a few tasks in parallel if that matters, which is a websocket/webserver, modbus client, modbus server and mqtt.
  1. void app_main()
  2. {
  3.   const static char *TAG = "main";
  4.  
  5.   esp_err_t err = nvs_flash_init();
  6.   if (err == ESP_ERR_NVS_NO_FREE_PAGES || err == ESP_ERR_NVS_NEW_VERSION_FOUND)
  7.   {
  8.     // NVS partition was truncated and needs to be erased
  9.     // Retry nvs_flash_init
  10.     ESP_ERROR_CHECK(nvs_flash_erase());
  11.     err = nvs_flash_init();
  12.   }
  13.   ESP_ERROR_CHECK(err);
  14.  
  15.   wifi_app_main();
  16.  
  17.   led_setup();
  18.   ws_server_start();
  19.  
  20.   xTaskCreate(&nvs_main, "nvs_main", 2000, NULL, 9, NULL);
  21.   xTaskCreate(&server_task, "server_task", 2000, NULL, 9, NULL);
  22.   xTaskCreate(&server_handle_task, "server_handle_task", 4000, NULL, 6, NULL);
  23.   xTaskCreate(&count_task, "count_task", 2000, NULL, 2, NULL);
  24.   xTaskCreate(&mb_master_main, "mb_master_main", 3500, NULL, 9, &mb_master_main_th);
  25.   xTaskCreate(&mb_slave_main, "mb_slave_main", 3500, NULL, 9, NULL);
  26.   xTaskCreate(&mqtt_ssl_main, "mqtt_ssl_main", 1024 * 8, NULL, 9, &mqtt_ssl_main_th);
  27. }
What could cause this issue and how to trace it back?
(I am a beginner with ESP IDF)
Attachments
mb_master.c
(11.25 KiB) Downloaded 178 times

ESP_alisitsyn
Posts: 211
Joined: Fri Feb 01, 2019 4:02 pm
Contact:

Re: Modbus Master Crashes: assert failed: xMBMasterRTUReceiveFSM mbrtu_m.c:235

Postby ESP_alisitsyn » Mon Nov 07, 2022 9:05 am

Hello Michael.Uray,

As I understand you use the freemodbus component from esp-idf v4.4. Unfortunately this component will not work with the configuration used in your application because your other tasks blocks the normal processing of modbus tasks.

Please try to fix this using the instruction below:
1. Create the components folder in the root folder of your application.
2. Copy the component folder "espressif__esp-modbus" from the project here https://github.com/alisitsyn/modbus_su ... components to your "components" folder.
3. Add the line to your root CMakeLists.txt file: https://github.com/alisitsyn/modbus_sup ... sts.txt#L6.
4. Change the other tasks priority of `9` to `8`.
4. `idf.py fullclean` or delete the build folder of your application manually then rebuild the project.
5. Rerun your project.

Please also take a look to the migration guide notes for modbus:
https://github.com/espressif/esp-idf/bl ... esp-modbus

If you still have issues with the update please send the log here. In this case it may require retries also to work in your configuration.
Thank you.

User avatar
Michael.Uray
Posts: 7
Joined: Sat Nov 05, 2022 3:13 pm

Re: Modbus Master Crashes: assert failed: xMBMasterRTUReceiveFSM mbrtu_m.c:235

Postby Michael.Uray » Tue Nov 08, 2022 5:44 pm

Thanks for your response.
I found in the meanwhile out, that a too low stack on another task caused the problem, even the highWatermark did not report a too low stack.
Please see also this forum entry:
https://forums.freertos.org/t/assert-fa ... -idf/16127

Who is online

Users browsing this forum: MicroController and 242 guests