目次

last update: 2024/04

FreeRTOS用BSPパッケージ
第3章: TCP/IPネットワーク通信
評価ボード:RX72N Envision Kit




テストサンプル

Demo Sample Application Folder:

Application
 └ _Exclude
     ├ IP  ..... TCP/IPネットワーク通信機能のデモサンプル

emNet (IP/UDP/TCP/TELNET/TFTP/mDNS/VLAN)

Sample説明
IP_ACD_StartACD(Address Collision Detection)機能の動作を確認します
IP_AUTOIP_StartAutoIPプロトコールを使用してIPアドレスの自動設定を確認します
IP_DHCPServerDHCPサーバー機能の実装方法を示すデモサンプル
IP_DNSClientネットワークホスト名を IP アドレスに解決する方法を示します
IP_MDNS_ServerSamplemDNSサーバー機能の実装方法を示すデモサンプル
IP_NETBIOS_StartNETBIOS Nameサービスクライアント機能を確認します
IP_NonBlockingConnectTCPソケットをノンブロッキングモードで実装します
IP_NTPClientNTPクライアント機能の実装方法を示すデモサンプル
IP_PingネットワークPINGテストでICMPプロトコールの動作を確認します
IP_SendMailSMTPクライアント機能の実装方法を示すデモサンプル
IP_SHELL_StartTELNETサーバー(emNet Shellコンソール)を実装します
IP_SimpleServer簡単なTELNETサーバーを実装します
IP_SNMP_AGENT_StartSNMPエージェントの実装方法を示すデモサンプル
IP_SNTPClientSNTPクライアント機能を使用してNTPサーバーからタイムスタンプを取得します
IP_SpeedClient_TCPTCPデータパケットの送受信速度パフォーマンスを確認できるサンプルプログラム
IP_StartemNet TCP/IPスタックの基本的なスタートアップ手順を示すサンプル
IP_TCP_TasklessServer専用タスク無しで簡単なTELNETサーバー機能を実装します
IP_UDPDiscoverUDPポート経由でターゲットデバイスの情報を確認します
IP_VLAN_StartVLANインターフェースを実装します
IP_TFTPClientSampleTFTPクライアント機能の実装方法を示すデモサンプル
IP_TFTPServerSampleTFTPサーバー機能の実装方法を示すデモサンプル

emNet CoAP

Sample説明
IP_COAP_ClientSampleCoAPクライアントの実装方法を示すデモサンプル
IP_COAP_ServerSampleCoAPサーバーの実装方法を示すデモサンプル

emNet MQTT

Sample説明
IP_MQTT_CLIENT_PublisherMQTT クライアントパブリッシャーの実装方法を示すデモサンプル
IP_MQTT_CLIENT_PublisherSubscriber_2TasksMQTT クライアントサブスクライバとパブリッシャー機能を同時に動かします
IP_MQTT_CLIENT_SubscriberMQTT クライアントサブスクライバの実装方法を示すデモサンプル

emNet WebSocket

Sample説明
IP_WEBSOCKET_printf_Clientサーバーにタイムスタンプメッセージを発行する簡単なWEBSOCKETクライアントターミナル
IP_WEBSOCKET_printf_Serverクライアントからタイムスタンプメッセージを受信する簡単なWEBSOCKETサーバートターミナル

emNet FTP

Sample説明
IP_FTPClientSampleFTPクライアントのデモサンプル
IP_FTPServerSampleFTPサーバーのデモサンプル

関連設定ファイル:

BSP
 |- BSP_IP.c  ..................... LANドライバのボード依存の初期化設定ファイル
 |
 |- Setup
     |- IP_Config_RX72N_ETH.c  .... LANドライバインターフェース設定ファイル

