Skip to content

Commit 0acac07

Browse files
committed
stm32/eth_phy: Move PHY initialization to a dedicated function.
Signed-off-by: Damien George <[email protected]>
1 parent 7713cdd commit 0acac07

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

ports/stm32/eth.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ typedef struct _eth_t {
142142
struct netif netif;
143143
struct dhcp dhcp_struct;
144144
uint32_t phy_addr;
145+
void (*phy_init)(uint32_t phy_addr);
145146
int16_t (*phy_get_link_status)(uint32_t phy_addr);
146147
} eth_t;
147148

@@ -212,6 +213,7 @@ int eth_init(eth_t *self, int mac_idx, uint32_t phy_addr, int phy_type) {
212213
mp_hal_get_mac(mac_idx, &self->netif.hwaddr[0]);
213214
self->netif.hwaddr_len = 6;
214215
self->phy_addr = phy_addr;
216+
self->phy_init = eth_phy_generic_init;
215217
if (phy_type == ETH_PHY_DP83825 || phy_type == ETH_PHY_DP83848) {
216218
self->phy_get_link_status = eth_phy_dp838xx_get_link_status;
217219
} else if (phy_type == ETH_PHY_LAN8720 || phy_type == ETH_PHY_LAN8742) {
@@ -417,9 +419,8 @@ static int eth_mac_init(eth_t *self) {
417419
ETH->DMA_CH[TX_DMA_CH].DMACCR &= ~(ETH_DMACxCR_DSL_Msk);
418420
#endif
419421

420-
// Reset the PHY
421-
eth_phy_write(self->phy_addr, PHY_BCR, PHY_BCR_SOFT_RESET);
422-
mp_hal_delay_ms(50);
422+
// Reset and initialize the PHY.
423+
self->phy_init(self->phy_addr);
423424

424425
// Wait for the PHY link to be established
425426
int phy_state = 0;

ports/stm32/eth_phy.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
#define PHY_RTL8211_PHYSR_SPEED_Msk (3 << PHY_RTL8211_PHYSR_SPEED_Pos)
4949
#define PHY_RTL8211_PHYSR_DUPLEX_Msk (0x0008)
5050

51+
void eth_phy_generic_init(uint32_t phy_addr) {
52+
// Reset the PHY.
53+
eth_phy_write(phy_addr, PHY_BCR, PHY_BCR_SOFT_RESET);
54+
mp_hal_delay_ms(50);
55+
}
56+
5157
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr) {
5258
// Get the link mode & speed
5359
uint16_t scsr = eth_phy_read(phy_addr, PHY_SCSR_LAN87XX);

ports/stm32/eth_phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
uint32_t eth_phy_read(uint32_t phy_addr, uint32_t reg);
6262
void eth_phy_write(uint32_t phy_addr, uint32_t reg, uint32_t val);
6363

64+
void eth_phy_generic_init(uint32_t phy_addr);
6465
int16_t eth_phy_lan87xx_get_link_status(uint32_t phy_addr);
6566
int16_t eth_phy_dp838xx_get_link_status(uint32_t phy_addr);
6667
int16_t eth_phy_rtl8211_get_link_status(uint32_t phy_addr);

0 commit comments

Comments
 (0)