Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review of mros2-esp32/pull/27. #1

Open
yamati-kz opened this issue Dec 30, 2024 · 3 comments
Open

Review of mros2-esp32/pull/27. #1

yamati-kz opened this issue Dec 30, 2024 · 3 comments

Comments

@yamati-kz
Copy link
Owner

yamati-kz commented Dec 30, 2024

mROS-base/mros2-esp32#27 を元にworkspace/sub_uint16にて検討する。
なぜuint16かというとgithub上あるいは、lsやtreeで表示させたときに、一番下にくるため。下の方に表示してethernetを主張しない。

  1. PR#27の構成のままで、Kconfig.projbuildを削除して今まで通りビルドできることを確認する。
    menuconfig内の定義がなくてビルドが通らないかも。
    -> 上記1、そのままだとビルドエラーとなるので、ethernetサンプルに追記したらビルドは通った。
    問題なく動作するか実際に実機を動かしてみる必要あり。
  2. 通らなかったら、考える
  3. 現状一通り、動いている。
     - Ethernet対応のmenuconfigがsub_uint16/mainにある状態で、切り替えてWifiもEthernetも。
     - 他のworkspaceでのEthernetが動いた時のログがREADMEに載せられていない。
     - 従来通りの手順で問題なく動くことを確認済み。
  4. 目次を入れる
@yamati-kz
Copy link
Owner Author

yamati-kz commented Dec 31, 2024

PR第2段 第1案

:以下のような構成でPRを受け入れていただけると個人的には良いけれど...
Kconfig.projbuild のコピーだけでEthernetを試せる

$ tree mros2-esp32
mros2-esp32
├── CMakeLists.txt   # Modify for Example Ethernet
├── cmsis-esp32
├── dev_tool
├── LICENSE
├── mros2
├── platform
│   ├── ethernet # add for Example Ethernet
│   │   ├── example_ethernet # add for Example Ethernet
│   │   │   ├── example_ethernet.c # add for Example Ethernet
│   │   │   └── example_ethernet.h # add for Example Ethernet
│   │   └── example_ethernet_components # add for Example Ethernet
│   │       ├── example_ethernet_components.c # add for Example Ethernet
│   │       └── example_ethernet_components.h # add for Example Ethernet
│   ├── mros2-platform.cpp # Modify for Example Ethernet
│   ├── mros2-platform.h
│   ├── rtps
│   ├── templates.hpp
│   └── wifi
├── README.md
└── workspace
    ├── echoback_string
    │   ├── CMakeLists.txt
    │   └── main
    │         ├── CMakeLists.txt
    │         └── echoback_string.cpp
    ├── echoreply_string
    ├── m5stack_sample
    ├── pub_float32
    ├── pub_image
    ├── pub_long_string_sub_crc
    ├── pub_twist
    ├── sub_pose
    ├── sub_uint16
    └── sub_uint16_ethernet
        ├── CMakeLists.txt
        ├── main
        │   ├── CMakeLists.txt
        │   ├── Kconfig.projbuild  # add for Example Ethernet
        │   └── sub_uint16_ethernet.cpp
        └── README_ethernet # add for Example Ethernet ビルド方法、テスト方法の詳細な記述。

@yamati-kz
Copy link
Owner Author

yamati-kz commented Dec 31, 2024

PR第2段 : 第2案

sub_int16_ethernetの下にethernetを使ってみたい人向けに必要なファイル群をまとめて置いて。
PR第2段その1と同じになるようにEthernet関連のディレクトリ毎コピー、Cmakelists,txtとmros2-platform.cppを上書き。
その上でidf.py buildを実行。こぴーしなけらばWifiのまま、ユーザは流石に気づく?あれれとなるかな。
どちらにせよ、READMEで事細かく記述する。
PR第2段その2のPRはこんなイメージ。

$ tree mros2-esp32
mros2-esp32
├── CMakeLists.txt   # Modify for Example Ethernet
├── cmsis-esp32
├── dev_tool
├── LICENSE
├── mros2
├── platform
│   ├── mros2-platform.cpp # Modify for Example Ethernet
│   ├── mros2-platform.h
│   ├── rtps
│   ├── templates.hpp
│   └── wifi
├── README.md
└── workspace
    ├── echoback_string
    │   ├── CMakeLists.txt
    │   └── main
    │         ├── CMakeLists.txt
    │         └── echoback_string.cpp
    ├── echoreply_string
    ├── m5stack_sample
    ├── pub_float32
    ├── pub_image
    ├── pub_long_string_sub_crc
    ├── pub_twist
    ├── sub_pose
    ├── sub_uint16
    └── sub_uint16_ethernet
        ├── CMakeLists.txt
        ├── Env_example_ethernet #ここにEthernet関連をひとまとめにして、ビルド前に移動及びファイル上書きを促す
         |   ├── ethernet # add for Example Ethernet
         |   │   ├── example_ethernet # add for Example Ethernet
         |   │   │   ├── example_ethernet.c # add for Example Ethernet
         |   │   │   └── example_ethernet.h # add for Example Ethernet
         |   │   └── example_ethernet_components # add for Example Ethernet
         |   │         ├── example_ethernet_components.c # add for Example Ethernet
         |   │         └── example_ethernet_components.h # add for Example Ethernet
         |   ├── CMakeLists.txt # Modify for Example Ethernet
         |   └── mros2-platform.cpp # Modify for Example Ethernet
        ├── main
        │   ├── CMakeLists.txt
        │   ├── Kconfig.projbuild  # add for Example Ethernet
        │   └── sub_uint16_ethernet.cpp
        └── README_ethernet # add for Example Ethernet ビルド方法、テスト方法の詳細な記述。

@yamati-kz
Copy link
Owner Author

yamati-kz commented Jan 4, 2025

以下、第一案のREADME。

Ethernet Example Trial Manual for mros2-esp32

Table of Contents

  1. Introduction
  2. Overview
  3. Licenses and Security policy
  4. About files related to Ethernet example for mros2-esp32
  5. Connecting the Hardware
  6. Configuration, Build and Flash the Program
  7. Testing Ethernet in another Workspace
  8. Troubleshooting
  9. Appendix

1. Introduction

This document provides instructions for trying Ethernet instead of WiFi in mros2-esp32.
The use of WiFi is standard in mros2-esp32, but here we will introduce an example of Ethernet connection.

2. Overview

  • We will use the example code for Ethernet provided by espressif/esp-idf on GitHub.
  • For the Ethernet connection, an SPI-connected Ethernet module will be used as the required hardware.
  • We have prepared a new Kconfig.projbuild for Ethernet. It allows configuration for switching between WiFi and Ethernet, as well as setting up the SPI interface.
  • We will proceed with the verification using workspace/sub_utint16_ethernet.

2.1 Hardware

  • ESP32 development board : ESP32-S3-DevKitC-1
  • Ethernet SPI module : W5500 is mounted on WIZ850io
  • Standard Ethernet cable
  • Ethernet router
  • Ubuntu native computer with development tools installed

2.2 Software

3. Licenses and Security policy

4. About files related to Ethernet example for mros2-esp32

4.1 Integration of Ethernet sample source code from ESP-IDF

4.2 Renaming of source code, addition of header files, and modifications to them

  • Files and Directory for the Ethernet Example.
$ tree ~/mros2-esp32
~/mros2-esp32
├── CMakeLists.txt
├── platform
│   ├── ethernet
│   │   ├── example_ethernet
│   │   │   ├── example_ethernet.c
│   │   │   └── example_ethernet.h
│   │   └── example_ethernet_components
│   │       ├── example_ethernet_components.c
│   │       └── example_ethernet_components.h
│   └── mros2-platform.cpp
└── workspace
    └── sub_uint16_ethernet
        ├── CMakeLists.txt
        ├── main
        │   ├── CMakeLists.txt
        │   ├── Kconfig.projbuild
        │   └── sub_uint16_ethernet.cpp
        └── README.md

4.2.1 Copy , Rename and Modify

  • examples/ethernet/basic/main/ethernet_example_main.c -> example_ethernet.c

4.2.2 Copy and Rename

  • examples/ethernet/basic/components/ethernet_init/ethernet_init.c -> example_ethernet_components.c
  • examples/ethernet/basic/components/ethernet_init/ethernet_init.h -> example_ethernet_components.h

4.2.3 addition of header files

  • example_ethernet.h : This is included from mros2-esp32/platform/mros2-platform.cpp

4.2.4 Modifications to existing files

  • mros2-esp32/platform/mros2-platform.cpp
    Switching between Wi-Fi and Ethernet, and calling functions related to Ethernet example.
  • mros2-esp32/CMakeLists.txt
    Additional files and modifications related to Ethernet and SPI.

4.2.5 Kconfig.projbuild

# mros2esp32-network-select.txt
menu "mros2-esp32 network interface"
    choice
        prompt "mros2-esp32 network interface"
	    default MROS2_ESP32_NETIF_WIFI
            config MROS2_ESP32_NETIF_WIFI
                bool "WiFi"
            config MROS2_ESP32_NETIF_ETHERNET
                bool "Example-Ethernet"
	endchoice
endmenu
  • It is generated using the following method.
#!/bin/bash
cat ./mros2esp32-network-select.txt \
    ~/esp/esp-idf/examples/ethernet/basic/components/ethernet_init/Kconfig.projbuild \
    ~/esp/esp-idf/examples/ethernet/basic/main/Kconfig.projbuild \
    > ./Kconfig.projbuild
if [ $? -eq 0 ]; then
    echo "Kconfig.projbuild has been generated. Merging the files."
else
fi
  • For example, copy it into 'workspace/sub_utint16_ethernet/main' and use it.

5. Connecting the Hardware

5.1 Connect the Ethernet module to the ESP32 board according to the specifications.

  • WIZ850io's 3.3V is supplied from a three-terminal regulator.
  • Table 5.1 ESP32-S3 and WIZ850io Connection

Table 5.1 ESP32-S3 and WIZ850io Connection

ESP32-S3 GPIO No. WIZ850io Pin (W5500) idf.py menuconfig
GPIO12 SCK SPI SCLK
GPIO11 MOSI SPI MOSI
GPIO13 MISO SPI MISO
GPIO10 SCNn SPI CS0
GPIO4 INTn Interrupt
GPIO9 RSTn PHY Reset

5.1.1 ESP32-S3-DevKitC-1 Pin Layout

image
Fig 5.1.1 ESP32-S3-DevKitC-1 Pin Layout

5.1.2 WIZ850io Pin out

  • The W5500 is mounted on the backside of the board.
image
Fig 5.1.2 WIZ850io Pin out

5.1.3 Example idf.py menuconfig SPI configuration

  • In this manual, "PHY Reset GPIO number of SPI Ethernet Module" has been changed to GPIO9.
  • The default value of "PHY Reset GPIO number of SPI Ethernet Module" is -1, which means it is not assigned to any GPIO.
  • However, by assigning it to a GPIO, the software can reset the PHY. This ensures a more stable initialization process for the W5500.
image
Fig 5.1.3 example idf.py menuconfig SPI setting

5.2 Checklist

  • Ensure all connections are secure and that the power supply is stable.
  • When using the WIZ850io, a measured current of 130mA was observed. Ensure that the 3.3V power supply has sufficient capacity.

6. Configuration, Build and Flash the Program

6.1 Ethernet-related configuration"

  • Run idf.py menuconfig. This is an example of the procedure.
