cancel
Showing results for 
Search instead for 
Did you mean: 

LAN8742A phy Link status register PHY_BSR, read stuck the code and causes the hard fault!

Hello Geeks!

I have costume hardware for the STM32F429Zi.

I'm using default HAL driver for the LWIP, generated from cubeMX (Nice tool) with FreeRTOS

For the Ethernet link, my board has external phy ic that is LAN8742A

My aim is to detect the Ethernet cable connections and disconnection, but unfortunately phy interrupt is not connected with any interrupt pin of the STM32 MCU and that's why I'm using polling for the PHY_BSR register for the LAN8742A

I have made the custom function for that to get the link status

ETH_Link_State VAP_ETH_LinkStatus(ETH_HandleTypeDef *heth){
 
	uint32_t readval, phyreg= 0;
 
		
 
 if((HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg)) == HAL_OK){
 
	if((phyreg & PHY_LINKED_STATUS)==0){
 
		/* Return Link Down status */
 
		return LAN8742_STATUS_LINK_DOWN;
 
	}
 
	if((phyreg & PHY_LINKED_STATUS)==1){
 
		/* Return Link Up status */
 
		return LAN8742_STATUS_LINK_UP;
 
	}
 
	}
 
}

In one of my FreeRTOS task I'm calling the function to get the status of the Ethernet cable

but unfortunately when the function calls then during HAL_ETH_ReadPHYRegister(heth, PHY_BSR, &phyreg) call the code stuck and enter in to Hard-fault !!

I have debug the code and identify, the hard fault cause when HAL_ETH_ReadPHYRegister function calls the ....

/* Get the ETHERNET MACMIIAR value */
  tmpreg1 = heth->Instance->MACMIIAR;

Can any one help me here (All suggestions and comments welcome!@)

Thanks!

0 REPLIES 0