1. Echo presentation
This application aims to demonstrate the TCP Echo feature over Wi-Fi.
The project serves as a starting point for developing many other projects.
The application starts in STA mode and connects to a Local_AP (gateway/hotspot/etc) available in the range. The credential (SSID & password) of the Local_AP must be configured by the user in the file "main_app.c".
Once a device is connected, it first pings the http://www.google.com.
Then it opens a TCP socket, and it echoes the http://tcpbin.com server by sending a message and receiving it back.
The results of the echo request are displayed through UART on the HyperTerminal.
2. Requirements
2.1. Software and system requirements
The following software is required (minimum IDEs version):
- STM32CubeIDE toolchain V1.18.1 [1]
- IAR Embedded Workbench for ARM (EWARM) toolchain V9.30.1
- RealView Microcontroller Development Kit (MDK-ARM) toolchain V5.39
Programmer:
- STM32CubeProgrammer [2] : To flash the board with an already generated binary
HyperTerminal:
- Use the application through the serial link
- Open a HyperTerminal client connected to the Host ST-LINK COM port
The serial COM port must be configured as below:
Baudrate | 921600 |
Data | 8b |
Stopbit | 1b |
Parity | None |
Flow control | None |
Rx | LF |
Tx | LF |
Local Echo | Off |
For more details see HyperTerminal setup page.
2.2. Hardware requirements
This project is available on NUCLEO-U575ZI-Q, NUCLEO-H563ZI, NUCLEO-H7S3L8, or NUCLEO-N657X0-Q host boards combined with the X-NUCLEO-67W61M1 board.
The X-NUCLEO-67W61M1 board is plugged into the NUCLEO host board through the Arduino connectors:
- The 5V, 3V3, GND through the CN6
- The SPI (CLK, MOSI, MISO), SPI_CS and USER_BUTTON signals through the CN5
- The BOOT, CHIP_EN, SPI_RDY and UART TX/RX signals through the CN9
3. ST67W6X_Echo application description
3.1. Project directory
The "ST67W6X_Echo" application is available by downloading the X-CUBE-ST67W61 Package.
Refer to Project directory wiki page for project directory information.
3.2. Project description
3.2.1. Topology structure
The device (host + X-NUCLEO-67W61M1) is in STA mode, and it connects to a Wi-Fi local access point (hotspot/gateway/etc.) which requires a connection to the internet (unless ECHO_SERVER_URL is redefined to use a local echo server available on the LAN).
3.2.2. Project Initialization
The different steps of the application initialization are described below:
In light blue are listed the common initialization steps between all the applications. The other steps are specific to the Echo application.
3.3. Build and Install
Refer to build and install chapter for details on how to build and download on the device.
3.4. User setup
3.4.1. ST67W6X default configuration
The default System configuration can be modified in "ST67W6X/Target/w6x_config.h":
/** NCP will go by default in low power mode when NCP is in idle mode */ #define W6X_POWER_SAVE_AUTO 1 /** NCP clock mode : 1: Internal RC oscillator, 2: External passive crystal, 3: External active crystal */ #define W6X_CLOCK_MODE 1
The default Wi-Fi configuration can be modified in the "ST67W6X/Target/w6x_config.h" file:
/** Define the DHCP configuration : 0: NO DHCP, 1: DHCP CLIENT STA, 2:DHCP SERVER AP, 3: DHCP STA+AP */ #define W6X_WIFI_DHCP 1 /** Define if the DNS addresses are set manually or automatically */ #define W6X_WIFI_DNS_MANUAL 0 /** String defining DNS IP 1 address to use * @note: This address will be used only if W6X_WIFI_DNS_MANUAL equals 1 */ #define W6X_WIFI_DNS_IP_1 {208, 67, 222, 222} /** String defining DNS IP 2 address to use * @note: This address will be used only if W6X_WIFI_DNS_MANUAL equals 1 */ #define W6X_WIFI_DNS_IP_2 {8, 8, 8, 8} /** String defining DNS IP 3 address to use * @note: This address will be used only if W6X_WIFI_DNS_MANUAL equals 1 */ #define W6X_WIFI_DNS_IP_3 {0, 0, 0, 0} /** Define the region code, supported values : [CN, JP, US, EU, 00] */ #define W6X_WIFI_COUNTRY_CODE "00" /** Define if the country code will match AP's one. * 0: match AP's country code, * 1: static country code */ #define W6X_WIFI_ADAPTIVE_COUNTRY_CODE 0 /** String defining Wi-Fi hostname */ #define W6X_WIFI_HOSTNAME "ST67W61_WiFi"
The default Net configuration can be modified in the "ST67W6X/Target/w6x_config.h" file:
/** Timeout in ticks when calling W6X_Net_Recv() */ #define W6X_NET_RECV_TIMEOUT 10000 /** Timeout in ticks when calling W6X_Net_Send() */ #define W6X_NET_SEND_TIMEOUT 10000
The AT driver can be configured in "ST67W6X\Target\w61_driver_config.h":
/** Maximum number of detected AP during the scan. Cannot be greater than 50 */ #define W61_WIFI_MAX_DETECTED_AP 50 /** Number of ping repetition */ #define W61_NET_PING_REPETITION 4 /** Default size of the ping sent */ #define W61_NET_PING_PACKET_SIZE 64 /** Interval between two sent of ping packets in ms */ #define W61_NET_PING_INTERVAL 1000 /** Debugging only: Enable AT log, i.e. logs the AT commands incoming/outcoming from/to the NCP */ #define W61_AT_LOG_ENABLE 0
Additionally, some other options can be modified in the "ST67W6X/Target" directory with different configuration files as below:
- logging_config.h: This file provides configuration for the logging component to set the log level.
- shell_config.h: This file provides configuration for shell component.
- w6x_config.h: This file provides configuration for the W6X APIs (used during initialization).
- w61_driver_config.h: This file provides configuration for the W61 configuration module.
All available defines are available in template directory "Middlewares/ST/ST67W6X_Network_Driver/Conf"
3.4.2. Application configuration
The Wi-Fi configuration used in this application is defined in "App_Echo/App/app_config.h":
#define WIFI_SSID "YOUR_SSID" #define WIFI_PASSWORD "YOUR_PASSWORD"
The logging output mode can be modified in "App_Echo/App/app_config.h":
/** Select output log mode [0: printf / 1: UART / 2: ITM] */ #define LOG_OUTPUT_MODE 1
The host low power mode can be modified in "App_Echo/App/app_config.h":
/** Low power configuration [0: disable / 1: sleep / 2: stop / 3: standby] */ #define LOW_POWER_MODE 1
The host debugger pins can be modified in "App_Echo/App/app_config.h":
/** * Enable/Disable MCU Debugger pins (dbg serial wires) * @note by HW serial wires are ON by default, need to put them OFF to save power */ #define DEBUGGER_ENABLED 1
The Echo client configuration can be modified in "App_Echo/App/app_config.h":
/** URL of Echo TCP remote server */ #define ECHO_SERVER_URL "tcpbin.com" /** Port of Echo TCP remote server */ #define ECHO_SERVER_PORT 4242 #endif /* NET_USE_IPV6 */ /** Minimal size of a packet */ #define ECHO_TRANSFER_SIZE_START 1000 /** Maximal size of a packet */ #define ECHO_TRANSFER_SIZE_MAX 2000 /** To increment the size of a group of packets */ #define ECHO_TRANSFER_SIZE_ITER 250 /** Number of packets to be sent */ #define ECHO_ITERATION_COUNT 10
3.5. How it works
The connection of the STA is established, after a scan, to the local AP defined in the main_app.c file, and the device receives an IP address from the DHCP server of the selected local AP.
Then the device tries to ping Google to verify internet connectivity. Finally, a socket is created and connected to the predefined echo server (by default ECHO_SERVER_URL is tcpbin.com which requires the local AP to have internet connectivity).
The device (in STA mode) sends packets of data using the TCP protocol to the echo server which sends them back.
Once the data is successfully received back by the device, the socket is closed, and the device disconnects from the local AP.
Expected results:
<INF> 1696 [defaultTsk] WiFi init is done (main_app.c:127) <INF> 1715 [defaultTsk] Net init is done (main_app.c:135) <INF> 4757 [AtRxParser] SCAN DONE (main_app.c:288) <INF> 4757 [AtRxParser] Cb informed APP that WIFI SCAN DONE. (main_app.c:289) <INF> 4757 [AtRxParser] MAC : [62:5d:b8:7a:b0:ba] | Channel: 1 | WPA2 | RSSI: -39 | SSID: ASUS (w6x_wifi.c:270) <INF> 4757 [defaultTsk] Connecting to Local Access Point (main_app.c:145) <INF> 4762 [AtRxParser] MAC : [34:53:d2:05:b8:80] | Channel: 11 | WPA2 | RSSI: -43 | SSID: Bbox-5455E47A (w6x_wifi.c:270) <INF> 4782 [AtRxParser] MAC : [2c:08:23:79:7b:42] | Channel: 1 | WPA2 | RSSI: -93 | SSID: Livebox-61D0 (w6x_wifi.c:270) <INF> 6717 [defaultTsk] NPC is treating the connect request (w6x_wifi.c:308) <INF> 8656 [defaultTsk] DHCP client start, this may take few seconds (w6x_wifi.c:335) <INF> 8766 [defaultTsk] Connected to following Access Point : (main_app.c:307) <INF> 8766 [defaultTsk] [62:5d:b8:7a:b0:ba] Channel: 1 | RSSI: -44 | SSID: ASUS (main_app.c:308) <INF> 8766 [defaultTsk] App connected (main_app.c:156) <INF> 8766 [defaultTsk] Pinging Google (main_app.c:159) <INF> 12964 [defaultTsk] 4 packets transmitted, 4 received, 0% packet loss, time 54ms (main_app.c:170) <INF> 13140 [defaultTsk] IP Address from Hostname [tcpbin.com]: 45.79.112.203 (main_app.c:183) <INF> 13140 [defaultTsk] Create a new socket (main_app.c:191) <INF> 13140 [defaultTsk] Socket creation done (main_app.c:200) <INF> 13141 [defaultTsk] Connecting the socket (main_app.c:203) <DBG> 13369 [AtRxParser] W6X got NET_EVT_SOCK_CONNECTED_ID for connection 0 (w6x_net.c:1243) <INF> 13369 [defaultTsk] Socket opened (main_app.c:216) <INF> 13369 [defaultTsk] Sending data to the socket (main_app.c:219) <INF> 13378 [defaultTsk] Data completely sent (main_app.c:233) <INF> 13582 [AtRxParser] Cb informed APP that WIFI 11 BYTES AVAILABLE ON SOCKET 0. (main_app.c:336) <INF> 13589 [defaultTsk] Socket data received 11bytes: 0123456789 (main_app.c:244) <DBG> 13597 [AtRxParser] W6X got NET_EVT_SOCK_DISCONNECTED_ID for connection 0 (w6x_net.c:1248) <INF> 13607 [defaultTsk] Socket closed (main_app.c:254) <INF> 14135 [defaultTsk] Station disconnected from Access Point (main_app.c:315) <INF> 14135 [defaultTsk] Disconnect success (main_app.c:260)
3.6. Memory footprint
Module | Description |
---|---|
[Driver] HAL/CMSIS/BSP | STM32 CMSIS Cortex, HAL and LL, Board Specific Package drivers |
[Project] Core | Native STM32 core components |
[Project] App | Main part of the application |
[Project] Target | Configuration files for ST67W6X_Network_Driver component |
[MW] ST67W6X_Network_Driver | Core and API System, Wi-Fi® and Network components Util/Logging: Utility to process shell and trace messages onto the UART interface (can be changed by ITM) |
[MW] FreeRTOS | FreeRTOS kernel source |
[Utility] lpm | Tiny Low-Power Management |
[Toolchain] Startup | Int_vect, init routines, init table, CSTACK and HEAP |
[Toolchain] EWARM Libraries | Native compiler libraries |
These values depend on the chosen toolset and they can change in next releases.
3.6.1. ROM/flash memory footprint
The picture below shows the sum of the read only memory (flash) of the Echo application.
The picture below shows the middleware ST67W6X_Network_Driver read-only memory (flash) used by Echo application.
3.6.2. Read/write (RW) memory footprint
The picture below shows only the sum of the static read/write memory (static RAM) of the Echo application.
4. References