Running TCP/IP Stack in Linux Print

 

With uClinux running on the STM32F7, you get the full Linux TCP/IP stack (kernel version 4.2.0). 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/ethernet/stmicro/stmmac/dwmac-stm32.c configured in the kernel using the СONFIG_DWMAC_STM32 build time option in Device Drivers -> Network device support -> Ethernet driver support -> STMicroelectronics devices -> STMicroelectronics 10/100/1000 Ethernet driver -> STMMAC Platform bus support.

For the run-time configuration of the kernel, Ethernet is enabled in rootfs.dts.STM32F7 in projects/rootfs as follows:

/*
* Ethernet controller
*/
&mac {
status = "okay";
phy-mode = "rmii";
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_mac_rmii>;
};

This will register a platform device for the STM32F7 Ethernet controller with the Ethernet driver.

The Linux project provided by Emcraft in the distribution (refer to projects/rootfs) and installed on each shipping module and kit includes the TCP/IP stack and various network related capabilities. The following spapshot shows the full Linux boosrap sequence from power-on to the Linux shell:

U-Boot 2010.03-cortexm-2.1.0 (Sep 19 2016 - 11:18:48)

CPU : STM32F7 (Cortex-M7)
Freqs: SYSCLK=200MHz,HCLK=200MHz,PCLK1=50MHz,PCLK2=100MHz
Board: STM32F7 SOM Rev 1.A, www.emcraft.com
DRAM: 32 MB
Flash: 16 MB
In: serial
Out: serial
Err: serial
Net: STM32_MAC
Hit any key to stop autoboot: 0
## Booting kernel from Legacy Image at 60020000 ...
Image Name: Linux-4.2.0-cortexm-2.1.0
Image Type: ARM Linux Multi-File Image (uncompressed)
Data Size: 5773859 Bytes = 5.5 MB
Load Address: c0008000
Entry Point: c0008001
Contents:
Image 0: 5756576 Bytes = 5.5 MB
Image 1: 17271 Bytes = 16.9 kB
Verifying Checksum ... OK
## Flattened Device Tree from multi component Image at 60020000
Booting using the fdt at 0x6059d6ec
Loading Multi-File Image ... OK
OK
Loading Device Tree to c1ff8000, end c1fff376 ... OK

Starting kernel ...

