Modbus Crash

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Modbus Crash

Postby NIghthunter101 » Thu Jul 15, 2021 4:35 am

I'm trying to communicate over modbus with a ESP32-WROOM-32D but I keep getting crashes while trying to read it. I've based my code on the modbus code in the examples and it works reliably until it randomly crashes.

I always get one of the two following crash logs;

Code: Select all

assertion "eSndState == STATE_TX_IDLE" failed: file "C:/msys32/home/user/esp/esp-idf/components/freemodbus/modb
us/rtu/mbrtu.c", line 229, function: xMBRTUReceiveFSM
abort() was called at PC 0x400dfe33 on core 1
0x400dfe33: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/std
lib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)


ELF file SHA256: 6b6a25b031be9da47933bd8915456fbbebbd1bc913aabf799b6a3479e6c83782

Backtrace: 0x4008d7d0:0x3ffdb630 0x4008da1d:0x3ffdb650 0x400dfe33:0x3ffdb670 0x4014ce32:0x3ffdb6a0 0x4014bd62:0x3ffdb6d
0 0x4014bda9:0x3ffdb6f0 0x40090331:0x3ffdb720
0x4008d7d0: invoke_abort at C:/msys32/home/user/esp/esp-idf/components/esp32/panic.c:716

0x4008da1d: abort at C:/msys32/home/user/esp/esp-idf/components/esp32/panic.c:716

0x400dfe33: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/std
lib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x4014ce32: xMBRTUReceiveFSM at C:/msys32/home/user/esp/esp-idf/components/freemodbus/modbus/rtu/mbrtu.c:229 (d
iscriminator 1)

0x4014bd62: vMBPortSerialRxPoll at C:/msys32/home/user/esp/esp-idf/components/freemodbus/port/portserial.c:278
(discriminator 1)

0x4014bda9: vUartTask at C:/msys32/home/user/esp/esp-idf/components/freemodbus/port/portserial.c:278 (discrimin
ator 1)

0x40090331: vPortTaskWrapper at C:/msys32/home/user/esp/esp-idf/components/freertos/port.c:403
or

Code: Select all

assertion "( eRcvState == STATE_RX_INIT ) || ( eRcvState == STATE_RX_RCV ) || ( eRcvState == STATE_RX_ERROR )" failed:
file "C:/msys32/home/user/esp/esp-idf/components/freemodbus/modbus/rtu/mbrtu.c", line 350, function: xMBRTUTime
rT35Expired
abort() was called at PC 0x400dfe33 on core 1
0x400dfe33: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/std
lib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)


ELF file SHA256: 6b6a25b031be9da47933bd8915456fbbebbd1bc913aabf799b6a3479e6c83782

Backtrace: 0x4008d7d0:0x3ffdb5c0 0x4008da1d:0x3ffdb5e0 0x400dfe33:0x3ffdb600 0x4014cfe1:0x3ffdb630 0x4014bd7d:0x3ffdb65
0 0x4014bda9:0x3ffdb670 0x40090331:0x3ffdb6a0
0x4008d7d0: invoke_abort at C:/msys32/home/user/esp/esp-idf/components/esp32/panic.c:716

0x4008da1d: abort at C:/msys32/home/user/esp/esp-idf/components/esp32/panic.c:716

0x400dfe33: __assert_func at /Users/ivan/e/newlib_xtensa-2.2.0-bin/newlib_xtensa-2.2.0/xtensa-esp32-elf/newlib/libc/std
lib/../../../.././newlib/libc/stdlib/assert.c:63 (discriminator 8)

0x4014cfe1: xMBRTUTimerT35Expired at C:/msys32/home/user/esp/esp-idf/components/freemodbus/modbus/rtu/mbrtu.c:3
50 (discriminator 3)

0x4014bd7d: vMBPortSerialRxPoll at C:/msys32/home/user/esp/esp-idf/components/freemodbus/port/portserial.c:278
(discriminator 1)

0x4014bda9: vUartTask at C:/msys32/home/user/esp/esp-idf/components/freemodbus/port/portserial.c:278 (discrimin
ator 1)

0x40090331: vPortTaskWrapper at C:/msys32/home/user/esp/esp-idf/components/freertos/port.c:403

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

Re: Modbus Crash

Postby ESP_alisitsyn » Mon Jul 19, 2021 5:37 am

@NIghthunter101,

Could you please provide additional information:
1. What is the version of ESP-IDF you are using?
2. What is the number of registers you are trying to read from slave?
3. Please provide your sdkconfig file.
4. What kind of physical interface is used in your example (RS485?)?

Thank you.

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Re: Modbus Crash

Postby NIghthunter101 » Mon Jul 19, 2021 7:33 am

@ESP_alisitsyn here is the information

1. v4.0-dev-512-g6fd535c98-dirty

2. 20 registers

3. Attached

4. Yes RS485

Thanks
Attachments
sdkconfig.txt
(27.42 KiB) Downloaded 396 times

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

Re: Modbus Crash

Postby ESP_alisitsyn » Tue Jul 20, 2021 6:29 am

@NIghthunter101,

