Why register?

  • Download software and technical materials
  • Purchase products at our on-line shop
  • Receive design news to stay up-to-date with Emcraft's new solutions



Running TCP/IP Stack in Linux Print


With uClinux running on the STM32F7 Discovery board, 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 Discovery. 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 Discovery. 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 Discovery.

The bootable Linux image ready to be installed to the embedded Flash of the STM32F7 Discovery (networking.uImage) is about 2.3 MBytes in size. Refer to Loading Linux images via Ethernet and TFTP for information on how to install the image to the STM32F7 Discovery.

When booted to the STM32F7 Discovery 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-cortexm-1.14.2 (Sep 04 2015 - 20:10:20)

CPU : STM32F7 (Cortex-M7)

Starting kernel ......
Linux version 2.6.33-arm1 (antonp‌‌‌@‌antonp.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #76 Thu Jun 25 17:01:31 MSK 2015
CPU: ARMv7-M Processor [410fc271] revision 1 (ARMv7M)
CPU: WBA data cache, WBA instruction cache
Machine: STMicro STM32
Built 1 zonelists in Zone order, mobility grouping off. Total pages: 2032
Kernel command line: stm32_platform=stm32f7-disco console=ttyS5,115200 panic=10 ip= ethaddr=C0:B1:3C:88:45:86
PID hash table entries: 32 (order: -5, 128 bytes)
Dentry cache hash table entries: 1024 (order: 0, 4096 bytes)
Inode-cache hash table entries: 1024 (order: 0, 4096 bytes)
Memory: 8MB = 8MB total
Memory: 5348k/5348k available, 2844k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0x00000000 - 0x00001000 ( 4 kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
vmalloc : 0x00000000 - 0xffffffff (4095 MB)
lowmem : 0xc0000000 - 0xc0800000 ( 8 MB)
modules : 0xc0000000 - 0xc0800000 ( 8 MB)
.init : 0xc0008000 - 0xc0092000 ( 552 kB)
.text : 0xc0092000 - 0xc0199000 (1052 kB)
.data : 0xc019a000 - 0xc01acd00 ( 76 kB)
Hierarchical RCU implementation.
Calibrating delay loop... 397.31 BogoMIPS (lpj=1986560)
Mount-cache hash table entries: 512
NET: Registered protocol family 16
stm32_flash_init: Unknown platform 0x6, exit
bio: create slab <bio-0> at 0
Switching to clocksource cm3-systick
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 512 (order: 0, 4096 bytes)
TCP bind hash table entries: 512 (order: -1, 2048 bytes)
TCP: Hash tables configured (established 512 bind 512)
TCP reno registered
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
JFFS2 version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 254)
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Serial: STM32 USART driver
stm32serial.5: ttyS5 at MMIO 0x40011400 (irq = 71) is a STM32 USART Port
console [ttyS5] enabled
blackfin-eth: Using SRAM for DMA buffers from 20001000
blackfin-eth: found MAC at 0x40028000, irq 61
blackfin_mii_bus: probed
found PHY id 0x7c131 addr 0
eth0: using MII interface
eth0: attached PHY driver [Generic PHY] (mii_bus:phy_addr=00:00, irq=-1)
TCP cubic registered
NET: Registered protocol family 17
ARMv7-M VFP Extension supported
IP-Config: Guessing netmask
IP-Config: Complete:
device=eth0, addr=, mask=, gw=,
host=stm32f7-disco, domain=, nis-domain=(none),
bootserver=, rootserver=, rootpath=
PHY: 00:00 - Link is Up - 100/Full
Freeing init memory: 552K
init started: BusyBox v1.17.0 (2015-06-25 12:17:23 MSK)
~ #
~ # ifconfig eth0
eth0Link encap:Ethernet HWaddr C0:B1:3C:88:45:86
inet addr: Bcast: Mask:
RX packets:71 errors:0 dropped:0 overruns:0 frame:0
TX packets:1 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:5594 (5.4 KiB) TX bytes:42 (42.0 B)
~ #

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

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

-bash-3.2$ ping
PING ( 56(84) bytes of data.
64 bytes from icmp_seq=1 ttl=64 time=3.79 ms
64 bytes from icmp_seq=2 ttl=64 time=0.532 ms
64 bytes from icmp_seq=3 ttl=64 time=0.550 ms
64 bytes from icmp_seq=4 ttl=64 time=0.538 ms
--- 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

Ping the development host from the STM32F7 Discovery:

~ # ping
PING ( 56 data bytes
64 bytes from seq=0 ttl=64 time=3.412 ms
64 bytes from seq=1 ttl=64 time=0.419 ms
64 bytes from seq=2 ttl=64 time=0.422 ms
64 bytes from seq=3 ttl=64 time=0.428 ms
64 bytes from seq=4 ttl=64 time=0.427 ms
--- ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.419/1.021/3.412 ms
~ #

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

~ # telnetd
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]
13   root 0 SW    [mtdblockd]
19   root 367 S    /bin/hush -i
23   root 332 S    telnetd
24   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
Connected to
Escape character is '^]'.

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

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

~ # dropbear
~ # ps
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]
13  root 0 SW   [mtdblockd]
19  root 367 S   /bin/hush -i
23  root 332 S   telnetd
26  root 292 S   dropbear
27  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 Discovery runs computation-extensive key calculations. Again, hit Enter on the password prompt:

-bash-3.2$ ssh root‌@
The authenticity of host ' (' 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 '' (DSA) to the list of known hosts.
root@‌'s password:
~ # ps
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 closed.

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
~ # vi /etc/resolv.conf

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

~ # date
Thu Jan 1 00:06:16 UTC 1970
~ # ntpd -p pool.ntp.org
~ # sleep 5
~ # date
Fri Jun 26 12:31:50 UTC 2015
~ #

Use wget to download a file from a remote server:

~ # wget ftp://ftp.gnu.org/README
Connecting to ftp.gnu.org (
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 /mnt
~ # ls
bin    dev    etc    httpd  init   mnt    proc   root   sys    usr    var
~ # ls /mnt
~ #