[M467 | M487] Build the bridge of Serial and Ethernet

Post Reply
morgandu
Posts: 45
Joined: 28 Apr 2017, 22:47

25 Jul 2023, 15:32

[For further inquiries, please e-mail to shchen2@nuvoton.com]
[Visit https://www.nuvoton.com/iot_startup for more IoT solutions]


This is a reference sample code for bridge of Serial and Ethernet, built on Mbed OS and NuMaker IoT boards that support Ethernet function, such as NuMaker-IoT-M487 and NuMaker-IoT-M467 boards.

Supported Features
  • Multiple UART ports
  • Static IP address or obtain via DHCP
  • TCP Client or Server mode
  • Optional simple web server for UART and Ethernet configuration
Application Architecture

Picture01.png
Picture01.png (67.56 KiB) Viewed 10490 times

Prerequisite
  • A NuMaker-IoT-M487 or NuMaker-IoT-M467 board
  • Two jumper wires
  • A LAN cable
  • A MicroUSB cable
  • A MicroSD card
    Picture02.png
    Picture02.png (109.14 KiB) Viewed 10490 times
  • Mbed Studio – the development tool
  • Terminal tool
    • Such as Putty, Realterm, etc., that support TCP connections
Build a loopback environment to simply the test

Picture03.jpg
Picture03.jpg (204.89 KiB) Viewed 10490 times

Create a Project
  • Run Mbed Studio
  • Log in your Mbed account if it asks
  • Click File
  • Click Import Program
Picture04.png
Picture04.png (24.55 KiB) Viewed 10490 times
Picture05.png
Picture05.png (41.05 KiB) Viewed 10490 times
  • Active program is “NuMaker-mbed-Serial-to-Ethernet”
  • Select target board
    • Select target on the pull down menu, use M487 or M467 as keyword to find “NuMaker-IoT-M487” or “NuMaker-IoT-M467”, then select it. Or you can
    • Plug the Nu-Link USB on NuMaker-IoT board. Mbed Studio will detect it automatically and then select Yes when it ask you to set the device as active.
Picture06.png
Picture06.png (70.2 KiB) Viewed 10490 times

View and Modify Code
  • Click main.cpp to show the source code
  • Declaration of UART pins in main.cpp. UART1 and UART5 pins are set for NuMaker-IoT-M487 board
  • Refer following files for other settings
    • main.cpp
    • ste_config.h
    • mbed_app.json
Picture07.png
Picture07.png (98.64 KiB) Viewed 10490 times

Modify Settings for NuMaker-IoT-M467
If use NuMaker-IoT-M467, modify the declaration of UART pins to match the test environment.
  • Still in main.cpp, find the UART declaration for NuMaker-IoT-M467
  • Modify pins of serial_1 to PA_5 and PA_4 as follows.

Code: Select all

#elif defined (TARGET_NUMAKER_IOT_M467) 
BufferedSerial serial_0(PB_3, PB_2);    // UART1
BufferedSerial serial_1(PA_5, PA_4);    // UART5
BufferedSerial serial_2(PF_7, PF_6);    // UART4
Picture08.png
Picture08.png (97.45 KiB) Viewed 10490 times

Check the Default IP address
The IP address is static by default. In main.cpp, find the IP_ADDRESS, NETWORK_MASK, and GATEWAY_ADDRESS settings. Two sets of settings have been declared.
  • 192.168.1.2 / 255.255.255.0
  • 169.254.108.2 / 255.255.0.0 (Default)
Picture09.png
Picture09.png (87.72 KiB) Viewed 10490 times

When the LAN on Windows PC doesn’t obtain IP from DHCP server, Windows will set its LAN IP to 169.254.xxx.xxx and netmask to 255.255.0.0.
The IP address of NuMaker IoT board set to 169.254.xxx.xxx is convenient for test without modifying Windows LAN setting. Of course, you can modify it to meet your needs.

Build Code
Click hammer to build code. After build finish, you get the firmware image file NuMaker-mbed-Serial-to-Ethernet.bin in the folder
  • Windows
    C:\Users\YOUR-ACCOUNT\Mbed Programs\NuMaker-mbed-Serial-to-Ethernet\BUILD\NUMAKER_IOT_M4X7\ARMC6
  • Linux
    ~/Mbed Programs/NuMaker-mbed-Serial-to-Ethernet/BUILD/NUMAKER_IOT_M4X7/ARMC6
  • X is 8 or 6 depends on your target board
Picture10.png
Picture10.png (103.39 KiB) Viewed 10490 times

Program Firmware via Nu-Link-ME
  • Make sure that all ISW1 switches set to ON
  • Plug in USB cable to PC
  • A NuMicro MCU drive appears on PC
  • Copy NuMaker-mbed-Serial-to-Ethernet.bin to NuMicro MCU drive to program firmware.
Picture11.png
Picture11.png (104 KiB) Viewed 10490 times

Program Firmware via Nu-Link2-ME
  • Make sure that no.1 & 2 are ON and no.3 & 4 are OFF of ICESW2
  • Plug in USB cable to PC
  • A NuMicro MCU drive appears on PC
  • Copy NuMaker-mbed-Serial-to-Ethernet.bin to NuMicro MCU drive to program firmware. Or
  • Click “Connect” icon to download firmware and run.
Picture12.png
Picture12.png (141.96 KiB) Viewed 10490 times

Open the Terminal for Message Output
Mbed Studio automatically open a serial monitor when a Mbed Enabled board detected. Or you can run a terminal tool to open Nu-Link(2)-ME virtual COM port. Remember to select baud rate to 115200. printf() will output here.
Picture13.png
Picture13.png (64.76 KiB) Viewed 10490 times

Run
  • Connect LAN cable for PC and NuMaker IoT board
  • Press RESET button on NuMaker IoT board to restart firmware.
  • The terminal shows the running messages
Picture14.png
Picture14.png (74.93 KiB) Viewed 10490 times

Run terminal tool (Putty as example) twice.
  • The one connects to 169.254.108.2 port 10001, and
  • the other one connects to 169.254.108.2 port 10002.
  • Then click “Open” to start the TCP connection.
Picture15.png
Picture15.png (78.2 KiB) Viewed 10490 times

The NuMaker IoT board terminal will show the established connections.
Picture16.png
Picture16.png (31.6 KiB) Viewed 10490 times

Type any characters and enter key in one Putty, these characters will show on the other Putty. So data are sent and received between two Putties.
Picture17.png
Picture17.png (66.14 KiB) Viewed 10490 times

Use browser to connect to http://169.254.108.2 to display the configuration page. A MicroSD card must be inserted to NuMaker IoT board to save settings.
Picture18.png
Picture18.png (42.48 KiB) Viewed 10490 times


That's all. ;)

Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 91 guests