Skip to content

Commit

Permalink
Merge pull request #15183 from maribu/pr15164-backport
Browse files Browse the repository at this point in the history
cpu/stm32: Fix periph_eth link status [backport 2020.10]
  • Loading branch information
aabadie authored Oct 13, 2020
2 parents baf041e + 6c47089 commit 830077d
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions cpu/stm32/periph/eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ static inline void _phy_write(uint16_t addr, uint8_t reg, uint16_t value)
_rw_phy(addr, reg, (value & 0xffff) | (ETH_MACMIIAR_MW << 16));
}

static inline bool _get_link_status(void)
{
return (_phy_read(0, PHY_BSMR) & BSMR_LINK_STATUS);
}

static void stm32_eth_get_mac(char *out)
{
unsigned t;
Expand Down Expand Up @@ -216,7 +221,12 @@ static int stm32_eth_get(netdev_t *dev, netopt_t opt,
res = ETHERNET_ADDR_LEN;
break;
case NETOPT_LINK:
res = (_phy_read(0, PHY_BSMR) & BSMR_LINK_STATUS);
assert(max_len == sizeof(netopt_enable_t));
{
netopt_enable_t tmp = _get_link_status();
memcpy(value, &tmp, sizeof(tmp));
}
res = sizeof(netopt_enable_t);
break;
default:
res = netdev_eth_get(dev, opt, value, max_len);
Expand All @@ -230,7 +240,7 @@ static int stm32_eth_get(netdev_t *dev, netopt_t opt,
static void _timer_cb(void *arg)
{
netdev_t *dev = (netdev_t *)arg;
if (stm32_eth_get(dev, NETOPT_LINK, NULL, 0)) {
if (_get_link_status()) {
_link_state = LINK_STATE_UP;
dev->event_callback(dev, NETDEV_EVENT_ISR);
}
Expand Down

0 comments on commit 830077d

Please sign in to comment.