New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32: Incorporate lwip stack and use Wiznet in MACRAW mode #3379

Open
wants to merge 3 commits into
base: master
from

Conversation

Projects
None yet
6 participants
@dpgeorge
Contributor

dpgeorge commented Oct 20, 2017

This PR is work-in-progress and the main aim is to begin incorporating the lwIP stack into the stm32 port, along with ussl and other networking components.

As a proof-of-concept in uses the Wiznet Ethernet module in MACRAW mode which allows to send and receive raw Ethernet frames. This send/recv is hooked into the back of lwIP so that the TCP/IP stack is provided by lwIP itself (as opposed to the internal TCP/IP stack in the Wiznet module).

The benefits are that the Wiznet module now supports the full socket module interface and behaves exactly the same as esp8266. The downside is reduced TCP throughput because the Wiznet doesn't have large enough Ethernet buffers to buffer the incoming frames before they get processed by lwIP. But the performance loss is not that bad (roughly a third of the throughput) and the benefits outweight the reduced performance.

The PR also enables the ussl module for stm32, and adds some useful modules to the frozen bytecode. The Wiznet W5500 chipset is enabled by default but can be changed to W5200 in stm32/mpconfigport.mk.

upip, urequests and uasyncio are all tested to work and are included in the frozen bytecode.

There is a script stm32/wiznet_connect.py which shows how to bring up the network.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 20, 2017

Contributor

@Li-Weiwei @Lisa999 FYI you may want to test this out to have full socket support on Wiznet hardware.

Contributor

dpgeorge commented Oct 20, 2017

@Li-Weiwei @Lisa999 FYI you may want to test this out to have full socket support on Wiznet hardware.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 20, 2017

Contributor

@mhanuel26 FYI this PR introduces a TCP/IP stack for stm32 which can be used as a basis to get Ethernet working on STM32F7xx MCUs.

Contributor

dpgeorge commented Oct 20, 2017

@mhanuel26 FYI this PR introduces a TCP/IP stack for stm32 which can be used as a basis to get Ethernet working on STM32F7xx MCUs.

@Li-Weiwei

This comment has been minimized.

Show comment
Hide comment
@Li-Weiwei

Li-Weiwei Oct 20, 2017

Contributor

@dpgeorge I use the following command to compile your commits, but some errors happen(make version 3.81).

git submodule update --init
make -C mpy-cross
make -C ports/stm32 MICROPY_PY_WIZNET5K=5200

I made the following modifications to make it complete:

diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index 37a6801..162b309 100644
--- a/ports/stm32/Makefile
+++ b/ports/stm32/Makefile
@@ -68,7 +68,7 @@ CFLAGS_MCU_f4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DM
 CFLAGS_MCU_f7 = $(CFLAGS_CORTEX_M) -mtune=cortex-m7 -mcpu=cortex-m7 -DMCU_SERIES_F7
 CFLAGS_MCU_l4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES_L4
 
-CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAG
+CFLAGS = $(INC) -Wall -Wpointer-arith -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_EXTRA)
 CFLAGS += -D$(CMSIS_MCU)
 CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
 CFLAGS += $(COPT)