Booting Linux on physical CPU 0x0
Linux version 4.2.0-cortexm-2.1.0 (psl‌@skywanderer.emcraft.com) (gcc version 4.4.1 (Sourcery G++ Lite 2010q1-189) ) #2 Mon Sep 19 11:19:44 +0400 2016
CPU: ARMv7-M [410fc271] revision 1 (ARMv7M), cr=00000000
CPU: WBA data cache, WBA instruction cache
Machine model: EmCraft Systems STM32F7-SOM board
Built 1 zonelists in Zone order, mobility grouping off. Total pages: 8128
Kernel command line: stm32_platform=stm32f7-som console=ttyS0,115200 panic=10
ip=192.168.1.132:192.168.1.65:::stm32f7-som:eth0:off
PID hash table entries: 128 (order: -3, 512 bytes)
Dentry cache hash table entries: 4096 (order: 2, 16384 bytes)
Inode-cache hash table entries: 2048 (order: 1, 8192 bytes)
Memory: 25624K/32768K available (2295K kernel code, 165K rwdata, 508K rodata, 2652K init, 96K bss, 7144K reserved, 0K cma-reserved)
Virtual kernel memory layout:
vector : 0x00000000 - 0x00001000 ( 4 kB)
fixmap : 0xffc00000 - 0xfff00000 (3072 kB)
vmalloc : 0x00000000 - 0xffffffff (4095 MB)
lowmem : 0xc0000000 - 0xc2000000 ( 32 MB)
.text : 0xc0008000 - 0xc02c5000 (2804 kB)
.init : 0xc02c5000 - 0xc055c000 (2652 kB)
.data : 0xc055c000 - 0xc05856a0 ( 166 kB)
.bss : 0xc0586000 - 0xc059e284 ( 97 kB)
NR_IRQS:16 nr_irqs:16 16
clocksource: arm_system_timer: mask: 0xffffff max_cycles: 0xffffff, max_idle_ns: 298634427 ns ARM System timer initialized as clocksource
/soc/timer@40000000: STM32 clockevent driver initialized (32 bits)
sched_clock: 32 bits at 100 Hz, resolution 10000000ns, wraps every 21474836475000000ns
Calibrating delay loop... 395.67 BogoMIPS (lpj=1978368)
pid_max: default: 4096 minimum: 301
Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
devtmpfs: initialized
clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
pinctrl core: initialized pinctrl subsystem
NET: Registered protocol family 16
stm32-pinctrl pin-controller: nbanks = 11
stm32-pinctrl pin-controller: nfunctions = 14
stm32-pinctrl pin-controller: ngroups = 15
stm32-pinctrl pin-controller: GPIOA bank added.
stm32-pinctrl pin-controller: GPIOB bank added.
stm32-pinctrl pin-controller: GPIOC bank added.
stm32-pinctrl pin-controller: GPIOD bank added.
stm32-pinctrl pin-controller: GPIOE bank added.
stm32-pinctrl pin-controller: GPIOF bank added.
stm32-pinctrl pin-controller: GPIOG bank added.
stm32-pinctrl pin-controller: GPIOH bank added.
stm32-pinctrl pin-controller: GPIOI bank added.
stm32-pinctrl pin-controller: GPIOJ bank added.
stm32-pinctrl pin-controller: GPIOK bank added.
stm32-pinctrl pin-controller: Function[0 name:i2c_1, groups:1]
stm32-pinctrl pin-controller: Function[1 name:i2c_2, groups:1]
stm32-pinctrl pin-controller: Function[2 name:i2c_3, groups:1]
stm32-pinctrl pin-controller: Function[3 name:mac, groups:2]
stm32-pinctrl pin-controller: Function[4 name:sdio, groups:1]
stm32-pinctrl pin-controller: Function[5 name:spi_2, groups:1]
stm32-pinctrl pin-controller: Function[6 name:spi_4, groups:1]
stm32-pinctrl pin-controller: Function[7 name:spi_5, groups:1]
stm32-pinctrl pin-controller: Function[8 name:usart1, groups:1]
stm32-pinctrl pin-controller: Function[9 name:usart6, groups:1]
stm32-pinctrl pin-controller: Function[10 name:usart7, groups:1]
stm32-pinctrl pin-controller: Function[11 name:usb_fs, groups:1]
stm32-pinctrl pin-controller: Function[12 name:usb_hs, groups:1]
stm32-pinctrl pin-controller: Function[13 name:ltdc, groups:1]
stm32_dma 40026000.dma: STM32 DMA Controller ( slave ), 8 channels
stm32_dma 40026400.dma: STM32 DMA Controller ( slave ), 8 channels
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
soc:phy_hs supply vcc not found, using dummy regulator
soc:phy_fs supply vcc not found, using dummy regulator
pps_core: LinuxPPS API ver. 1 registered
pps_core: Software ver. 5.3.6 - Copyright 2005-2007 Rodolfo Giometti
<giometti@linux.it>
PTP clock support registered
Bluetooth: Core ver 2.20
NET: Registered protocol family 31
Bluetooth: HCI device and connection manager initialized
Bluetooth: HCI socket layer initialized
Bluetooth: L2CAP socket layer initialized
Bluetooth: SCO socket layer initialized
clocksource: Switched to clocksource arm_system_timer
NET: Registered protocol family 2
TCP established hash table entries: 1024 (order: 0, 4096 bytes)
TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
TCP: Hash tables configured (established 1024 bind 1024)
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
futex hash table entries: 16 (order: -5, 192 bytes)
jffs2: version 2.2. (NAND) © 2001-2006 Red Hat, Inc.
fuse init (API version 7.23)
Block layer SCSI generic (bsg) driver version 0.4 loaded (major 251)
io scheduler noop registered
io scheduler cfq registered (default)
stm32-pinctrl pin-controller: maps: function ltdc group ltdc-0 num 29
stm32_lcdfb 40016800.ltdc: fb0: fb device registered successfully
STM32 USART driver initialized
stm32-pinctrl pin-controller: maps: function usart1 group usart1-0 num 3
40011000.serial: ttyS0 at MMIO 0x40011000 (irq = 21, base_baud = 6250000) is a stm32f7-usart console [ttyS0] enabled
stm32-pinctrl pin-controller: maps: function usart6 group usart6-0 num 3
40011400.serial: ttyS5 at MMIO 0x40011400 (irq = 22, base_baud = 6250000) is a stm32f7-usart
physmap-flash.0: Found 1 x16 devices at 0x0 in 16-bit bank. Manufacturer ID 0x000001 Chip ID 0x002101
Amd/Fujitsu Extended Query Table at 0x0040
Amd/Fujitsu Extended Query version 1.5.
number of CFI chips: 1
3 ofpart partitions found on MTD device physmap-flash.0
Creating 3 MTD partitions on "physmap-flash.0":
0x000000000000-0x000000020000 : "flash_uboot_env"
0x000000020000-0x000000a20000 : "flash_linux_image"
0x000000a20000-0x000001000000 : "flash_jffs2"
stm32-pinctrl pin-controller: maps: function mac group mac_rmii num 10
stmmac - user ID: 0x10, Synopsys ID: 0x35
Ring mode enabled
DMA HW capability register supported
Enhanced/Alternate descriptors
Enabled extended descriptors
RX Checksum Offload Engine supported (type 2)
TX Checksum insertion supported
Wake-Up On Lan supported
Enable RX Mitigation via HW Watchdog Timer
libphy: stmmac: probed
eth0: PHY ID 00221560 at 0 IRQ POLL (stmmac-0:00) active
eth0: PHY ID 00221560 at 1 IRQ POLL (stmmac-0:01)
PPP generic driver version 2.4.2
PPP BSD Compression module registered
PPP Deflate Compression module registered
usbcore: registered new interface driver rt2800usb
stm32-pinctrl pin-controller: maps: function usb_hs group usb_hs-0 num 13
dwc2 40040000.usb: DWC OTG Controller
dwc2 40040000.usb: new USB bus registered, assigned bus number 1
dwc2 40040000.usb: irq 40, io mem 0x00000000
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 1 port detected
usbcore: registered new interface driver cdc_acm
cdc_acm: USB Abstract Control Model driver for USB modems and ISDN adapters
usbcore: registered new interface driver usb-storage
stm32-rtc 40002800.rtc: rtc core: registered 40002800.rtc as rtc0
i2c /dev entries driver
stm32-pinctrl pin-controller: maps: function i2c_1 group i2c_1-0 num 3
crtouch_drv 0-0049: failed to read size of screen
crtouch_drv: probe of 0-0049 failed with error -5
stm32f7-i2c 40005400.i2c: I2C Controller i2c-0 at 40005400,irq=19
usbcore: registered new interface driver btusb
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
NET: Registered protocol family 17
Bluetooth: RFCOMM TTY layer initialized
Bluetooth: RFCOMM socket layer initialized
Bluetooth: RFCOMM ver 1.11
stm32-rtc 40002800.rtc: setting system clock to 2000-01-01 05:12:04 UTC (946703524)
IP-Config: Guessing netmask 255.255.255.0
IP-Config: Complete:
device=eth0, hwaddr=c0:b1:3c:88:88:86, ipaddr=192.168.1.132, mask=255.255.255.0,
gw=255.255.255.255
host=stm32f7-som, domain=, nis-domain=(none)
bootserver=192.168.1.65, rootserver=192.168.1.65, rootpath=
vmmc: disabling
Freeing unused kernel memory: 2652K (c02c5000 - c055c000)
init started: BusyBox v1.17.0 (2016-09-19 11:07:14 +0400)
stm32-dwmac 40028000.ethernet eth0: Link is Up - 100Mbps/Full - flow control off
/ #

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 192.168.1.132
PING 192.168.1.132 (192.168.1.132) 56(84) bytes of data.
64 bytes from 192.168.1.132: icmp_seq=1 ttl=64 time=4.79 ms
64 bytes from 192.168.1.132: icmp_seq=2 ttl=64 time=1.20 ms
64 bytes from 192.168.1.132: icmp_seq=3 ttl=64 time=1.29 ms
64 bytes from 192.168.1.132: icmp_seq=4 ttl=64 time=1.19 ms
^C
--- 192.168.1.132 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 1.196/2.120/4.791/1.542 ms

Ping the development host from the STM32F7:

/ # ping 192.168.1.65
PING 192.168.1.65 (192.168.1.65): 56 data bytes
64 bytes from 192.168.1.65: seq=0 ttl=128 time=3.422 ms
64 bytes from 192.168.1.65: seq=1 ttl=128 time=1.663 ms
64 bytes from 192.168.1.65: seq=2 ttl=128 time=1.683 ms
64 bytes from 192.168.1.65: seq=3 ttl=128 time=1.703 ms
64 bytes from 192.168.1.65: seq=4 ttl=128 time=1.659 ms
^C
--- 192.168.1.65 ping statistics ---
5 packets transmitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 1.659/2.026/3.422 ms

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

/ # telnetd
/ # ps
PID USER       VSZ STAT COMMAND
1 root       364 S    init
2 root         0 SW   [kthreadd]
3 root         0 SW   [ksoftirqd/0]
4 root         0 SW   [kworker/0:0]
5 root         0 SW<  [kworker/0:0H]
6 root         0 SW   [kworker/u2:0]
7 root         0 SW<  [khelper]
8 root         0 SW   [kdevtmpfs]
9 root         0 SW<  [writeback]
10 root        0 SW<  [crypto]
11 root        0 SW<  [bioset]
12 root        0 SW<  [kblockd]
13 root        0 SW<  [cfg80211]
14 root        0 SW   [kworker/0:1]
15 root        0 SW<  [rpciod]
16 root        0 SW   [kswapd0]
17 root        0 SW   [fsnotify_mark]
18 root        0 SW<  [nfsiod]
40 root        0 SW   [spi1]
41 root        0 SW<  [dwc2]
42 root        0 SW<  [krfcommd]
43 root        0 SW<  [deferwq]
44 root        0 SW   [kworker/u2:1]
50 root      400 S    -/bin/hush
53 root      356 S    telnetd
54 root      372 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 192.168.1.132
Trying 192.168.1.132...
Connected to 192.168.1.132.
Escape character is '^]'.

stm32f7-som login: root
Password:
/ # ls
bin etc init mnt mnt2 mnt4 root sys usr
dev httpd lib mnt1 mnt3 proc sbin tmp 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       364 S    init
2 root         0 SW   [kthreadd]
3 root         0 SW   [ksoftirqd/0]
4 root         0 SW   [kworker/0:0]
5 root         0 SW<  [kworker/0:0H]
6 root         0 SW   [kworker/u2:0]
7 root         0 SW<  [khelper]
8 root         0 SW   [kdevtmpfs]
9 root         0 SW<  [writeback]
10 root        0 SW<  [crypto]
11 root        0 SW<  [bioset]
12 root        0 SW<  [kblockd]
13 root        0 SW<  [cfg80211]
14 root        0 SW   [kworker/0:1]
15 root        0 SW<  [rpciod]
16 root        0 SW   [kswapd0]
17 root        0 SW   [fsnotify_mark]
18 root        0 SW<  [nfsiod]
40 root        0 SW   [dwc2]
42 root        0 SW<  [krfcommd]
43 root        0 SW<  [deferwq]
44 root        0 SW   [kworker/u2:1]
50 root      400 S    -/bin/hush
53 root      364 S    telnetd
59 root      316 S    dropbear
60 root      372 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 This e-mail address is being protected from spambots. You need JavaScript enabled to view it
The authenticity of host '192.168.1.132 (192.168.1.132)' 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 '192.168.1.132' (DSA) to the list of known hosts.
This e-mail address is being protected from spambots. You need JavaScript enabled to view it 's password:
/ # ps
PID USER       VSZ STAT COMMAND
1 root       364 S    init
2 root         0 SW   [kthreadd]
3 root         0 SW   [ksoftirqd/0]
4 root         0 SW   [kworker/0:0]
5 root         0 SW<  [kworker/0:0H]
6 root         0 SW   [kworker/u2:0]
7 root         0 SW<  [khelper]
8 root         0 SW   [kdevtmpfs]
9 root         0 SW<  [writeback]
10 root        0 SW<  [crypto]
11 root        0 SW<  [bioset]
12 root        0 SW<  [kblockd]
13 root        0 SW<  [cfg80211]
14 root        0 SW   [kworker/0:1]
15 root        0 SW<  [rpciod]
16 root        0 SW   [kswapd0]
17 root        0 SW   [fsnotify_mark]
18 root        0 SW<  [nfsiod]
40 root        0 SW   [dwc2]
42 root        0 SW<  [krfcommd]
43 root        0 SW<  [deferwq]
44 root        0 SW   [kworker/u2:1]
50 root       400 S    -/bin/hush
53 root       364 S    telnetd
59 root       396 D    dropbear
64 root       396 R    dropbear
65 root       384 S    -sh
66 root       372 R    ps
/ #
~ # exit
Connection to 192.168.1.132 closed.
>-bash-3.2$

On the target, enable access to the Internet by configuring a default gateway. Note also that the system makes use of the public name server provided by Google:

/ # route add default gw 192.168.1.1
/ # cat /etc/resolv.conf
# This configuration makes use of the Google public DNS server.
# If you would like to use something else, replace with the IP
# of your DNS server

nameserver 8.8.8.8
/ #

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

/ # date
Sat Jan 1 05:26:37 UTC 2000
/ # ntpd -p 0.fedora.pool.ntp.org
/ # sleep 5
/ # date
Mon Sep 19 16:13:15 UTC 2016
/ #

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 192.168.1.65:/mnt/work/emcraft/bsp/nfs /mnt
/ # ls /mnt
100MB hello.uImage.42 ...

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: