HOME
Shop
  • English
  • 简体中文
HOME
Shop
  • English
  • 简体中文
  • Product Series

    • FPGA+ARM

      • GM-3568JHF

        • 1. Introduction

          • GM-3568JHF Introduction
        • 2. Quick Start

          • 01 Environment Construction
          • 02 Compilation Instructions
          • 03 Burning Guide
          • 04 Debugging Tools
          • 05 Software Update
          • 06 View information
          • 07 Test Command
          • 08 Application Compilation
          • 09 Source code acquisition
        • 3. Peripherals and Interfaces

          • USB
          • Display and touch
          • Ethernet
          • WIFI
          • Bluetooth
          • TF-Card
          • Audio
          • Serial Port
          • CAN
          • RTC
        • 4. Application Development

          • 01 UART read and write case
          • 02 Key detection case
          • 03 LED light flashing case
          • 04 MIPI screen detection case
          • 05 Read USB device information example
          • 06 FAN Detection Case
          • 07 FPGA FSPI Communication Case
          • 08 FPGA DMA read and write case
          • 09 GPS debugging case
          • 10 Ethernet Test Cases
          • 11 RS485 reading and writing examples
          • 12 FPGA IIC read and write examples
          • 13 PN532 NFC card reader case
          • 14 TF card reading and writing case
        • 5. QT Development

          • 01 ARM64 cross compiler environment construction
          • 02 QT program added automatic startup service
        • 6. Others

          • 01 Modification of the root directory file system
          • 02 System auto-start service
    • ShimetaPi

      • M4-R1

        • Introduction

          • M4-R1 Introduction
        • Get started quickly

          • OpenHarmony概述
          • 镜像烧录
          • 开发环境准备
          • Hello World应用以及部署
        • Application Development

          • getting Started

            • 第一章 ArkTS语言简介
            • 第二章 UI组件介绍和实际应用(上)
            • 第三章 UI组件介绍和实际应用(中)
            • 第四章 UI组件介绍和实际应用(下)
          • Advanced

            • 第一章 入门指引
            • 第二章 三方库的引用和使用
            • 第三章 应用编译以及部署
            • 第四章 命令行恢复出厂设置
            • 第五章 系统调试--HDC调试
            • 第六章 APP 稳定性测试
            • 第七章 应用测试
        • Equipment Development

          • 第一章 环境搭建
          • 第二章 下载源码
          • 第三章 编译源码
        • Peripherals and interfaces

          • 树莓派接口
          • GPIO 接口
          • I2C 接口
          • SPI通信
          • PWM控制
          • 串口通讯
          • TF Card
          • 屏幕
          • 触摸
          • 音频
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI&BT
          • 树莓派拓展板
        • Frequently asked questions

          • 资源下载
      • M5-R1

        • Introduction

          • Introduction to ShimetaPi M5-R1
    • OpenHarmony

      • SC-3568HA

        • Introduction

          • SC-3568HA Overview
        • Quick Start Guide

          • OpenHarmony Overview
          • Image Flashing
          • Setting Up the Development Environment
          • Hello World Application and Deployment
        • Application Development

          • ArkUI

            • Chapter 1 Introduction to ArkTS Language
            • Chapter 2 Introduction to UI Components and Practical Applications (Part 1)
            • Chapter 3 Introduction to UI Components and Practical Applications (Part 2)
            • Chapter 4 Introduction to UI Components and Practical Applications (Part 3)
          • Expand

            • Chapter 1 Getting Started Guide
            • Chapter 2 Referencing and Using Third-Party Libraries
            • Chapter 3: Application Compilation and Deployment
            • Chapter 4: Command-Line Factory Reset
            • Chapter 5: System Debugging -- HDC (Huawei Device Connector) Debugging
            • Chapter 6 APP Stability Testing
            • Chapter 7 Application Testing
        • Device Development

          • Chapter 1 Environment Setup
          • Chapter 2 Download Source Code
          • Chapter 3 Compiling Source Code
        • Peripheral And Iinterface

          • Raspberry Pi interface
          • GPIO Interface
          • I2C Interface
          • SPI communication
          • PWM (Pulse Width Modulation) control
          • Serial port communication
          • TF Card
          • Display Screen
          • Touch
          • Audio
          • RTC
          • Ethernet
          • M.2
          • MINI-PCIE
          • Camera
          • WIFI&BT
          • Raspberry Pi expansion board
        • Frequently Asked Questions

          • Resource Downloads
      • M-K1HSE

        • Introduction

          • M-K1HSE Introduction
        • Quick Start

          • Development environment construction
          • Source code acquisition
          • Compilation Notes
          • Burning Guide
        • Peripherals and interfaces

          • 01 Audio
          • 02 RS485
          • 03 Display
        • System customization development

          • System transplant
          • System customization
          • Driver Development
          • System Debugging
          • OTA Update
    • EVS-Camera

      • CF-NRS1

        • 1. Introduction

          • Event Camera Technical Documentation
        • 2. Quick Start

          • Host driver and software installation
        • 3. SDK application development

          • API Usage Instructions
      • CF-CRA2

        • Introduction

          • About CF-NRS1
    • AI-model

      • 1684XB-32T

        • Introduction

          • AIBOX-1684XB-32 Introduction
        • Get started quickly

          • First time use
          • Network Configuration
          • Disk usage
          • Memory allocation
          • Fan Strategy
          • Firmware Upgrade
        • Deployment Tutorial

          • Algorithm deployment
          • Deploy Llama3 Example
        • Application Development

          • Sophgo SDK Development
          • Sophon LLM_api_server development
          • Deploy MiniCPM-V-2_6
          • Qwen-2-5-VL Image and Video Recognition DEMO
          • Qwen3-chat-DEMO
          • Qwen3-Qwen Agent-MCP-Demo
          • Qwen3-langchain-AI Agent
      • 1684X-416T

        • Introduction

          • AIBOX-1684X-416 Introduction
        • Demo simple operation guide

          • Simple instructions for using shimeta smart monitoring demo
    • Core-Board

      • C-3568BQ

        • Introduction

          • C-3568BQ Overview
      • C-3588LQ

        • Introduction

          • C-3588LQ Introduction
      • GC-3568JBAF

        • Introduction

          • GC-3568JBAF Introduction
      • C-K1BA

        • Introduction

          • C-K1BA Introduction

