δΈζ | English
An AUTOSAR communication stack demonstration project based on STM32F407, supporting CAN communication and UDS diagnostic services.
- Features
- Hardware Platform
- Quick Start
- Project Structure
- Build Instructions
- CAN Tools Setup
- UDS Diagnostics
- Code Generators
- Troubleshooting
- Follow Us
- AUTOSAR Stack: Integrated CanIf, PduR, Com, Dcm, EcuM modules
- CAN Communication: Support standard and extended frames, 500Kbps baudrate
- DBC Code Generator: Auto-generate CAN signal packing/unpacking code from Excel
- UDS Diagnostics: Support 0x10, 0x11, 0x22, 0x2E, 0x27, 0x3E services
- Serial Debug: USART1 115200bps with full debug logging
- LED Control: Support 3 LED status indicators
Watch the project demonstration video to see the AUTOSAR CAN communication and UDS diagnostics in action!
Video Contents:
- π Hardware connection and setup
- π‘ CAN message transmission and reception
- π UDS diagnostic service demonstration
- π οΈ DBC code generation workflow
- π Real-time debugging with serial output
Note: The demo video (
docs/videos/demo.mp4) is included in the repository. You can also download it from the Releases page.
| Parameter | Specification |
|---|---|
| MCU | STM32F407ZGT6 (Cortex-M4, 168MHz, 1MB Flash, 192KB RAM) |
| External Crystal | 8MHz HSE |
| System Clock | 168MHz |
| Peripheral | Configuration | Pin Assignment | Clock Source |
|---|---|---|---|
| CAN | CAN1, 500Kbps | PA11(RX), PA12(TX) | APB1 (42MHz) |
| USART | USART1, 115200bps | PA9(TX), PA10(RX) | APB2 (84MHz) |
| GPIO | 3 LED outputs | PE3, PE4, PG9 | AHB (168MHz) |
| Timer | SysTick | Core timer | HCLK (168MHz) |
8MHz HSE
|
βΌ
βββββββββββ βββββββββββ βββββββββββ
β β β β β β
βSTM32F407βββββββΊβ CAN βββββββΊβ PCAN-USBβ
β PA11 β βTranceiverβ β β
β PA12 β β β β β
β β βββββββββββ βββββββββββ
β PA9 β
β PA10 βββββββΊ USB to Serial Module
β β
β PE3 βββββββΊ LED0 (Run Indicator)
β PE4 βββββββΊ LED1 (Reserved)
β PG9 βββββββΊ LED2 (Reserved)
βββββββββββ
| Tool | Model | Purpose |
|---|---|---|
| Debugger | J-Link Plus / ST-Link V2 | Program and Debug |
| CAN Interface | PCAN-USB / PEAK CAN | CAN Communication |
| Serial Tool | USB to TTL (CH340/CP2102) | Log Output |
git clone https://github.com/your-username/STM32_AUTOSAR.git
cd STM32_AUTOSARcd STM32_AUTOSAR
mkdir -p build && cd build
cmake ..
make -j$(nproc)# Using J-Link (Default)
make flash
# Or using OpenOCD
openocd -f interface/jlink.cfg -f target/stm32f4x.cfg \
-c "program STM32F407_CAN.elf verify reset exit"# Load CAN drivers
sudo modprobe can
sudo modprobe can_raw
sudo modprobe peak_usb
# Create CAN interface
sudo ip link add dev can0 type can bitrate 500000
sudo ip link set can0 up
# Verify
ip link show can0# Terminal 1: Monitor CAN frames
candump -ta can0
# Terminal 2: Send test frame
cansend can0 7DF#0227010000000000
# Terminal 3: View serial logs
minicom -D /dev/ttyACM0 -b 115200STM32_AUTOSAR/
βββ src/ # Source code
β βββ board/ # Board support
β β βββ main.c # Main entry
β β βββ startup_stm32f407xx.s
β β βββ system_stm32f4xx.c
β βββ drivers/ # Hardware drivers
β β βββ CanDriver.c # CAN driver
β βββ utils/ # Utilities
β βββ DebugLog.c # Debug logging
β βββ DbcHandler.c # DBC handling
βββ include/ # Header files
βββ ld/ # Linker scripts
βββ tools/ # Development tools
β βββ code_generators/ # Code generators
β β βββ dbc_generator.py
β β βββ uds_generator/
β βββ build_tools/ # Build scripts
β βββ debug_tools/ # Debug utilities
β βββ diagnostic_tools/ # Diagnostic tools
βββ AUTOSAR/ # AUTOSAR modules
β βββ Std/ # Standard types
β βββ CanIf/ # CAN Interface
β βββ PduR/ # PDU Router
β βββ Com/ # Communication
β βββ Dcm/ # Diagnostic
β βββ EcuM/ # ECU Manager
β βββ UdsConfig/ # UDS configuration
βββ docs/ # Documentation
β βββ images/ # Images
βββ CMakeLists.txt # CMake configuration
βββ LICENSE # MIT License
βββ README.md # This file
| Tool | Version | Installation |
|---|---|---|
| CMake | >= 3.20 | sudo apt install cmake |
| GCC ARM | >= 13.2 | sudo apt install gcc-arm-none-eabi |
| OpenOCD | >= 0.12.0 | sudo apt install openocd |
| Python | >= 3.6 | sudo apt install python3 python3-pip |
| openpyxl | - | pip3 install openpyxl |
# Generate build files
cd STM32_AUTOSAR
mkdir -p build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
# Build
make -j$(nproc)
# Output files:
# - STM32F407_CAN.elf (with debug info)
# - STM32F407_CAN.hex (Intel Hex)
# - STM32F407_CAN.bin (Binary)# Debug build (default)
cmake .. -DCMAKE_BUILD_TYPE=Debug
# Release build
cmake .. -DCMAKE_BUILD_TYPE=Release# Disable AUTOSAR stack
cmake .. -DENABLE_AUTOSAR=OFF
# Use ST-Link instead of J-Link
cmake .. -DINTERFACE_CFG="interface/stlink.cfg"# Install CAN utilities
sudo apt install can-utils
# Load drivers
sudo modprobe can can_raw peak_usb
# Setup interface
sudo ip link add dev can0 type can bitrate 500000
sudo ip link set can0 up# Monitor all frames
candump can0
# Monitor specific ID
candump can0,123:7FF
# Send standard frame
cansend can0 123#1122334455667788
# Send extended frame (UDS request)
cansend can0 7DF#0227010000000000
# Send diagnostic request
cansend can0 735#0322F19000000000
# Data sniffing (show changed data)
cansniffer can0- PCAN-View - PEAK official tool
- BusMaster - Open source CAN analyzer
- CANalyzer - Vector professional tool (commercial)
| SID | Service | Description |
|---|---|---|
| 0x10 | DiagnosticSessionControl | Switch diagnostic sessions |
| 0x11 | ECUReset | Reset ECU |
| 0x22 | ReadDataByIdentifier | Read DID data |
| 0x2E | WriteDataByIdentifier | Write DID data |
| 0x27 | SecurityAccess | Security access |
| 0x3E | TesterPresent | Keep session alive |
# 0x3E - TesterPresent
cansend can0 7DF#023E800000000000
# Response: 7E 00
# 0x10 - Default Session
cansend can0 7DF#0210010000000000
# Response: 50 01 00 32 13 88
# 0x22 - Read VIN (0xF190)
cansend can0 7DF#0322F19000000000
# Response: 62 F1 90 31 32 33...
# 0x22 - Read ECU Name (0xF197)
cansend can0 735#0322F19700000000
# Response: 62 F1 97 53 54 4D...| ID | Name | Direction | Description |
|---|---|---|---|
| 0x7DF | Meg_FunDiag | RX | Functional diagnostic request |
| 0x735 | Meg_PhyDiag | RX | Physical diagnostic request |
| 0x73D | Meg_ResDiag | TX | Diagnostic response |
# Run diagnostic test suite
cd tools/diagnostic_tools
python3 diag_test.py can0Generate C code from Excel DBC configuration:
cd tools/code_generators
./generate_dbc.shInput: tools/config/XZ_CAN_V2.xlsx
Output:
include/DbcConfig.hsrc/utils/DbcHandler.c
Generate UDS diagnostic configuration from Excel:
cd tools/code_generators/uds_generator
# Create example config
./generate_uds.sh --example
# Edit UDS_Config_Example.xlsx, then generate
./generate_uds.sh UDS_Config_Example.xlsxConfiguration Sheets:
- SessionConfig: Session parameters (0x10 service)
- DIDConfig: Data identifiers (0x22/0x2E services)
- SecurityConfig: Security levels (0x27 service)
- RoutineConfig: Routines (0x31 service)
- DTCConfig: DTC definitions (0x19 service)
Q: can0: No such device
# Check if drivers are loaded
lsmod | grep can
# Reload drivers
sudo modprobe -r peak_usb
sudo modprobe peak_usb
# Verify USB device
lsusb | grep -i peakQ: CAN frames not received
# Check interface status
ip -details link show can0
# Verify bitrate matches
# Hardware: 500Kbps, Software: 500Kbps
# Check statistics
ip -s link show can0Q: Error: J-Link not found
# Check USB connection
lsusb | grep -i jlink
# Check permissions
sudo usermod -a -G dialout $USER
# Or use ST-Link
cmake .. -DINTERFACE_CFG="interface/stlink.cfg"Q: /dev/ttyACM0: Permission denied
# Add user to dialout group
sudo usermod -a -G dialout $USER
# Temporary fix
sudo chmod 666 /dev/ttyACM0Q: Garbled serial output
# Check baudrate
stty -F /dev/ttyACM0
# Reconfigure
stty -F /dev/ttyACM0 115200 cs8 -cstopb -parenb rawThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Follow our WeChat Official Account for more AUTOSAR and embedded development content!
Scan to follow and learn together!
- π§ AUTOSAR Tutorials - From beginner to advanced
- π‘ CAN/LIN Bus Technology - Protocol deep dive
- π‘ Embedded Tips - Practical experience sharing
- π° Industry News - Automotive electronics trends
Made with β€οΈ by STM32F407 AUTOSAR Project Contributors