Running TCP/IP Stack in Linux Print

 

With uClinux running on the STM32F7, you get the full Linux TCP/IP stack (kernel version 2.6.33). Userspace POSIX APIs are provided by the uClibc library. Key user-space networking tools and utilities are available from the multi-call busybox. Additional tools and packages, such as for instance the SSH dropbear server, can be built specifically for uClinux. All in all, you have the powerful Linux TCP/IP stack at your disposal.

There is a full-functioning Ethernet device driver available in the kernel tree for the STM32F7. The device driver is linux/drivers/net/arm/stm32_eth.c configured in the kernel using the CONFIG_STM32_ETHER build time option in Device Drivers -> Network device support -> Etherner (10 or 100Mbit). You can also chose whether you want the Ethernet buffer descriptors and buffers to reside in the internal SRAM of the STM32F7 or in external RAM managed by the kernel:

Once you have enabled CONFIG_STM32_ETHER, go to System Type -> STM32 I/O interfaces and enable STM32 Ethernet port (CONFIG_STM32_MAC). This will register a platform device for the STM32F7 Ethernet controller with the Ethernet driver:

Emcraft provides a sample Linux project called networking that demonstrates TCP/IP over Ethernet on the STM32F7. In the Emcraft Linux distribution, the project can be found at projects/networking. The following provides detailed information on running that project on the STM32F7.

The bootable Linux image ready to be installed to the embedded Flash of the STM32F7 (networking.uImage) is about 2.3 MBytes in size. It easily fits into the on-module Flash of the STM32F7 SOM with plenty of room for custom enhancements. Refer to Installing Linux Images to Flash for information on how to install the image to the STM32F7 SOM.

When booted to the STM32F7 target, boot time to the shell is about 2 seconds from power-on / reset. In other words, in 2 seconds from power-on you have your unit running shell with the TCP/IP stack and Ethernet interface fully configured and connected to the network:

U-Boot 2010.03-linux-cortexm-1.13.0 (Feb 17 2015 - 13:58:38)

CPU  : STM32F7 (Cortex-M7)
...
Linux version 2.6.33-arm1 (vlad@ocean.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #108 Tue Feb 17 13:21:29 MSK 2015
...
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 1024 (order: 1, 8192 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
TCP reno registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
...
blackfin-eth: Using SRAM for DMA buffers from 20001000
blackfin-eth: found MAC at 0x40028000, irq 61
blackfin_mii_bus: probed
found PHY id 0x221556 addr 0
eth0: using MII interface
eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=00:00, irq=-1)
rtc-stm32f2 rtc-stm32f2: rtc core: registered rtc-stm32f2 as rtc0
TCP cubic registered
NET: Registered protocol family 17
ARMv7-M VFP Extension supported
rtc-stm32f2 rtc-stm32f2: setting system clock to 2000-01-03 23:48:05 UTC (946943285)
IP-Config: Guessing netmask 255.255.0.0
IP-Config: Complete:
device=eth0, addr=172.17.4.211, mask=255.255.0.0, gw=255.255.255.255,
host=stm32f7-som, domain=, nis-domain=(none),
bootserver=172.17.0.0, rootserver=172.17.0.0, rootpath=
PHY: 00:00 - Link is Up - 100/Full
...
init started: BusyBox v1.17.0 (2015-02-17 16:15:05 MSK)
~ # ifconfig eth0
eth0      Link encap:Ethernet  HWaddr C0:B1:3C:88:88:89
inet addr:172.17.4.211  Bcast:172.17.255.255  Mask:255.255.0.0
UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
RX packets:17 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2092 (2.0 KiB)  TX bytes:0 (0.0 B)
~ #

Let's test the TCP/IP stack on the STM32F7.

From the development host validate that the STM32F7 is visible using ping:

-bash-3.2$ ping 172.17.4.211
PING 172.17.4.211 (172.17.4.211) 56(84) bytes of data.
64 bytes from 172.17.4.211: icmp_seq=1 ttl=64 time=3.79 ms
64 bytes from 172.17.4.211: icmp_seq=2 ttl=64 time=0.532 ms
64 bytes from 172.17.4.211: icmp_seq=3 ttl=64 time=0.550 ms
64 bytes from 172.17.4.211: icmp_seq=4 ttl=64 time=0.538 ms
^C
--- 172.17.4.211 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3387ms
rtt min/avg/max/mdev = 0.532/1.352/3.790/1.407 ms
-bash-3.2$

Ping the development host from the STM32F7:

~ # ping 172.17.0.1
PING 172.17.0.1 (172.17.0.1): 56 data bytes
64 bytes from 172.17.0.1: seq=0 ttl=64 time=1.191 ms
64 bytes from 172.17.0.1: seq=1 ttl=64 time=1.057 ms
64 bytes from 172.17.0.1: seq=2 ttl=64 time=1.057 ms
64 bytes from 172.17.0.1: seq=3 ttl=64 time=1.054 ms
64 bytes from 172.17.0.1: seq=4 ttl=64 time=1.057 ms
64 bytes from 172.17.0.1: seq=5 ttl=64 time=1.024 ms
^C
--- 172.17.0.1 ping statistics ---
6 packets transmitted, 6 packets received, 0% packet loss
round-trip min/avg/max = 1.024/1.073/1.191 ms
~ #

On the target, start the telnetd daemon to allow connections to the STM32F7:

~ # telnetd
~ # ps
PID USER VSZ STAT COMMAND
1 root 352 S init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [events/0]
5 root 0 SW [khelper]
6 root 0 SW [async/mgr]
7 root 0 SW [sync_supers]
8 root 0 SW [bdi-default]
9 root 0 SW [kblockd/0]
10 root 0 SW [rpciod/0]
11 root 0 SW [kswapd0]
12 root 0 SW [nfsiod]
18 root 367 S /bin/hush -i
25 root 332 S telnetd
26 root 348 R ps
~ #

Connect to the target from the development host using telnet. The target is configured to accept an empty password for root so just hit Enter when asked for password:

-bash-3.2$ telnet 172.17.4.211
Trying 172.17.4.211...
Connected to 172.17.4.211.
Escape character is '^]'.

stm32f7-som login: root
Password:
~ # ls
bin    dev    etc    httpd  init   mnt    proc   root   sys    usr    var
~ # exit
Connection closed by foreign host.
-bash-3.2$

Start the dropbear SSH daemon to allow secure connections to the target:

~ # dropbear
~ # ps
PID USER VSZ STAT COMMAND
1 root 352 S init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [events/0]
5 root 0 SW [khelper]
6 root 0 SW [async/mgr]
7 root 0 SW [sync_supers]
8 root 0 SW [bdi-default]
9 root 0 SW [kblockd/0]
10 root 0 SW [rpciod/0]
11 root 0 SW [kswapd0]
12 root 0 SW [nfsiod]
18 root 367 S /bin/hush -i
25 root 340 S telnetd
30 root 296 S dropbear
31 root 348 R ps
~ #

Connect to the target from the development host using ssh. The first connection takes several seconds to establish as the STM32F7 runs computation-extensive key calculations. Again, hit Enter on the password prompt:

-bash-3.2$ ssh root @172.17.4.211
The authenticity of host '172.17.4.211 (172.17.4.211)' can't be established.
DSA key fingerprint is d2:d1:5f:dd:84:65:1d:2f:ee:69:0c:85:d0:22:0c:87.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '172.17.4.211' (DSA) to the list of known hosts.
[email protected] 172.17.4.211's password:
~ # ps
PID USER       VSZ STAT COMMAND
1 root       356 S    init
2 root         0 SW   [kthreadd]
3 root         0 SW   [ksoftirqd/0]
4 root         0 SW   [events/0]
5 root         0 SW   [khelper]
6 root         0 SW   [async/mgr]
7 root         0 SW   [sync_supers]
8 root         0 SW   [bdi-default]
9 root         0 SW   [kblockd/0]
10 root        0 SW   [rpciod/0]
11 root        0 SW   [kswapd0]
12 root        0 SW   [nfsiod]
13 root        0 SW   [mtdblockd]
19 root       371 S    /bin/hush -i
23 root       344 S    telnetd
28 root       352 D    dropbear
30 root       352 S    dropbear
31 root       363 S    -sh
32 root       352 R    ps
~ # exit
Connection to 172.17.4.211 closed.
-bash-3.2$

On the target, configure a default gateway and a name resolver. Note how the sample configuration below makes use of the public name server provided by Google. Note also use of vi to edit target files on the target:

~ # route add default gw 172.17.0.1
~ # vi /etc/resolv.conf
nameserver 8.8.8.8
~

Use ntpd to synchronize the time on the target with the time provided by a public server:

~ # date
Thu Jan 1 00:40:53 UTC 1970
~ # ntpd -p 0.fedora.pool.ntp.org
~ # sleep 5
~ # date
Tue Feb 17 08:53:18 UTC 2015
~ #

Use wget to download a file from a remote server:

~ # wget ftp://ftp.gnu.org/README
Connecting to ftp.gnu.org (208.118.235.20:21)
README 100% |*******************************| 1962 --:--:-- ETA
~ # cat README
This is ftp.gnu.org, the FTP server of the the GNU project.
...

Mount a directory exported by a development host over NFS:

~ # mount -o nolock,rsize=1024 172.17.0.1:/home/vlad/test/ /mnt
~ # ls
bin    dev    etc    httpd  init   mnt    proc   root   sys    usr    var
~ # ls /mnt
linux-STMDISCO-1.12.1.tar.bz2
linux-cortexm-1.12.0
linux-cortexm-1.12.1
linux-cortexm-1.12.1.tar.bz2
linux-cortexm-1.12.2
...
~ #

Start the HTTP daemon:

~ # httpd -h /httpd/html/
~ #

From a local host, open a Web browser to the STM32F7 and watch the demo web page provided by the target. The STM32F7 shows the current time and date as well as the list of the currently running processes: