Page 1 of 1

Point-to-point connection: MAC link not active

Posted: Thu Apr 24, 2014 9:56 am
by rubenswerk
Hello,

I want to establish a connection between two STM32 boards using ChibiOS
+ LWIP.
Everything works fine as long as there's a simple 5-port switch between both boards.
A problem arises when I use a direct point-to-point connection (without switch) between the boards.
One of the boards does not activate the link status, which means that the link remains down, and no communication is possible.

The main loop of the lwip thread looks as shown below. Please note that I added two debug LEDs. The MAC is polled for its status every 1000ms. The result of macPollLinkStatus is indicated by LED_1.
If the link status is different from the status of the interface, the corresponding link_up/down functions are called, indicated by LED_2.

Code: Select all

while (TRUE) {
  eventmask_t mask = chEvtWaitAny(ALL_EVENTS);
  if (mask & PERIODIC_TIMER_ID) {
    bool_t current_link_status = macPollLinkStatus(&ETHD1);
    if (current_link_status) DEBUG_LED_1_ON else DEBUG_LED_1_OFF; // DEBUGGING
    if (current_link_status != netif_is_link_up(&thisif)) {
      if (current_link_status) {
        tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_up,
                                   &thisif, 0);
        DEBUG_LED_2_ON; // DEBUGGING
      }
      else {
        tcpip_callback_with_block((tcpip_callback_fn) netif_set_link_down,
                                   &thisif, 0);
        DEBUG_LED_2_OFF; // DEBUGGING
      }
    }
  }

What happens in my setup when I use point-to-point connection:
1. Both boards power off
2. Switch on the first board. Both debug LEDs remain off, the link LED on the RJ45 plug remains off. This is obvious, because the communication partner is not powered.
3. Switch on the second board. RJ45 link LEDs on both boards are on. DEBUG_LED_1 (macPollLinkStatus) on both boards are on. DEBUG_LED_2 (netif_set_link_up/down) is only on at the board which was powered first. The link is not activated at the other board. No communication possible.
4. I can exchange both boards and the situation is vice versa. The board which is powered first activates the link. The other board does not.

To verify this behaviour, there's no need to do any communication between the boards. It's enough to switch the debug LEDs as suggested in the code above. Both boards can run exactly the same software. Only the default lwip thread has to be active, as it is the case in all LWIP demos.
The described behaviour happens in 90% of my test cases. In 10%, both boards activate the link and everything works fine. I use a Micrel PHY, don't know if this matters.

What's going on at the second board? macPollLinkStatus returns the correct state. But netif_is_link_up seems to return a wrong state, because DEBUG_LED_2 is not switched on.

Is there some kind of deadlock situation, because each board is waiting for an active link on the other side before it activates its own link? When I use a network switch in between, everything is fine.

Is it necessary to do this netif_set_link_up/down stuff if power consumption doesn't matter? Or is it ok to hardcode netif_set_link_up once during lwip initialization and never switch it off again?

Regards, RuWe

Re: Point-to-point connection: MAC link not active

Posted: Thu Apr 24, 2014 10:36 am
by Giovanni
Hi,

Is it possible you need a null cable? switches have some kind of auto-detect feature that allows them to use any cable.

Anyway, I think that the detection of the other end is done inside the PHY so, if there is a solution to this, it should be something to configure inside the PHY registers.

Giovanni

Re: Point-to-point connection: MAC link not active

Posted: Fri Apr 25, 2014 10:07 am
by rubenswerk
Ok I found the problem.
There are different places in the software (LWIP) where the link status can be changed. I thought it was only in the lwip thread main loop, but that's wrong.