$ cd ~/mros2-esp32/workspace/
$ cd sub_uint16_ethernet
$ . $HOME/esp/esp-idf/export.sh
$ rm -rf build
$ idf.py fullclean
$ idf.py set-target esp32s3
$ idf.py menuconfig
  • Select the "mros2-esp32 network interface" and press the Enter key. This is to switch to Ethernet. In Fig. 6.1.1.
image
Fig. 6.1.1 Select Menu item, mros2-esp32 network interface
  • This represents the current WiFi configuration. Press Enter to switch to Ethernet. In Fig. 6.1.2.
image
Fig. 6.1.2 Select mros2-esp32 network interface
  • This represents the current WiFi configuration. Press Enter to switch to Ethernet. In Fig. 6.1.3.
image
Fig. 6.1.3 Choice Example-Ethernet
  • It indicates that the connection has switched to Ethernet. In Fig. 6.1.4.
  • Pressing the ESC key will exit this settings window.
image
Fig. 6.1.4 Set Example-Ethernet

6.2 Select "Example and SPI setting

  • Select "Example Ethernet Configuration" and press the Enter key. After this, the SPI configuration will be done. In Fig. 6.2.1.
image
Fig 6.2.1 Select Example Ethernet Configuration
  • "SPI Ethernet" is disabled. Press the space key or Enter key to enable it. In Fig. 6.2.2.
image
Fig.6.2.2 Disable SPI Ethernet
  • This indicates that SPI Ethernet is enabled, and various settings for SPI connection are displayed. In Fig. 6.2.3.
image
Fig.6.2.3 SPI ethernet
  • Select "PHY Reset GPIO number of SPI Ethernet Module" and press the Enter key. In Fig. 6.2.4.
image
Fig.6.2.4 select PHY reset
  • Enter 9 and press the Enter key. This number represents the GPIO number. In Fig. 6.2.5.
image
Fig 6.2.5 Assign GPIO number to "PHY Reset GPIO number of SPI Ethernet Module
  • In this manual, do not modify 'Example Configuration'. The original description in Kconfig.projbuild has not been modified.
image
Fig 6.2.6 Not change 'Example Configuration'
  • Save the settings. Press 'q' to open a confirmation window for saving the settings, then press 'y' to save. In Fig. 6.2.6.
image
Fig 6.2.6 Save Configuration

6.3 Building and Flash the Firmware.

  • Connect the Ubuntu PC and the ESP32-S3 Board via USB-to-UART Port. In Fig 6.3.1
image
Fig 6.3.1 Connect to the USB-to-UART Port
  • Configure the settings to access the USB-to-UART Port
$ sudo chmod 666 /dev/ttyUSB0
  • Build and flash the firmware.
$ idf.py build
$ idf.py -p /dev/ttyUSB0 flash

6.4 Testing Ethernet Connectivity

6.4.1 After flashing, monitor the device logs using:

  • Power on all the devices and connect the Ethernet cable.
  • Run idf.py -p /dev/ttyUSB0 monitor.
$ idf.py -p /dev/ttyUSB0 monitor
  • Check the terminal log. When the ESP32 board successfully obtains an IP address from the Ethernet router.
I (197) app_init: Project name:     sub_uint16_ethernet
I (292) main_task: Started on CPU0
I (312) main_task: Calling app_main()
I (332) esp_eth.netif.netif_glue: xx:xx:xx:xx:xx:xx
I (332) esp_eth.netif.netif_glue: ethernet attached to netif
I (342) eth_example: Ethernet Started
I (2342) eth_example: Ethernet Link Up
I (2342) eth_example: Ethernet HW Addr xx:xx:xx:xx:xx:xx
I (4342) esp_netif_handlers: eth ip: 192.168.11.2, mask: 255.255.255.0, gw: 192.168.11.1
I (4342) eth_example: Ethernet Got IP Address
I (4342) eth_example: ~~~~~~~~~~~
I (4342) eth_example: ETHIP:192.168.11.2
I (4342) eth_example: ETHMASK:255.255.255.0
I (4352) eth_example: ETHGW:192.168.11.1
I (4352) eth_example: ~~~~~~~~~~~

6.4.2 Topic communication with mros2-host-examples

  • Perform aPublish/Subscribe test with mros2-host-examples
# Terminal-1 / mros2-esp32, Subscribe node
$ idf.py -p /dev/ttyUSB0 monitor
# Terminal-2 / mros2-host-examples, mros2_pub_uint16 pub_node
$ cd ~/ros2_ws
$ source /opt/ros/humble/setup.bash
$ source install/local_setup.bash
$ ros2 run mros2_pub_uint16 pub_node
  • Etternet example of successful Subscribe. In Fig 6.4.1
image
Fig 6.4.1 Etternet example of successful Subscribe

7. Testing Ethernet in another Workspace

  • Example workspace/echoback_string

7.1 Copy Kconfig.projbuild

$ cd ~/mros2-esp32/workspace
$ cp ./sub_uint16_ethernet/main/Kconfig.projbuild ./echoback_string/main

7.2 Configuration and Build

$ cd echoback_string
$ . $HOME/esp/esp-idf/export.sh
$ rm -rf build
$ idf.py fullclean
$ idf.py set-target esp32s3
$ idf.py menuconfig

7.3 Example of the results after building and running in another workspace

Terminalログを添付

8. Troubleshooting

  • Lower the SPI clock speed below the default value in idf.py menuconfig.
  • In idf.py menuconfig, the "PHY Reset GPIO number of SPI Ethernet Module" has not been changed and remains at its default value.

9 .Appendix

9.1 How to check whether the setting is for WiFi or Ethernet after running "idf.py menuconfig".

  • Search the sdkconfig file to determine whether Ethernet or Wi-Fi is configured.
# example
$ cd ~/mros2-esp32/workspace/sub_uint16_ethernet
$ grep "MROS2_ESP32_NETIF" sdkconfig
  • Check for when Ethernet enabled, WiFi nou define Fig 9.1.1
image
image
image
Fig 9.1.1 Ethernet is enabled
  • Check for when WiFi enabled, Ethernet not define Fig 9.1.2
image
image
image
Fig 9.1.2 Wifi enabled
  • The log when sub_uint16_ethernet is set to Wi-Fi configuration.
image
FIg 9.1.3 No changes to the source file of sub_uint16_ethernet, enable Wi-Fi idf.py menuconfig.

9.2 Verify if it operates as expected using the conventional procedure

  • Take echoback_string as an example. We will proceed with the standard procedure.
  • First step, set the target. In Fig 9.2.1.
image
Fig 9.2.1. The flow up to set-target.
  • 2nd step, Verify that the items displayed in idf.py menuconfig are the same as before, and ensure that there are no Ethernet-related settings. In, Fig 9.2.2.
image
Fig 9.2.2. As usual idf.py menuconfig
  • Verify that MROS2_ESP32_NETIF for switching between Wi-Fi and Ethernet is not present in the sdkconfig.
image
Fig 9.2.3 There is no setting to switch between Wi-Fi and Ethernet.
  • Check the logs.
# Terminal-1 / mros2-esp32, Subscribe node
$ idf.py -p /dev/ttyUSB0 monitor
# Terminal-2 / mros2-host-examples, mros2_pub_uint16 pub_node
$ cd ~/ros2_ws
$ source /opt/ros/humble/setup.bash
$ source install/local_setup.bash
$ ros2 run  ros2 run mros2_echoback_string sub_node
  • Even without the Kconfig.projbuild, the logs are as usual.
image
Fig 9.2.4 Ooperates as usual.

@yamati-kz yamati-kz changed the title mros2-esp32/pull/27を元に検討 Review of mros2-esp32/pull/27. Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant