Turn-key PCB assembly services in prototype quantities or low-volume to mid-volume production runs

Using SVN for embedded projects. Part 1.

Writing software is complex task. In every microcontroller program you usually try to reuse previously written libraries, downloaded code and other data that is being updated. What if you are developing something in team? How to keep track of everything? Storing project files in directories eventually get messy – eventually you loose track of whats done. For instance some time you have written LCD library and used in several microcontroller projects. But eventually you found a bug, or optimized code. Normally you would have to copy new library files in every project to keep updated. This is hard when you already have dozens of projects. There is one way to stay organized by using version control software. In this case we will talk about SVN.

Subversion (SVN) is an open source system that allows controlling files and folders, keep track of changes made during time. Simply speaking SVN is a virtual file system that keeps track of every change in files, directories. It’s a smart way of storing project files either you are working alone or in team. Using this system smart you will always have things organized and never loose version of your files gain.

TortoiseSVN your repository tool

TortoiseSVN is popular tool to work with SVN system. You can download it from project site here. We won’t be discussing on how to install it on your machine as it is well described in documentation you can download here. So Assume you already downloaded installed one that fits to your operating system. For instance if you have 64-bit Windows – download TortoiseSVN- or later release if its already there. After installation click right mouse button on any folder and you should see new menu items:

SVN context menu

This means that installation went smooth and you can continue further. Before we begin there are couple terms to be remembered. Repository and working copy (WC).

The repository is an SVN itself where file structure is stored. It also keeps all changes since project creation. Every change is assigned with the revision number to keep track. Each revision can be accessed and used when needed. Changes cannot be made inside repository for this a local working copy is used. All changes are made here, and then they are fixed in the repository with the new revision number.

SVN Repo-browser

Repo-browser gives us access to projects stored in repository. Using this tool we can create, import new projects, copy project to working copy and do other things. Let’s go by example to make it simpler. Create directory somewhere in your hard drive. For instance D:\SVN. Click right mouse button on it and select TortoiseSVN->Create repository here. What happens here is that folder becomes a place for repository where all necessary structure is created to hold your projects. If you open Repo-broser you will see that empty repository named file:///D:/SVN is created.

path to SVN repository

Now you can create or add your projects here. First of all create project folder where your project will be. Name it as you would name your next project. For instance AVRLCD:

Create folder in SVN

And then in this folder create three additional folders named branch, tags and trunk. You should see this in Repo-browser:

SVN repository browser

So why these three weird folders? Each of them has a special purpose. Main project files are stored in the trunk folder, Which is a place for current project. Branch folder is used when your project evolves in to several related projects that have same history. Tag folder holds releases of project. So when we create new project or import existing one we always store it in trunk folder.

Now lets import existing project in to repository. To do so locate project folder in your hard drive, click right click on it and select TortoiseSNV->Import. A dialog window will pop up asking where to import project:

Import files to SVN

Obviously, we tell to import the project into the trunk folder of our AVR LCD project by writing URL: file:///D:/SVN/AVRLCD/trunk. Be sure on each action to write short messages of your actions. This helps to keep track of whats done. After confirmation an import window opens where you can see what files were imported:

SVN importing files

It automatically adds revision number to project. Don’t afraid if import fails. You can delete project in Repo-browser and start over. Note that import can be performed by simply dragging files in to directory. Once you have successfully imported or created project later actions with project files must be done using Working Copy of project.

Using Working Copy

Let us say our project already sits in the repository and we want to do some coding, adding new files and so on. We need to import project files to working directory. Simply create new folder in your desired place. For our project we can name it WC. Then go to Repository browser, click on your projects trunk folder right mouse button and select Checkout

Working copy in SVN

select Checkout directory your WC directory and click OK. Files from trunk folder is then copied to the working directory.

WC directory

Now you can go to WC directory and do your necessary changes, writing code, creating new files or deleting some.

Simple actions required in working copy

There are some rules you need to follow when working with the working copy. Since working copy now holds some hidden information (in .svn folder) that keeps track of files, all file actions like creation, or deletion must be done through TortoiseSVN menu. For instance, if we need to delete some file, we must select it and delete with menu item from mouse right click: TortoiseSVN->Delete


Same situation with adding new files to working copy. Say you are creating a new C file in your project named test.c. Create it and you will see the difference in list:

new file in SVN

It does not have check mark what means SVN does not know it is here. To make it happen to click on file right mouse button and select menu TortoiseSVN->Add. A small plus sign appears on file icon meaning that it will be added to the repository on next commit.

If you edit existing files you don’t have to do additional actions. SVN will track changes automatically. Once you save edited file – a note mark will appear near file icon:

SVN track changes

Let us say you are done for today and want to store current changes to the repository. Just click on WC directory right mouse button and select SVN Commit. In the next window, you will see a list of files that will be changed in the repository. Some of them will be modified; some of them will be deleted or added. In the message window be sure to add a brief note on what’s changed.

SVN Commit

Once you click OK changes will be made to repository:

SVN repository

As you can see revision number of project increased. As we mentioned SVN repository keeps all files from beginning of project creation. So you can always reverse back to earlier revision if needed. This can be done by changing revision number in repository browser. This is it for now. Next time we will see more cool features of SVN.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.