Config
 |- IP_Conf.h  ............... emNet IPコンフィグレーション設定ファイル
 |- IP_COAP_Conf.h  .......... emNet CoAPコンフィグレーション設定ファイル
 |- IP_MQTT_CLIENT_Conf.h  ... emNet MQTTコンフィグレーション設定ファイル
 |- FTPC_Conf.h  ............. emNet FTPcコンフィグレーション設定ファイル
 |- SMTPC_Conf.h  ............ emNet SMTP Clientコンフィグレーション設定ファイル
 |- IP_FTP_SERVER_Conf.h  .... emNet FTP Serverコンフィグレーション設定ファイル
 |- IP_SNMP_AGENT_Conf.h  .... emNet SNMP Agentコンフィグレーション設定ファイル
 |
 |- IO
 |   |- IP_ConfigIO.c  ....... デバッグコンソールIOインターフェース設定ファイル
 |
 |- OS
 |   |- libFreeRT_OSLayer_RXv3_L.lib  ....... OSインターフェース設定ファイル
 |
 |- SYS   .................... SYS インターフェース設定(ソース・ヘッダ)

ビルド・動作確認方法

プロジェクト設定では「\Application\_Exclude\IP」フォルダはビルド対象外に設定しています。

「\_Exclude\IP」フォルダ下の動作確認を行うテストサンプルファイルをビルド対象設定の「\Application」フォルダ下にコピーします。
各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。

テスト環境の設定:

評価ボードのLANポートをテスト用パソコンに接続して、TCP/IPネットワーク通信が正常にできることを確認してください。

PC Setup

ネットワーク環境に合わせて評価ボード側のemNetスタックのコンフィグレーション設定を編集してください。

File: BSP\Setup\IP_Config_RX72N_ETH.c

#define USE_DHCP     1    // Use DHCP client or static IP configuration.

//
// The following parameters are only used when the DHCP client is not active.
//
#define IP_ADDR      IP_BYTES2ADDR(192, 168,  11,  8)
#define SUBNET_MASK  IP_BYTES2ADDR(255, 255, 255,  0)
#define GW_ADDR      IP_BYTES2ADDR(192, 168,  11,  1)
#define DNS_ADDR     IP_BYTES2ADDR(192, 168,  11,  1)

テストレポート(TCP/IP)

Sample: IP_Ping

Debug IO Console:

SEGGER Software Evaluation Sample
Eval Board: RX72N Envision Kit
Base: FreeRTOS V10.0.0
------------------------------------------------
0:022 MAIN_TASK - INIT: emNet init started. Version 3.52.0
0:023 MAIN_TASK - *********************************************************************
0:024 MAIN_TASK - *                        emNet Configuration                        *
0:025 MAIN_TASK - *********************************************************************
0:026 MAIN_TASK - * IP_DEBUG: 2
0:027 MAIN_TASK - * Memory added: 40952 bytes
0:028 MAIN_TASK - * Buffer configuration:
0:029 MAIN_TASK - *   12 buffers of 256 bytes
0:030 MAIN_TASK - *   10 buffers of 1516 bytes
0:031 MAIN_TASK - * TCP Tx/Rx window size per socket: 11680/8760 bytes
0:032 MAIN_TASK - * Number of interfaces added: 1
0:033 MAIN_TASK - * Interface #0 configuration:
0:034 MAIN_TASK - *   Type: ETH
0:035 MAIN_TASK - *   MTU: 1500
0:036 MAIN_TASK - *   HW addr.: 00:22:C7:FF:FF:FF
0:037 MAIN_TASK - *********************************************************************
0:039 MAIN_TASK - INIT: Link is down
0:040 MAIN_TASK - DRIVER: Found PHY with Id 0x22 at addr 0x1
0:044 MAIN_TASK - INIT: Init completed
2:023 IP_Task - LINK: Link state changed: Full duplex, 100MHz
2:024 IP_Task - DHCPc: Sending discover!
2:323 IP_Task - NDP: Link-local IPv6 addr.: FE80:0000:0000:0000:0222:C7FF:FEFF:FFFF added to IFace: 0
2:337 IP_Task - NDP: IPv6 addr.: 2400:4050:A0E0:1F00:0222:C7FF:FEFF:FFFF added to IFace: 0
3:476 IP_Task - DHCPc: IFace 0: Offer: IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
4:023 IP_Task - DHCPc: IP addr. checked, no conflicts
4:024 IP_Task - DHCPc: Sending Request.
4:034 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
5:045 MAIN_TASK - Sending PING to IP addr 192.168.1.3
5:048 IP_Task - ICMP echo reply received!
6:046 MAIN_TASK - Sending PING to IP addr 192.168.1.3
6:048 IP_Task - ICMP echo reply received!
7:047 MAIN_TASK - Sending PING to IP addr 192.168.1.3
7:050 IP_Task - ICMP echo reply received!
8:048 MAIN_TASK - Sending PING to IP addr 192.168.1.3
8:051 IP_Task - ICMP echo reply received!
9:049 MAIN_TASK - Sending PING to IP addr 192.168.1.3
9:052 IP_Task - ICMP echo reply received!
10:050 MAIN_TASK - Sending PING to IP addr 192.168.1.3
10:053 IP_Task - ICMP echo reply received!
11:051 MAIN_TASK - Sending PING to IP addr 192.168.1.3
11:053 IP_Task - ICMP echo reply received!

Sample: IP_SpeedClient_TCP

パソコン側に「SpeedTestServer.exe」サーバープログラムを起動して評価ボードのTCP速度パフォーマンスを確認します。
LAN HUB: NETGEAR 100Mbps

File: IP_SpeedClient_TCP.c (サーバーIPアドレス設定)

#define   SERVER_IP_ADDR          IP_BYTES2ADDR(192, 168, 1, 3)

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:033 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
131:446 Client - 4194304 Bytes received (without headers) in 363 ms.
131:447 Client - 4349446 Bytes received (with headers) in 363 ms.
131:448 Client - Average transfer speed (without headers): 11554000 Bytes/s
131:449 Client - Average transfer speed (with headers): 11981000 Bytes/s

131:843 Client - 4194304 Bytes sent (without headers) in 392 ms.
131:845 Client - 4349446 Bytes sent (with headers) in 392 ms.
131:846 Client - Average transfer speed (without headers): 10699000 Bytes/s
131:847 Client - Average transfer speed (with headers): 11095000 Bytes/s

132:277 Client - 4194304 Bytes received (without headers) in 379 ms.
132:278 Client - 4349446 Bytes received (with headers) in 379 ms.
132:279 Client - Average transfer speed (without headers): 11066000 Bytes/s
132:280 Client - Average transfer speed (with headers): 11476000 Bytes/s

132:675 Client - 4194304 Bytes sent (without headers) in 393 ms.
132:676 Client - 4349446 Bytes sent (with headers) in 393 ms.
132:677 Client - Average transfer speed (without headers): 10672000 Bytes/s
132:678 Client - Average transfer speed (with headers): 11067000 Bytes/s

133:090 Client - 4194304 Bytes received (without headers) in 361 ms.
133:091 Client - 4349446 Bytes received (with headers) in 361 ms.
133:092 Client - Average transfer speed (without headers): 11618000 Bytes/s
133:093 Client - Average transfer speed (with headers): 12048000 Bytes/s

Sample: IP_SNTPClient

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:035 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
5:194 SNTPClient - Timestamp received: 3921108322 seconds passed since January 1st 1900.
10:312 SNTPClient - Timestamp received: 3921108327 seconds passed since January 1st 1900.
15:660 SNTPClient - Timestamp received: 3921108332 seconds passed since January 1st 1900.
20:831 SNTPClient - Timestamp received: 3921108337 seconds passed since January 1st 1900.
26:001 SNTPClient - Timestamp received: 3921108342 seconds passed since January 1st 1900.

Sample: IP_NTPClient

Debug IO Console:

4:024 IP_Task - DHCPc: Sending Request.
4:034 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
9:054 NTPClient - --- UTC time: 2024.04.03  04:48:07 ---
14:045 NTPClient - --- UTC time: 2024.04.03  04:48:12 ---
19:046 NTPClient - --- UTC time: 2024.04.03  04:48:17 ---
24:047 NTPClient - --- UTC time: 2024.04.03  04:48:22 ---
29:048 NTPClient - --- UTC time: 2024.04.03  04:48:27 ---
34:049 NTPClient - --- UTC time: 2024.04.03  04:48:32 ---
39:050 NTPClient - --- UTC time: 2024.04.03  04:48:37 ---
44:051 NTPClient - --- UTC time: 2024.04.03  04:48:42 ---

テストレポート(MQTT)

Sample: IP_MQTT_CLIENT_Publisher

Debug IO Console:

4:024 IP_Task - DHCPc: Sending Request.
4:033 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
4:917 MAIN_TASK - APP: Connected to 91.121.93.94, port 1883.
5:782 MAIN_TASK - APP: --------
5:783 MAIN_TASK - APP: Message No. 1:
5:784 MAIN_TASK - APP:   Topic  : "eMQTT"
5:785 MAIN_TASK - APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
7:278 MAIN_TASK - APP: --------
7:279 MAIN_TASK - APP: Message No. 2:
7:280 MAIN_TASK - APP:   Topic  : "eMQTT"
7:281 MAIN_TASK - APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
8:770 MAIN_TASK - APP: --------
8:771 MAIN_TASK - APP: Message No. 3:
8:772 MAIN_TASK - APP:   Topic  : "eMQTT"
8:773 MAIN_TASK - APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
10:264 MAIN_TASK - APP: --------
10:265 MAIN_TASK - APP: Message No. 4:
10:266 MAIN_TASK - APP:   Topic  : "eMQTT"
10:267 MAIN_TASK - APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"

Sample: IP_MQTT_CLIENT_Subscriber

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:033 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
5:564 MAIN_TASK - APP: Connected to 91.121.93.94, port 1883.
5:822 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
5:823 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
6:240 MAIN_TASK - APP: Message (Type: SUBACK, Id: 5824) received. Reason Code: IP_MQTT_REASON_SUCCESS.
6:241 MAIN_TASK - APP: ----
96:869 MAIN_TASK - IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer.
96:870 MAIN_TASK - _Disconnect: closing socket 1
96:871 MAIN_TASK - APP: Done.
102:120 MAIN_TASK - APP: Connected to 91.121.93.94, port 1883.
102:367 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
102:368 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
102:615 MAIN_TASK - APP: Message (Type: SUBACK, Id: 36833) received. Reason Code: IP_MQTT_REASON_SUCCESS.
102:616 MAIN_TASK - APP: ----
192:787 MAIN_TASK - IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer.
192:788 MAIN_TASK - _Disconnect: closing socket 2
192:789 MAIN_TASK - APP: Done.
198:042 MAIN_TASK - APP: Connected to 91.121.93.94, port 1883.
198:299 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
198:300 MAIN_TASK - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
198:552 MAIN_TASK - APP: Message (Type: SUBACK, Id: 1693) received. Reason Code: IP_MQTT_REASON_SUCCESS.
198:553 MAIN_TASK - APP: ----

テストレポート(CoAP)

Sample: IP_COAP_ClientSample

File: IP_COAP_ClientSample.c (サーバーIPアドレス設定)

#define COAP_PORT     IP_COAP_DEFAULT_PORT
#define COAP_SERVER   "192.168.1.19"

Debug IO Console:

4:024 IP_Task - DHCPc: Sending Request.
4:050 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
4:097 MAIN_TASK - 
Test 0: Sending PING
4:098 MAIN_TASK - Test 0: Success!
4:099 MAIN_TASK - 
Test 1: Sending Discover
4:110 MAIN_TASK - /obs: Simple observable data.
/test: test entry
/separate: simple variable with GET with LATE reply
/BlockTransfer/ObsData: Observable data block.
/ObsSensor: 
4:111 MAIN_TASK - Test 1: Success!
4:112 MAIN_TASK - 
Test 2: Sending GET separate
4:113 MAIN_TASK - 
  00:00:00
