Skip to main content
Associate II
Question

mx_wifi component does not compile with CMSIS-RTOS v2 (MX_WIFI_USE_CMSIS_OS == 1) — CMSIS layer still uses RTOS v1 API

Hi,
I'm developing an STM32 application that utilizes mx wifi component from  B-U585I-IOT02A board support package, i am trying to configure it to utilize CMSIS_OS but it fails to build out of the box then.
Symptom. Setting MX_WIFI_USE_CMSIS_OS == 1 does not compile against a CMSIS-RTOS v2 environment. The component's CMSIS layer declares and uses CMSIS-RTOS v1 identifiers that do not exist in the v2 shim (cmsis_os.h here only forwards to cmsis_os2.h, osCMSIS = 0x20001U):

/* mx_wifi_cmsis_os.h */
#define LOCK_DECLARE(A)  osMutexId A          /* v2 type is osMutexId_t            */
#define FIFO_DECLARE(Q)  osMessageQId Q       /* line 187: v1 type, v2 has none    */
void *fifo_get(osMessageQId queue, uint32_t timeout);          /* line 238        */
osThreadId thread_new(const char *name, void (*thread)(void const *), ...); /* 250 */

/* LOCK_INIT's osCMSIS >= 0x20000U branch still calls v1 macros: */
osMutexDef(MUTEX); (A) = osMutexNew(osMutex(MUTEX));           /* osMutexDef/osMutex are v1 */

/* core/mx_rtos_abs.c:65 — same v1 parameter type */
void *fifo_get(osMessageQId queue, uint32_t timeout) { ... }


So the osCMSIS >= 0x20000U branches inside the macros call osMutexNew/osMessageQueueNew (v2 functions) but build them from v1 definition macros and v1 type names - the layer is a hybrid that matches neither API.
Steps to reproduce
1. FreeRTOS + CMSIS_RTOS_V2 wrapper only (no CMSIS-RTOS v1 headers on the include path).
2. Set MX_WIFI_USE_CMSIS_OS to 1 in mx_wifi_conf.h.
3. Build → unresolved osMessageQId, osMutexDef, osMessageQDef, v1 thread signature.
In the basic BARE OS mode MX_WIFI_USE_CMSIS_OS = 0, mx wifi component works, but it utilizes polling, which is not desired for my application
The question is: Are there some things in the configuration that I am missing or I should patch the module myself, so that it builds with the CMSIS RTOS? 

2 replies

ST Technical Moderator

Hello ​@Whoing23 

Thank you for bringing this issue to our attention.

I reported this internally.

Internal ticket number: CDM0067432 (This is an internal tracking number and is not accessible or usable by customers).

 

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
ST Technical Moderator

Hello ​@Whoing23 

Setting MX_WIFI_USE_CMSIS_OS = 1 enables the driver’s RTOS support through cmsis_os.h. The driver selects its CMSIS-RTOS v1 or v2 code path based on the osCMSIS macro.

However, cmsis_os2.h does not define osCMSIS, so the driver falls back to its v1 code path. In addition, the driver’s v2 code path still uses CMSIS-RTOS v1 types and macros, such as osMutexId, osMessageQId, osMutexDef, and osMutexWait. As a result, a project that provides only cmsis_os2.h will not compile.

With FreeRTOS: you can add ST's cmsis_os.h compatibility header, which provides the CMSIS-RTOS v1 API on top of CMSIS-RTOS v2: stm32-mw-freertos/Source/CMSIS_RTOS_V2/cmsis_os.h at master · STMicroelectronics/stm32-mw-freertos

With this cmsis_os.h header, and the cmsis_os2.c from stm32-mw-freertos/Source/CMSIS_RTOS_V2 at master · STMicroelectronics/stm32-mw-freertos, the driver compiles without modification.

Two configuration adjustments will be required:

  • Set configSUPPORT_STATIC_ALLOCATION = 1 in FreeRTOSConfig.h .The compatibility macros create mutexes and semaphores with static control blocks.
  • Increase the Wi-Fi thread stack sizes in mx_wifi_conf.h by a factor of 4.CMSIS-RTOS v2 interprets stack sizes in bytes instead of 32-bit words, so the default value of 1024 gives 1 KB instead of 4 KB.

With other RTOS kernels: this configuration is not supported. The customer would need to adapt mx_wifi_cmsis_os.h and core/mx_rtos_abs.c to the native CMSIS-RTOS v2 API, and redefine MX_WIFI_MALLOC and MX_WIFI_FREE , which default to the FreeRTOS functions pvPortMalloc and vPortFree .

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