Ethernet

Taking SC-3568HA as an example, there are dual Ethernet ports on the board.

TOOL

1. dts configuration

  • arch/arm64/boot/dts/rockchip/rk3568-toybrick-x0.dtsi
    &gmac0 {
        phy-mode = "rgmii";
        clock_in_out = "output";

        snps,reset-gpio = <&gpio2 RK_PD3 GPIO_ACTIVE_LOW>;
        snps,reset-active-low;
        /* Reset time is 20ms, 100ms for rtl8211f */
        snps,reset-delays-us = <0 20000 100000>;

        assigned-clocks = <&cru SCLK_GMAC0_RX_TX>, <&cru SCLK_GMAC0>;
        assigned-clock-parents = <&cru SCLK_GMAC0_RGMII_SPEED>, <&cru CLK_MAC0_2TOP>;
        assigned-clock-rates = <0>, <125000000>;

        pinctrl-names = "default";
        pinctrl-0 = <&gmac0_miim
                &gmac0_tx_bus2
                &gmac0_rx_bus2
                &gmac0_rgmii_clk
                &gmac0_rgmii_bus>;

        tx_delay = <0x2d>;
        rx_delay = <0x13>;

        phy-handle = <&rgmii_phy0>;
        status = "okay";
    };

    &gmac1 {
        phy-mode = "rgmii";
        clock_in_out = "output";

        snps,reset-gpio = <&gpio2 RK_PD1 GPIO_ACTIVE_LOW>;
        snps,reset-active-low;
        /* Reset time is 20ms, 100ms for rtl8211f */
        snps,reset-delays-us = <0 20000 100000>;

        assigned-clocks = <&cru SCLK_GMAC1_RX_TX>, <&cru SCLK_GMAC1>;
        assigned-clock-parents = <&cru SCLK_GMAC1_RGMII_SPEED>, <&cru CLK_MAC1_2TOP>;
        assigned-clock-rates = <0>, <125000000>;

        pinctrl-names = "default";
        pinctrl-0 = <&gmac1m1_miim
                &gmac1m1_tx_bus2
                &gmac1m1_rx_bus2
                &gmac1m1_rgmii_clk
                &gmac1m1_rgmii_bus>;

        tx_delay = <0x37>;
        rx_delay = <0x0f>;

        phy-handle = <&rgmii_phy1>;
        status = "okay";
    };

