Professional containerized AVR development environment with comprehensive build system and testing framework.
- π³ DevContainer: Fully containerized development environment
- ποΈ Dual Build System: CMake for firmware + Ceedling for testing
- π§ͺ Unit Testing: CMock/Unity framework with hardware abstraction mocking
- π Code Coverage: LLVM-based coverage analysis with detailed reporting
- π‘ IntelliSense: Advanced code navigation with clangd configuration
- π USB Programming: Direct AVR device programming from container
- π Professional Structure: Clean separation of firmware and test code
- Docker Desktop with WSL2 backend
- Cursor or VS Code with Dev Containers extension
- usbipd-win for USB forwarding
# Install usbipd-win
winget install usbipd
# Share your AVR programmer (as Administrator)
usbipd list
usbipd bind --busid <BUSID># Attach USB device to WSL
usbipd attach --wsl --busid <BUSID>- Open project in Cursor
- Click "Reopen in Container" when prompted
- Container builds automatically
avr-dev-container/
βββ firmware/ # Firmware source code
β βββ src/
β β βββ main.c # Application entry point
β β βββ led.c # LED control module
β β βββ hardware_interface.c # Hardware abstraction layer
β βββ include/
β βββ led.h # LED module interface
β βββ hardware_interface.h # Hardware abstraction interface
βββ test/ # Unit testing
β βββ unit/
β β βββ test_led.c # LED module unit tests
β βββ support/
β βββ avr_io.h # AVR header mocks
βββ toolchain/ # CMake toolchain configurations
β βββ avr.cmake # AVR-GCC toolchain setup
β βββ test.cmake # Host compiler toolchain for testing
βββ .devcontainer/ # DevContainer setup
β βββ devcontainer.json # Container configuration
β βββ Dockerfile # Container image definition
β βββ setup-git.sh # Git configuration script
βββ .github/ # GitHub Actions CI/CD
β βββ workflows/
β βββ ci.yml # Continuous integration pipeline
βββ build/ # AVR firmware build artifacts (generated)
βββ build-test/ # Test build artifacts (generated)
β βββ mocks/ # Auto-generated CMock files
βββ CMakeLists.txt # Main build configuration
βββ CMakePresets.json # Build presets for AVR and testing
βββ project.yml # Ceedling test configuration
βββ LICENSE # Project license
βββ README.md # Project documentation
cmake --preset avr
cmake --build buildcmake --build build --target firmware-upload# Run all tests
ceedling test:all
# Run specific test
ceedling test:test_led
# Clean test artifacts
ceedling clean# Generate coverage report
ceedling gcov:all
# Display coverage summary (custom script)
./scripts/coverage_summary.sh
# Clean coverage files
./scripts/clean_coverage.sh
# View detailed coverage data
find build-test/gcov/out/test_led -name "*.gcov" -exec cat {} \;Coverage File Organization:
- Coverage Data:
build-test/gcov/out/test_led/ - Generated Reports:
build-test/artifacts/gcov/ - Cleanup Script:
scripts/clean_coverage.sh - Summary Script:
scripts/coverage_summary.sh
Current Coverage Results:
- Source Code: 100% line coverage (15/15 lines)
- Test Code: 100% line coverage (34/34 lines)
# Clean AVR build artifacts
cmake --build build --target clean
# Clean everything (custom target)
cmake --build build --target clean-all- Toolchain: AVR-GCC with optimized settings for ATmega328p
- Output Formats: ELF, Intel HEX, and binary files
- Memory Analysis: Automatic flash/RAM usage reporting
- Framework: Unity + CMock for comprehensive testing
- Mocking: Hardware abstraction layer automatically mocked
- Mock Prefix:
mock_functions (e.g.,mock_hardware_interface_Init()) - Test Structure: Clean separation of test code and fixtures
- Build Integration: Seamless CMake and Ceedling integration
Override default settings with environment variables:
export AVR_MCU=atmega328p
export F_CPU=16000000UL
cmake --preset avravr: Release build for AVR firmware (optimized)test: Debug build for unit testing with Ceedling
- Mock Generation: Automatic in
build-test/mocks/ - Test Support: AVR headers stubbed for host compilation
- CMock Settings: Hardware interface mocked with
mock_prefix
The project uses a clean hardware abstraction layer:
hardware_interface.h/c: GPIO operations abstractedled.h/c: High-level LED control using hardware interface- Testability: Hardware layer mocked for unit testing
- Dual Toolchains: AVR-GCC for firmware, Clang for tests
- Separate Build Directories:
build/for firmware,build-test/for tests - IntelliSense Support:
.clangdconfiguration for code navigation
USB device not found:
- Check:
usbipd list(device should show "Attached - WSL") - Re-attach:
usbipd attach --wsl --busid <BUSID> - Verify in container:
lsusb
Build issues:
cmake --build build --target clean-all
cmake --preset avr && cmake --build buildContainer issues:
Ctrl+Shift+P β Dev Containers: Rebuild Container