Menu

#1287 mii_find_phy or mii_read behaviour

21.11.4
open
nobody
None
Other
Medium
21.11.3
False
2024-08-05
2024-08-05
No

MCU: stm32h743xih6
Chibios github commit: 8fc176ac1d68cde532a25c9b802372063a2246cb

I've collected logs from the custom board with Ethernet PHY LAN8720.
From our investigation it was found that there is an issue with the detection of the Ethernet PHY chip in the current Chibi OS HAL implementation.

After debugging the described issue it was found that it can be fixed with the following change:

ChibiOS/os/hal/ports/STM32/LLD/MACv2/hal_mac_lld.c

#if !defined(BOARD_PHY_ADDRESS)
/**
 * @brief   PHY address detection.
 *
 * @param[in] macp      pointer to the @p MACDriver object
 */
static bool mii_find_phy(MACDriver *macp) {
  uint32_t i;

#if STM32_MAC_PHY_TIMEOUT > 0
  unsigned n = STM32_MAC_PHY_TIMEOUT;
 do {
#endif
    for (i = 0U; i <= 31U; i++) {
      macp->phyaddr = i << ETH_MACMDIOAR_PA_Pos;
      ETH->MACMDIOAR = (i << ETH_MACMDIOAR_RDA_Pos) | MACMDIODR_CR;
      ETH->MACMDIODR = (i << ETH_MACMDIODR_RA_Pos) | MACMDIODR_CR;
      printf("HAL_MACv2: i: %lu ", i);  
      printf("mii_read(macp, MII_PHYSID1) = %lx ", mii_read(macp, MII_PHYSID1));
      printf("(mii_read(macp, MII_PHYSID2) & 0xFFF0U)  = %lx ", (mii_read(macp, MII_PHYSID2) & 0xFFF0U));
      if (((mii_read(macp, MII_PHYSID1) /* & 0xFFFFU */) == (BOARD_PHY_ID >> 16U)) &&
          ((mii_read(macp, MII_PHYSID2) & 0xFFF0U) == (BOARD_PHY_ID & 0xFFF0U))) {
        return true;
      }
    }
#if STM32_MAC_PHY_TIMEOUT > 0
    n--;
  } while (n > 0U);
#endif
 return false;
}
#endif

logs attached
also we fixed this for us by adding & 0xFFFFU (commented in code)

1 Attachments

Discussion


Log in to post a comment.