last update: 2025/03
Demo Sample Application Folder:
Application └ _Exclude ├ IP ..... TCP/IPネットワーク通信機能のデモサンプル
Sample | 説明 |
---|---|
IP_ACD_Start | ACD(Address Collision Detection)機能の動作を確認します |
IP_AUTOIP_Start | AutoIPプロトコールを使用してIPアドレスの自動設定を確認します |
IP_DNSClient | ネットワークホスト名を IP アドレスに解決する方法を示します |
IP_MDNS_ServerSample | mDNSサーバー機能の実装方法を示すデモサンプル |
IP_NETBIOS_Start | NETBIOS Nameサービスクライアント機能を確認します |
IP_NonBlockingConnect | TCPソケットをノンブロッキングモードで実装します |
IP_NTPClient | NTPクライアント機能の実装方法を示すデモサンプル |
IP_Ping | ネットワークPINGテストでICMPプロトコールの動作を確認します |
IP_SendMail | SMTPクライアント機能の実装方法を示すデモサンプル |
IP_SNTPClient | SNTPクライアント機能を使用してNTPサーバーからタイムスタンプを取得します |
IP_SpeedClient_TCP | TCPデータパケットの送受信速度パフォーマンスを確認できるサンプルプログラム |
IP_Start | emNet TCP/IPスタックの基本的なスタートアップ手順を示すサンプル |
IP_TCP_TasklessServer | 専用タスク無しで簡単なTELNETサーバー機能を実装します |
IP_VLAN_Start | VLANインターフェースを実装します |
Sample | 説明 |
---|---|
IP_COAP_ClientSample | CoAPクライアントの実装方法を示すデモサンプル |
Sample | 説明 |
---|---|
IP_MQTT_CLIENT_Publisher | MQTT クライアントパブリッシャーの実装方法を示すデモサンプル |
IP_MQTT_CLIENT_Subscriber | MQTT クライアントサブスクライバの実装方法を示すデモサンプル |
Sample | 説明 |
---|---|
IP_FTPClientSample | FTPクライアントのデモサンプル |
BSP |- BSP_IP.c ..................... LANドライバのボード依存の初期化設定ファイル | |- Setup |- IP_Config_RX72N_ETH.c .... LANドライバインターフェース設定ファイル |- IP_FS_emFile.c ........... ファイルシステムインターフェース設定ファイル 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コンフィグレーション設定ファイル | |- IO | |- IP_ConfigIO.c ....... デバッグコンソールIOインターフェース設定ファイル | |- OS | |- libNo_OSLayer_RXv3_L.lib ....... OSインターフェース設定ファイル | |- SYS .................... SYS インターフェース設定(ソース・ヘッダ)
Windows └ IP ├ COAP_Server .......... CoAPサーバーのEXEプログラム ├ FTPserver .......... FTPサーバーのEXEプログラム ├ SpeedTestServer ...... TCP速度パフォーマンスチェック用EXEプログラム
マクロ名 | 説明 |
---|---|
ALLOC_SIZE | emNetスタック用メモリプールのサイズ(単位:Byte) |
TARGET_NAME | DHCPクライアントのターゲット名(設定値:"AP-RX72N-0A") |
HW_ADDR | Ethernet MACアドレス BSPサンプルでは評価ボードのEEPROM(メモリアドレス:00~06)からボード個別のMACアドレス(6Byte)を読み出します。 File: BSP_IP.c Function: BSP_EEPROM_Read_MacAddr() |
USE_DHCP | 1:DHCPモードでIPアドレスを自動取得します。 0:マニュアルモード設定、固定IPアドレスを使用します。 |
IP_ADDR | マニュアルモード(DHCP=0)のIPアドレス設定 |
SUBNET_MASK | マニュアルモード(DHCP=0)のサブネットマスクのアドレス設定 |
GW_ADDR | マニュアルモード(DHCP=0)のゲートウエイIPアドレス設定 |
DNS_ADDR | マニュアルモード(DHCP=0)のDNSサーバーのIPアドレス設定 |
マクロ名 | 説明 |
---|---|
ETH_INT_PRIORITY | LANドライバの割り込み優先度(設定値:5) |
プロジェクト設定では「\Application\_Exclude\IP」フォルダはビルド対象外に設定しています。以下のどちらかの方法で動作確認を行うサンプルアプリケーションを選択します。
各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。
評価ボードのLANポートをテスト用パソコンに接続して、TCP/IPネットワーク通信が正常にできることを確認してください。
ネットワーク環境に合わせて評価ボード側の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, 1, 252) #define SUBNET_MASK IP_BYTES2ADDR(255, 255, 255, 0) #define GW_ADDR IP_BYTES2ADDR(192, 168, 1, 1) #define DNS_ADDR IP_BYTES2ADDR(192, 168, 1, 1)
各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。テストサーバーのIPアドレスなどコンフィグレーション設定を編集して動作確認を行います。
「IP_Ping.c」ファイルにPINGテストサーバーのIPアドレスを設定します。
#define HOST_TO_PING IP_BYTES2ADDR(192, 168, 1, 4) // IP addr. of host
Debug IO Console:
SEGGER Software Evaluation Sample Eval Board: AP-RX72N-0A (RX72N RXv3 @240MHz) Base: Baremetal (No RTOS) ------------------------------------------------ 0:101 emNet - INIT: emNet init started. Version 3.52.0 0:122 emNet - ********************************************************************* 0:123 emNet - * emNet Configuration * 0:124 emNet - ********************************************************************* 0:125 emNet - * IP_DEBUG: 2 0:125 emNet - * Memory added: 49144 bytes 0:126 emNet - * Buffer configuration: 0:127 emNet - * 12 buffers of 256 bytes 0:127 emNet - * 20 buffers of 1516 bytes 0:128 emNet - * TCP Tx/Rx window size per socket: 11680/8760 bytes 0:129 emNet - * Number of interfaces added: 1 0:130 emNet - * Interface #0 configuration: 0:131 emNet - * Type: ETH 0:131 emNet - * MTU: 1500 0:132 emNet - * HW addr.: 00:0C:7B:4E:02:08 0:132 emNet - ********************************************************************* 0:133 emNet - INIT: Link is down 0:134 emNet - DRIVER: Found PHY with Id 0x7 at addr 0x0 0:139 emNet - INIT: Init completed 2:122 emNet - LINK: Link state changed: Full duplex, 100MHz 2:123 emNet - DHCPc: Sending discover! 2:502 emNet - NDP: Link-local IPv6 addr.: FE80:0000:0000:0000:020C:7BFF:FE4E:0208 added to IFace: 0 2:508 emNet - NDP: IPv6 addr.: 2400:4050:A0E0:1F00:020C:7BFF:FE4E:0208 added to IFace: 0 3:183 emNet - DHCPc: IFace 0: Offer: IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:122 emNet - DHCPc: IP addr. checked, no conflicts 4:122 emNet - DHCPc: Sending Request. 4:133 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 5:170 emNet - Sending PING to IP addr. 192.168.1.4 . 5:180 emNet - ICMP echo reply received! 6:171 emNet - Sending PING to IP addr. 192.168.1.4 . 6:270 emNet - ICMP echo reply received! 7:172 emNet - Sending PING to IP addr. 192.168.1.4 . 7:228 emNet - ICMP echo reply received! 8:173 emNet - Sending PING to IP addr. 192.168.1.4 . 8:294 emNet - ICMP echo reply received! 9:174 emNet - Sending PING to IP addr. 192.168.1.4 . 9:276 emNet - ICMP echo reply received!
「segger.com」のIPアドレスを取得します。
File:IP_DNSClient.c
#define HOST_NAME "segger.com"
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:034 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 5:364 emNet - IP addr. 116.203.153.115 resolved from host name "segger.com". 6:366 emNet - IP addr. 116.203.153.115 resolved from host name "segger.com". 7:368 emNet - IP addr. 116.203.153.115 resolved from host name "segger.com".
NTPサーバーから日付時刻情報を取得します。
File:IP_SNTPClient.c
#define NTP_SERVER "us.pool.ntp.org"
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:033 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:071 emNet - Requesting time stamp from us.pool.ntp.org: 4:408 emNet - Timestamp received: 3948929286 seconds passed since January 1st 1900.
NTPサーバーから日付時刻情報(UTC)を取得します。
Debug IO Console:
4:035 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 9:073 emNet - --- UTC time: 2025.02.19 04:49:58 --- 14:078 emNet - --- UTC time: 2025.02.19 04:50:03 --- 19:072 emNet - --- UTC time: 2025.02.19 04:50:08 --- 24:077 emNet - --- UTC time: 2025.02.19 04:50:13 --- 29:071 emNet - --- UTC time: 2025.02.19 04:50:18 --- 34:076 emNet - --- UTC time: 2025.02.19 04:50:23 --- 39:070 emNet - --- UTC time: 2025.02.19 04:50:28 --- 44:075 emNet - --- UTC time: 2025.02.19 04:50:33 ---
「IP_TCP_TasklessServer.c」プログラムを実行してボード側に非タスクモードでTELNETサーバーを実装します。テストPCからTELNETクライエントコマンドを実行して接続を確認します。サンプルプログラムは接続後にTELNETクライエントに「Hello and goodbye...」メッセージを送信して切断します。
パソコン側のDOSプロンプト:
C:\>telnet 192.168.1.18 Hello and goodbye... C:\>telnet 192.168.1.18 Hello and goodbye...
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:033 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 127:816 emNet - New connection accepted for server on local port 23. 133:047 emNet - New connection accepted for server on local port 23.
File: IP_NonBlockingConnect.c (パソコンテストサーバーのIPアドレス設定)
#define SERVER_IP_ADDR IP_BYTES2ADDR(192, 168, 1, 4)
パソコン側「SpeedTestServer.exe」ツールを実行します。
Windows └ IP ├ SpeedTestServer ├ SpeedTestServer.exe ..... TCPテストサーバーサンプル
パソコン側「SpeedTestServer.exe」のコンソール:
TCP/IP Echo server V1.00.00. Compiled 11:26:58 on Sep 29 2023. Waiting for client on port 1234 2025-02-19 14:06:18 : Client connected 2025-02-19 14:06:18 : Client disconnected 2025-02-19 14:06:20 : Client connected 2025-02-19 14:06:21 : Client disconnected 2025-02-19 14:06:23 : Client connected 2025-02-19 14:06:23 : Client disconnected 2025-02-19 14:06:26 : Client connected 2025-02-19 14:06:26 : Client disconnected 2025-02-19 14:06:28 : Client connected 2025-02-19 14:06:29 : Client disconnected 2025-02-19 14:06:31 : Client connected 2025-02-19 14:06:32 : Client disconnected
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:033 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:071 emNet - Connecting using non-blocking socket... 4:081 emNet - Succesfully connected after 10ms and 6 loops! 4:582 emNet - 1 of 1 tries were successful. 6:583 emNet - Connecting using non-blocking socket... 6:713 emNet - Succesfully connected after 130ms and 66 loops! 7:215 emNet - 2 of 2 tries were successful. 9:216 emNet - Connecting using non-blocking socket... 9:276 emNet - Succesfully connected after 60ms and 31 loops! 9:778 emNet - 3 of 3 tries were successful. 11:779 emNet - Connecting using non-blocking socket... 12:037 emNet - Succesfully connected after 258ms and 130 loops! 12:539 emNet - 4 of 4 tries were successful. 14:540 emNet - Connecting using non-blocking socket... 14:904 emNet - Succesfully connected after 364ms and 183 loops! 15:406 emNet - 5 of 5 tries were successful. 17:407 emNet - Connecting using non-blocking socket... 17:771 emNet - Succesfully connected after 364ms and 183 loops! 18:273 emNet - 6 of 6 tries were successful.
「test.mosquitto.org」MQTTブローカーに接続してテストを行います。
File:IP_MQTT_CLIENT_Publisher.c
#define MQTT_BROKER_ADDR "test.mosquitto.org" #define MQTT_BROKER_PORT 1883 #define TOPIC_PUBLISH_QOS IP_MQTT_CLIENT_FLAGS_PUBLISH_QOS2 #define MQTT_CLIENT_NAME "eMQTT_Pub" #define TOPIC_FILTER_TO_PUBLISH "eMQTT" #define PAYLOAD "www.SEGGER.com MQTT_HelloWorld_Sample"
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:034 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:579 emNet - APP: Connected to 5.196.78.28, port 1883. 5:351 emNet - APP: -------- 5:351 emNet - APP: Message No. 1: 5:352 emNet - APP: Topic : "eMQTT" 5:352 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample" 6:861 emNet - APP: -------- 6:861 emNet - APP: Message No. 2: 6:862 emNet - APP: Topic : "eMQTT" 6:862 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample" 8:370 emNet - APP: -------- 8:370 emNet - APP: Message No. 3: 8:371 emNet - APP: Topic : "eMQTT" 8:371 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample" 9:895 emNet - APP: -------- 9:895 emNet - APP: Message No. 4: 9:896 emNet - APP: Topic : "eMQTT" 9:896 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample" 11:416 emNet - APP: -------- 11:416 emNet - APP: Message No. 5: 11:417 emNet - APP: Topic : "eMQTT" 11:417 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample" 12:930 emNet - APP: -------- 12:930 emNet - APP: Message No. 6: 12:931 emNet - APP: Topic : "eMQTT" 12:931 emNet - APP: Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
「test.mosquitto.org」MQTTブローカーに接続してテストを行います。
File:IP_MQTT_CLIENT_Subscriber.c
#define MQTT_BROKER_ADDR "test.mosquitto.org" #define MQTT_BROKER_PORT 1883 #define TOPIC_SUBSCRIBE_QOS IP_MQTT_CLIENT_FLAGS_PUBLISH_QOS1 #define MQTT_CLIENT_NAME "eMQTT_Sub" #define TOPIC_FILTER_TO_SUBSCRIBE "eMQTT"
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:043 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 6:357 emNet - APP: Connected to 5.196.78.28, port 1883. 6:613 emNet - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0. 6:614 emNet - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0. 6:870 emNet - APP: Message (Type: SUBACK, Id: 6615) received. Reason Code: IP_MQTT_REASON_SUCCESS. 6:871 emNet - APP: ---- 97:546 emNet - IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer. 97:547 emNet - _Disconnect: closing socket 1 97:547 emNet - APP: Done. 102:801 emNet - APP: Connected to 5.196.78.28, port 1883. 103:054 emNet - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0. 103:055 emNet - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0. 103:307 emNet - APP: Message (Type: SUBACK, Id: 37520) received. Reason Code: IP_MQTT_REASON_SUCCESS. 103:308 emNet - APP: ---- 193:558 emNet - IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer. 193:559 emNet - _Disconnect: closing socket 2 193:560 emNet - APP: Done. 198:941 emNet - APP: Connected to 5.196.78.28, port 1883. 199:204 emNet - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0. 199:205 emNet - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0. 199:458 emNet - APP: Message (Type: SUBACK, Id: 2598) received. Reason Code: IP_MQTT_REASON_SUCCESS. 199:459 emNet - APP: ---- 289:536 emNet - IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer. 289:537 emNet - _Disconnect: closing socket 3 289:538 emNet - APP: Done. 294:790 emNet - APP: Connected to 5.196.78.28, port 1883. 295:048 emNet - APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0. 295:049 emNet - APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0. 295:317 emNet - APP: Message (Type: SUBACK, Id: 32906) received. Reason Code: IP_MQTT_REASON_SUCCESS. 295:318 emNet - APP: ----
サーバーPC側に「COAP_Server.exe」プログラムを実行して、ターゲット側のプログラムを起動します。
File: IP_COAP_ClientSample.c (サーバーのIPアドレス設定)
#define COAP_PORT IP_COAP_DEFAULT_PORT #define COAP_SERVER "192.168.1.4"
Debug IO Console:
4:023 emNet - DHCPc: Sending Request. 4:033 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:072 emNet - Test 0: Sending PING 4:419 emNet - Test 0: Success! 4:419 emNet - Test 1: Sending Discover 4:673 emNet - /obs: Simple observable data. /test: test entry /separate: simple variable with GET with LATE reply /BlockTransfer/ObsData: Observable data block. /ObsSensor: 4:674 emNet - Test 1: Success! 4:674 emNet - Test 2: Sending GET separate 5:189 emNet - 00:00:00 5:189 emNet - Test 2: Success! 5:189 emNet - Test 3: Sending NON GET block of 16 bytes 5:201 emNet - Test data 5:201 emNet - Test 3: Success! 5:201 emNet - Test 4: PUT test 5:224 emNet - Test 4: Success! 5:224 emNet - Test 5: PUT that should fail 5:236 emNet - received error: 4.05 5:236 emNet - Test 5: Success! 5:237 emNet - Test 6: DELETE test 5:248 emNet - Test 6: Success! 5:248 emNet - Test 7: POST test 5:271 emNet - Test 7: Success! 5:271 emNet - Test 8: Observe 5:283 emNet - Obs data 5:283 emNet - GET 1 from Observe completed 15:483 emNet - Obs data 15:483 emNet - GET 2 from Observe completed 25:695 emNet - Obs data 25:695 emNet - GET 3 from Observe completed 35:883 emNet - Obs data 35:883 emNet - GET 4 from Observe completed 46:119 emNet - Obs data 46:119 emNet - GET 5 from Observe completed 46:120 emNet - Test 8: Success!
サーバーPC側に「C:\ftp」フォルダ下のデータをすべて削除して、「FTPServer.exe」プログラムを実行します。評価ボードにSDカードを差し込んで、「IP_FTPClientSample」プログラムを実行します。デバッグコンソールのFTPクライエントの操作ログを確認します
Debug IO Console:
4:169 emNet - DHCPc: Sending Request. 4:181 emNet - DHCPc: IFace 0: Using IP: 192.168.1.18, Mask: 255.255.255.0, GW: 192.168.1.1. 4:208 emNet - APP: Connect to server "Admin@192.168.1.4:21". 4:351 emNet - APP: Connected to 192.168.1.4, port 21. 4:371 emNet - APP: Creating directory "Test". 4:376 emNet - APP: --- Test with old API that needs to CWD into the directory to operate within. 4:377 emNet - APP: Changing to directory "/Test/". 4:388 emNet - APP: List directory (before upload): 4:406 emNet - APP: Data connection established on local port: 1225 4:409 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. 4:410 emNet - APP: Uploading "Readme.txt". 4:473 emNet - APP: Data connection established on local port: 1226 4:531 emNet - APP: List directory (after upload): 4:537 emNet - APP: Data connection established on local port: 1227 4:540 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. -rw-r--r-- 1 root root 76 Feb 19 2025 Readme.txt 4:541 emNet - APP: Deleting "Readme.txt". 4:545 emNet - APP: List directory (after delete): 4:557 emNet - APP: Data connection established on local port: 1228 4:561 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. 4:562 emNet - APP: Changing to parent directory. 4:566 emNet - APP: --- Test with new API using IP_FTPC_CMD_CONFIG that can operate regardless of current directory. 4:567 emNet - APP: List directory (before upload, old API with path parameter): 4:585 emNet - APP: Data connection established on local port: 1229 4:588 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. 4:589 emNet - APP: Uploading "Readme.txt" to "/Test/Test.txt" (new API). 4:605 emNet - APP: Data connection established on local port: 1230 4:653 emNet - APP: List directory (after upload, new API): 4:659 emNet - APP: Data connection established on local port: 1231 4:662 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. -rw-r--r-- 1 root root 76 Feb 19 2025 Test.txt 4:663 emNet - APP: Deleting "/Test/Test.txt" (new API). 4:668 emNet - APP: List directory (after delete, new API): 4:674 emNet - APP: Data connection established on local port: 1232 4:678 emNet - drw-r--r-- 1 root root 0 Feb 19 2025 . drw-r--r-- 1 root root 0 Feb 19 2025 .. 4:679 emNet - APP: Delete directory "/Test/" (new API). 4:688 emNet - APP: Done.
FAT32 ファイルシステム