This repository contains the firmware for the Smart Car Central Control Unit (CCU) developed on the STM32F401VETx microcontroller.
-
Non-Blocking Architecture: Elimination of
HAL_Delay()to ensure high-frequency responsiveness for button sampling and critical operations. - Dual-Channel ADC Multiplexing: Dynamic runtime reconfiguration of ADC channels to sample an LDR (Light Dependent Resistor) and an LM35 temperature sensor sequentially without hardware blocking.
- Smart Tunnel Mode (Auto Light): Automatic activation of lights via high-resolution PWM when sudden darkness is detected.
-
Hysteresis Cooling Control: Automated cabin ventilation/cooling trigger with built-in thermal hysteresis (
$37^\circ\text{C}$ to$40^\circ\text{C}$ ) to prevent relay/LED chattering. -
Interrupt-Driven Telemetry (Phase 3): Real-time system monitoring over UART. Transmits core temperature, warning LED status, and PWM light levels using non-blocking interrupt routines (
HAL_UART_Transmit_IT) at 9600 baud.
Based on the STM32CubeMX layout, the peripherals are mapped as follows:
| Peripheral / Signal | MCU Pin | Mode / Configuration | Description |
|---|---|---|---|
| TIM2_CH1 | PA0 |
PWM Generation | Automatic/Manual Light Intensity Control |
| ADC1_IN1 | PA1 |
Analog Input (Rank 1) | LDR Sensor for Ambient Light Intensity |
| ADC1_IN2 | PA2 |
Analog Input (Rank 2) | LM35 Sensor for Core Temperature Tracking |
| RED_LED | PA3 |
GPIO Output | Temperature Warning Status Indicator |
| USART1_TX | PA9 |
Asynchronous | Serial Telemetry Data Output (9600 Baud) |
| USART1_RX | PA10 |
Asynchronous | Serial Receive (Reserved) |
| BTN_UP | PB0 |
GPIO Input (Pull-up) | Manual PWM Increment Button |
| BTN_DOWN | PB1 |
GPIO Input (Pull-up) | Manual PWM Decrement Button |
| RCC | PH0 / PH1 |
Crystal/Ceramic Resonator | Main System Clock Source |
| SYS | PA13 / PA14 |
Serial Wire Debug (SWD) | Debugging and Flashing Interface |
- Environmental Sampling (Every 500ms):
- Writes
ADC_ChannelConfTypeDefat runtime to sampleADC_CHANNEL_1(LM35) thenADC_CHANNEL_2(LDR). - Processes the raw ADC value to extract temperature values using the standard analog voltage transfer function.
- Writes
- Telemetry Broadcast (Every 500ms):
- Packages system state (Temperature, Warn LED ON/OFF, PWM value) into a formatted string buffer.
- Dispatches data to the Virtual Terminal via UART interrupts, ensuring the main loop continues execution without stalling.
- Driver Input Polling (Every 200ms):
- Scans
PB0andPB1for manual override commands. - Adjusts PWM Compare Register values dynamically in steps of 50 units (Max: 1000).
- Scans
- STM32CubeMX (Clock configuration & Peripheral initialization)
- Keil uVision 5 / STM32CubeIDE (Embedded C Firmware)
- Proteus 8.17 (Hardware circuit simulation)
The project is organized into the following directories:
firmware/: Contains the full STM32CubeMX configuration (.iocfile), generated HAL drivers, and the Keil MDK-ARM project source code.simulation/: Contains the Proteus ISIS circuit schematic and real-time simulation file (.pdsprj).docs/: Contains project documentation, phase reports (in Persian), timing diagrams, and sensor datasheets.
- Parinaz Kari - @ParinazKari