Compare commits

..
2 Commits
Author SHA1 Message Date
novlean 72b74a5565 Merge pull request #3800 from cesanta/novlean-patch-1
Update README with new article links
2026-11-27 16:13:09 +01:00
novlean 32d6f201de Update README with new article links
Added new articles about Ethernet over 802.15.4, ESP32 crashes, and Ethernet on nRF52840.
2026-11-27 16:12:52 +01:00
7 changed files with 131 additions and 150 deletions

No files matched your search

+3
View File
@@ -254,6 +254,9 @@ Technical guides and deep dives into embedded web servers, WebUI integration and
- [How to connect STM32 to EMQX](https://mongoose.ws/articles/stm32-emqx/) - [How to connect STM32 to EMQX](https://mongoose.ws/articles/stm32-emqx/)
- [STM32 Device Management deep dive: Secure OTA, Remote Control, health monitor](https://mongoose.ws/articles/stm32-mdash-deep-dive/) - [STM32 Device Management deep dive: Secure OTA, Remote Control, health monitor](https://mongoose.ws/articles/stm32-mdash-deep-dive/)
- [STM32 TCP/IP footprint: how much flash and RAM does Mongoose take?](https://mongoose.ws/articles/tcp-ip-footprint/) - [STM32 TCP/IP footprint: how much flash and RAM does Mongoose take?](https://mongoose.ws/articles/tcp-ip-footprint/)
- [Ethernet over 802.15.4 radio](https://mongoose.ws/articles/ethernet-over-802154-radio/)
- [Debug ESP32 crashes in production](https://mongoose.ws/articles/esp32-crashes-in-production/)
- [Ethernet on nRF52840 over USB and BLE radio](https://mongoose.ws/articles/ethernet-on-nrf52/)
## Contributions ## Contributions
+62 -71
View File
@@ -33128,7 +33128,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
NETC_EMDIO->EMDIO_CFG = NETC_EMDIO->EMDIO_CFG =
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD ((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); mg_phy_init(&phy, d->phy_addr, 0);
// Initialize ENETC1 PSI0 and port // Initialize ENETC1 PSI0 and port
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
@@ -33632,22 +33632,20 @@ bool __attribute__((weak)) mg_wifi_ap_stop(void) {
enum { // ID1 ID2 enum { // ID1 ID2
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
MG_PHY_DP83x = 0x2000, // MG_PHY_DP83x = 0x2000,
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720 MG_PHY_RTL82x = 0x1c,
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02 MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
MG_PHY_RTL82x = 0x1c, // MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F MG_PHY_ICS1894x = 0x15,
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
MG_PHY_ICS1894x = 0x15, //
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894 MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
MG_PHY_YT85x = 0x4f51, // MG_PHY_YT85x = 0x4f51,
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531 MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
}; };
enum { enum {
@@ -33666,44 +33664,45 @@ enum {
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7 MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43 MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
MG_PHY_ICS189432_REG_POLL = 17, MG_PHY_ICS189432_REG_POLL = 17,
MG_PHY_VSC8531_REG_DACS = 28,
MG_PHY_YT8531_REG_PHYSTS = 17, MG_PHY_YT8531_REG_PHYSTS = 17,
MG_PHY_YT8531_REG_EXT_ADDR = 30, MG_PHY_YT8531_REG_EXT_ADDR = 30,
MG_PHY_YT8531_REG_EXT_DATA = 31 MG_PHY_YT8531_REG_EXT_DATA = 31
}; };
// clang-format off
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) { static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
switch (id1) { switch (id1) {
case MG_PHY_DP83x: case MG_PHY_DP83x:
switch (id2) { switch (id2) {
case MG_PHY_DP83867: return "DP83867"; case MG_PHY_DP83867:
case MG_PHY_DP83848: return "DP83848"; return "DP83867";
case MG_PHY_DP83825: return "DP83825"; case MG_PHY_DP83848:
default: return "DP83x"; return "DP83848";
} case MG_PHY_DP83825:
case MG_PHY_KSZ8x: return "KSZ8x"; return "DP83825";
case MG_PHY_LANxVSCx:
switch (id2) {
case MG_PHY_VSC8531: return "VSC8531";
default: default:
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x"; return "DP83x";
} }
break; case MG_PHY_KSZ8x:
return "KSZ8x";
case MG_PHY_LAN87x:
return "LAN87x";
case MG_PHY_RTL82x: case MG_PHY_RTL82x:
switch (id2) { switch (id2) {
case MG_PHY_RTL8201: return "RTL8201"; case MG_PHY_RTL8201:
case MG_PHY_RTL8211: return "RTL8211"; return "RTL8201";
default: return "RTL82x"; case MG_PHY_RTL8211:
return "RTL8211";
default:
return "RTL82x";
} }
case MG_PHY_ICS1894x: return "ICS1894x"; case MG_PHY_ICS1894x:
return "ICS1894x";
case MG_PHY_YT85x: case MG_PHY_YT85x:
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x"; return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
default: break; default:
return "unknown";
} }
return "unknown";
} }
// clang-format on
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) { void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
uint16_t id1, id2; uint16_t id1, id2;
@@ -33715,28 +33714,29 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2))); MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
if (config & MG_PHY_RGMII) { if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) { uint16_t value;
uint16_t value; // TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset // We temporarily force enabling autoneg, until a workaround is found.
// We temporarily force enabling autoneg, until a workaround is found. phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12)); phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003); value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA); value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0)); phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA, (uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps }
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
phy->write_reg(phy_addr, 0x0d, if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
0x1f); // write 0x10d to IO_MUX_CFG (0x0170) phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
phy->write_reg(phy_addr, 0x0e, 0x170); phy->write_reg(phy_addr, 0x0e, 0x170);
phy->write_reg(phy_addr, 0x0d, 0x401f); phy->write_reg(phy_addr, 0x0d, 0x401f);
phy->write_reg(phy_addr, 0x0e, 0x10d); phy->write_reg(phy_addr, 0x0e, 0x10d);
} }
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
if (config & MG_PHY_CLOCKS_MAC) {
// Use PHY crystal oscillator (preserve defaults) // Use PHY crystal oscillator (preserve defaults)
// nothing to do // nothing to do
} else { // RMII, MAC clocks PHY, PHY has no xtal. } else { // MAC clocks PHY, PHY has no xtal
// Enable 50 MHz external ref clock at XI (preserve defaults) // Enable 50 MHz external ref clock at XI (preserve defaults)
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) { if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0)); phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
@@ -33749,7 +33749,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
// now do clock stuff // now do clock stuff
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R, phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7))); (uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) { } else if (id1 == MG_PHY_LAN87x) {
// nothing to do // nothing to do
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) { } else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
// assume PHY has been hardware strapped properly // assume PHY has been hardware strapped properly
@@ -33795,19 +33795,10 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R); uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
*full_duplex = pc1r & MG_BIT(2); *full_duplex = pc1r & MG_BIT(2);
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M; *speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
} else if (id1 == MG_PHY_LANxVSCx) { } else if (id1 == MG_PHY_LAN87x) {
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
if (id2 == MG_PHY_VSC8531) { *full_duplex = scsr & MG_BIT(4);
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS); *speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
*full_duplex = dacs & MG_BIT(5);
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
: MG_PHY_SPEED_10M;
} else {
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
*full_duplex = scsr & MG_BIT(4);
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
}
} else if (id1 == MG_PHY_RTL82x) { } else if (id1 == MG_PHY_RTL82x) {
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
if (id2 == MG_PHY_RTL8211) { if (id2 == MG_PHY_RTL8211) {
@@ -39816,7 +39807,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
// init phy // init phy
struct mg_phy phy = {eth_read_phy, eth_write_phy}; struct mg_phy phy = {eth_read_phy, eth_write_phy};
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
(void) d; (void) d;
return true; return true;
+2 -4
View File
@@ -5605,10 +5605,8 @@ struct mg_phy {
enum { enum {
// Set if PHY LEDs are connected to ground // Set if PHY LEDs are connected to ground
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0), MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY // Set when PHY clocks MAC. Otherwise, MAC clocks PHY
MG_PHY_CLOCKS_MAC = (1 << 1), MG_PHY_CLOCKS_MAC = (1 << 1)
// Set on RGMII. Otherwise, we assume RMII
MG_PHY_RGMII = (1 << 2)
}; };
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M }; enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
+1 -1
View File
@@ -242,7 +242,7 @@ static bool mg_tcpip_driver_netc_init(struct mg_tcpip_if *ifp) {
NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS NETC_EMDIO_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
NETC_EMDIO->EMDIO_CFG = NETC_EMDIO->EMDIO_CFG =
((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD ((mdc_cr & 0x1ffU) << 7) | MG_BIT(2); // MDIO_CLK_DIV, MDIO_HOLD
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); mg_phy_init(&phy, d->phy_addr, 0);
// Initialize ENETC1 PSI0 and port // Initialize ENETC1 PSI0 and port
NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS NETC_ENETC1_PCI->CMD |= MG_BIT(2) | MG_BIT(1); // BUS_MASTER_EN, MEM_ACCESS
+60 -69
View File
@@ -2,22 +2,20 @@
#include "log.h" #include "log.h"
#include "util.h" #include "util.h"
enum { // ID1 ID2 enum { // ID1 ID2
MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB MG_PHY_KSZ8x = 0x22, // 0022 156x - KSZ8081RNB, KSZ8091RNB
MG_PHY_DP83x = 0x2000, // MG_PHY_DP83x = 0x2000,
MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I MG_PHY_DP83867 = 0xa231, // 2000 a231 - TI DP83867I
MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I MG_PHY_DP83825 = 0xa140, // 2000 a140 - TI DP83825I
MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I MG_PHY_DP83848 = 0x5ca2, // 2000 5ca2 - TI DP83848I
MG_PHY_LANxVSCx = 0x7, // 0007 xxxx | cxxx: SMSC | 0xxx: Vitesse MG_PHY_LAN87x = 0x7, // 0007 c0fx - LAN8720
MG_PHY_LAN87x = 0xc0f0, // 0007 c0fx - LAN8720 MG_PHY_RTL82x = 0x1c,
MG_PHY_VSC8531 = 0x0572, // 0007 0572 - VSC8531-02 MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F
MG_PHY_RTL82x = 0x1c, // MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
MG_PHY_RTL8201 = 0xc816, // 001c c816 - RTL8201F MG_PHY_ICS1894x = 0x15,
MG_PHY_RTL8211 = 0xc916, // 001c c916 - RTL8211F
MG_PHY_ICS1894x = 0x15, //
MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894 MG_PHY_ICS189432 = 0xf450, // 0015 f450 - ICS1894
MG_PHY_YT85x = 0x4f51, // MG_PHY_YT85x = 0x4f51,
MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531 MG_PHY_YT8531 = 0xe91a // 4f51 e91a - Motorcomm YT8531
}; };
enum { enum {
@@ -36,44 +34,45 @@ enum {
MG_PHY_RTL8201_REG_RMSR = 16, // in page 7 MG_PHY_RTL8201_REG_RMSR = 16, // in page 7
MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43 MG_PHY_RTL8211_REG_PHYSR = 26, // in page a43
MG_PHY_ICS189432_REG_POLL = 17, MG_PHY_ICS189432_REG_POLL = 17,
MG_PHY_VSC8531_REG_DACS = 28,
MG_PHY_YT8531_REG_PHYSTS = 17, MG_PHY_YT8531_REG_PHYSTS = 17,
MG_PHY_YT8531_REG_EXT_ADDR = 30, MG_PHY_YT8531_REG_EXT_ADDR = 30,
MG_PHY_YT8531_REG_EXT_DATA = 31 MG_PHY_YT8531_REG_EXT_DATA = 31
}; };
// clang-format off
static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) { static const char *mg_phy_id_to_str(uint16_t id1, uint16_t id2) {
switch (id1) { switch (id1) {
case MG_PHY_DP83x: case MG_PHY_DP83x:
switch (id2) { switch (id2) {
case MG_PHY_DP83867: return "DP83867"; case MG_PHY_DP83867:
case MG_PHY_DP83848: return "DP83848"; return "DP83867";
case MG_PHY_DP83825: return "DP83825"; case MG_PHY_DP83848:
default: return "DP83x"; return "DP83848";
} case MG_PHY_DP83825:
case MG_PHY_KSZ8x: return "KSZ8x"; return "DP83825";
case MG_PHY_LANxVSCx:
switch (id2) {
case MG_PHY_VSC8531: return "VSC8531";
default: default:
if ((id2 & 0xFFF0) == MG_PHY_LAN87x) return "LAN87x"; return "DP83x";
} }
break; case MG_PHY_KSZ8x:
return "KSZ8x";
case MG_PHY_LAN87x:
return "LAN87x";
case MG_PHY_RTL82x: case MG_PHY_RTL82x:
switch (id2) { switch (id2) {
case MG_PHY_RTL8201: return "RTL8201"; case MG_PHY_RTL8201:
case MG_PHY_RTL8211: return "RTL8211"; return "RTL8201";
default: return "RTL82x"; case MG_PHY_RTL8211:
return "RTL8211";
default:
return "RTL82x";
} }
case MG_PHY_ICS1894x: return "ICS1894x"; case MG_PHY_ICS1894x:
return "ICS1894x";
case MG_PHY_YT85x: case MG_PHY_YT85x:
return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x"; return id2 == MG_PHY_YT8531 ? "YT8531" : "YT85x";
default: break; default:
return "unknown";
} }
return "unknown";
} }
// clang-format on
void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) { void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
uint16_t id1, id2; uint16_t id1, id2;
@@ -85,28 +84,29 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2))); MG_INFO(("PHY ID: %#04x %#04x (%s)", id1, id2, mg_phy_id_to_str(id1, id2)));
if (config & MG_PHY_RGMII) { if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) {
if (id1 == MG_PHY_YT85x && id2 == MG_PHY_YT8531) { uint16_t value;
uint16_t value; // TODO (robertc2000): Autonegotiation remains disabled after PHY is reset
// TODO (robertc2000): Autonegotiation remains disabled after PHY is reset // We temporarily force enabling autoneg, until a workaround is found.
// We temporarily force enabling autoneg, until a workaround is found. phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12));
phy->write_reg(phy_addr, MG_PHY_REG_BCR, MG_BIT(12)); phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003);
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_ADDR, 0xa003); value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA);
value = phy->read_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA); value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0));
value &= (uint16_t) ~(MG_BIT(3) | MG_BIT(2) | MG_BIT(1) | MG_BIT(0)); phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA,
phy->write_reg(phy_addr, MG_PHY_YT8531_REG_EXT_DATA, (uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps
(uint16_t) (value | MG_BIT(1))); // TXDLY: 2 * 150 ps }
} else if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
phy->write_reg(phy_addr, 0x0d, if (id1 == MG_PHY_DP83x && id2 == MG_PHY_DP83867) {
0x1f); // write 0x10d to IO_MUX_CFG (0x0170) phy->write_reg(phy_addr, 0x0d, 0x1f); // write 0x10d to IO_MUX_CFG (0x0170)
phy->write_reg(phy_addr, 0x0e, 0x170); phy->write_reg(phy_addr, 0x0e, 0x170);
phy->write_reg(phy_addr, 0x0d, 0x401f); phy->write_reg(phy_addr, 0x0d, 0x401f);
phy->write_reg(phy_addr, 0x0e, 0x10d); phy->write_reg(phy_addr, 0x0e, 0x10d);
} }
} else if (config & MG_PHY_CLOCKS_MAC) { // RMII
if (config & MG_PHY_CLOCKS_MAC) {
// Use PHY crystal oscillator (preserve defaults) // Use PHY crystal oscillator (preserve defaults)
// nothing to do // nothing to do
} else { // RMII, MAC clocks PHY, PHY has no xtal. } else { // MAC clocks PHY, PHY has no xtal
// Enable 50 MHz external ref clock at XI (preserve defaults) // Enable 50 MHz external ref clock at XI (preserve defaults)
if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) { if (id1 == MG_PHY_DP83x && id2 != MG_PHY_DP83867 && id2 != MG_PHY_DP83848) {
phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0)); phy->write_reg(phy_addr, MG_PHY_DP83x_REG_RCSR, MG_BIT(7) | MG_BIT(0));
@@ -119,7 +119,7 @@ void mg_phy_init(struct mg_phy *phy, uint8_t phy_addr, uint8_t config) {
// now do clock stuff // now do clock stuff
phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R, phy->write_reg(phy_addr, MG_PHY_KSZ8x_REG_PC2R,
(uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7))); (uint16_t) (MG_BIT(15) | MG_BIT(8) | MG_BIT(7)));
} else if (id1 == MG_PHY_LANxVSCx && (id2 & 0xFFF0) == MG_PHY_LAN87x) { } else if (id1 == MG_PHY_LAN87x) {
// nothing to do // nothing to do
} else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) { } else if (id1 == MG_PHY_RTL82x && id2 == MG_PHY_RTL8201) {
// assume PHY has been hardware strapped properly // assume PHY has been hardware strapped properly
@@ -165,19 +165,10 @@ bool mg_phy_up(struct mg_phy *phy, uint8_t phy_addr, bool *full_duplex,
uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R); uint16_t pc1r = phy->read_reg(phy_addr, MG_PHY_KSZ8x_REG_PC1R);
*full_duplex = pc1r & MG_BIT(2); *full_duplex = pc1r & MG_BIT(2);
*speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M; *speed = (pc1r & 3) == 1 ? MG_PHY_SPEED_10M : MG_PHY_SPEED_100M;
} else if (id1 == MG_PHY_LANxVSCx) { } else if (id1 == MG_PHY_LAN87x) {
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
if (id2 == MG_PHY_VSC8531) { *full_duplex = scsr & MG_BIT(4);
uint16_t dacs = phy->read_reg(phy_addr, MG_PHY_VSC8531_REG_DACS); *speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
*full_duplex = dacs & MG_BIT(5);
*speed = (dacs & MG_BIT(4)) ? MG_PHY_SPEED_1000M
: (dacs & MG_BIT(3)) ? MG_PHY_SPEED_100M
: MG_PHY_SPEED_10M;
} else {
uint16_t scsr = phy->read_reg(phy_addr, MG_PHY_LAN87x_REG_SCSR);
*full_duplex = scsr & MG_BIT(4);
*speed = (scsr & MG_BIT(3)) ? MG_PHY_SPEED_100M : MG_PHY_SPEED_10M;
}
} else if (id1 == MG_PHY_RTL82x) { } else if (id1 == MG_PHY_RTL82x) {
uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2); uint16_t id2 = phy->read_reg(phy_addr, MG_PHY_REG_ID2);
if (id2 == MG_PHY_RTL8211) { if (id2 == MG_PHY_RTL8211) {
+2 -4
View File
@@ -11,10 +11,8 @@ struct mg_phy {
enum { enum {
// Set if PHY LEDs are connected to ground // Set if PHY LEDs are connected to ground
MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0), MG_PHY_LEDS_ACTIVE_HIGH = (1 << 0),
// Set on RMII when PHY clocks MAC. Otherwise, MAC clocks PHY // Set when PHY clocks MAC. Otherwise, MAC clocks PHY
MG_PHY_CLOCKS_MAC = (1 << 1), MG_PHY_CLOCKS_MAC = (1 << 1)
// Set on RGMII. Otherwise, we assume RMII
MG_PHY_RGMII = (1 << 2)
}; };
enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M }; enum { MG_PHY_SPEED_10M, MG_PHY_SPEED_100M, MG_PHY_SPEED_1000M };
+1 -1
View File
@@ -149,7 +149,7 @@ static bool mg_tcpip_driver_xmc7_init(struct mg_tcpip_if *ifp) {
// init phy // init phy
struct mg_phy phy = {eth_read_phy, eth_write_phy}; struct mg_phy phy = {eth_read_phy, eth_write_phy};
mg_phy_init(&phy, d->phy_addr, MG_PHY_RGMII); mg_phy_init(&phy, d->phy_addr, MG_PHY_CLOCKS_MAC);
(void) d; (void) d;
return true; return true;