2. Check the eth interface

Use the ifconfig command to check whether the ethX node is generated:

TOOL

3. Connectivity test

Use the following command to test the network port

  • eth0:
    ~# ping -I eth0 -c 10 www.baidu.com
    Ping www.baidu.com (183.2.172.42) from eth0 (192.168.49.35): 56(84) bytes.
    64 bytes from 183.2.172.42: icmp_seq=1 ttl=50 time=12 ms
    64 bytes from 183.2.172.42: icmp_seq=2 ttl=50 time=10 ms
    64 bytes from 183.2.172.42: icmp_seq=3 ttl=50 time=10 ms
    64 bytes from 183.2.172.42: icmp_seq=4 ttl=50 time=10 ms
    64 bytes from 183.2.172.42: icmp_seq=5 ttl=50 time=17 ms
    64 bytes from 183.2.172.42: icmp_seq=6 ttl=50 time=8 ms
    64 bytes from 183.2.172.42: icmp_seq=7 ttl=50 time=9 ms
    64 bytes from 183.2.172.42: icmp_seq=8 ttl=50 time=8 ms
    64 bytes from 183.2.172.42: icmp_seq=9 ttl=50 time=10 ms
    64 bytes from 183.2.172.42: icmp_seq=10 ttl=50 time=9 ms

    --- 183.2.172.42 ping statistics ---
    10 packets transmitted, 10 received, 0% packet loss
    round-trip min/avg/max = 8/10/17 ms
  • eth1:
    ~# ping -I eth1 -c 10 www.baidu.com
    Ping www.baidu.com (183.2.172.185) from eth1 (192.168.49.241): 56(84) bytes.
    64 bytes from 183.2.172.185: icmp_seq=1 ttl=50 time=9 ms
    64 bytes from 183.2.172.185: icmp_seq=2 ttl=50 time=9 ms
    64 bytes from 183.2.172.185: icmp_seq=3 ttl=50 time=9 ms
    64 bytes from 183.2.172.185: icmp_seq=4 ttl=50 time=9 ms
    64 bytes from 183.2.172.185: icmp_seq=5 ttl=50 time=8 ms
    64 bytes from 183.2.172.185: icmp_seq=6 ttl=50 time=8 ms
    64 bytes from 183.2.172.185: icmp_seq=7 ttl=50 time=9 ms
    64 bytes from 183.2.172.185: icmp_seq=8 ttl=50 time=8 ms
    64 bytes from 183.2.172.185: icmp_seq=9 ttl=50 time=8 ms
    64 bytes from 183.2.172.185: icmp_seq=10 ttl=50 time=9 ms

    --- 183.2.172.185 ping statistics ---
    10 packets transmitted, 10 received, 0% packet loss
    round-trip min/avg/max = 8/8/9 ms

4. Ethernet API usage and practice

4.1 HDC related instructions

The hdc command can be used to query Ethernet information and connection status

    hdc shell ifconfig

Turn off/on Ethernet hdc command:

    ifconfig eth0 X.X.X.X up
    ifconfig eth0 X.X.X.X down
    注:x.x.x.x 为网卡地址。

4.2 How to use standard API

Tips

Ethernet connection management mainly provides the capability of a wired network. It allows users to set information such as the IP address, subnet mask, gateway, DNS, and proxy for the wired network.

