Skip to main content
Associate II
Question

MX_WIFI_Socket_setsockopt() rejects MX_SO_BLOCKMODE (0x1000) on EMW3080 - non-blocking sockets unusable; select() is a stub

Hi,
I am developing application on B-U585I-IOT02A (STM32U585), using mx_wifi component V2.3.3 (SPI transport, socket mode MX_WIFI_NETWORK_BYPASS_MODE == 0), EMW3080B module firmware V2.3.4, bare-OS shim, link associated and DHCP lease verified before every test.
Symptom. MX_WIFI_Socket_setsockopt() returns -1 immediately for MX_SO_BLOCKMODE (0x1000) at level MX_SOL_SOCKET (0xfff). The refusal is value-invariant: optval 0 and 1 behave identically (0 would request the module's default state), and OptLen 1, 2 and 4 all fail — so the option name, not the payload, is rejected. MX_WIFI_Socket_getsockopt() on the same option is refused as well, so the effective mode cannot even be read back. Mainstream options on the same socket (MX_SO_REUSEADDR, MX_SO_SNDTIMEO, MX_SO_RCVTIMEO) succeed.
Minimal repro

int32_t sock = MX_WIFI_Socket_create(obj, MX_AF_INET, MX_SOCK_STREAM, MX_IPPROTO_TCP);
int32_t optval = 1;                        /* 1 = non-blocking */
int32_t ret = MX_WIFI_Socket_setsockopt(obj, sock, MX_SOL_SOCKET, MX_SO_BLOCKMODE,
                                        &optval, sizeof(optval));
/* FAILS HERE: ret == -1 immediately, for optval 0 and 1 alike */

For my application it is important because other library that i am using recommend socket to be non blocking, for now it works with blocking implementation, but I would like to determine the reason.
Has anyone got MX_SO_BLOCKMODE accepted on the EMW3080 (any module firmware version), or can ST confirm whether the option is implemented in the module firmware for plain TCP sockets? Is there another sanctioned non-blocking read/write mechanism?
Wi-Fi component: https://github.com/STMicroelectronics/stm32-mx-wifi

1 reply

ST Technical Moderator

Hello ​@Whoing23 

MX_SO_BLOCKMODE is not supported for plain TCP sockets.
The module firmware forwards setsockopt() and getsockopt() unchanged to its internal TCP/IP stack. This stack does not implement option 0x1000 at SOL_SOCKET, so the call returns -1. This is consistent with the observed behavior.
The module firmware provides no non-blocking command for plain TCP sockets.

select() is supported by firmware V2.3.4, but it is not exposed by the driver: MX_WIFI_Socket_select() in driver V2.3.3 is a stub that always returns -1.

Recommended approach with the current driver and firmware: Short receive/send timeouts: by default, the module sets a 10 s receive and send timeout on each socket. You can reduce these timeouts with MX_SO_RCVTIMEO and MX_SO_SNDTIMEO:

uint32_t timeout_ms = 10U;

MX_WIFI_Socket_setsockopt(&wifi, sock, MX_SOL_SOCKET,
                          MX_SO_RCVTIMEO, &timeout_ms,
                          (int32_t)sizeof(timeout_ms));
MX_WIFI_Socket_setsockopt(&wifi, sock, MX_SOL_SOCKET,
                          MX_SO_SNDTIMEO, &timeout_ms,
                          (int32_t)sizeof(timeout_ms));
The value is a uint32_t in milliseconds and must be at least 1 ms, because 0 means “wait forever”. recv() then returns after at most this delay, allowing you to poll several sockets in a loop.

Full non-blocking socket API: use network bypass mode (MX_WIFI_NETWORK_BYPASS_MODE = 1) with a TCP/IP stack (NetX Duo or LwIP) running on the STM32. LwIP or NetX Duo then provides non-blocking sockets, select() and poll() natively.

See the STM32CubeU5 example for the B-U585I-IOT02A: NetX Duo applications with bypass mode. Another option is X-CUBE-AWS, which uses LwIP with bypass mode.

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Saket_Om