Skip to main content

Architecture

PAGE 7: System Architecture & Integration

System Architecture Overview

┌────────────────────────────────────────────────────┐
│            Sensor Board (STM32H753ZI)              │
│              480 MHz ARM Cortex-M7                  │
────────────────────────────────────────────────────┤
│                                                    │
│  ┌─────────────────────────────────────────────┐   │
│  │           FreeRTOS Kernel                   │   │
│  │     (CMSIS-RTOS V2 compatible)              │   │
│  │     64KB heap | 8KB stack min               │   │
│  └─────────────────────────────────────────────┘   │
│                       ↓                            │
│  ┌─────────────────────────────────────────────┐   │
│  │           Main Sensor Task                  │   │
│  │   - Poll all sensors                        │   │
│  │   - Validate measurements                   │   │
│  │   - Build diagnostics                       │   │
│  │   - Send via UDP/Ethernet                   │   │
│  └─────────────────────────────────────────────┘   │
│          ↓                         ↓               │
│  ┌──────────────────┐   ┌──────────────────────┐   │
│  │     Sensors      │   │   Packet │             │
│  │          │         │  Dispatcher  │   │
│  │ ├─ GPS   │         │              │             │
│  │ ├─ IMU                  │   │      (Incoming)      │   │
│  │  ├─ pHGPS          │   └──────────────────────┘   │
│  │  ├─ IMU          │                              │
│  │  ├─ pH           │                              │
│  │  ├─ Load Cells   │                              │
│  │  └─ PresPressure     │                              │
│  └──────────────────┘                              │
│            ↓                                       │
│  ┌─────────────────────────────────────────────┐   │
│  │      Protobuf Message Encoder               │   │
│  │         (Nanopb library)                    │   │
│  └─────────────────────────────────────────────┘   │
│                       ↓                            │
│  ┌─────────────────────────────────────────────┐   │
│  │        UDP/Ethernet Stack (LwIP)            │   │
│  │   - MAC filtering (3 addresses)             │   │
│  │   - ARP management                          │   │
│  │   - Priority queues (2 levels)              │   │
│  └─────────────────────────────────────────────┘   │
│                        ↓                           │
└────────────────────────────────────────────────────┘
           Network (192.168.0.x)
           UDP Port 7 (broadcast)

Main Loop Operation

while (1) {
    // STEP 1: System Health Check
    ├─// - Check heap (critical: <8KB)
    ├─// - Toggle status LEDs
    └─// - Send raw Ethernet beacon
    
    // STEP 2: Initialize Diagnostics Message
    └─ SensorBoardDiagnostics diagnostics_msgdiagnostics_msg;
    
    // STEP 3: Poll All Sensors
    ├─// - pH Sensor
    // Poll and validate
    ├─- GPS Sensor
    // Parse NMEA, validate
    ├─- IMU Sensor
    // Read 3-axis data
    ├─- Load Cells (x2)
    // Read and calibrate (×2)
    └─- Pressure Sensors // Temperature compensate (×2)x2)
    
    // STEP 4: Encode & Transmit
    ├─// - Encode diagnostics to Protobuf
    ├─// Prepare- Send UDP packet
    └─ Send broadcast (192.168.0.255:7)
    
    // STEP 5: Wait
    for Next Cycle
    └─ osDelay(5000 ms)5000); // 5 seconds
}

Error Handling Strategy

Polling Error States

if (poll_result == RESULT_ERR_UNIMPLEMENTED) {
    // Hardware not connected / not implemented
    sensor.state = SENSOR_IDLE;
    sensor.error_code = COMMUNICATION_FAILURE;

} else if (poll_result == RESULT_ERR_COMMS) {
    // I2C/UART/SPI communication error
    sensor.state = SENSOR_ERROR;
    sensor.error_code = COMMUNICATION_FAILURE;

} else if (poll_result == RESULT_OK) {
    // Data received, validate
    if (validate_sensor_data(value) == RESULT_OK) {
        sensor.state = SENSOR_OPERATING;
        sensor.error_code = NO_ERROR;
    } else {
        // Out of range / invalid
        sensor.state = SENSOR_ERROR;
        sensor.error_code = INVALID_DATA;
    }
}

Sensor Status Codes

Code

Meaning

SENSOR_IDLE

Not connected or not implemented

SENSOR_OPERATING

Normal operation, valid data

SENSOR_ERROR

Communication failure or invalid data

Initialization Sequence

Phase 1: Hardware Setup

1. MPU/Cache configuration
2. HAL initialization
3. System clock → 480 MHz
4. RTOS kernel init
5. GPIO initialization
6. Timer initialization (TIM1)

Phase 2: Communication Setup

1. UART initialization (115200 baud)
2. Logging system init
3. Ethernet PHY init (LAN8742)
4. MAC address filtering
(3 addresses)
5. ARP table populationsetup

Phase 3: Application Setup

1. Packet dispatcher registration
2. AllSensor 6 sensor initializationsinitialization
3. UDP queue creation (priority buffers)
4. UDP callback registration

Phase 4: Main Loop

1. LED initialization
2. Sensor polling starts
3. Continuous 5-second cycles

Memory Layout

Heap (64 KB total)
├─ Sensor data structures (~2 KB)
├─ Protobuf buffers (~4 KB)
├─ UDP TX queues (~16 KB)
├─ FreeRTOS kernel structuresRTOS (~8 KB)
└─ Remaining freeFree (~34 KB)

Critical Threshold: 8 KB
└─ Trigger when < 8KB detected