Project StructureÂś
Understanding the Nexus project structure will help you navigate the codebase and know where to find what you need.
OverviewÂś
Nexus follows a layered architecture with clear separation of concerns. The directory structure reflects this design:
nexus/
âââ hal/ # Hardware Abstraction Layer
âââ osal/ # OS Abstraction Layer
âââ framework/ # Framework components
âââ platforms/ # Platform-specific code
âââ applications/ # Example applications
âââ tests/ # Unit and integration tests
âââ docs/ # Documentation
âââ scripts/ # Build and utility scripts
âââ cmake/ # CMake modules and toolchains
âââ vendors/ # Vendor SDKs
âââ ext/ # External dependencies
âââ .github/ # CI/CD workflows
Directory StructureÂś
Core LayersÂś
HAL - Hardware Abstraction LayerÂś
Location: hal/
Provides unified APIs for hardware peripherals.
hal/
âââ include/hal/ # Public API headers
â âââ hal.h # Main HAL header
â âââ gpio.h # GPIO interface
â âââ uart.h # UART interface
â âââ spi.h # SPI interface
â âââ i2c.h # I2C interface
â âââ timer.h # Timer interface
â âââ adc.h # ADC interface
â âââ pwm.h # PWM interface
â âââ can.h # CAN interface
â âââ dma.h # DMA interface
âââ src/ # Common implementations
â âââ hal_common.c # Common HAL functions
â âââ hal_utils.c # Utility functions
âââ docs/ # HAL documentation
â âââ README.md # Overview
â âââ USER_GUIDE.md # User guide
â âââ DESIGN.md # Design document
â âââ TEST_GUIDE.md # Testing guide
â âââ PORTING_GUIDE.md # Porting guide
â âââ TROUBLESHOOTING.md # Troubleshooting
âââ Kconfig # HAL configuration
âââ CMakeLists.txt # Build configuration
Key Files:
hal.h- Main header, includes all HAL interfacesgpio.h- GPIO operations (read, write, toggle, configure)uart.h- UART communication (send, receive, configure)spi.h- SPI master/slave operationsi2c.h- I2C master/slave operations
Documentation: See Hardware Abstraction Layer (HAL) for detailed HAL documentation.
OSAL - OS Abstraction LayerÂś
Location: osal/
Provides portable RTOS primitives.
osal/
âââ include/osal/ # Public API headers
â âââ osal.h # Main OSAL header
â âââ task.h # Task management
â âââ mutex.h # Mutex operations
â âââ semaphore.h # Semaphore operations
â âââ queue.h # Message queues
â âââ timer.h # Software timers
â âââ event.h # Event flags
â âââ memory.h # Memory management
âââ adapters/ # RTOS adapters
â âââ baremetal/ # Bare-metal implementation
â âââ freertos/ # FreeRTOS adapter
â âââ rtthread/ # RT-Thread adapter
â âââ zephyr/ # Zephyr adapter
âââ docs/ # OSAL documentation
â âââ README.md # Overview
â âââ USER_GUIDE.md # User guide
â âââ DESIGN.md # Design document
â âââ TEST_GUIDE.md # Testing guide
â âââ PORTING_GUIDE.md # Porting guide
â âââ TROUBLESHOOTING.md # Troubleshooting
âââ Kconfig # OSAL configuration
âââ CMakeLists.txt # Build configuration
Key Files:
osal.h- Main header, includes all OSAL interfacestask.h- Task creation, deletion, delay, prioritymutex.h- Mutual exclusion lockssemaphore.h- Binary and counting semaphoresqueue.h- Inter-task message passing
Documentation: See OS Abstraction Layer (OSAL) for detailed OSAL documentation.
Framework LayerÂś
Location: framework/
High-level framework components.
framework/
âââ config/ # Configuration management
â âââ include/config/ # Public headers
â âââ src/ # Implementation
â âââ docs/ # Documentation
â âââ Kconfig # Configuration
â âââ CMakeLists.txt # Build
âââ log/ # Logging framework
â âââ include/log/ # Public headers
â âââ src/ # Implementation
â âââ docs/ # Documentation
â âââ Kconfig # Configuration
â âââ CMakeLists.txt # Build
âââ shell/ # Command shell
â âââ include/shell/ # Public headers
â âââ src/ # Implementation
â âââ docs/ # Documentation
â âââ Kconfig # Configuration
â âââ CMakeLists.txt # Build
âââ init/ # Initialization framework
âââ include/init/ # Public headers
âââ src/ # Implementation
âââ docs/ # Documentation
âââ Kconfig # Configuration
âââ CMakeLists.txt # Build
Components:
Config: Key-value configuration storage with namespaces, JSON/binary import/export
Log: Flexible logging with multiple backends, log levels, module filtering
Shell: Interactive command-line interface with command registration, history, completion
Init: Initialization framework with dependency management and priority levels
Documentation:
Config Manager - Configuration system
Log Framework - Logging framework
Shell Framework - Shell system
Platform LayerÂś
Location: platforms/
Platform-specific implementations.
platforms/
âââ native/ # Native platform (PC simulation)
â âââ include/ # Platform headers
â âââ src/ # Platform implementation
â â âââ gpio_native.c # GPIO simulation
â â âââ uart_native.c # UART simulation
â â âââ ... # Other peripherals
â âââ defconfig # Default configuration
â âââ defconfig.example # Example configuration
â âââ Kconfig # Platform configuration
â âââ README.md # Platform documentation
â âââ CMakeLists.txt # Build configuration
âââ stm32/ # STM32 family
â âââ src/ # STM32 implementations
â â âââ stm32f4/ # STM32F4 specific
â â âââ stm32h7/ # STM32H7 specific
â â âââ common/ # Common STM32 code
â âââ defconfig_stm32f4 # STM32F4 default config
â âââ defconfig_stm32h7 # STM32H7 default config
â âââ Kconfig # STM32 configuration
â âââ Kconfig_chip # Chip selection
â âââ Kconfig_peripherals # Peripheral configuration
âââ gd32/ # GD32 family
â âââ src/ # GD32 implementations
â âââ Kconfig # GD32 configuration
â âââ CMakeLists.txt # Build configuration
âââ esp32/ # ESP32 family (planned)
â âââ Kconfig # ESP32 configuration
âââ nrf52/ # nRF52 family (planned)
â âââ Kconfig # nRF52 configuration
âââ Kconfig # Platform selection
âââ CMakeLists.txt # Platform build logic
Platform Guides:
Native Platform Guide - Native platform
STM32F4 Platform Guide - STM32F4 platform
STM32H7 Platform Guide - STM32H7 platform
GD32 Platform Guide - GD32 platform
ApplicationsÂś
Location: applications/
Example applications demonstrating Nexus features.
applications/
âââ blinky/ # LED blinky example
â âââ main.c # Application code
â âââ CMakeLists.txt # Build configuration
âââ shell_demo/ # Shell/CLI demo
â âââ main.c # Application code
â âââ CMakeLists.txt # Build configuration
âââ config_demo/ # Config manager demo
â âââ main.c # Application code
â âââ CMakeLists.txt # Build configuration
âââ freertos_demo/ # FreeRTOS demo
â âââ main.c # Application code
â âââ CMakeLists.txt # Build configuration
âââ CMakeLists.txt # Applications build logic
Examples:
blinky: Simple LED blinking (GPIO, delays)
shell_demo: Interactive CLI (UART, Shell, commands)
config_demo: Configuration management (Config API, JSON/binary)
freertos_demo: Multi-tasking (FreeRTOS, tasks, queues, mutexes)
See Examples Tour for detailed example descriptions.
TestsÂś
Location: tests/
Comprehensive test suite with 1539+ tests.
tests/
âââ hal/ # HAL tests
â âââ test_gpio.cpp # GPIO unit tests
â âââ test_uart.cpp # UART unit tests
â âââ test_spi.cpp # SPI unit tests
â âââ test_i2c.cpp # I2C unit tests
â âââ ... # Other peripheral tests
âââ osal/ # OSAL tests
â âââ test_task.cpp # Task tests
â âââ test_mutex.cpp # Mutex tests
â âââ test_queue.cpp # Queue tests
â âââ ... # Other OSAL tests
âââ config/ # Config framework tests
â âââ test_config.cpp # Config API tests
â âââ test_namespace.cpp # Namespace tests
â âââ ... # Other config tests
âââ log/ # Log framework tests
â âââ test_log.cpp # Log API tests
â âââ test_backend.cpp # Backend tests
â âââ ... # Other log tests
âââ shell/ # Shell framework tests
â âââ test_shell.cpp # Shell API tests
â âââ test_command.cpp # Command tests
â âââ ... # Other shell tests
âââ init/ # Init framework tests
â âââ test_init.cpp # Init tests
âââ integration/ # Integration tests
â âââ test_integration.cpp
âââ CMakeLists.txt # Test build configuration
Test Statistics:
Total: 1539+ tests
HAL: ~400 tests
OSAL: ~200 tests
Config: ~300 tests
Log: ~130 tests
Shell: ~400 tests
Init: ~15 tests
Integration: ~40 tests
Documentation: See Testing for testing guide.
DocumentationÂś
Location: docs/
Project documentation.
docs/
âââ sphinx/ # Sphinx documentation
â âââ getting_started/ # Getting started guides
â âââ user_guide/ # User guides
â âââ tutorials/ # Step-by-step tutorials
â âââ platform_guides/ # Platform-specific guides
â âââ api/ # API reference
â âââ reference/ # Reference documentation
â âââ development/ # Development guides
â âââ _static/ # Static assets
â âââ _templates/ # Documentation templates
â âââ locale/ # Translations (Chinese)
â âââ conf.py # Sphinx configuration
â âââ index.rst # Documentation index
â âââ requirements.txt # Python dependencies
âââ api/ # Doxygen API docs (generated)
Build Documentation:
# Build all documentation
python scripts/tools/docs.py
# Or build separately
doxygen Doxyfile # API docs
cd docs/sphinx && sphinx-build -b html . _build/html # User guides
Build SystemÂś
Location: cmake/
CMake modules and toolchains.
cmake/
âââ modules/ # CMake helper modules
â âââ FreeRTOS.cmake # FreeRTOS integration
â âââ NexusHelpers.cmake # Utility functions
âââ toolchains/ # Toolchain files
â âââ arm-none-eabi.cmake # ARM cross-compilation
âââ linker/ # Linker scripts
â âââ nx_sections.ld # GCC linker script
â âââ nx_sections.sct # ARM linker script
âââ CTestConfig.cmake # CTest configuration
âââ CTestScript.cmake # CTest script
Documentation: See Build System for build system details.
ScriptsÂś
Location: scripts/
Build and utility scripts.
scripts/
âââ building/ # Build scripts
â âââ build.py # Cross-platform build script
â âââ build.sh # Linux/macOS build script
â âââ build.bat # Windows build script
âââ test/ # Test scripts
â âââ test.py # Cross-platform test script
â âââ test.sh # Linux/macOS test script
â âââ test.bat # Windows test script
âââ tools/ # Utility scripts
â âââ format.py # Code formatting
â âââ clean.py # Clean build artifacts
â âââ docs.py # Documentation generation
âââ coverage/ # Coverage scripts
â âââ run_coverage_linux.sh
â âââ run_coverage_windows.ps1
âââ kconfig/ # Kconfig scripts
âââ generate_config.py # Configuration generation
âââ validate_kconfig.py # Configuration validation
Documentation: See Build Scripts and Tools for script documentation.
External DependenciesÂś
Location: ext/
External libraries and dependencies.
ext/
âââ freertos/ # FreeRTOS kernel (submodule)
â âââ Source/ # FreeRTOS source
â âââ portable/ # Port files
âââ googletest/ # Google Test framework (submodule)
âââ googletest/ # GTest
âââ googlemock/ # GMock
Vendor SDKs: vendors/
vendors/
âââ st/ # STMicroelectronics
â âââ cmsis/ # CMSIS headers
â âââ stm32f4xx_hal/ # STM32F4 HAL
â âââ stm32h7xx_hal/ # STM32H7 HAL
âââ arm/ # ARM CMSIS
â âââ cmsis/ # CMSIS core
âââ espressif/ # Espressif (planned)
âââ nordic/ # Nordic Semiconductor (planned)
Configuration FilesÂś
Root ConfigurationÂś
CMakeLists.txt
Root CMake configuration file.
Kconfig
Root Kconfig file for configuration system.
nexus_config.h
Generated configuration header (auto-generated from .config).
.config
Kconfig configuration file (user-editable or generated from defconfig).
defconfig
Default configuration for each platform (in platforms/*/defconfig).
Build ConfigurationÂś
.clang-format
Code formatting rules for clang-format.
.clang-tidy
Static analysis rules for clang-tidy.
.editorconfig
Editor configuration for consistent coding style.
Version ControlÂś
.gitignore
Git ignore rules.
.gitmodules
Git submodule configuration.
.gitattributes
Git attributes for line endings and diff.
CI/CDÂś
.github/workflows/
GitHub Actions workflows:
build.yml- Multi-platform buildtest.yml- Unit tests with coveragedocs.yml- Documentation deployment
File Naming ConventionsÂś
HeadersÂś
Public headers:
include/<module>/<name>.hPrivate headers:
src/<name>_internal.hPlatform headers:
platforms/<platform>/include/<name>.h
Source FilesÂś
Implementation:
src/<name>.cPlatform implementation:
platforms/<platform>/src/<name>_<platform>.cTests:
tests/<module>/test_<name>.cpp
DocumentationÂś
Markdown:
README.md,DESIGN.md,USER_GUIDE.mdreStructuredText:
*.rst(Sphinx documentation)Doxygen: In-source comments with
\brief,\param,\return
Code OrganizationÂś
Module StructureÂś
Each module follows a consistent structure:
<module>/
âââ include/<module>/ # Public API headers
â âââ <module>.h # Main module header
âââ src/ # Implementation
â âââ <module>.c # Main implementation
â âââ <module>_internal.h # Private headers
âââ docs/ # Module documentation
â âââ README.md # Overview
â âââ USER_GUIDE.md # User guide
â âââ DESIGN.md # Design document
âââ Kconfig # Module configuration
âââ CMakeLists.txt # Build configuration
Header OrganizationÂś
Headers are organized by visibility:
Public Headers (include/):
Installed with the library
Used by applications
Stable API
Private Headers (src/):
Internal implementation details
Not installed
Can change without breaking API
Include PathsÂś
Use module-qualified includes:
/* Correct */
#include "hal/gpio.h"
#include "osal/task.h"
#include "config/config.h"
/* Incorrect */
#include "gpio.h"
#include "task.h"
#include "config.h"
Next StepsÂś
Now that you understand the project structure:
Build and Flash - Learn build and deployment workflows
First Application - Create your own application
Core Concepts - Understand Nexus architecture
Architecture - Deep dive into architecture
See AlsoÂś
Build System - Build system documentation
Coding Standards - Coding standards
Contributing - Contributing guide