4:114 MAIN_TASK - Test 2: Success!
4:115 MAIN_TASK - 
Test 3: Sending NON GET block of 16 bytes
4:116 MAIN_TASK - 
  Test data
4:117 MAIN_TASK - Test 3: Success!
4:118 MAIN_TASK - 
Test 4: PUT test
4:119 MAIN_TASK - Test 4: Success!
4:121 MAIN_TASK - 
Test 5: PUT that should fail
4:122 MAIN_TASK - received error: 4.05
4:123 MAIN_TASK - Test 5: Success!
4:124 MAIN_TASK - 
Test 6: DELETE test
4:125 MAIN_TASK - Test 6: Success!
4:126 MAIN_TASK - 
Test 7: POST test
4:128 MAIN_TASK - Test 7: Success!
4:129 MAIN_TASK - 
Test 8: Observe
4:130 MAIN_TASK - 
  Obs data
4:131 MAIN_TASK - 
  GET 1 from Observe completed
14:057 MAIN_TASK - 
  Obs data
14:058 MAIN_TASK - 
  GET 2 from Observe completed
24:052 MAIN_TASK - 
  Obs data
24:053 MAIN_TASK - 
  GET 3 from Observe completed
34:047 MAIN_TASK - 
  Obs data
34:048 MAIN_TASK - 
  GET 4 from Observe completed
44:042 MAIN_TASK - 
  Obs data
44:044 MAIN_TASK - 
  GET 5 from Observe completed
44:045 MAIN_TASK - Test 8: Success!

Sample: IP_COAP_ServerSample

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:033 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
21:461 MAIN_TASK - Getting with LATE reply.
21:463 MAIN_TASK - Getting with LATE reply.
21:465 MAIN_TASK - Getting Test.
21:466 MAIN_TASK - Putting Test.
21:468 MAIN_TASK - Putting Test.
21:470 MAIN_TASK - Deleting Test.
21:471 MAIN_TASK - Putting Test.
21:473 MAIN_TASK - Putting Test.
21:474 MAIN_TASK - Getting Observer.
31:475 MAIN_TASK - Getting Observer.
41:477 MAIN_TASK - Getting Observer.
51:479 MAIN_TASK - Getting Observer.
61:481 MAIN_TASK - Getting Observer.
61:483 MAIN_TASK - Getting Observer.

テストレポート(WebSocket)

Sample: IP_WEBSOCKET_printf_Client

File: IP_WEBSOCKET_printf_Client.c (サーバーIPアドレス設定)

//
// WebSocket sample configuration.
//
#define SERVER_HOST      "192.168.1.19"   // Host to connect to.

Debug IO Console:

4:024 IP_Task - DHCPc: Sending Request.
4:034 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
4:046 MAIN_TASK - APP: Connected to 192.168.1.19:8181.

4:048 MAIN_TASK - WebSocket successfully opened.

Sample: IP_WEBSOCKET_printf_Server

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:033 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
18:656 MAIN_TASK - WebSocket client connected.

19:650 MAIN_TASK - Client: OS time: 6025

20:842 MAIN_TASK - Client: OS time: 7223

22:033 MAIN_TASK - Client: OS time: 8419

23:223 MAIN_TASK - Client: OS time: 9614

24:413 MAIN_TASK - Client: OS time: 10809

25:613 MAIN_TASK - Client: OS time: 12014

26:813 MAIN_TASK - Client: OS time: 13220

28:013 MAIN_TASK - Client: OS time: 14426

29:212 MAIN_TASK - Client: OS time: 15631

30:402 MAIN_TASK - Client: OS time: 16827
前の章

圧縮・解凍機能のデモサンプル

次の章

MODBUS通信(TCP、RS232経由)