The first batch of interfaces of this module is supported starting from API version 9. For newly added interfaces in subsequent versions, the starting version of each interface is separately marked with a superscript.

This module consists of system interfaces.

  • Ethernet standard interface

    @ohos.net.ethernet (Ethernet connection management) (system interface)

  • API Usage Instructions

    When developing with Ethernet APIs, you need to first understand how to create your first open Harmony project. Related documents: Hello World application and deployment

When using an API, you need to pay attention to the following points:

  • API Permissions Description
  • API parameters and return values
  • When an API call fails, refer to the API error code and general error code.
  • Correct use of API examples

As shown in the figure below, this is the standard API document

TOOL

Official standard development documents

Ethereum official standard API development document

4.3 Community Demo

  • Introduction

In order to help developers develop and learn more quickly using the board, we have provided an Ethernet-related usage example on gitee. Each project is an independent DevEco Studio project. Developers can import the project into DevEco Studio and understand the usage of the API involved in the application example by browsing the code, compiling the project, installing and running the application example.

giteeWIFI Example

Tips

When importing a community Demo project, developers need to pay attention to whether the local development environment is consistent with the project, that is, whether the local SDK is consistent with the project SDK.

  • Importing modules

When using the Ethernet standard API, the most important step is to import the Ethernet module so that you can use the corresponding Ethernet API interface. Usually the module is imported in the file header.

Import the module as follows:

import ethernet from '@ohos.net.ethernet'

  • API Introduction

The implementation of the community demo references the following API to implement how to open and obtain Ethernet information, set static and dynamic, and the basic implementation of Ethernet connection.

Note

