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 <jared@greezybacon.me>
The W5100 and W5100S only have 4 available sockets and 16kB of socket
buffer. Allocating 16kB to either the receive or transmit buffer of a
single socket is not allowed, so the current setup does not change the
allocation for socket 0 from the reset default. ctlwizchip is returning -1
to indicate the error, but the response isn't being inspected and probably
doesn't need to be.
Signed-off-by: Jared Hancock <jared@greezybacon.me>
According to the datasheet, the IEN bit to enable the interrupt is in the
MR2 register, not the MR register.
This is just cleanup as the interrupt appears to be enabled by default
after resetting the chip.
Tested on W5100S_EVB_PICO.
This commit implements a new <AbstractNIC>.ipconfig() function for the NIC
classes that use lwIP, to set and retrieve network configuration for a NIC.
Currently this method supports:
- ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently
configured ipv4 address
- ipconfig("addr6"): obtain a list of tuples (addr, state,
prefered_lifetime, valid_lifetime) of all currently active ipv6
addresses; this includes static, slaac and link-local addresses
- ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address
- ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address
- ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask
- ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this
does not configure an interface route, as this does not seem supported by
lwIP
- ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac
- ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway
- ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask,
gateway and a dns server
- ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the
configured ipv4 address.
- ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server
There is also a new global configuration function network.ipconfig() that
supports the following:
- network.ipconfig(dns="2a01::2"): set the primary dns server (can be a
ipv4 or ipv6 address)
- network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as
dns responses (falling back to ipv4 if the host does not have an ipv6
address); note that this does not flush the dns cache, so if a host is
already in the dns cache with its v4 address, subsequent lookups will
return that address even if prefer=6 is set
This interface replaces NIC.ifconfig() completely, and ifconfig() should be
marked as deprecated and removed in a future version.
Signed-off-by: Felix Dörre <felix@dogcraft.de>
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The contents of machine_mem.h, machine_i2c.h and machine_spi.h have been
moved into extmod/modmachine.h.
Signed-off-by: Damien George <damien@micropython.org>
This was previously implemented by adding additional members to the
mp_obj_type_t defined for each NIC, which is difficult to do cleanly with
the new object type slots mechanism. The way this works is also not
supported on GCC 8.x and below.
Instead replace it with the type protocol, which is a much simpler way of
achieving the same thing.
This affects the WizNet (in non-LWIP mode) and Nina NIC drivers.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.
Make all extmod variables (src, flags, etc) private to extmod.mk.
Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.
Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Instead of being an explicit field, it's now a slot like all the other
methods.
This is a marginal code size improvement because most types have a make_new
(100/138 on PYBV11), however it improves consistency in how types are
declared, removing the special case for make_new.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This will always have the maximum/minimum size of a mp_obj_type_t
representation and can be used as a member in other structs.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Instead of using the fixed machine_spi_type entity to get the SPI transfer
function, this transfer function is now extracted dynamically from the type
of the SPI object.
This allows the SPI object used to communicate with the WIZNET5K hardware
to be SoftSPI or hardware SPI, or anything that has the SPI protocol (at
the C level).
Signed-off-by: Damien George <damien@micropython.org>
Avoiding conflicts between the IRQ and an active transfers. Before this
change the device could lock up in heavy traffic situations.
Fix found and code supplied by @omogenot.
If nic.active(True) is called several times in a row, the device may lock
up. Even if that is bad coding practice, calling wiznet5k_deinit() in
wiznet5k_init() prevents the lock.
Drop an obsolete and wrong argument check, which prevented specifying a pin
for the interrupt signal. The proper checks are now done further down in
the code.
Originally based on both stm32/network_wiznet5k and stm32/modnwwiznet5k.
If MICROPY_PY_LWIP is enabled it uses the lwIP TCP stack in MicroPython,
communicating with the Wiznet controller in MACRAW mode. In this mode it
supports using the INTN pin from Wiznet controller to receive data from an
interrupt trigger.
If lwIP is not enabled, it runs in modnetwork/socket mode providing an
interface to the TCP stack running on the Wiznet controller chip. In this
mode it includes some updates by @irinakim12 from #8021, most notably
bringing in DHCP support.
Supports defining hardware pins in board config or dynamically set at
runtime. Sets a default MAC address in the random namespace from board
unique-id.
Signed-off-by: Andrew Leech <andrew@alelec.net>