AnsweredAssumed Answered

STM32F4 memory corruption

Question asked by Teddy Bonkers on Jul 24, 2015

I am doing a project with STM32F411RE and Microchip's ENC28J60 Ethernet-to-SPI chip. So far I have it working properly thanks to the code of However, my program exhibits some very peculiar behavior.

I have the following function that sends an ACK for a HTTP request, and then sends back the requested file in one segment only:
void www_server_reply(uint8_t *buf, const uint16_t dlen)
  make_tcp_ack_from_any(buf,info_data_len,0);        // send ack for http get
  HAL_Delay(1);                                         // Not working without this delay      
  make_tcp_ack_with_data_noflags(buf, dlen);            // send data

Before calling this function, I have constructed the TCP segment. The first line sends an ACK for the HTTP GET, then some flags are added and the actual HTTP document is sent with the last line. Here comes my bug: without the delay of 1 ms, the function sends the same TCP segment as the previous one, which results in a duplicate ACK. If the delay is in place, the function works as expected by modifying the data before sending it.
When I step in the program with the debugger I cannot see the problem - it never happens. It occurs only when there's no delay, or I send two HTTP GET requests one after another without any delay in between. The strange thing is that even the flags are not modified - it is just resending the exact same packet.

I have one external interrupt which is modifying only one variable and I don't think it has something to do with the problem. I googled a lot but I could not find an answer.