title: How to Determine if Ethernet Cable Has Been Unplugged During Runtime
body: <p>*Update: Cube has Status and Link callbacks. Have not tried them yet but I expect that is the best solution</p>
  
  <p>I am using the Ethernet peripheral on my <code>STM32F429ZI</code> with the </p>
  
  <p><strong>LWIP Middleware generated by CubeMX</strong></p>
  
  <p>. <a href="https://stackoverflow.com/questions/14227007/howto-detect-that-a-network-cable-has-been-unplugged-in-a-tcp-connection">This question</a> is similar but for PC.</p>
  
  <p>I find it hard to understand the Ethernet section in the product specs. It is not obvious what registers I could watch to check for downed links.</p>
  
  <p>I also looked into the <strong>LWIP</strong> code in case there was an obvious non-register-watching approach to this. In the main loop it polls the network interface with <code>MX_LWIP_Process</code>. On read it knows if there is a packet via the following: </p>
  
  <pre><code>void ethernetif_input(struct netif *netif)
  {
    err_t err;
    struct pbuf *p;
  
    /* move received packet into a new pbuf */
    p = low_level_input(netif);
  
    /* no packet could be read, silently ignore this */
    if (p == NULL) return;
  </code></pre>
  
  <p>On send, the <code>tcp_output()</code> function is very cumbersome. It has errors for invalid netif, invalid local_ip and a general error that I could watch but nothing that directly tells me that the link is down.</p>
  
  <p>My last thought is that the Ethernet headers have LED's that turn off if a cable is unplugged. I am going to look at the hardware diagrams for the STM32F4 DK's to see if I can watch those. </p>