https://github.com/rubberduck203/avr-template
Template for avr-gcc projects utilizing CppUTest for unit tests
https://github.com/rubberduck203/avr-template
avr avr-gcc avr-template cpputest makefile template
Last synced: 4 months ago
JSON representation
Template for avr-gcc projects utilizing CppUTest for unit tests
- Host: GitHub
- URL: https://github.com/rubberduck203/avr-template
- Owner: rubberduck203
- License: mit
- Created: 2017-10-10T00:07:36.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2019-04-22T20:38:43.000Z (about 7 years ago)
- Last Synced: 2025-04-09T04:34:13.970Z (over 1 year ago)
- Topics: avr, avr-gcc, avr-template, cpputest, makefile, template
- Language: Makefile
- Size: 19.5 KB
- Stars: 14
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# avr-template
This project is a bare bones directory structure and makefiles for working with [avr-gcc][avr-gcc] and [CppUTest][cpputest].
It's designed to work with the [rubberduck/avr docker image][avr-docker], but should work on any *nix (or Mac) system, given you've installed avr-gcc, CppUTest, and pkg-config.
I've not tested on Windows, but I suspect a little bit of work would need to be done in order to make everything work correctly for that OS. (Pull Requests welcome!)
As of now, the makefiles only support C for the AVR code, but I'd like to add full support for C++ in the future.
[avr-gcc]: http://www.atmel.com/webdoc/avrlibcreferencemanual/overview_1overview_gcc.html
[cpputest]: http://cpputest.github.io/
[avr-docker]: https://hub.docker.com/r/rubberduck/avr/
## Getting Started
To use, clone this project and copy into a new repository.
```bash
mkdir newProject
git clone https://github.com/rubberduck203/avr-template.git
cd $_
```
In `src/makefile` modify the following lines as appropriate for your device.
```bash
# name of the resulting program/hex file
PROGNAME = demo
# Valid avr-gcc device from this list:
# http://www.atmel.com/webdoc/avrlibcreferencemanual/index_1supp_devices.html
DEVICE = atxmega128a1
# Processor speed (check your datasheet)
F_CPU = 32000000UL
```
The file that holds `main` in the `src` directory must be excluded from the test build,
or you'll get an error about having multiple mains defined.
If you change the name of `Demo.c` you must update this line in `test/makefile` accordingly.
```bash
# Include all the source from src, except the entry point
srcFiles := $(filter-out $(SRC)/Demo.c, $(wildcard $(SRC)/*.c*))
```
Running `make` will build and run the tests, then, if successful, compile, link, and generate the *.hex file for your avr device.
`obj` and `bin` directories are created automatically.
## Supported Make targets
- all: Run tests, build hex file, display size
- avr: Build hex file, display size
- size: Display the AVR Memory Usage
- check: Run tests
- clean: Delete all files in all `bin` and `obj` directories
- install: Use AVRDUDE to upload your program to the device
## Mocks
Mocks are stored in the `test/mocks` directory and made available as system includes in the test builds.
This allows you to reference `` and `` in your code under test without referencing the real AVR include files, which is problematic as the avr-asm has some instructions that are unavailable to the regular gcc compiler.
The `PORT_t` definition in `` should be updated according to your particular target device.
The real headers for these are available in the avr-gcc installation directory under `avr/include/avr`.
More mocks may be added in this directory as needed. The test makefile will automatically put them on the path as system (angle bracket) includes.
## Docker-Compose
There's a docker-compose file in the root of this directory that points to an [AVR toolchain docker image](https://hub.docker.com/r/rubberduck/avr).
To use it, run this command.
```bash
docker-compose run --rm buildtools
```
## License
The template and makefiles are licensed under the [MIT License](LICENSE) so you're free to include the template in your own projects. The MIT License is used in order to limit the licensing restrictions that other licenses would impose on your project. I want you to be free to use this in your own work without worrying about the implications of viral licenses. Just give credit where credit is due and pay it forward.