Sorry for late response. You are using very old commit for v4.0. Many issues were fixed in v4.0 but most of them are not synchronized with github yet.
In order to solve your issue could you:
1. checkout commit fa1f7e112ccc17c5a86b20e94e76ebb0db3108bf (

Code: Select all

git checkout fa1f7e112ccc17c5a86b20e94e76ebb0db3108bf
2. Apply patch

Code: Select all

git apply modbus_patch_fa1f7e112ccc17c5a86b20e94e76ebb0db3108bf.diff
3. Compile the example using

Code: Select all

idf.py build
If you have any issues with the steps above or you can't change your project to use different commit, let me know.
Thanks.
Attachments
modbus_patch_fa1f7e112ccc17c5a86b20e94e76ebb0db3108bf.diff.txt
modbus v4.0 patch for commit fa1f7e112ccc17c5a86b20e94e76ebb0db3108bf (v4.0.3)
(212.54 KiB) Downloaded 405 times

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Re: Modbus Crash

Postby NIghthunter101 » Thu Jul 22, 2021 12:30 am

@ESP_alisitsyn

I couldn't get the file to checkout and trying to apply the attached one gives a bunch of errors saying patch does not apply and a few no such file or directory.

I don't know if it's relevant but mine is so old I'm using msys32 and make (instead of idf.py).

Thanks

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

Re: Modbus Crash

Postby ESP_alisitsyn » Thu Jul 22, 2021 5:57 am

I couldn't get the file to checkout and trying to apply the attached one gives a bunch of errors
The patch will work only with later release. Please try the commands below in your msys32 in your esp-idf repo folder:

Code: Select all

cd $IDF_PATH
git fetch origin
git checkout origin/release/v4.0 -f
git submodule update --init --recursive
git log -n 2
then send me the output of `git log -n 2`
don't know if it's relevant but mine is so old I'm using msys32 and make (instead of idf.py).
If the above will not work for you for some reason I will provide the zip archive to overwrite your `esp-idf/components/freemodbus` folder.

Let me know the results and I will provide solution applicable for you. Thanks.

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Re: Modbus Crash

Postby NIghthunter101 » Thu Jul 22, 2021 6:23 am

This is what I got when I ran git log -n 2

Code: Select all

# git log -n 2
commit 7504329ef9fb01f01a382416af7453c54b47fb2b (HEAD, origin/release/v4.0)
Merge: c2f9002b03 f3f1190959
Author: Jiang Jiang Jian <jack@espressif.com>
Date:   Fri Jun 25 11:45:15 2021 +0000

    Merge branch 'bugfix/fix_amsdu_fragment_vulnerability_v4.0' into 'release/v4.0'

    esp_wifi: fix amsdu & fragment vulnerabilities(v4.0)

    See merge request espressif/esp-idf!14101

commit c2f9002b03e71d5c734665094168911acfbf08c2
Merge: b0097bb64f 03fc307e21
Author: Jiang Jiang Jian <jack@espressif.com>
Date:   Fri Jun 25 11:42:07 2021 +0000

    Merge branch 'update/version_4_0_3' into 'release/v4.0'

    Update version to 4.0.3

    See merge request espressif/esp-idf!14141

NIghthunter101
Posts: 9
Joined: Thu Feb 06, 2020 3:49 am

Re: Modbus Crash

Postby NIghthunter101 » Sun Jul 25, 2021 11:29 pm

@ESP_alisitsyn

Since running the commands you suggested I can no longer even build it. Whenever I try to build I get a bunch of errors related to stdatomic.h

Thanks

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

Re: Modbus Crash

Postby ESP_alisitsyn » Tue Jul 27, 2021 5:23 am

@NIghthunter101,

This is because you need to update the submodules, environment and toolchain
submodules update:

Code: Select all

git update submodules --init -recursive
install required toolchain (library):

Code: Select all

%IDF_PATH%/install.bat
update environment:

Code: Select all

%IDF_PATH%/export.bat
after that you will be able to use idf.py to build project
Refer to: https://docs.espressif.com/projects/es ... pdate.html

If for some reason you can not use the latest release with idf.py in the project you can return back to your previous release 6fd535c98

Code: Select all

git checkout 6fd535c98 -f
git update submodules --init -recursive
but I recommend to use latest release of release/v4.0.
I do have a patch for the commit 7504329ef9fb01f01a382416af7453c54b47fb2b you are located now but latest v4.0 example also works in most conditions. Once you are able to compile the code using idf.py the patch can be applied. Please follow the instruction above to setup your build environment.

Once you solved your issue with the compilation please check the simple example project here:
https://github.com/alisitsyn/modbus_sup ... bus_master
This project for v4.0 overrides the `components/freemodbus` and UART driver as well.
The overriden components included into `components`, you need to include this folder into your project or just overwrite the sources in your esp-idf component folder accordingly. It implements the simple modbus master but regular modbus_slave example will work too.

Let me know if you have any issues.

Thank you.

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

Re: Modbus Crash

Postby ESP_alisitsyn » Fri Jul 30, 2021 7:16 am

@NIghthunter101,

Did you solve the issues with the crashing of Modbus? Let me know if you have any issues.

Who is online

Users browsing this forum: No registered users and 188 guests