@@ -521,7 +521,7 @@ $(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FI
        $(ECHO) "Create $@"
        $(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@
 
-$(BUILD)/libaxtls.a:
+$(BUILD)/libaxtls.a: | $(BUILD)
        cd $(TOP)/lib/axtls; cp config/upyconfig config/.config
        cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B
        cd $(TOP)/lib/axtls; $(MAKE) clean
Contributor

Li-Weiwei commented Oct 20, 2017

@dpgeorge I use the following command to compile your commits, but some errors happen(make version 3.81).

git submodule update --init
make -C mpy-cross
make -C ports/stm32 MICROPY_PY_WIZNET5K=5200

I made the following modifications to make it complete:

diff --git a/ports/stm32/Makefile b/ports/stm32/Makefile
index 37a6801..162b309 100644
--- a/ports/stm32/Makefile
+++ b/ports/stm32/Makefile
@@ -68,7 +68,7 @@ CFLAGS_MCU_f4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DM
 CFLAGS_MCU_f7 = $(CFLAGS_CORTEX_M) -mtune=cortex-m7 -mcpu=cortex-m7 -DMCU_SERIES_F7
 CFLAGS_MCU_l4 = $(CFLAGS_CORTEX_M) -mtune=cortex-m4 -mcpu=cortex-m4 -DMCU_SERIES_L4
 
-CFLAGS = $(INC) -Wall -Wpointer-arith -Werror -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAG
+CFLAGS = $(INC) -Wall -Wpointer-arith -std=gnu99 -nostdlib $(CFLAGS_MOD) $(CFLAGS_EXTRA)
 CFLAGS += -D$(CMSIS_MCU)
 CFLAGS += $(CFLAGS_MCU_$(MCU_SERIES))
 CFLAGS += $(COPT)
@@ -521,7 +521,7 @@ $(GEN_CDCINF_FILE): $(CDCINF_TEMPLATE) $(INSERT_USB_IDS) $(USB_IDS_FI
        $(ECHO) "Create $@"
        $(Q)$(PYTHON) $(INSERT_USB_IDS) $(USB_IDS_FILE) $< > $@
 
-$(BUILD)/libaxtls.a:
+$(BUILD)/libaxtls.a: | $(BUILD)
        cd $(TOP)/lib/axtls; cp config/upyconfig config/.config
        cd $(TOP)/lib/axtls; $(MAKE) oldconfig -B
        cd $(TOP)/lib/axtls; $(MAKE) clean
@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 20, 2017

Contributor

I have also some problem in building
first, it complained about the directory build-PYBV11 not existing. After I created that manually
next, there was a compile error:

In file included from ../../lib/lwip/src/include/lwip/netif.h:41:0,
                 from ../../lib/lwip/src/include/lwip/udp.h:40,
                 from ../../lib/lwip/src/core/dhcp.c:75:
../../lib/lwip/src/core/dhcp.c: In function 'dhcp_bind':
../../lib/lwip/src/include/ipv4/lwip/ip_addr.h:200:39: error: the comparison will always evaluate as 'false' for the address of 'gw_addr' will never be NULL [-Werror=address]
 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
                                       ^
../../lib/lwip/src/core/dhcp.c:987:7: note: in expansion of macro 'ip_addr_isany'
   if (ip_addr_isany(&gw_addr)) {
       ^
cc1: all warnings being treated as errors

Edit: OK, the second one is the same problem Li-Weiwei reported.

Contributor

robert-hh commented Oct 20, 2017

I have also some problem in building
first, it complained about the directory build-PYBV11 not existing. After I created that manually
next, there was a compile error:

In file included from ../../lib/lwip/src/include/lwip/netif.h:41:0,
                 from ../../lib/lwip/src/include/lwip/udp.h:40,
                 from ../../lib/lwip/src/core/dhcp.c:75:
../../lib/lwip/src/core/dhcp.c: In function 'dhcp_bind':
../../lib/lwip/src/include/ipv4/lwip/ip_addr.h:200:39: error: the comparison will always evaluate as 'false' for the address of 'gw_addr' will never be NULL [-Werror=address]
 #define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
                                       ^
../../lib/lwip/src/core/dhcp.c:987:7: note: in expansion of macro 'ip_addr_isany'
   if (ip_addr_isany(&gw_addr)) {
       ^
cc1: all warnings being treated as errors

Edit: OK, the second one is the same problem Li-Weiwei reported.

@Li-Weiwei

This comment has been minimized.

Show comment
Hide comment
@Li-Weiwei

Li-Weiwei Oct 20, 2017

Contributor

I test the commits with my company code.
It seems to be much less efficient than before. I'm not sure if it's any other reason. I'll try to construct the test code later.

Contributor

Li-Weiwei commented Oct 20, 2017

I test the commits with my company code.
It seems to be much less efficient than before. I'm not sure if it's any other reason. I'll try to construct the test code later.

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 21, 2017

Contributor

It works at some level, and I could get some sample code running, including a little ftp server. Just the sending from Pyboard to PC is remarkably slow, at about 2.5kBytes/sec, while receiving from PC to Pyboard works at 160kbytes/sec. It seems as if there is some waiting after every 1k sent from Pyboard.
Edit: for comparison:
ESP32 WiFi: 50k/sec send, 160k/sec receive
ESP8266 WiFi: 5k/sec send, 150k/sec receive; the first ~20k of send are much faster.
WiPy2 WIFi: 80k/sec send/250k/sec receive
all w/o any file operations

In each case 100k of data was transferred.

Contributor

robert-hh commented Oct 21, 2017

It works at some level, and I could get some sample code running, including a little ftp server. Just the sending from Pyboard to PC is remarkably slow, at about 2.5kBytes/sec, while receiving from PC to Pyboard works at 160kbytes/sec. It seems as if there is some waiting after every 1k sent from Pyboard.
Edit: for comparison:
ESP32 WiFi: 50k/sec send, 160k/sec receive
ESP8266 WiFi: 5k/sec send, 150k/sec receive; the first ~20k of send are much faster.
WiPy2 WIFi: 80k/sec send/250k/sec receive
all w/o any file operations

In each case 100k of data was transferred.

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 22, 2017

Contributor

I tried a small tweak/hack to network_wiznet.c, before line 73.., If the interface has been initialized once, like during boot, you can call the constructor w/o arguments by nic = network.WIZNET5K(), you simply get back the existing nic object. That matches the ESP8266 situation.

    if (n_args == 0 && wiznet5k_obj.base.type != NULL) {
        return &wiznet5k_obj;
    }
Contributor

robert-hh commented Oct 22, 2017

I tried a small tweak/hack to network_wiznet.c, before line 73.., If the interface has been initialized once, like during boot, you can call the constructor w/o arguments by nic = network.WIZNET5K(), you simply get back the existing nic object. That matches the ESP8266 situation.

    if (n_args == 0 && wiznet5k_obj.base.type != NULL) {
        return &wiznet5k_obj;
    }
@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 23, 2017

Contributor

Thanks all for testing. I updated the Makefile so hopefully it doesn't have any errors during build anymore.

I also increased the amount of memory available for lwIP by about 2.5k to improve the TCP throughput. With my simple TCP tests within a local network (ie not over the internet) I can now get around 310k/s upload and download (before the patch the upload was about 10k/s).

Contributor

dpgeorge commented Oct 23, 2017

Thanks all for testing. I updated the Makefile so hopefully it doesn't have any errors during build anymore.

I also increased the amount of memory available for lwIP by about 2.5k to improve the TCP throughput. With my simple TCP tests within a local network (ie not over the internet) I can now get around 310k/s upload and download (before the patch the upload was about 10k/s).

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 26, 2017

Contributor

Some improvement. Sending speed from Pyboard to PC roughly doubled to 5 kBytes/Sec in chunks of ~2.5 kBytes. It's funny that uploading to the Pyboard is so much faster.

Contributor

robert-hh commented Oct 26, 2017

Some improvement. Sending speed from Pyboard to PC roughly doubled to 5 kBytes/Sec in chunks of ~2.5 kBytes. It's funny that uploading to the Pyboard is so much faster.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 27, 2017

Contributor

@robert-hh can you please point to code for the tests you run so I can try to reproduce and improve the speed?

Contributor

dpgeorge commented Oct 27, 2017

@robert-hh can you please point to code for the tests you run so I can try to reproduce and improve the speed?

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 27, 2017

Contributor

Hello @damien, I used this little script below for testing on pyboard, and nc on the pc. The script uses a fixed IP address, which you have to change, or use dhcp. The latter fails pretty often here. Pyboard and PC are connected to the same switch. There is also a second problem, explained below:

import socket
import network
import pyb
import time
buffer = "***************************************************************\n" * 8

nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
nic.active(1)
nic.ifconfig(('10.0.0.139', '255.255.255.0','10.0.0.240', '10.0.0.240'))
#nic.ifconfig('dhcp')

DATA_PORT = 8001

data_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
data_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
data_socket.bind(socket.getaddrinfo("0.0.0.0", DATA_PORT)[0][4])
data_socket.settimeout(2)
data_socket.listen(1)
if True:
    print("Waiting for a connection")
    data_client = None
    while data_client == None:
        try:
            data_client, data_addr = data_socket.accept()
        except:
            pass
        time.sleep_ms(50)
    print("connected to ", data_addr)

    for _ in range(200):
        data_client.sendall("%5d" % _ + buffer[5:])

    data_client.close()

data_socket.close()

Second observation: If I power on Pyboard w/o the network cable connected, then nno connection can be established, and frequent errors turn up like:
WIZCHIP fatal error in send_ethernet: -5
A reset will not cure that, only a power cycle with the cable connected at power on.
Update on the above: I had the network init in main.py. This issue happens when the network is init'ed the first time while no cable is connected, but the error state remains even if there is a second network init later with the cable connected.
Update 2: I personally see that more as a non-issue.

Contributor

robert-hh commented Oct 27, 2017

Hello @damien, I used this little script below for testing on pyboard, and nc on the pc. The script uses a fixed IP address, which you have to change, or use dhcp. The latter fails pretty often here. Pyboard and PC are connected to the same switch. There is also a second problem, explained below:

import socket
import network
import pyb
import time
buffer = "***************************************************************\n" * 8

nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
nic.active(1)
nic.ifconfig(('10.0.0.139', '255.255.255.0','10.0.0.240', '10.0.0.240'))
#nic.ifconfig('dhcp')

DATA_PORT = 8001

data_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
data_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
data_socket.bind(socket.getaddrinfo("0.0.0.0", DATA_PORT)[0][4])
data_socket.settimeout(2)
data_socket.listen(1)
if True:
    print("Waiting for a connection")
    data_client = None
    while data_client == None:
        try:
            data_client, data_addr = data_socket.accept()
        except:
            pass
        time.sleep_ms(50)
    print("connected to ", data_addr)

    for _ in range(200):
        data_client.sendall("%5d" % _ + buffer[5:])

    data_client.close()

data_socket.close()

Second observation: If I power on Pyboard w/o the network cable connected, then nno connection can be established, and frequent errors turn up like:
WIZCHIP fatal error in send_ethernet: -5
A reset will not cure that, only a power cycle with the cable connected at power on.
Update on the above: I had the network init in main.py. This issue happens when the network is init'ed the first time while no cable is connected, but the error state remains even if there is a second network init later with the cable connected.
Update 2: I personally see that more as a non-issue.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 30, 2017

Contributor

@robert-hh thanks for the test code. I can confirm that pyb->pc is very slow. lwIP is only sending 8 Ethernet packets every 500ms which is limiting the speed. It seems related to this post: http://lwip.100.n7.nabble.com/lwIP-delays-outgoing-TCP-packets-by-up-to-500ms-td26785.html

Contributor

dpgeorge commented Oct 30, 2017

@robert-hh thanks for the test code. I can confirm that pyb->pc is very slow. lwIP is only sending 8 Ethernet packets every 500ms which is limiting the speed. It seems related to this post: http://lwip.100.n7.nabble.com/lwIP-delays-outgoing-TCP-packets-by-up-to-500ms-td26785.html

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 30, 2017

Contributor

Yes, the 500ms bursts are obvious. Besides the sending speed, it seems to work reasonably well and is a good extension. The WIZNET5500 adapters are widely available and affordable.

Contributor

robert-hh commented Oct 30, 2017

Yes, the 500ms bursts are obvious. Besides the sending speed, it seems to work reasonably well and is a good extension. The WIZNET5500 adapters are widely available and affordable.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Oct 31, 2017

Contributor

@robert-hh I pushed a few commits to improve the throughput. I now see faster pyb->PC TCP speeds (about 600kbytes/sec) than PC->pyb. You might like to test it. The same patch also improves esp8266 TCP sending by about a factor of 10 (with no change in RAM usage).

Contributor

dpgeorge commented Oct 31, 2017

@robert-hh I pushed a few commits to improve the throughput. I now see faster pyb->PC TCP speeds (about 600kbytes/sec) than PC->pyb. You might like to test it. The same patch also improves esp8266 TCP sending by about a factor of 10 (with no change in RAM usage).

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Oct 31, 2017

Contributor

Wow! That's quite an improvement. With my little test set-up, I'll get ~300kBytes/sec send and 150kBytes/sec receive. But that's with small messages and some python overhead. Using the ftp server script feels really snappy. Files on Pyboard opened for editing in Fireftp open almost immediately.

Edit: Also on ESP8266 a very impressive boost. That MUST go into the master branch.

Contributor

robert-hh commented Oct 31, 2017

Wow! That's quite an improvement. With my little test set-up, I'll get ~300kBytes/sec send and 150kBytes/sec receive. But that's with small messages and some python overhead. Using the ftp server script feels really snappy. Files on Pyboard opened for editing in Fireftp open almost immediately.

Edit: Also on ESP8266 a very impressive boost. That MUST go into the master branch.

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Nov 10, 2017

Sorry for the long delay in answering. I've updated the local repository to the latest version and then merged the PR in the local repository. Now i can't build anymore using 'make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV10':
modussl_axtls.c:124:22: error: 'SSL_EAGAIN' undeclared
:-( help?

Lisa999 commented Nov 10, 2017

Sorry for the long delay in answering. I've updated the local repository to the latest version and then merged the PR in the local repository. Now i can't build anymore using 'make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV10':
modussl_axtls.c:124:22: error: 'SSL_EAGAIN' undeclared
:-( help?

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Nov 10, 2017

Contributor

did you run the command:
git submodule update --init
after updating the repository?

Contributor

robert-hh commented Nov 10, 2017

did you run the command:
git submodule update --init
after updating the repository?

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Nov 10, 2017

@robert-hh: Thx! That was indeed the problem, it's compiling now without errors. I was unaware that that is needed after a merge.

Lisa999 commented Nov 10, 2017

@robert-hh: Thx! That was indeed the problem, it's compiling now without errors. I was unaware that that is needed after a merge.

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Nov 10, 2017

`>>> import network,pyb

nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X4, pyb.Pin.board.X5)
nic.ifconfig('dhcp')
Traceback (most recent call last):
File "", line 1, in
OSError: timeout waiting for DHCP to get IP address

`
Same problem as robert-hh earlier reported, which is ok because the fixed ip adress works just fine.

Lisa999 commented Nov 10, 2017

`>>> import network,pyb

nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X4, pyb.Pin.board.X5)
nic.ifconfig('dhcp')
Traceback (most recent call last):
File "", line 1, in
OSError: timeout waiting for DHCP to get IP address

`
Same problem as robert-hh earlier reported, which is ok because the fixed ip adress works just fine.

@boochow

This comment has been minimized.

Show comment
Hide comment
@boochow

boochow Nov 22, 2017

I have tested on NUCLEO-F401RE with w5500 module.
Building process failed due to F401RE's lack of hardware rng function.
I edited rng.c so as to have yasmarang() in modurandom.c been called from rng_get() and now it successfully works. Much faster than using w5500's socket function. Awesome.

boochow commented Nov 22, 2017

I have tested on NUCLEO-F401RE with w5500 module.
Building process failed due to F401RE's lack of hardware rng function.
I edited rng.c so as to have yasmarang() in modurandom.c been called from rng_get() and now it successfully works. Much faster than using w5500's socket function. Awesome.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Nov 23, 2017

Contributor

@boochow thanks for testing! Following your suggestion I pushed a commit to this PR that uses yasmarang() for MCUs that don't have a hardware RNG.

Contributor

dpgeorge commented Nov 23, 2017

@boochow thanks for testing! Following your suggestion I pushed a commit to this PR that uses yasmarang() for MCUs that don't have a hardware RNG.

@boochow

This comment has been minimized.

Show comment
Hide comment
@boochow

boochow Dec 11, 2017

Hi,
I wrote the driver code for STM32 on-chip ethernet for NUCLEO-F767ZI based on this PR.
My code is still in early stage but is working. You can see it here ( stm32-ethernet branch).
https://github.com/boochow/micropython/tree/stm32-ethernet/ports/stm32

How to build:
git clone -b stm32-ethernet https://github.com/boochow/micropython.git
cd micropython
git submodule update --init
make -C mpy-cross
make -C ports/stm32 MICROPY_PY_ETH=RMII BOARD=NUCLEO_F767ZI

boochow commented Dec 11, 2017

Hi,
I wrote the driver code for STM32 on-chip ethernet for NUCLEO-F767ZI based on this PR.
My code is still in early stage but is working. You can see it here ( stm32-ethernet branch).
https://github.com/boochow/micropython/tree/stm32-ethernet/ports/stm32

How to build:
git clone -b stm32-ethernet https://github.com/boochow/micropython.git
cd micropython
git submodule update --init
make -C mpy-cross
make -C ports/stm32 MICROPY_PY_ETH=RMII BOARD=NUCLEO_F767ZI

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Dec 22, 2017

git clone https://github.com/micropython/micropython.git micropython
git pull origin pull/3379/head
make clean
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 deploy

CC build-PYBV3/pins_PYBV3.c
LINK build-PYBV3/firmware.elf
arm-none-eabi-ld: cannot find -laxtls

?

Lisa999 commented Dec 22, 2017

git clone https://github.com/micropython/micropython.git micropython
git pull origin pull/3379/head
make clean
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 deploy

CC build-PYBV3/pins_PYBV3.c
LINK build-PYBV3/firmware.elf
arm-none-eabi-ld: cannot find -laxtls

?

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Dec 22, 2017

Contributor

run:
make axtls
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 deploy

Contributor

robert-hh commented Dec 22, 2017

run:
make axtls
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 deploy

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Dec 22, 2017

I've tried that before (analogue to unix):
make axtls
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
make: *** No rule to make target 'axtls'. Stop.

Lisa999 commented Dec 22, 2017

I've tried that before (analogue to unix):
make axtls
Use make V=1 or set BUILD_VERBOSE in your environment to increase build verbosity.
make: *** No rule to make target 'axtls'. Stop.

@robert-hh

This comment has been minimized.

Show comment
Hide comment
@robert-hh

robert-hh Dec 22, 2017

Contributor

Wouldn't you have to run:
make BOARD=PYBV3
to clean beforehand?

Contributor

robert-hh commented Dec 22, 2017

Wouldn't you have to run:
make BOARD=PYBV3
to clean beforehand?

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Dec 22, 2017

@robert-hh I already had changed the Makefile : BOARD ?= PYBV3

Strangely enough are you right!
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 clean
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3

Solved the problem, although it shouldn't.. ;-)
Thx!

Lisa999 commented Dec 22, 2017

@robert-hh I already had changed the Makefile : BOARD ?= PYBV3

Strangely enough are you right!
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3 clean
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3

Solved the problem, although it shouldn't.. ;-)
Thx!

@mhanuel26

This comment has been minimized.

Show comment
Hide comment
@mhanuel26

mhanuel26 Dec 22, 2017

Hi @boochow , would you mind to place here an example code of your stm32 lwip port? An example that shows what is working so far?
Thanks in advance,

mhanuel26 commented Dec 22, 2017

Hi @boochow , would you mind to place here an example code of your stm32 lwip port? An example that shows what is working so far?
Thanks in advance,

@boochow

This comment has been minimized.

Show comment
Hide comment
@boochow

boochow Dec 23, 2017

Hi @mhanuel26, do you mean a python example code?
here you are. This code works on the port on my NUCLEO-F767ZI.

# stm32 version of wiznet_connect.py
import network
nic = network.Ethernet()
while not nic.isconnected():
    pass
nic.active(True)
nic.ifconfig('dhcp')
print(nic.ifconfig())
import socket
print(socket.getaddrinfo('micropython.org', 80))

# usage of static ip address
nic.ifconfig(('192.168.0.123','255.255.255.0','192.168.0.1','192.168.0.1'))
print(nic.ifconfig())

# ascii art star wars
addr = socket.getaddrinfo("towel.blinkenlights.nl", 23)[0][-1]
s = socket.socket()
s.connect(addr)
while True:
    data = s.recv(500)
    print(str(data, 'utf8'), end='')

boochow commented Dec 23, 2017

Hi @mhanuel26, do you mean a python example code?
here you are. This code works on the port on my NUCLEO-F767ZI.

# stm32 version of wiznet_connect.py
import network
nic = network.Ethernet()
while not nic.isconnected():
    pass
nic.active(True)
nic.ifconfig('dhcp')
print(nic.ifconfig())
import socket
print(socket.getaddrinfo('micropython.org', 80))

# usage of static ip address
nic.ifconfig(('192.168.0.123','255.255.255.0','192.168.0.1','192.168.0.1'))
print(nic.ifconfig())

# ascii art star wars
addr = socket.getaddrinfo("towel.blinkenlights.nl", 23)[0][-1]
s = socket.socket()
s.connect(addr)
while True:
    data = s.recv(500)
    print(str(data, 'utf8'), end='')
@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Mar 27, 2018

git clone https://github.com/micropython/micropython.git micropython
cd micropython/
git submodule update --init
git pull origin pull/3379/head
cd ports/stm32
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3

Result:
...
CC network_wiznet.c
network_wiznet.c: In function 'wiznet5k_make_new':
network_wiznet.c:79:5: error: implicit declaration of function 'spi_get_handle' [-Werror=implicit-function-declaration]
wiznet5k_obj.spi = spi_get_handle(args[0]);
^
network_wiznet.c:79:22: error: assignment makes pointer from integer without a cast [-Werror]
wiznet5k_obj.spi = spi_get_handle(args[0]);
^
network_wiznet.c:95:14: error: passing argument 1 of 'spi_init' from incompatible pointer type [-Werror]
spi_init(wiznet5k_obj.spi, false);
^
In file included from network_wiznet.c:10:0:
spi.h:51:6: note: expected 'const struct spi_t *' but argument is of type 'struct SPI_HandleTypeDef *'
void spi_init(const spi_t *spi, bool enable_nss_pin);
^
cc1: all warnings being treated as errors
../../py/mkrules.mk:47: recept voor doel 'build-PYBV3/network_wiznet.o' is mislukt
make: *** [build-PYBV3/network_wiznet.o] Fout 1

Help?

Lisa999 commented Mar 27, 2018

git clone https://github.com/micropython/micropython.git micropython
cd micropython/
git submodule update --init
git pull origin pull/3379/head
cd ports/stm32
make MICROPY_PY_WIZNET5K=5500 BOARD=PYBV3

Result:
...
CC network_wiznet.c
network_wiznet.c: In function 'wiznet5k_make_new':
network_wiznet.c:79:5: error: implicit declaration of function 'spi_get_handle' [-Werror=implicit-function-declaration]
wiznet5k_obj.spi = spi_get_handle(args[0]);
^
network_wiznet.c:79:22: error: assignment makes pointer from integer without a cast [-Werror]
wiznet5k_obj.spi = spi_get_handle(args[0]);
^
network_wiznet.c:95:14: error: passing argument 1 of 'spi_init' from incompatible pointer type [-Werror]
spi_init(wiznet5k_obj.spi, false);
^
In file included from network_wiznet.c:10:0:
spi.h:51:6: note: expected 'const struct spi_t *' but argument is of type 'struct SPI_HandleTypeDef *'
void spi_init(const spi_t *spi, bool enable_nss_pin);
^
cc1: all warnings being treated as errors
../../py/mkrules.mk:47: recept voor doel 'build-PYBV3/network_wiznet.o' is mislukt
make: *** [build-PYBV3/network_wiznet.o] Fout 1

Help?

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Mar 30, 2018

@dpgeorge Can we PLEASE have this committed into the master branch!!!

Lisa999 commented Mar 30, 2018

@dpgeorge Can we PLEASE have this committed into the master branch!!!

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 Apr 14, 2018

Work around until this is fixed:

git clone https://github.com/micropython/micropython.git micropython-stm32
cd micropython-stm32/
git submodule update --init
git checkout a275cb0f487cd6517760271dc01d369c32600c63
git pull origin pull/3379/head

Lisa999 commented Apr 14, 2018

Work around until this is fixed:

git clone https://github.com/micropython/micropython.git micropython-stm32
cd micropython-stm32/
git submodule update --init
git checkout a275cb0f487cd6517760271dc01d369c32600c63
git pull origin pull/3379/head
@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Apr 26, 2018

Contributor

I rebased this on the current master, fixed the build errors, and force-pushed it to this branch. It should now compile cleanly.

Can we PLEASE have this committed into the master branch!

I do intend to do this in the near future, but right now it's not possible in its current state because it changes behaviour of the stm32 port too much (existing CC3000 and WizNet5k drivers are no longer usable, and general performance is degraded because of the lwIP hook which is called too often).

Contributor

dpgeorge commented Apr 26, 2018

I rebased this on the current master, fixed the build errors, and force-pushed it to this branch. It should now compile cleanly.

Can we PLEASE have this committed into the master branch!

I do intend to do this in the near future, but right now it's not possible in its current state because it changes behaviour of the stm32 port too much (existing CC3000 and WizNet5k drivers are no longer usable, and general performance is degraded because of the lwIP hook which is called too often).

@Lisa999

This comment has been minimized.

Show comment
Hide comment
@Lisa999

Lisa999 May 19, 2018

1.9.4 does compile cleanly.

However these don't work anymore:

socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
TypeError: function takes 2 positional arguments but 4 were given

setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
AttributeError: 'module' object has no attribute 'SOL_SOCKET'
AttributeError: 'module' object has no attribute 'SO_REUSEADDR'

Meaning: UASYNCIO is NOT working...

Ps. network.active(True) isn't working either.

Lisa999 commented May 19, 2018

1.9.4 does compile cleanly.

However these don't work anymore:

socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)
TypeError: function takes 2 positional arguments but 4 were given

setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
AttributeError: 'module' object has no attribute 'SOL_SOCKET'
AttributeError: 'module' object has no attribute 'SO_REUSEADDR'

Meaning: UASYNCIO is NOT working...

Ps. network.active(True) isn't working either.

@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge May 22, 2018

Contributor

I've started to merge parts of this to master. See cda9641 for lwIP intergration.

And I've rebased this and cleaned it up and it now compiles cleanly with master and works.

Contributor

dpgeorge commented May 22, 2018

I've started to merge parts of this to master. See cda9641 for lwIP intergration.

And I've rebased this and cleaned it up and it now compiles cleanly with master and works.

dpgeorge added some commits Oct 17, 2017

stm32: Enable lwip with Wiznet MACRAW mode.
It works!  And provides a full socket implementation.

But some performance is lost: with a lot of memory allocated to lwIP it
gives Around 750,000 bytes/sec max TCP download, compared with 1M/sec
when using the TCP/IP stack on the Wiznet module.
@dpgeorge

This comment has been minimized.

Show comment
Hide comment
@dpgeorge

dpgeorge Jun 1, 2018

Contributor

The main network Wiznet driver from this PR was merged in 7d86ac6 . This PR has been rebased and the main thing left that it adds is ussl integration via axtls.

Contributor

dpgeorge commented Jun 1, 2018

The main network Wiznet driver from this PR was merged in 7d86ac6 . This PR has been rebased and the main thing left that it adds is ussl integration via axtls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment