Skip to content

feat(nucleo-f401re): implement comprehensive ThreadX RTOS monitor and primitives showcase#40

Open
AmmarOkla12772 wants to merge 12 commits into
eclipse-threadx:devfrom
AmmarOkla12772:main
Open

feat(nucleo-f401re): implement comprehensive ThreadX RTOS monitor and primitives showcase#40
AmmarOkla12772 wants to merge 12 commits into
eclipse-threadx:devfrom
AmmarOkla12772:main

Conversation

@AmmarOkla12772

Copy link
Copy Markdown
Contributor

Overview

This PR extends the validation demo for the STMicroelectronics NUCLEO-F401RE board under STMicroelectronics/NUCLEO_F401RE/.

The goal is to provide a comprehensive ThreadX RTOS demonstration showcasing dynamic memory management, runtime diagnostics, thread monitoring, and synchronization primitives using public ThreadX APIs.

Changes

  • Replaced static thread stack allocation with a central TX_BYTE_POOL
  • Added runtime memory diagnostics reporting total, allocated, and free byte pool capacity
  • Added TX_BLOCK_POOL for fixed-size deterministic memory allocation
  • Added message passing between sender and receiver threads using TX_QUEUE
  • Added pointer-based queue transfers backed by block pool allocations
  • Added TX_MUTEX synchronization with two competing worker threads sharing a simulated SPI resource
  • Added TX_EVENT_FLAGS_GROUP synchronization between the LED heartbeat thread and an event-processing thread
  • Added TX_SEMAPHORE synchronization with a dedicated consumer thread awakened by LED activity
  • Added TX_TIMER periodic callback executing once per second from the ThreadX system timer thread
  • Expanded the demo from 3 threads to 9 threads to exercise core ThreadX scheduling and synchronization features
  • Added registry-based thread diagnostics using tx_thread_info_get()
  • Added stack high-water mark monitoring by scanning the ThreadX stack fill pattern (0xEFEFEFEF)
  • Added per-thread stack usage and utilization reporting
  • Added formatted runtime telemetry output over USART2 including thread states, priorities, run counts, memory statistics, and synchronization activity counters

Validation

Tested on physical NUCLEO-F401RE board:

  • System runs continuously without crashes or scheduler instability
  • UART output remains stable at 115200 baud
  • Free memory remains constant at 79028 bytes during operation, indicating no byte pool or block pool leaks
  • Thread diagnostics correctly report state transitions, run counts, priorities, and stack watermarks
  • Stack utilization remains within safe limits for all threads
  • System uptime tracks wall-clock time accurately
  • ThreadX synchronization primitives operate as expected under active scheduling
  • No build warnings with Arm GNU Toolchain 15.2.Rel1

Toolchain

  • Arm GNU Toolchain 15.2.Rel1
  • CMake + Ninja build system

Notes

All runtime diagnostics are implemented using documented ThreadX public APIs. No private kernel structures or undocumented internal ThreadX data are accessed, maintaining portability across ThreadX targets.

	new file:   STMicroelectronics/NUCLEO_F401RE/README.md
	new file:   STMicroelectronics/NUCLEO_F401RE/app/CMakeLists.txt
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/board_init.c
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/board_init.h
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/console.c
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/sntp_client.c
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/startup/NUCLEO_F401RE.ld
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/startup/startup_stm32f401xe.s
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/startup/tx_initialize_low_level.S
	new file:   STMicroelectronics/NUCLEO_F401RE/app/common/stm32cubef4/stm32f4xx_hal_msp.c
	new file:   STMicroelectronics/NUCLEO_F401RE/app/starter/cloud_config.h
	new file:   STMicroelectronics/NUCLEO_F401RE/app/starter/main.c
	new file:   STMicroelectronics/NUCLEO_F401RE/cmake/FindCMSIS.cmake
	new file:   STMicroelectronics/NUCLEO_F401RE/cmake/FindSTM32HAL.cmake
	new file:   STMicroelectronics/NUCLEO_F401RE/cmake/arm-gcc-cortex-m4.cmake
	new file:   STMicroelectronics/NUCLEO_F401RE/cmake/arm-gcc-cortex-toolchain.cmake
	new file:   STMicroelectronics/NUCLEO_F401RE/cmake/utilities.cmake
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/CMakeLists.txt
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/nucleo_bsp/CMakeLists.txt
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/nucleo_bsp/nucleo_bsp.c
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/nucleo_bsp/nucleo_bsp.h
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/stm32cubef4/CMakeLists.txt
	new file:   STMicroelectronics/NUCLEO_F401RE/lib/stm32cubef4/config/stm32f4xx_hal_conf.h
Booted ThreadX on NUCLEO-F401RE
Validated scheduler operation
Validated UART console output
Validated LED thread
Validated flashing and hardware execution
…and event flags. Modified demo README file to reflect changes.
…aphore functionality and 1 hz applicaion timer.

@fdesbiens fdesbiens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small change needed. I will merge once this is addressed.

@@ -1,3 +1,3 @@
/*
* Copyright (c) 2026 Eclipse ThreadX contributors
*

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing this part of the header:

  • This program and the accompanying materials are made available
  • under the terms of the MIT license which is available at

https://opensource.org/license/mit.

…ard folders under targets/ and centralized duplicate CMake/toolchain utilities to the root. Also set up directories for shared bsp_interface headers, apps/threadx_demo, and target templates.

@fdesbiens fdesbiens left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Amar. Thank you for this contribution. However, I cannot merge this PR in its current state.

I understand that you tried to refactor the Nucleo and MXChip AZ3166 samples to avoid code duplication. This is a good idea in theory, since both leverage an STM Cortex-M4 MCU. However, we lack the source code for the AZ3166 driver. This means we are stuck with whatever version of ThreadX was current when the last version of the WiFi driver was contributed.

Thus, it is not possible to share code between the AZ3166 sample and the other samples. This is why this sample is leveraging ThreadX and NetX modules inside its own folder structure and not at the top level like the others. Those modules pull the specific version of ThreadX that work with the WiFi driver we have.

I would suggest to close this PR and create a new one where you would submit only your F410re code. Do not touch the AZ3166 sample, unless you want to add new features to it. Let's not try to share BSP code between that one and the others.

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

Successfully merging this pull request may close these issues.

3 participants