I'm working on a group project that is based around designing an automotive CAN bus system. Essentially there are multiple different nodes on the bus, acting as sensors, displays, controllers or transmitters. My question is how to share/include common code?

Each node is based around an Atmel AVR µC, usually an Atmega or Attiny. All the nodes are making use of Microchip MCP2515 CAN Controllers and MCP2561 CAN Transceivers. Our team consists of multiple members each working on their own nodes. We are using Github & SourceTree for source control.

Some code is common to each node, mainly the SPI/CAN functions for TX and RX. We have this working at proof of concept level at the moment. I'm used to working on individual projects however I'm lost as how to share code among projects effectively.

Really what I would like to do is have each node's code in its own directory and then have the common 'library' code in a directory that is referenced in each nodes source code. This way changes to the 'library' code only need to happen in one place and not in multiple copies.

Something like this:
Code>> Display Node>> Display_main.c Sensor Node>> Sensor_main.c TX Node>> TX_main.c Shared lib>> SPI.c SPI.h MCP2515_func.c MCP2515_func.h

I am using Eclipse + AVR plugin for my dev, other members are using Atmel Studio.

I'm not too sure if I should: a) Lump all the shared code in a folder and #include "../Shared lib/xxxx.h"

b) Lump all the shared code in a folder and set Eclipse compiler to include this folder? then #include "xxxx.h" will work ? (what about ATStudio friends? )

c) Create an Eclipse project without a main.c, that contains all the code and include this project with my other projects?

d) Compile the code into a 'static library' ?

I've done a fair bit of research and haven't found any good idea of direction. I guess it comes down to how to manage multiple code projects (nodes) by multiple members on multiple platforms ? I seem to be pretty good at basic stuff but this is the next level in code organization for me.


To add to this question, how could I create a Github project with all my own custom librarys and macros that I can keep updated and then just include in any project I work on?


2 Answers 2


Your option b is probably the most reasonable. Every environment should be able to set library paths. Another option is to decouple the build from the IDE with makefiles and set the library path there. I know AVR studio supports makefile-based projects. I presume eclipse does as well. This could be a good option to look at if you have different people on the team using different IDEs.

As for a github repo for libraries, I recommend using git subtree. This will include the entire history of the library inside the project repos and allows commits to be pulled into the project repos from the library repo or sectioned off in the project repo and pushed back to the library repo. I use this setup for a bunch of my projects; take a look at my github and look for repos with a lib folder in the root, such as verilog-ethernet.

  • \$\begingroup\$ Thanks Alex, Do you perhaps know of any online resources that show how to create this sort of setup? Perhaps a good makefile guide tailored to AVRs and embedded stuff? I'm a Linux guy so it makes sense, but I'm thinking more of my windows based team mates. \$\endgroup\$
    – Rambo
    Commented Mar 29, 2015 at 18:33
  • 1
    \$\begingroup\$ I have a project template repo here github.com/alexforencich/templates that has makefile projects for avr and xmega. It is possible to install gnu make on Windows as well. \$\endgroup\$ Commented Mar 29, 2015 at 18:36

Use a version control tool like subversion, where everyone involved can check out the latest copy and commit changes. Working from a shared directory is asking for trouble, and you lose any audit trail and the ability to roll back. Of course there are issues with any version control system, but they're better than the alternatives.

  • \$\begingroup\$ Hi Scott, I did mention briefly that we are using Git, however I'm more interested in how to keep common code between projects in a central directory and link this in? Would this code be compiled separately or in place? \$\endgroup\$
    – Rambo
    Commented Mar 30, 2015 at 21:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.