Conventions

DO NOT SKIP THIS ! 

You don’t want to come back here after a while, when you are in something really interesting ! So read this and keep the following points in mind.

NOTE : This is a note. Little things to remember or to notify, will be here.

REMINDER : Like it says, it’s a reminder to remind the reader of something.

CAUTION : Reader should be careful about this.

Create a project – this line refers to creating a new project. Right after it there will be another line like “Name it as Project1“. This means that reader should do the following steps –

  1. Create a folder and name it as Project1.
  2. Inside this folder create 3 more folders – firmwareschematic  and docs.
  3. Go to my github repository here and download AVR-Makefile-Suite-v3.1.zip (if there is a new version use it instead). Unzip it. You will get a folder with the same name. Inside there are 6 files(README, Makefile, Makefile_Win32, Makefile_Linux, Config and Common) and 1 folder. Copy and paste those 6 files in firmware folder.
  4. Create 2 more folders under firmware named src and include.

After this, your directory structure will look something like this –

Screenshot from 2016-03-01 01-26-05

Here the blue colored names are for folders and others are files.

Explanation – as I will be using a Linux, there is no fancy and fat IDE like AVR Studio for Linux right now. But thanks to the distributions and the developers, there are many ways to sort this out. Basically you don’t need an IDE to do development. I am going to use a C Compiler, so all I need is the Compiler suite along with C libraries for AVR controllers, a text editor, a burner software and to make life easier a Makefile suite that will automate the building procedure. So this folder structure will help you to maintain the project in an efficient way. Let’s see what they are for –

  • Project1 – this is the top level project folder. whatever you do, do it here.
    • docs – keep your documentations, necessary documents related to this project here.
    • schematic – keep your circuit schematics here with proper names.
    • firmware – under this folder you will develop the project’s source code.
      • src – all your source files with extensions like .c , .cpp , .cxx , .S will be here. This folder may contain more folders.
      • include – all your include files with extensions like .h, .hpp. hh will be saved here. This folder may contain more folders.
      • the six files – these are the Makefile Suite I was talking about. this will automate the building procedure.

Coding conventions – I will be following a particular coding convention like the following. If you prefer something else it’s your choice. Mine may not be so nice to your eyes. Feel free to find your style. But don’t mess up !

  • Local variables will be named like this – int thisIsALocalVar 
  • Global variables will be named like this – int ThisIsAGlobalVar
  • Functions will be named like this – void do_something(int someVar)
  • Structures, unions, enumerations will be named like Global variables.
  • Macros will be all capital like this – #define SOMETHING 100
  • Single line comments will be used only to explain one statement.
  • Multi-line comments will be used to explain some functions, structures, unions, enumerations.
  • Multi-line comments may be used to explain the procedure of a loop or a segment of codes.

I may not explain the whole code here, but there will e pictures and diagrams explaining almost everything to do. If I miss anything ask me here in the comments.

TASK : this is something for you. You can skip it. But it will be like a practice for you.

TASK : Why don’t you create a template project folder right now ?

For the following stuffs you need to Open a Terminal inside the firmware folder and run the commands as specified –

Build  – to compile and build run this –

make

Program/Burn – to program/burn/download code to the controller run this –

make program

Burn/Program Low Fuse – to program/burn the low fuse byte(I’ll explain later what’s fuse byte) run this –

make lfuse

Burn/Program High Fuse – same like low fuse –

make hfuse

Burn/Program Extended Fuse – same like low fuse –

make efuse

I will be using USBasp burner . This is an open source burner. It’s also very low cost. But to make this you will need another burner first. There are several serial port burners out there which are easy to build and very low cost too. Go to this site if you want to build it yourself.

For software needs I will be using avr-gcc , avr-binutils, avrdude , avr-libc packages. If you are using other Linux search for the similar software packages. For Archlinux I installed one more package called sudo for the Makefile-suite , but you probably won’t need it. All Debian based distros come with it preinstalled. If not, install it too.

At the begging of any tutorial a list of components will be provided, so make sure you have them on your table. After it’s not just reading and simulating by some simulator software, you need to see what your code can do, right ?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s