Skip to content

Commit bb290c3

Browse files
committed
renamed Ethernet PHY model LAN8742 into LAN87XX to support both LAN8742 and LAN8720
added DP83848 PHY model added missing GPIO_InitStructure declarations in the EthInitPinmappings function for some STM32 boards support a range of models in a single Ethernet PHY driver
1 parent 6702976 commit bb290c3

File tree

9 files changed

+49
-11
lines changed

9 files changed

+49
-11
lines changed

connectivity/drivers/emac/CompositeEMAC.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ Unlike the MAC driver and the DMA, the PHY driver does not need to be subclassed
6363

6464
```json5
6565
"MY_TARGET": {
66-
"nsapi.emac-phy-model": "LAN8742",
66+
"nsapi.emac-phy-model": "LAN87XX",
6767
"nsapi.emac-phy-mdio-address": 0
6868
}
6969
```
7070

71-
This will work out of the box, as long as `LAN8742` names a PHY driver defined in PhyDrivers.cpp. Individual PHY models will generally need their own drivers, since often PHYs have errata that need to be worked around or need other configuration that isn't defined in the standard. However, GenericEthPhy allows implementing the absolute minimum amount of logic per-phy as possible!
71+
This will work out of the box, as long as `LAN87XX` names a PHY driver defined in PhyDrivers.cpp. Individual PHY models will generally need their own drivers, since often PHYs have errata that need to be worked around or need other configuration that isn't defined in the standard. However, GenericEthPhy allows implementing the absolute minimum amount of logic per-phy as possible!
7272

7373
Since user boards may want to use a different ethernet PHY, the driver can be customized in an application by overriding the `mbed::get_eth_phy_driver` weak function to return a different driver class. This might look something like
7474

