How waterloo-rocketry/cansw_processor_canards works
Project Type & Purpose
• This is an embedded firmware project built for the 2024-2025 processor board. Its purpose is to perform state estimation and control of the “canards” system.
• The project integrates real-time operations (via FreeRTOS), hardware peripheral access (using STM32 HAL, CMSIS, and custom drivers), and high-level application logic (under src/application) that coordinates components such as the controller, estimator, sensor handlers, and logging.
Analyzing the File Structure – Identifying Components
• Core/Startup, Core/Inc, and Core/Src: These represent the core initialization, system configuration, and low-level hardware abstraction. They also include FreeRTOS configurations.
• Drivers and Middlewares:
• The Drivers directory contains both CMSIS and HAL drivers which abstract the STM32H7 hardware.
• The Middlewares folder wraps third-party libraries such as FatFs and FreeRTOS and handles additional functionality.
• src/ Directory Submodules:
• src/drivers/: Custom peripheral driver implementations (e.g., ADC, I2C, UART, GPIO, timer) that interface with the hardware.
• src/application/: Contains high-level logic modules such as the can_handler, controller (and its associated algorithm and gain table), estimator, imu_handler, flight_phase, init, and logger.
• src/common/: Shared resources and math libraries to support application computations.
• src/third_party/: Third-party libraries (like CMSIS-DSP, rocketlib, printf) required for additional processing.
• tests/ Directory:
• Contains unit testing infrastructure, including GoogleTest-based unit tests and mocks for HAL, FreeRTOS, and other functions. This shows separation of concerns for testing versus production code.
a. Main Components to Represent:
• Core Firmware Layer: Startup code, system initialization, FreeRTOS integration (Core directory content).
• Hardware Abstraction & Drivers: Libraries (CMSIS, HAL) and custom drivers that interact directly with peripheral hardware.
• Middleware: FatFs for file system support, FreeRTOS for scheduling/RTOS functions, plus any additional third-party libraries.
• Application Logic: Divided into modules such as:
• CAN Handler – managing CAN bus communications.
• Controller and its algorithm – performing control operations.
• Estimator – reading sensor inputs and handling state estimation.
• IMU Handler, Flight Phase – managing sensor processing/flight mode.
• Logger – managing data logging and message formatting.
• Unit Testing Framework: GoogleTest and Fake Function Framework (fff) used for testing components.
b. Relationships and Interactions:
• That several application components (controller, estimator, logger) interact with each other and read/write from hardware peripherals via the drivers.
• A separate section (or overlay) for Unit Testing that “mocks” underlying HAL/RTOS calls to isolate logic from hardware, illustrating dependency inversion.
c. Architectural Patterns and Design Principles:
• Modular Design: Indicate grouping of similar modules (e.g., all sensor drivers in one grouping; all application features in another).
• Use of a RTOS pattern where tasks or threads are scheduled for different modules (if applicable).
• Integration of third-party libraries via dedicated modules (e.g., FreeRTOS, FatFs, CMSIS libraries).
d. Relevant Technologies/Frameworks:
• STM32 HAL/CMSIS for hardware access.
• FreeRTOS (and its integration via Middlewares and Core) for real-time operations.
• CMake as the build system (configured in the project with CMakeLists.txt files).
• GoogleTest and fff for unit testing.
• Custom-developed drivers and application modules for handling CAN communications, state estimation, control logic, and data logging.