Developing for the Atmel AVR Microcontroller on Linux
A Makefile target that is interesting, whether for sanity checking, optimization, low-level debugging or simply to get to know the AVR internals, is disasm. Running: $ make disasm prints some information concerning the program, such as its text/data/bss size, to the console and creates helloavr.s. This file contains a disassembled version of the executable, intermixed with the original C source code. A peek inside reveals AVR Libc and avr-gcc's work behind the scenes, initializing the interrupt vector table and data, followed by the Assembly and C versions of the program.
Now we use GDB as a source-level debugger with simulavr running as a remote target. To do so, launch simulavr in the background and create a suitable gdbinit file:
$ simulavr --gdbserver --device at90s8515 & $ make gdbinit
Running make in this manner creates gdbinit-helloavr, a file containing instructions for setting up GDB correctly, such that it connects to a simulavr, loads the compiled program, inserts a breakpoint and begins execution. Launch avr-gdb using the command:
$ avr-gdb -x gdbinit-helloavr
and you are presented with the GDB prompt; program execution is halted before the first instruction in main(). Set a breakpoint on line 71, using b 71, and enter C (continue) a few times. Every time you step over the instruction on line 71:
71 PORTB = ~currentValue;
~currentValue is output through PORTB. You should see a message to that effect, for example, writing 0xff to 0x0038. When you are done, issue a quit and kill the simulavr process, which is running in the background.
If you've built or purchased the programmer hardware, you can install and test the software on a real AT90S8515 chip. Configure the avrdude section in the Makefile by setting the AVRDUDE_PROGRAMMERID and AVRDUDE_PORT variables, as explained in the comments above. Use:
for an STK500 programmer connected to the first serial port. Ensure that the programmer is connected to the appropriate port, insert the microcontroller in the programmer, apply power and type make writeflash. This generates the hex file used by AVRDUDE and writes its contents to the chip's Flash program memory.
For those using the STK500 development kit, simply connect PORTB to the eight onboard LEDs using the ten-wire cable (as illustrated in Figure 3), and watch das blinkenlights. You can set up your own test hardware by constructing the schematic shown in Figure 4, which connects LEDs with suitable limiting resistors such that each pin of PORTB can activate one by going low and sinking current.
You've seen the flashing LEDs? Congratulate yourself; you are ready to begin creating your own AVR designs and software. See Resources for loads of AVR-related information and projects. There's almost no limit to what you can do.
Atmel shares a number of interesting project ideas through its AVR application notes, where it details implementation of stepper motor controllers, IR remote control receivers and transmitters and even an embedded Web server. One amazing project, ContikiOS (see Resources), distributes an open-source Internet-enabled, multitasking, graphical operating system that has been ported to the AVR and uses a version of the VNC server instead of a regular screen.
Enjoy experimenting with these versatile microcontrollers, be sure to share your discoveries and good luck building that robot horde!
Resources for this article: www.linuxjournal.com/article/7920.
Patrick Deegan was converted to IT and free software after being in contact with Linux while a student in the joint Math and Physics program at McGill U. Torn between working in physics, electronics and software development, Pat was bound to cofound Psychogenic, where he now gets to spend many days (and nights) playing with all three.
|Chemistry on the Desktop||Mar 23, 2017|
|Five HPC Cost Considerations to Maximize ROI||Mar 23, 2017|
|Two Ways GDPR Will Change Your Data Storage Solution||Mar 22, 2017|
|Android Candy: That App Is for the Birds!||Mar 22, 2017|
|Hodge Podge||Mar 21, 2017|
|William Rothwell and Nick Garner's Certified Ethical Hacker Complete Video Course (Pearson IT Certification)||Mar 20, 2017|
- Two Ways GDPR Will Change Your Data Storage Solution
- Chemistry on the Desktop
- Five HPC Cost Considerations to Maximize ROI
- Hodge Podge
- Preseeding Full Disk Encryption
- Returning Values from Bash Functions
- Two Factors Are Better Than One
- Android Candy: That App Is for the Birds!
- GRUB Boot from ISO