Closed ThomasDQS closed 11 months ago
Hello @ThomasDQS,
Thank you for this issue. Could you additionally set the log verbosity to DEBUG in kconfig, restart your project and attach log here? Please also attach your sdkconfig and map file in the build folder or your whole project. This will allow to find the exact reason for this issue and fix the destroy sequence for v5.1.
Thank you.
Hello @alisitsyn
Hereby the debug_log, the sdkconfig file & the map file.
Thank you. debug_log.txt sdkconfig.txt modbus_tcp_master_map.txt
@ThomasDQS ,
Thank you for update. The destroy sequence of master should be revised. I will update it and test as soon as possible.
Update: In your case when the modbus_tcp_master_task
waits for poll events the destroy sequence is started, and event handler is deleted that causes to send zero value (unexpected event) to unblock task waiting for the event. Unfortunately in my ESP32-C6 DevKit v1.1 environment with your sdkconfig I could not reproduce the issue.
Before go further could you please move the managed_components
folder to your_project\components
then make the modification of the component as below then check if it fixes the issue?
static esp_err_t mbc_tcp_master_destroy(void)
{
MB_MASTER_ASSERT(mbm_interface_ptr != NULL);
mb_master_options_t* mbm_opts = &mbm_interface_ptr->opts;
MB_MASTER_CHECK((mbm_opts != NULL), ESP_ERR_INVALID_ARG, "mb incorrect options pointer.");
eMBErrorCode mb_error = MB_ENOERR;
// Stop polling by clearing correspondent bit in the event group
xEventGroupClearBits(mbm_opts->mbm_event_group,
(EventBits_t)MB_EVENT_STACK_STARTED);
// Disable and then destroy the Modbus port
mb_error = eMBMasterDisable();
MB_MASTER_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE, "mb stack disable failure.");
(void)vTaskDelete(mbm_opts->mbm_task_handle);
mbm_opts->mbm_task_handle = NULL;
mb_error = eMBMasterClose();
MB_MASTER_CHECK((mb_error == MB_ENOERR), ESP_ERR_INVALID_STATE,
"mb stack close failure returned (0x%x).", (int)mb_error);
(void)vEventGroupDelete(mbm_opts->mbm_event_group);
mbm_opts->mbm_event_group = NULL;
mbc_tcp_master_free_slave_list();
free(mbm_interface_ptr); // free the memory allocated for options
vMBPortSetMode((UCHAR)MB_PORT_INACTIVE);
mbm_interface_ptr = NULL;
return ESP_OK;
}
Could you give me an example code of your initialization - read/write - destroy sequence? Do you read the parameters in one task and destroy it from other tasks?
Thank you.
@alisitsyn
I moved the managed_components
folder and made the changes in the mbc_tcp_master.c
file as you indicated. These changes have solved the problem! Thank you for the assistance!
@ThomasDQS ,
Thank you for your issue and the feedback. The fix will go through the formal process and will be fixed ASAP. Feel free to reopen the issue if you observe something later.
Hi @ThomasDQS ,
The fix has been merged and released in component version v1.0.12. The issue is closed. Please check the update and feel free to reopen the issue if you still have similar issue.
Goal:
The ESP32 is working as a master device. I want to open a TCP/IP socket to a slave device, read some registers and stop the modbus communication stack, destroy the interface & free all used objects by using the “mbc_master_destroy()” function.
This flow is perfectly working with the ESP-IDF v5.0.1 on a ESP32-C3-DevKitM-1.
Problem: I want to get the same code flow working on a ESP32-C6-DevKitC-1, which required an upgrade of the ESP-IDF to v5.1. Opening the connection to the slave and reading the desired registers is working perfectly, only the “mbc_master_destroy()” function is not working; some unexpected events got triggered resulting in running an endless loop until the IDLE task wachtdog got triggered.
Logs:
Any help on this would be great, thanks!