esp-idf: Modbus TCP/IP vMBTCPPortMasterGetCurrInfo() Error (IDFGH-4623)
Environment
- Module or chip used: [ESP32-WROOM-32]
- IDF version (run
git describe --tagsto find it): v4.3-dev-2586-g526f682397 - Build System: [|idf.py]
- Compiler version (run
xtensa-esp32-elf-gcc --versionto find it): xtensa-esp32-elf-gcc (crosstool-NG esp-2020r3) 8.4.0 - Operating System: [Linux]
- Using an IDE?: [No|Yes (please give details)]
- Power Supply: [USB]
Problem Description
I am creating a Modbus TCP/IP application where I need to use the slave addresses [1, 2, 200]. However, for the slave address
200 the device resets and gets a problem in port_tcp_master.c file in line 895 specifically in the
if (pxInfo->xSockId > -1) { line.
I tried to debug this and found out that the function vMBTCPPortMasterGetCurrInfo() returns a wrong item from the
MbSlaveInfo_t ** table. That happens because my slave address is 200. Therefore, it tries to get the
xMbPortConfig.pxMbSlaveInfo[xMbPortConfig.ucCurSlaveIndex - 1]; But the ucCurSlaveIndex is 200.
This needs to change into xMbPortConfig.pxMbSlaveInfo[xMbPortConfig.usMbSlaveInfoCount - 1];
Now, even though I don’t get an error, I get the correct pxInfo struct in the code.
Expected Behavior
Actual Behavior
Steps to reproduce
- Create a descriptor table with a slave address 200.
- Connect to a Modbus TCP/IP device with its IP
- Setup the communication as stated in the example tutorial.
- Attempt to use
mbc_master_get_parameter()to get the data from that slave address.
Code to reproduce this issue
Debug Logs
Guru Meditation Error: Core 0 panic'ed (LoadStoreError). Exception was unhandled.
Core 0 register dump:
PC : 0x4000c3f0 PS : 0x00060130 A0 : 0x80058ac0 A1 : 0x3ffe5850
A2 : 0x3ffe5beb A3 : 0x400902e0 A4 : 0x00000002 A5 : 0x3ffdf738
0x400902e0: prvCopyItemByteBuf at /home/pro_kampas/esp/esp-idf/components/esp_ringbuf/ringbuf.c:466
A6 : 0x00000075 A7 : 0x00000001 A8 : 0x00000000 A9 : 0x400902e0
0x400902e0: prvCopyItemByteBuf at /home/pro_kampas/esp/esp-idf/components/esp_ringbuf/ringbuf.c:466
A10 : 0x00000020 A11 : 0x3ffdf784 A12 : 0x00000000 A13 : 0x00000001
A14 : 0x00000000 A15 : 0x3ffbc058 SAR : 0x00000016 EXCCAUSE: 0x00000003
EXCVADDR: 0x400902e0 LBEG : 0x400014fd LEND : 0x4000150d LCOUNT : 0xffffffff
0x400902e0: prvCopyItemByteBuf at /home/pro_kampas/esp/esp-idf/components/esp_ringbuf/ringbuf.c:466
Backtrace:0x4000c3ed:0x3ffe5850 0x40058abd:0x3ffe5870 0x401c4d07:0x3ffe58a0 0x401ca2ae:0x3ffe58d0 0x401ca403:0x3ffe5be0 0x401c74cc:0x3ffe5d00 0x401bd1ed:0x3ffe6010 0x4013ee2a:0x3ffe6060 0x4013f3f5:0x3ffe6090 0x4013f0cb:0x3ffe60b0 0x4013db12:0x3ffe60f0 0x400941a5:0x3ffe6120
0x401c4d07: __sprint_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:433
(inlined by) __sprint_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:403
0x401ca2ae: _vfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:1773 (discriminator 1)
0x401ca403: __sbprintf at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:480
0x401c74cc: _vfprintf_r at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/vfprintf.c:868 (discriminator 5)
0x401bd1ed: printf at /builds/idf/crosstool-NG/.build/xtensa-esp32-elf/src/newlib/newlib/libc/stdio/printf.c:56 (discriminator 5)
0x4013ee2a: xMBMasterTCPPortSendResponse at /home/pro_kampas/esp/esp-idf/components/freemodbus/tcp_master/port/port_tcp_master.c:896
0x4013f3f5: eMBMasterTCPSend at /home/pro_kampas/esp/esp-idf/components/freemodbus/modbus/tcp/mbtcp_m.c:145
0x4013f0cb: eMBMasterPoll at /home/pro_kampas/esp/esp-idf/components/freemodbus/modbus/mb_m.c:337 (discriminator 15)
0x4013db12: modbus_tcp_master_task at /home/pro_kampas/esp/esp-idf/components/freemodbus/tcp_master/modbus_controller/mbc_tcp_master.c:60
0x400941a5: vPortTaskWrapper at /home/pro_kampas/esp/esp-idf/components/freertos/port/xtensa/port.c:168
Other items if possible
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 32
120422.ZIP I attached the project, everything is OK with IP, I launched it, I also set the output of coredump to UART, I will wait for a failure. I also attached a log from the monitor, but I can’t enter the IP in it, I use another com Terminal with logging.