Skip to main content

Architecture

Complete system overview showing FreeRTOS, sensor polling loop, protobuf encoding, UDP transmission, and memory layout. Includes initialization sequence and error handling strategy.

System Architecture Overview

┌────────────────────────────────────────────────────┐
│            Sensor Board (STM32H753ZI)              │
├────────────────────────────────────────────────────┤
│                                                    │
│  ┌─────────────────────────────────────────────┐   │
│  │           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  │   │
│  │                  │   │      (Incoming)      │   │
│  │  ├─ GPS          │   └──────────────────────┘   │
│  │  ├─ IMU          │                              │
│  │  ├─ pH           │                              │
│  │  ├─ Load Cells   │                              │
│  │  └─ Pressure     │                              │
│  └──────────────────┘                              │
│            ↓                                       │
│  ┌─────────────────────────────────────────────┐   │
│  │      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_msg;
    
    // STEP 3: Poll All Sensors
    // - pH Sensor
    // - GPS Sensor
    // - IMU Sensor
    // - Load Cells (x2)
    // - Pressure Sensors (x2)
    
    // STEP 4: Encode & Transmit
    // - Encode diagnostics to Protobuf
    // - Send UDP broadcast (192.168.0.255:7)
    
    // STEP 5: Wait
    osDelay(5000); // 5 seconds
}

Error Handling Strategy

Polling Error States

if (poll_result == RESULT_ERR_UNIMPLEMENTED) {
    sensor.state = SENSOR_IDLE;
    sensor.error_code = COMMUNICATION_FAILURE;

} else if (poll_result == RESULT_ERR_COMMS) {
    sensor.state = SENSOR_ERROR;
    sensor.error_code = COMMUNICATION_FAILURE;

} else if (poll_result == RESULT_OK) {
    if (validate_sensor_data(value) == RESULT_OK) {
        sensor.state = SENSOR_OPERATING;
        sensor.error_code = NO_ERROR;
    } else {
        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
5. ARP table setup

Phase 3: Application Setup

1. Packet dispatcher registration
2. Sensor initialization
3. UDP queue creation
4. UDP callback registration

Phase 4: Main Loop

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