Requirements and Environment setup
Hardware requirements
- I have used ATMEGA328P micro-controller here. (Arduino Uno hardware board)
Software requirements
avr-gcc
- You can go to https://www.microchip.com/en-us/tools-resources/develop/microchip-studio/gcc-compilers and download (unzip) the 8-bit AVR toolchain.
- Make sure to add the
bin
folder in the unzipped toolchain folder in the path. This can be achieved in Ubuntu 22 Linux as shown:- Copy the path of the bin folder.
- Open terminal and make sure you’re in the root directory (which is
~
).
- Now type
nano .bashrc
to open up the global bash path variable settings file.
- Add in the path entry for avr toolchain in the end of file.
export PATH=$PATH:<path to your toolchain> # In my case it was, # export PATH=$PATH:~/avr8-gnu-toolchain-linux_x86_64/bin
- Save the file and exit. Now run
source .bashrc
to reload the path settings.
- Type in
avr-gcc --version
in the terminal and now you should see the version details.
avr-objcopy
would be present in the toolchain, so we now don’t need to worry about its installation.
avrdude
- This is an open-source programmer for AVR based micro-controllers.
- Can be installed from package manager using the line
sudo apt-get install avrdude
- Typing in
avrdude --version
should give you the version results implying that the install was right!
make
- make is used as the build automation tool for generation of object, elf and hex files.
avrdude
is also mentioned in the Makefile to flash the chips (needs fix, currently works only for arduino based programmer and/dev/ttyACM0
port of USB.
Now, you can get started with the Bare-metal programming for AVR Microcontrollers!
Project directory tree
.
├── build
│ ├── main.elf
│ ├── main.hex
│ ├── main.o
│ └── obj
│ ├── delay.o
│ ├── lcd16x2.o
│ └── memorymap.o
├── examples
│ └── blinky.c
├── inc
│ ├── atmega328p
│ │ ├── delay.c
│ │ ├── delay.h
│ │ ├── memorymap.c
│ │ └── memorymap.h
│ └── lib
│ └── lcd16x2
│ ├── lcd16x2.c
│ └── lcd16x2.h
├── Makefile
└── src
└── main.c
- The user code goes in
main.c
.
- The micro-controller’s memory map and other relevant files, user defined functions for libraries (under
/inc/lib
) and header files for the microcontroller such as memory map file go under./inc/<mcu_name>
folder.
- The intermediary object files are compiled to
/build/obj/
and the finalmain.hex
file is present in the/build
directory.
- Running make commands, will create the necessary
elf
,hex
and.o
files.
- The
examples
directory would contain all the example codes that can be pasted in themain.c
file to observe the outputs.