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

Example Flow For Sending A Message:

  • Initialize UDP Fill DiagnosticsData using FillDiagnostics
  • Encode using DBMDiagnostics
  • Encode 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(Simulink folder)
  • 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)
  • Populates motor data (rpm, voltage, angle).
  • Updates global variables used in diagnostics
  • Runs every 100 ms