mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
stm32/eth_phy: Move PHY initialization to a dedicated function.
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -142,6 +142,7 @@ typedef struct _eth_t {
|
||||
struct netif netif;
|
||||
struct dhcp dhcp_struct;
|
||||
uint32_t phy_addr;
|
||||
void (*phy_init)(uint32_t phy_addr);
|
||||
int16_t (*phy_get_link_status)(uint32_t phy_addr);
|
||||
} eth_t;
|
||||
|
||||
@@ -212,6 +213,7 @@ int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type) {
|
||||
mp_hal_get_mac(mac_idx, &self->netif.hwaddr[0]);
|
||||
self->netif.hwaddr_len = 6;
|
||||
self->phy_addr = phy_addr;
|
||||
self->phy_init = eth_phy_generic_init;
|
||||
if (phy_type == ETH_PHY_DP83825 || phy_type == ETH_PHY_DP83848) {
|
||||
self->phy_get_link_status = eth_phy_dp838xx_get_link_status;
|
||||
} else if (phy_type == ETH_PHY_LAN8720 || phy_type == ETH_PHY_LAN8742) {
|
||||
@@ -417,9 +419,8 @@ static int eth_mac_init(eth_t *self) {
|
||||
ETH->DMA_CH[TX_DMA_CH].DMACCR &= ~(ETH_DMACxCR_DSL_Msk);
|
||||
#endif
|
||||
|
||||
// Reset the PHY
|
||||
eth_phy_write(self->phy_addr, PHY_BCR, PHY_BCR_SOFT_RESET);
|
||||
mp_hal_delay_ms(50);
|
||||
// Reset and initialize the PHY.
|
||||
self->phy_init(self->phy_addr);
|
||||
|
||||
// Wait for the PHY link to be established
|
||||
int phy_state = 0;
|
||||
|
||||
@@ -48,6 +48,12 @@
|
||||
#define PHY_RTL8211_PHYSR_SPEED_Msk (3 << PHY_RTL8211_PHYSR_SPEED_Pos)
|
||||
#define PHY_RTL8211_PHYSR_DUPLEX_Msk (0x0008)
|
||||
|
||||
void eth_phy_generic_init(uint32_t phy_addr) {
|
||||
// Reset the PHY.
|
||||
eth_phy_write(phy_addr, PHY_BCR, PHY_BCR_SOFT_RESET);
|
||||
mp_hal_delay_ms(50);
|
||||
}
|
||||
|
||||
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr) {
|
||||
// Get the link mode & speed
|
||||
uint16_t scsr = eth_phy_read(phy_addr, PHY_SCSR_LAN87XX);
|
||||
|
||||
@@ -61,6 +61,7 @@
|
||||
uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg);
|
||||
void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val);
|
||||
|
||||
void eth_phy_generic_init(uint32_t phy_addr);
|
||||
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr);
|
||||
int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr);
|
||||
int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr);
|
||||
|
||||
Reference in New Issue
Block a user