Skip to main content

Main

src/driving_board/main.c

contains the main firmware entry point and runtime logic for the driving board. The system is built on FreeRTOS (CMSIS-RTOS v2) and runs multiple tasks concurrently.


Initialization init_board This function initializes the full system before starting the scheduler.

It: Configures MPU and cache Initializes HAL and system clock Initializes GPIO, timers, and UART logging Initializes control algorithm (control_initialize) Initializes Ethernet and MAC filtering Creates FreeRTOS tasks Starts PWM and encoder peripherals Starts the RTOS kernel. After this, the scheduler takes over.

Tasks

The system runs 3 main threads:

MainTask

This task handles: Ethernet communication Diagnostics message creation and sending Periodic data updates

Flow: Initialize UDP Fill DiagnosticsData using FillDiagnostics Encode using DBMDiagnosticsEncode Send encoded data over Ethernet Free allocated memory after sending Also sends test UDP and raw Ethernet messages.

PwmTask This task runs the control loop.

It: Calls control_step() from control module Reads outputs from rtY Updates motor PWM using set_bldc_pwm Runs periodically (1 ms)

DrivingEncoderTask This task processes encoder data. It: Reads timer counters Calculates: revolutions radians (position) rpm (speed) Updates global variables used in diagnostics Runs every 100 ms Diagnostics Data FillDiagnostics Fills a DiagnosticsData struct with current system values.

It: Sets board state Sets motor count Populates motor data (rpm, voltage, angle).