The following introductions briefly describe the system capabilities of the APIs and the corresponding functions.Please refer to the Gitee Ethereum examples and Ethereum official standard API development documentsto get familiar with the development.

  • ethernet.setIfaceConfig (set network interface configuration information)
	setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise<void>
	需要权限: ohos.permission.CONNECTIVITY_INTERNAL 。
  • ethernet.getIfaceConfig (get the specified network interface information)
	getIfaceConfig(iface: string): Promise<InterfaceConfiguration>
	需要权限: ohos.permission.GET_NETWORK_INFO 。
  • ethernet.isIfaceActive (determine whether the interface is activated)
	isIfaceActive(iface: string): Promise<number>
	需要权限: ohos.permission.GET_NETWORK_INFO 。
  • ethernet.getAllActiveIfaces (get active network interfaces)
	getAllActiveIfaces(): Promise<Array<string>>
	需要权限: ohos.permission.GET_NETWORK_INFO 。
  • ethernet.on('interfaceStateChange') (register network card hot plug event)
	getAllActiveIfaces(): Promise<Array<string>>
	需要权限: ohos.permission.GET_NETWORK_INFO 。
  • Demo mainly implements source code

  • ent.ets

  import ethernet from '@ohos.net.ethernet'
  import { BusinessError } from '@ohos.base';

  @Entry
  @Component
  struct Index {
  @State message: string = '以太网Demo';
  private  TAG : string = 'ent_Demo'
  @State entModeTest : string = '当前动态Ip'
  @State entName : string = "eth0"
  @State entModeStatus : boolean = true;//动/静态Ip的判断
  @State entMsg : string = ''
  @State entIp : string = ''
  @State entRoute : string = ''
  @State entGateway : string = ''
  @State entMask : string = ''
  @State entDNS : string = ''
  @State entMode : number = 1;


  aboutToAppear(): void {
	 this.getAllActiveIfaces();
	 this.getIfaceConfig();
  }


  setIfaceConfig(){
	 let config: ethernet.InterfaceConfiguration = {
		mode: this.entMode,
		ipAddr: this.entIp,
		route: this.entRoute,
		gateway: this.entGateway,
		netMask: this.entMask,
		dnsServers: this.entDNS
	 };

	 const setConfigPromise = ethernet.setIfaceConfig("eth0", config);

	 setConfigPromise.then(() => {
		console.log(this.TAG,"setIfaceConfig promise ok");
	 }).catch((error: BusinessError)  => {
		console.error(this.TAG,"setIfaceConfig promise error = " + JSON.stringify(error));
	 });
  }

  getIfaceConfig(){
	 ethernet.getIfaceConfig(this.entName).then((data: ethernet.InterfaceConfiguration) => {
		console.log(this.TAG,"getIfaceConfig promise mode = " + data.mode);
		console.log(this.TAG,"getIfaceConfig promise ipAddr = " + JSON.stringify(data.ipAddr));
		console.log(this.TAG,"getIfaceConfig promise route = " + JSON.stringify(data.route));
		console.log(this.TAG,"getIfaceConfig promise gateway = " + JSON.stringify(data.gateway));
		console.log(this.TAG,"getIfaceConfig promise netMask = " + JSON.stringify(data.netMask));
		console.log(this.TAG,"getIfaceConfig promise dnsServers = " + JSON.stringify(data.dnsServers));
		if (data.mode == 0) {
		this.entModeStatus = false;
		}else {
		this.entModeStatus = true
		}
		this.entMode = data.mode
		this.entMsg = JSON.stringify(data).toString();
		this.entRoute = data.route.toString();
		this.entGateway = data.gateway.toString();
		this.entMask = data.netMask.toString();
		this.entDNS = data.dnsServers.toString();
	 }).catch((error: BusinessError) => {
		console.error(this.TAG,"getIfaceConfig promise error = " + JSON.stringify(error));
	 });
  }

  isIfaceActive(){
	 ethernet.isIfaceActive("eth0").then((data: number) => {
		console.log(this.TAG,"isIfaceActive promise = " + JSON.stringify(data));
	 }).catch((error: BusinessError) => {
		console.log(this.TAG,"isIfaceActive promise error = " + JSON.stringify(error));
	 });
  }

  getAllActiveIfaces(){
	 ethernet.getAllActiveIfaces().then((data: string[]) => {
		console.log(this.TAG,"getAllActiveIfaces promise data.length = " + JSON.stringify(data.length));
		if (JSON.stringify(data.length) == '1' ) {
		console.log(this.TAG,'data.length')
		}
		for (let i = 0; i < data.length; i++) {
		console.log(this.TAG,"getAllActiveIfaces promise  = " + JSON.stringify(data[i]));
		}
	 }).catch((error:BusinessError) => {
		console.error(this.TAG,"getAllActiveIfaces promise error = " + JSON.stringify(error));
	 });
  }

  build() {
		Column() {
		Text(this.message)
		   .fontSize(50)
		   .fontWeight(FontWeight.Bold)
		   .padding(20)
		Button('点击切换动/静态IP')
		   .onClick(()=>{
			  if (this.entMode == 0) {
			  this.entMode = 1;
			  this.entModeTest = '当前动态Ip'
			  this.entModeStatus = true;
			  }else{
			  this.entMode = 0;
			  this.entModeTest = '当前静态Ip'
			  this.entModeStatus = false;
			  }
			  this.setIfaceConfig();
			  this.getIfaceConfig();
		   })
		if (this.entModeStatus){
		   Column(){
			  TextInput({placeholder : '静态Ip'})
			  .onChange((value : string)=>{
				 this.entIp = value
			  })
		   }
		   .height(80)
		   .width(300)
		   .padding(10)
		   .margin(10)
		}
		Text(this.entModeTest)
		   .fontSize(50)
		   .fontWeight(FontWeight.Bold)
		   .padding(30)
		Column(){
		   Text('网口信息')
		   Blank()
		   Text(this.entMsg)
		}
		.height(80)
		.padding(10)
		}
		.width('100%')
  }

  }

4.4 Code Compilation

Tips

The detailed process of code compilation can be seen in:Hello World application and deployment in the second part (building part of the first page)

4.5 Code Running Effect

Use the above standard API interface to implement Ethernet Demo, as shown in the following figure:

TOOL
Edit this page on GitHub
Last Updated:
Contributors: zsl, zwhuang
Prev
RTC
Next
M.2