connectivity/drivers/emac/TARGET_STM/TARGET_STM32F4/TARGET_NUCLEO_F439ZI/stm32f4_eth_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
void EthInitPinmappings(void)
3737
{
38+
GPIO_InitTypeDef GPIO_InitStructure;
39+
3840
/* Enable GPIOs clocks */
3941
__HAL_RCC_GPIOA_CLK_ENABLE();
4042
__HAL_RCC_GPIOB_CLK_ENABLE();

connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_DISCO_F746NG/stm32f7_eth_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
void EthInitPinmappings(void)
3636
{
37+
GPIO_InitTypeDef GPIO_InitStructure;
38+
3739
/* Enable GPIOs clocks */
3840
__HAL_RCC_GPIOA_CLK_ENABLE();
3941
__HAL_RCC_GPIOC_CLK_ENABLE();

connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F746ZG/stm32f7_eth_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
void EthInitPinmappings(void)
3737
{
38+
GPIO_InitTypeDef GPIO_InitStructure;
39+
3840
/* Enable GPIOs clocks */
3941
__HAL_RCC_GPIOA_CLK_ENABLE();
4042
__HAL_RCC_GPIOB_CLK_ENABLE();

connectivity/drivers/emac/TARGET_STM/TARGET_STM32F7/TARGET_NUCLEO_F756ZG/stm32f7_eth_init.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
void EthInitPinmappings(void)
3737
{
38+
GPIO_InitTypeDef GPIO_InitStructure;
39+
3840
/* Enable GPIOs clocks */
3941
__HAL_RCC_GPIOA_CLK_ENABLE();
4042
__HAL_RCC_GPIOB_CLK_ENABLE();

connectivity/drivers/emac/include/GenericEthPhy.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ class GenericEthPhy : public mbed::CompositeEMAC::PHYDriver {
8585
/// 24-bit OUI of the organization that produced the ethernet PHY.
8686
uint32_t OUI;
8787

88-
/// 5-bit model number of the phy. This plus the OUI is used to verify that the
88+
/// Range of 5-bit model number of the phy. This plus the OUI is used to verify that the
8989
/// chip in hardware matches what's expected.
90-
uint8_t model;
90+
uint8_t model_min;
91+
uint8_t model_max;
9192

9293
/// MDIO address of the phy chip.
9394
/// NOTE: 0 is *supposed* to be reserved as the general call address but lots of phy chips use

connectivity/drivers/emac/sources/GenericEthPhy.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ CompositeEMAC::ErrCode GenericEthPhy::init() {
4949
// ID1 should be the upper 18 MSBits of the OUI, with the two MSBits chopped off.
5050
const uint16_t expectedID1 = config.OUI >> 6;
5151
// Bits 10-15 of ID2 are the 6 LSBits of the OUI. Bits 4-9 are the model number. Bits 0-3 are the revision and may be anything.
52-
const uint16_t expectedID2 = (config.OUI << 10) | (config.model << 4);
52+
const uint16_t expectedID2Min = (config.OUI << 10) | (config.model_min << 4);
53+
const uint16_t expectedID2Max = (config.OUI << 10) | (config.model_max << 4);
5354
const uint16_t expectedID2Mask = 0xFFF0;
5455

5556
// Read IDs
@@ -58,7 +59,7 @@ CompositeEMAC::ErrCode GenericEthPhy::init() {
5859
FORWARD_ERR(mac->mdioRead(config.address, GenPhyRegs::PHYIDR1, actualID1));
5960
FORWARD_ERR(mac->mdioRead(config.address, GenPhyRegs::PHYIDR2, actualID2));
6061

61-
if(actualID1 == expectedID1 && (actualID2 & expectedID2Mask) == expectedID2) {
62+
if(actualID1 == expectedID1 && (actualID2 & expectedID2Mask) >= expectedID2Min && (actualID2 & expectedID2Mask) <= expectedID2Max) {
6263
// OK
6364
tr_info("Detected ethernet PHY at MDIO addr %" PRIu8 " with OUI 0x%" PRIx32 ", model 0x%" PRIx8 ", and revision number %" PRIu8, config.address, config.OUI, config.model, actualID2 % 0xF);
6465
}

connectivity/drivers/emac/sources/PhyDrivers.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ namespace mbed {
2020

2121
using namespace std::chrono_literals;
2222

23-
namespace LAN8742 {
23+
namespace LAN87XX {
2424

25-
/// Driver for the Microchip LAN8742 PHY
25+
/// Driver for the Microchip LAN8742 & LAN8720 PHY
2626
/// Datasheet: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ProductDocuments/DataSheets/DS_LAN8742_00001989A.pdf
27+
/// https://ww1.microchip.com/downloads/en/devicedoc/8720a.pdf
2728
/// @{
2829

2930
inline constexpr GenericEthPhy::Config DefaultConfig = {
3031
.OUI = 0x1F0,
31-
.model = 0x13,
32+
.model_min = 0x0F, // LAN8720
33+
.model_max = 0x13, // LAN8742
3234
.address = 0, // Address set via PHYAD[0] strap.
3335
};
3436

@@ -52,7 +54,8 @@ namespace IP101G {
5254

5355
inline constexpr GenericEthPhy::Config DefaultConfig = {
5456
.OUI = 0x90C3,
55-
.model = 0x5,
57+
.model_min = 0x5,
58+
.model_max = 0x5,
5659
.address = 1, // Address set via strapping pins, 1 is used on Nuvoton boards
5760
};
5861

@@ -68,6 +71,31 @@ namespace IP101G {
6871

6972
}
7073

74+
namespace DP83848 {
75+
76+
/// Driver for the DP83848 PHY
77+
/// Datasheet: https://www.ti.com/lit/ds/symlink/dp83848c.pdf
78+
/// @{
79+
80+
inline constexpr GenericEthPhy::Config DefaultConfig = {
81+
.OUI = 0x80017,
82+
.model_min = 0x09, // DP83848VV
83+
.model_max = 0x0A, // DP83848C/I/VYB/YB
84+
.address = 1, // Address set via PHYAD[0] strap.
85+
};
86+
87+
class Driver : public GenericEthPhy {
88+
public:
89+
explicit Driver(GenericEthPhy::Config const & config = DefaultConfig):
90+
GenericEthPhy(config)
91+
{}
92+
};
93+
94+
95+
/// @}
96+
97+
}
98+
7199
/**
72100
* @brief Obtains the PHY driver for Ethernet port 0.
73101
*

connectivity/netsocket/mbed_lib.json5

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
},
114114
"MCU_STM32": {
115115
// First-party STM32 boards generally use a LAN8742 PHY at MDIO address 0
116-
"nsapi.emac-phy-model": "LAN8742",
116+
"nsapi.emac-phy-model": "LAN87XX",
117117
"nsapi.emac-phy-mdio-address": 0
118118
},
119119
"MCU_M480": {

0 commit comments

Comments
 (0)