I am using the STM32F7 chip with +TCP, and the corresponding NetworkInterface.c, etc.
I have the device connected to a TP-Link switch.
Per router wiresharks, the first prvSendDHCPDiscover() never hits the router.
Is there some misconfiguration I should look for, or do I need to restructure something else to make this work faster? Its taking a good 10 seconds + to get an address.
If I understand correctly, the first DHCP request does not make it onto the wire, but the second does. If so, this may be due to the receive timeout as follows:
When the system boots up the ARP cache is empty, so when you create a socket the first DHCP request will get replaced by and ARP packet to find the address of the DHCP server. That happens inside the TCP/IP stack though, the socket doesn’t see it and is still waiting for the DHCP reply. After a while the receive time out will expire and it will re-send the DHCP request, and this time the DHCP server address will hopefully be known from the ARP reply so the DHCP packet makes it onto the wire. So if the receive time out is long you will see that as a delay.
I don’t think that is quite right, because ARP relates to IP, and dhcp is pre arp, sent to a broadcast address.
I tracked it down to a unifi switch though, there must be some managed switch setting I haven’t figured out yet as bypassing the switch yields first time response.
When you look well, you will see that the two DHCP requests are slightly different:
The first request has the broadcast flag turned off ( 0 ).
When it doesn’t receive a reply, it will resubmit the DHCP request with the broadcast flag switched on ( 1 ).
When the flag if turned off, the reply will be directed to the offered IP-address.
in other words: always request an answer in a broadcast packet.
Explanation: when the flag is off, the reply will be sent to e.g. 192.168.1.124 along with the MAC-address of your device.
Normally the unicast reply should arrive, but maybe in your case, the packet is dropped somewhere along the line.