Skip to content

Commit

Permalink
extmod/network_wiznet5k: Add support for IPv6.
Browse files Browse the repository at this point in the history
This adds support for the WIZNET5K nic to use IPv6 with the LWIP stack.
Additionally, if LWIP_IPV6 is disabled, the device is configured to drop
all IPv6 packets to reduce load on the MCU.

Signed-off-by: Jared Hancock <[email protected]>
  • Loading branch information
Jared Hancock authored and dpgeorge committed Aug 26, 2024
1 parent b82c9ca commit e901ff8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion extmod/network_wiznet5k.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include "lwip/err.h"
#include "lwip/dns.h"
#include "lwip/dhcp.h"
#include "lwip/ethip6.h"
#include "netif/etharp.h"

#define TRACE_ETH_TX (0x0002)
Expand Down Expand Up @@ -297,13 +298,21 @@ static err_t wiznet5k_netif_init(struct netif *netif) {
netif->hwaddr_len = sizeof(netif->hwaddr);
int ret = WIZCHIP_EXPORT(socket)(0, Sn_MR_MACRAW, 0, 0);
if (ret != 0) {
printf("WIZNET fatal error in netifinit: %d\n", ret);
printf("WIZNET fatal error in netif_init: %d\n", ret);
return ERR_IF;
}

// Enable MAC filtering so we only get frames destined for us, to reduce load on lwIP
setSn_MR(0, getSn_MR(0) | Sn_MR_MFEN);

#if LWIP_IPV6
netif->output_ip6 = ethip6_output;
netif->flags |= NETIF_FLAG_MLD6;
#else
// Drop IPv6 packets if firmware does not support it
setSn_MR(0, getSn_MR(0) | Sn_MR_MIP6B);
#endif

return ERR_OK;
}

Expand Down Expand Up @@ -847,6 +856,10 @@ static mp_obj_t wiznet5k_active(size_t n_args, const mp_obj_t *args) {
setSHAR(mac);
}

#if WIZNET5K_WITH_LWIP_STACK && LWIP_IPV6
netif_create_ip6_linklocal_address(&self->netif, 1);
#endif

// seems we need a small delay after init
mp_hal_delay_ms(250);

Expand Down

0 comments on commit e901ff8

Please sign in to comment.