-
Notifications
You must be signed in to change notification settings - Fork 7.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
W5500 ethernet examples don't work unless compiler is set to Debug (-Og) (IDFGH-4776) #6579
Comments
Quick fix based on similar solution in #6233 static esp_err_t w5500_get_rx_received_size(emac_w5500_t *emac, uint16_t *size)
{
esp_err_t ret = ESP_OK;
uint16_t received0, received1 = 0;
volatile uint16_t timeout = 0;
do {
MAC_CHECK(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received0, sizeof(received0)) == ESP_OK, "read RX RSR failed", err, ESP_FAIL);
MAC_CHECK(w5500_read(emac, W5500_REG_SOCK_RX_RSR(0), &received1, sizeof(received1)) == ESP_OK, "read RX RSR failed", err, ESP_FAIL);
} while (received0 != received1 && (timeout++ < 5000));
if (timeout >= 5000 && (received0 != received1)) {
ESP_LOGE(TAG, "Timeout exceeded: %d, received0 = %d, received1 = %d\n", timeout, received0, received1);
ret = ESP_FAIL;
goto err;
}
*size = __builtin_bswap16(received0);
err:
return ret;
} |
Hi @ntwallace Thanks for reporting this bug. The reason for this infinite looping is different from the linked issue, though (we should read the register multiple times according to the datasheet) The problem here is that the underlying SPI communication uses 4-byte boundary operations and thus rewriting the other register during the second read (registers are 2 byte size, but usually placed 4 bytes apart, esp. for The below patch should fix the issue: |
@david-cermak would you care to elaborate a bit more about this issue? I didn't understand. |
@KaeLL The main trouble was in reading w5500 registers with SPI driver using DMA, which implies 1) data must be aligned to 4 byte boundary 2) data size must min 4 bytes. Fixed by using direct reads to the SPI internal structure (which correctly defines the alignment and padding requirements) for all registers of size smaller than 4 bytes. An alternatively we could promote all register declarations to
I'm also looking at other drivers which could suffer from the same symptoms. |
Reading SPI data may come in 4-byte units and thus result in unwanted overwrites if smaller size registers read, especially if multiple placed one after another. Fixed by using direct reads to `trans` structure for sizes smaller or equal to 4. Closes #6579
Environment
Problem Description
The existing W5500 ethernet implementation does not work unless
COMPILER_OPTIMIZATION
=COMPILER_OPTIMIZATION_DEFAULT
. Setting compiler flags to any other level results in WDT panics from the TCP/IP task. This is true of all examples and other code. I have tested with IDF 4.2-release, 4.3-dev, and 4.4-dev.This appears similar to #6233, where the emac is stuck inside a while loop at the end of the transmit function, but in this case it is stuck inside the do while loop in
w5500_get_rx_received_size
Expected Behavior
W5500 implementation works at all compile levels.
Actual Behavior
WDT panic, I have added LOGIs inside all the while loops in
esp_eth_mac_w5500.c
:...
Steps to reproduce
COMPILER_OPTIMIZATION
to level other thanDEBUG
(-Og) in menuconfig for ethernet examplesThe text was updated successfully, but these errors were encountered: