Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions STMicroelectronics/STM32F767ZI-Nucleo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Copyright (c) 2026 Eclipse ThreadX contributors
#
# 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.
#
# SPDX-License-Identifier: MIT
#
# Contributors:
# Ali Eissa - 2026 version.

cmake_minimum_required(VERSION 3.5 FATAL_ERROR)
set(CMAKE_C_STANDARD 99)

# Set the toolchain if not defined
if(NOT CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_LIST_DIR}/cmake/arm-gcc-cortex-m7.cmake")
endif()

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake)

include(utilities)

# Define the Project
project(stm32f767_threadx C CXX ASM)

# Define ThreadX User Configurations
set(TX_USER_FILE "${CMAKE_CURRENT_LIST_DIR}/lib/threadx/tx_user.h" CACHE STRING "Enable TX user configuration")
set(TX_USER_FILE_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/threadx")

# Set up standard paths for find modules
set(STM32_FAMILY "F7")
set(STM32Cube_DIR "${CMAKE_CURRENT_LIST_DIR}/lib/stm32cubef7")

# Find CMSIS and HAL driver packages
find_package(CMSIS REQUIRED)
find_package(STM32HAL REQUIRED COMPONENTS cortex pwr rcc gpio uart dma eth)

# Compile the STM32F7xx HAL Driver Library as an Object Library
set(HAL_TARGET stm32cubef7)
add_library(${HAL_TARGET} OBJECT ${STM32HAL_SOURCES})

target_compile_definitions(${HAL_TARGET}
PUBLIC
STM32F767xx
USE_HAL_DRIVER
STM32F7
)

target_include_directories(${HAL_TARGET}
PUBLIC
${CMSIS_INCLUDE_DIRS}
${STM32HAL_INCLUDE_DIR}
${CMAKE_CURRENT_LIST_DIR}/app
)

# Compile ThreadX Kernel from root shared libs submodule
set(THREADX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../libs/threadx")
add_subdirectory(${THREADX_DIR} threadx)

# Create the Main Executable
set(EXE_TARGET stm32f767_threadx)

add_executable(${EXE_TARGET}
app/startup/startup_stm32f767zitx.s
app/startup/system_stm32f7xx.c
app/startup/tx_initialize_low_level.S
app/board_init.c
app/console.c
app/ethernet_phy.c
app/main.c
app/stm32f7xx_hal_msp.c
app/sysmem.c
app/syscalls.c
)

# Set compile definitions for our executable
target_compile_definitions(${EXE_TARGET}
PRIVATE
STM32F767xx
USE_HAL_DRIVER
STM32F7
)

# Include paths
target_include_directories(${EXE_TARGET}
PRIVATE
${CMAKE_CURRENT_LIST_DIR}/app
${CMSIS_INCLUDE_DIRS}
${STM32HAL_INCLUDE_DIR}
${TX_USER_FILE_DIR}
)

# Link libraries (includes ThreadX kernel and HAL object libraries)
target_link_libraries(${EXE_TARGET}
PRIVATE
threadx
stm32cubef7
)

# Apply GCC linker script and print memory usage (utilities.cmake function)
set_target_linker(${EXE_TARGET} "${CMAKE_CURRENT_LIST_DIR}/app/startup/STM32F767ZITx_FLASH.ld")

# Post-build commands to generate raw .bin and .hex files
post_build(${EXE_TARGET})
97 changes: 97 additions & 0 deletions STMicroelectronics/STM32F767ZI-Nucleo/NOTICE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Third-Party Software Notices

This directory contains build automation scripts that download and compile third-party software components. This notice lists the licenses and copyrights applicable to those components.

---

## 1. STMicroelectronics STM32F7xx HAL Driver
* **Source**: https://github.com/STMicroelectronics/stm32f7xx_hal_driver
* **License**: BSD 3-Clause

```text
Copyright (c) 2016 STMicroelectronics.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of STMicroelectronics nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

---

## 2. STMicroelectronics CMSIS Device F7
* **Source**: https://github.com/STMicroelectronics/cmsis_device_f7
* **License**: BSD 3-Clause

```text
Copyright (c) 2016 STMicroelectronics.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of STMicroelectronics nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

---

## 3. STMicroelectronics CMSIS Core
* **Source**: https://github.com/STMicroelectronics/cmsis-core
* **License**: Apache License 2.0 / BSD 3-Clause (Arm Limited / STMicroelectronics)

```text
Copyright (c) 2009-2025 Arm Limited. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
```
95 changes: 95 additions & 0 deletions STMicroelectronics/STM32F767ZI-Nucleo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# STM32F767ZI-Nucleo Board Enablement Demo

This directory contains the Board Support Package (BSP) and build environment for running the Eclipse ThreadX RTOS on the **STMicroelectronics NUCLEO-F767ZI** evaluation board (ARM Cortex-M7).

The project is structured with an isolated build framework, keeping all platform dependencies localized to ensure clean integration.

---

## Hardware Configuration

* **Development Board**: NUCLEO-F767ZI (Nucleo-144)
* **Microcontroller**: STM32F767ZIT6 (ARM Cortex-M7 running at 216 MHz)
* **Memory**: 2 MB Flash, 320 KB SRAM
* **Virtual COM Port**: USART3 (PD8/PD9) connected to ST-LINK debugger (115,200 baud, 8N1)
* **Board LEDs**:
* `LD1` (Green) - PB0
* `LD2` (Blue) - PB7
* `LD3` (Red) - PB14
* **User Button**: PC13 (Blue button, Active High)

---

## Demo Application Architecture

The application runs a multi-threaded demo showcasing cooperation between ThreadX scheduling, queues, hardware interrupts, and status indicator peripherals:

1. **Thread 1 (Green LED - Heartbeat)** (Priority 15):
* Toggles the green LED (`LD1`) continuously at `2 Hz` (250 ms active, 250 ms idle) to verify basic scheduler clock ticks.
2. **Thread 2 (User Button Scanner)** (Priority 10):
* Scans the blue User Button (`PC13`) using software-level mechanical debouncing (20 ms).
* Turns the Blue LED (`LD2`) ON when the button is held.
* Sends the current system tick count over a **ThreadX Message Queue** on a button press transition.
3. **Thread 3 (System Logger)** (Priority 10):
* Blocks efficiently on the Message Queue.
* Wakes up when a button press event is queued and prints a timestamped system log over the serial port.
4. **Thread 4 (Serial Terminal Input)** (Priority 5):
* Integrates an asynchronous, non-blocking **Interrupt Service Routine (ISR)** (`USART3_IRQHandler`) and a 256-byte volatile circular **ring buffer** to read keyboard input at 115,200 baud.
* Collects incoming characters, prints the received string on carriage return/newline, and flashes the Red LED (`LD3`) for 50 ms.
* Avoids the use of `HAL_GetTick()` to prevent CPU starvation when idle.

---

## Prerequisites

Before building, ensure you have the following cross-compilation tools installed on your PATH:

* **ARM GNU Toolchain** (`arm-none-eabi-gcc`)
* **CMake** (version 3.5 or higher)
* **Ninja** or **Make**
* **Git** (for downloading SDK dependencies)

---

## Quick Start Guide

### 1. Download SDK Dependencies
Run the driver fetcher script to clone the official, lightweight STMicroelectronics HAL drivers and CMSIS files locally:

* **On Windows (PowerShell)**:
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\fetch_sdk.ps1
```
* **On Linux (Bash - Ubuntu 24.04)**:
```bash
chmod +x ./scripts/fetch_sdk.sh
./scripts/fetch_sdk.sh
```

### 2. Build the Project
Run the compilation script to compile the libraries and application, linking the ThreadX RTOS kernel:

* **On Windows (PowerShell)**:
```powershell
powershell -ExecutionPolicy Bypass -File .\scripts\build.ps1 -Rebuild
```
* **On Linux (Bash - Ubuntu 24.04)**:
```bash
chmod +x ./scripts/build.sh
./scripts/build.sh --rebuild
```

---

## Deployment & Verification

1. **Flash the Board**:
* Connect the NUCLEO-F767ZI board to your computer using a Micro-USB cable via the ST-LINK port.
* The board will mount as an external USB drive (e.g., `NUCLEO_F767ZI`).
* Copy the raw binary output file `build/stm32f767_threadx.bin` and paste it directly onto the board's drive.
* The ST-LINK status LED will blink rapidly while writing, then the board will auto-reboot.

2. **Monitor Serial Console**:
* Connect a serial terminal program (VS Code Serial Monitor, PuTTY, or Tera Term) to the virtual ST-LINK COM Port.
* Configuration: **115,200 baud**, **8 data bits**, **1 stop bit**, **no parity**, **CRLF line endings** (`\r\n`).
* Press the blue button to check log telemetry, and type strings into the console to test the interrupt-driven echo thread!
Loading