w5500 MAC triggering an unrecoverable error.
Posted: Wed Oct 09, 2024 12:57 pm
In my application, I have initialised Ethernet in a standard mode with clock speed of 30MHZ. I also use the SPIRAM. Both the application share the same bus config and hosted using SPI_HOST 2. I was previously hosting a web server along side using PSRAM, which never had any problem. However, now I have disable the web server to use ethernet over MODBUS TCP/IP stack. I use the standard freemodbus library and create a continuous polling loop to monitor the incoming packets at the port. Here is the RTOS task created:
The task mostly uses the standard library function and works as expected. However, it keeps triggering a unrecoverable error at random times (usually after 30 mins of runtime) as follows:
I have tried initialising different clock speed for the ethernet. A similar error was specified as bug in this issue https://github.com/espressif/esp-idf/issues/11845 and has been fixed for ESP-IDF 5.0v and above, but I'm still facing this issue. Any suggestions are welcome. Thanks.
- void modbus_tcp_task(void* pvParameters)
- {
- // Modbus TCP slave handler
- memset(&mbc_slave_handler, 0, sizeof(mbc_slave_handler));
- // Initialize Modbus TCP stack
- esp_err_t err = mbc_tcp_slave_create(&mbc_slave_handler);
- if (err != ESP_OK) {
- ESP_LOGE(TAG5, "Failed to initialize Modbus TCP stack: %d", err);
- vTaskDelete(NULL);
- return;
- }
- // Set communication parameters
- mb_communication_info_t comm_info = {
- .ip_port = 502, // Default Modbus TCP port
- .ip_addr_type = MB_IPV4,
- .ip_mode = MB_MODE_TCP,
- };
- // Start Modbus TCP stack
- err = mbc_tcp_slave_start();
- if (err != ESP_OK) {
- ESP_LOGE(TAG5, "Failed to start Modbus TCP stack: %d", err);
- vTaskDelete(NULL);
- return;
- }
- ESP_LOGI(TAG5, "Modbus TCP stack initialized and started");
- // Main loop for handling incoming Modbus TCP requests
- while (1) {
- // Check if the Modbus stack is active
- if (eMBState == STATE_ENABLED) {
- // Process requests from Modbus TCP client
- eMBErrorCode status = eMBPoll(); // Check if a request has been received
- if (status != MB_ENOERR) {
- ESP_LOGE(TAG5, "Error polling Modbus TCP: 0x%x", (int)status);
- } else {
- ESP_LOGI(TAG5, "Modbus TCP request processed successfully");
- }
- }
- vTaskDelay(pdMS_TO_TICKS(500)); // Poll every 100 ms
- }
- }
- E (4158012) w5500.mac: w5500_spi_read(163): spi transmit failed
- E (4158012) w5500.mac: w5500_read_buffer(276): read RX buffer failed
- E (4158012) w5500.mac: emac_w5500_receive(680): read payload failed, len=60, offset=65529
- E (4158022) w5500.mac: frame read from module failed
- I (4158062) adc_api: Multisource Control Mode. Fans are controlled via Modbus/BMS, Webserver, and 0-10V 1 : 0.000000
- I (4158122) adc_api: Fan Speed: 6553/65535, 10.00%
- I (4159292) adc_api: Multisource Control Mode. Fans are controlled via Modbus/BMS, Webserver, and 0-10V 1 : 0.000000
- I (4159352) adc_api: Fan Speed: 6553/65535, 10.00%
- E (4159552) w5500.mac: w5500_spi_write(139): spi transmit failed
- E (4159552) w5500.mac: w5500_write_buffer(253): write TX buffer failed
- E (4159552) w5500.mac: emac_w5500_transmit(582): write frame failed
- I (4160502) adc_api: Multisource Control Mode. Fans are controlled via Modbus/BMS, Webserver, and 0-10V 1 : 0.000000
- I (4160562) adc_api: Fan Speed: 6553/65535, 10.00%