21/3/17 |
Commended this week's tasks a little late
due to the delayed finishing of wee 6's works. First some reading: Spent time reading the beautiful tutorial at http://www.ladyada.net/learn/avr/index.html about avr programming. What is that? It is programming or embedded programming of a microcontroller based circuit ckt44 we have already constructed and tested. The programming is not done directly from the PC. But, from a programmer circuit fab-isp which we have made much earlier. Why the term AVR? Don't know. No official expansion either. Anyway, it refers to the family of Atmel micrcontrollers and its programming especially as embedded devices. So in our case we have an ATtiny45 based fab-isp programmer programming the Attiny44A based ckt44 circuit. Here is the connection. ![]() |
Learned a lot more about programming the
target board(ckt44) using the programmer (fab-isp) through
the above mentioned tutorial. Also spent time reading the
explanation about the command avrdude which is the software that writes
programs from our machine onto the target chip's flash
memory via the programmer isp. It also performs
some associated target programming tasks like
setting the fuses. Gone through the man pages of avrdude also. ![]() |
For example to know which programmer
options are supported the -c option with a dummy argument
is used. Towards the end we have filtered out that usbtiny is our programmer. |
Similarly which microcontrollers are
programmable and how they could be specified are
determined by the -p option with dummy argument. Determined that 't44' is our target. |
|
Then read further on the fuse settings. It
is to program the IC on how it should behave, like its clk
source, clk frequency settings, and so on. avrdude is
again used. With the -m option an immediate value can be
written. The calculation of the fuse values are explained
in the tutorial and calculation could be performed here -
http://www.engbedded.com/fusecalc/ |
Also, noted that both ATtiny45 and
ATtiny44A have 4KB of flash memory, 256B of EEPROM, 256B
of SRAM. Refer: http://www.microchip.com/wwwproducts/en/ATTINY45.
The programs in hexcode we send using avrdude goes to the
flash memory and stored there. The microcontroller can
only read from the flash memory, it cannot write there.
The program is loaded into the SRAM for execution.
The EEPROM could be read and written by the IC, byte by
byte. But, writing is to be as per specific procedures to
prevent unintentional writing. EEPROM retains its data on
power-off. |
|
22/3/17 |
Plans to do the programming in assembly
language. Reading the instructio set of ATtiny44A, sheet,
and avr-instruction-set-mnual.![]() ![]() |
Once I have spent time reading these I need
to do some programming experimentation. First I want
to see that the circuits are not behaving abnormal
when fab-ist and t44 boards are connected in series and
both ends connected to two USB ports. Checked both the
boards and found okay. Placed my fingers on th ICs and no
heating up!!![]() |
23/3/17 |
First checked the connection of t44 via
fab-isp again okay. Once again send the hello-world program to t44. make program-usbtiny And using arduino interface verified that it is running. |
sbi 16,3 out DDRA, r16 out PORTA, r16 this code written as led1.asm and issued avr-gcc led1.asm result: file format not recognized renamed it as led1.avr and same result. man avr-gcc or man gcc shown that the assembly code extension is .s [fab@ask embed]$ avr-gcc led1.s /tmp/ccOtmOvi.o:(.text+0x2): undefined reference to `DDRA' /tmp/ccOtmOvi.o:(.text+0x4): undefined reference to `PORTA' collect2: error: ld returned 1 exit status With -c option (telling compile but not link) error is gone [fab@ask embed]$ ll total 3832 -rw-r--r-- 1 fab fab 2527656 Mar 22 12:25 Atmel-0856-AVR-Instruction-Set-Manual.pdf -rw-r--r-- 1 fab fab 5656 Mar 21 21:59 embed.pgm.connect.jpg -rw-r--r-- 1 fab fab 125823 Mar 22 23:35 isp.t44.usb.jpg -rw-r--r-- 1 fab fab 38 Mar 23 16:06 led1.s -rw-r--r-- 1 fab fab 188017 Mar 22 11:13 ssho.ebd.is.t44.png -rw-r--r-- 1 fab fab 206991 Mar 22 12:45 ssho.emb.avr.ins.png -rw-r--r-- 1 fab fab 840617 Mar 21 19:18 ssho.manavrdude.png -rw-r--r-- 1 fab fab 4019 Mar 21 20:06 trmnl.avd.part.txt -rw-r--r-- 1 fab fab 6354 Mar 21 19:51 trmnl.avd.pgmr.txt [fab@ask embed]$ avr-gcc led1.s -c [fab@ask embed]$ ll total 3836 -rw-r--r-- 1 fab fab 2527656 Mar 22 12:25 Atmel-0856-AVR-Instruction-Set-Manual.pdf -rw-r--r-- 1 fab fab 5656 Mar 21 21:59 embed.pgm.connect.jpg -rw-r--r-- 1 fab fab 125823 Mar 22 23:35 isp.t44.usb.jpg -rw-r--r-- 1 fab fab 564 Mar 23 16:49 led1.o -rw-r--r-- 1 fab fab 38 Mar 23 16:06 led1.s -rw-r--r-- 1 fab fab 188017 Mar 22 11:13 ssho.ebd.is.t44.png -rw-r--r-- 1 fab fab 206991 Mar 22 12:45 ssho.emb.avr.ins.png -rw-r--r-- 1 fab fab 840617 Mar 21 19:18 ssho.manavrdude.png -rw-r--r-- 1 fab fab 4019 Mar 21 20:06 trmnl.avd.part.txt -rw-r--r-- 1 fab fab 6354 Mar 21 19:51 trmnl.avd.pgmr.txt [fab@ask embed]$ [fab@ask embed]$ avr-gcc led1.s -mmcu=attiny44 -c aslo produced same result the assembler seems to produce same result [fab@ask embed]$ avr-as led1.s |
Three small .s pgm written intende to do
the same function of lighting the LED. First one is producing error on compiling Now compiling and loading the second one led1.2.s But the LED is not lighted. Checking next program Again writing okay. No LED glowing. Requested my colleague Tanvir to check my board with his code. Board is okay. |
Here is the general pattern of commands I
tried during this stage of the debugging process. avr-as led1.4.s -o led1.4.o avr-objcopy -O ihex led1.4.o led1.4.hex avrdude -p t44 -P usb -c usbtiny -U flash:w:led1.4.hex -c flag no linking -s removes symbol table information from executable error of led1.1.s is gone as we enclosed the erroneous code portion quoted avr-objdump -S led1.6.o //to dump the code of the objectfile codes genrated are not seemed correct Happened come across via google this site and the tips by clawson athttp://www.avrfreaks.net/forum/cant-compile-avr-assembly-code-gnulinuxhelped to include some settings and include file information at the beginning of the assembler file. Also changing file name form .s to .S also helped. some includes are entered. avr-as is not generating the right code avr-gcc -mmcu=attiny44a led1.4.S -o led1.4.elf -nostartfiles avr-objdump -S led1.4.elf avr-objcopy -O ihex led1.4.elf led1.4.hex tried avra also after installin it, but seems not giving the desired result. |
|
Finally the LED is glowing!! code: #define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: ldi r16,0b00001000 out DDRA, r16 out PORTA, r16 loop: rjmp loop (one observed possible mistake might be that the r16 bits might not have set the way I intended it.) steps 1. avr-gcc -mmcu=attiny44a led1.8.S -o led1.8.elf -nostartfiles 2. avr-objcopy -O ihex led1.8.elf led1.8.hex 3. avrdude -p t44 -P usb -c usbtiny -U flash:w:led1.8.hex Additional steps: [fab@ask embed]$ cat led1.8.hex :0A00000000C008E00ABB0BBBFFCFF5 :00000001FF [fab@ask embed]$ [fab@ask embed]$ avr-objdump -S led1.8.elf led1.8.elf: file format elf32-avr Disassembly of section .text: 00000000 <__ctors_end>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 08 e0 ldi r16, 0x08 ; 8 4: 0a bb out 0x1a, r16 ; 26 6: 0b bb out 0x1b, r16 ; 27 00000008 <loop>: 8: ff cf rjmp .-2 ; 0x8 <loop> [fab@ask embed]$ |
||
24/3/17 |
Let us now consolidate various codes,
commands, and results of yesterday and add some more
results, as shown below. |
File |
Code |
Compiling commands |
avr-objdump result |
Remarks |
led1.1.s |
#define __SFR_OFFSET 0 #include <avr/io.h> ldi r16,"(1<<PA3)" out DDRA, r16 out PORTA, r16 |
avr-gcc -c led1.1.s or avr-as led1.1.s |
0: 00
e0
ldi r16, 0x00 ; 0 2: 00 b9 out 0x00, r16 ; 0 4: 00 b9 out 0x00, r16 ; 0 |
Not the desired |
led1.2.s |
sbi 16,3 out DDRA, r16 out PORTA, r16 |
avr-gcc -c led1.2.s or avr-as led1.2.s |
0: 83
9a
sbi 0x10, 3 ; 16 2: 00 b9 out 0x00, r16 ; 0 4: 00 b9 out 0x00, r16 ; 0 |
Not the desired |
led1.3.s |
sbi DDRA,3 sbi PORTA,3 |
avr-gcc -c led1.3.s or avr-as led1.3.s |
0: 03
9a
sbi 0x00, 3 ; 0 2: 03 9a sbi 0x00, 3 ; 0 |
Not the desired |
led1.5.s |
.org 0 rjmp main main: sbi DDRA,3 sbi PORTA,3 loop: rjmp loop |
avr-gcc -c led1.5.s or avr-as led1.5.s |
00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 03 9a sbi 0x00, 3 ; 0 4: 03 9a sbi 0x00, 3 ; 0 00000006 <loop>: 6: 00 c0 rjmp .+0 ; 0x8 <loop+0x2> |
Not the desired |
led1.6.s |
#define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main ldi r16,"(1<<PA3)" out DDRA, r16 out PORTA, r16 loop: rjmp loop |
avr-gcc -c led1.6.s or avr-as led1.6.s |
00000000 <loop-0x8>: 0: 00 c0 rjmp .+0 ; 0x2 <loop-0x6> 2: 00 e0 ldi r16, 0x00 ; 0 4: 00 b9 out 0x00, r16 ; 0 6: 00 b9 out 0x00, r16 ; 0 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> |
Not the desired |
led1.4.S |
#include <avr/io.h> .org 0 rjmp main main: sbi 16,3 out DDRA, r16 out PORTA, r16 loop: rjmp loop |
[fab@ask embed]$ avr-gcc -c led1.4.S In file included from led1.4.S:1:0: /usr/avr/include/avr/io.h:581:6: warning: #warning "device type not defined" [-Wcpp] # warning "device type not defined" ^~~~~~~ or avr-as led1.4.S (No warning) |
00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 83 9a sbi 0x10, 3 ; 16 4: 00 b9 out 0x00, r16 ; 0 6: 00 b9 out 0x00, r16 ; 0 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> [f |
Not the desired |
led1.7.S |
#define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: SBI 16,3 out DDRA, R16 out PORTA, R16 loop: rjmp loop |
[fab@ask embed]$ avr-gcc -c led1.7.S In file included from led1.7.S:2:0: /usr/avr/include/avr/io.h:581:6: warning: #warning "device type not defined" [-Wcpp] # warning "device type not defined" ^~~~~~~ or avr-as led1.7.S (No warning) |
00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 83 9a sbi 0x10, 3 ; 16 4: 00 b9 out 0x00, r16 ; 0 6: 00 b9 out 0x00, r16 ; 0 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> |
Not the desired |
led1.8.S | #define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: ldi r16,0b00001000 out DDRA, r16 out PORTA, r16 loop: rjmp loop |
[fab@ask embed]$ avr-gcc -c led1.8.S In file included from led1.8.S:2:0: /usr/avr/include/avr/io.h:581:6: warning: #warning "device type not defined" [-Wcpp] # warning "device type not defined" ^~~~~~~ or avr-as led1.8.S (No warning) |
00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 08 e0 ldi r16, 0x08 ; 8 4: 00 b9 out 0x00, r16 ; 0 6: 00 b9 out 0x00, r16 ; 0 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> |
Not the desired |
led1.8.S | #define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: ldi r16,0b00001000 out DDRA, r16 out PORTA, r16 loop: rjmp loop |
avr-gcc -mmcu=attiny44a led1.8.S -o
led1.8.elf -nostartfiles avr-objcopy -O ihex led1.8.elf led1.8.hex |
00000000 <__ctors_end>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 08 e0 ldi r16, 0x08 ; 8 4: 0a bb out 0x1a, r16 ; 26 6: 0b bb out 0x1b, r16 ; 27 00000008 <loop>: 8: ff cf rjmp .-2 ; 0x8 <loop> |
Right. LED lights See the capital .S extension also |
led1.7.S | #define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: SBI 16,3 out DDRA, R16 out PORTA, R16 loop: rjmp loop |
avr-gcc -mmcu=attiny44a
led1.7.S -o led1.7.elf -nostartfiles |
00000000 <__ctors_end>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 83 9a sbi 0x10, 3 ; 16 4: 0a bb out 0x1a, r16 ; 26 6: 0b bb out 0x1b, r16 ; 27 00000008 <loop>: 8: ff cf rjmp .-2 ; 0x8 <loop> |
LED not lighted |
led1.8.S | #define __SFR_OFFSET 0 #include <avr/io.h> .org 0 rjmp main main: ldi r16,0b00001000 out DDRA, r16 out PORTA, r16 loop: rjmp loop |
avr-gcc -c -mmcu=attiny44a
led1.8.S avr-objcopy -O ihex led1.8.o led1.8.hex |
00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 08 e0 ldi r16, 0x08 ; 8 4: 0a bb out 0x1a, r16 ; 26 6: 0b bb out 0x1b, r16 ; 27 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> |
Right. LED glows. |
led1.9.S | #include <avr/io.h> .org 0 rjmp main main: ldi r16,0b00001000 out DDRA, r16 out PORTA, r16 loop: rjmp loop |
avr-gcc -c -mmcu=attiny44a led1.9.S | 00000000 <main-0x2>: 0: 00 c0 rjmp .+0 ; 0x2 <main> 00000002 <main>: 2: 08 e0 ldi r16, 0x08 ; 8 4: 0a bf out 0x3a, r16 ; 58 6: 0b bf out 0x3b, r16 ; 59 00000008 <loop>: 8: 00 c0 rjmp .+0 ; 0xa <loop+0x2> |
Wrong code First line is needed. |
led1.1.S |
#define __SFR_OFFSET 0 #include <avr/io.h> ldi r16,"(1<<PA3)" out DDRA, r16 out PORTA, r16 |
avr-gcc -c -mmcu=attiny44a led1.1.S |
00000000 <.text>: 0: 00 e0 ldi r16, 0x00 ; 0 2: 0a bb out 0x1a, r16 ; 26 4: 0b bb out 0x1b, r16 ; 27 |
Wrong. Seems ldi r16,"(1<<PA3)" didn't work |
led1.10.S |
#define __SFR_OFFSET 0 #include <avr/io.h> ldi r16,(1<<PA3) out DDRA, r16 out PORTA, r16 |
avr-gcc -c -mmcu=attiny44a led1.10.S | 00000000 <.text>: 0: 08 e0 ldi r16, 0x08 ; 8 2: 0a bb out 0x1a, r16 ; 26 4: 0b bb out 0x1b, r16 ; 27 |
Right. Glows. So removing quote mark helped. |
led1.2.S |
#define __SFR_OFFSET 0 #include <avr/io.h> sbi 16,3 out DDRA, r16 out PORTA, r16 |
avr-gcc -c -mmcu=attiny44a led1.2.S | 00000000 <.text>: 0: 83 9a sbi 0x10, 3 ; 16 2: 0a bb out 0x1a, r16 ; 26 4: 0b bb out 0x1b, r16 ; 27 |
No. What's wrong? |
led1.3.S |
#define __SFR_OFFSET 0 #include <avr/io.h> sbi DDRA,3 sbi PORTA,3 |
avr-gcc -c -mmcu=attiny44a led1.3.S |
00000000 <.text>: 0: d3 9a sbi 0x1a, 3 ; 26 2: db 9a sbi 0x1b, 3 ; 27 |
Right. Glows. |
File |
Code |
avr-objdump result |
Remarks |
led2.1.S |
#define __SFR_OFFSET 0 #include <avr/io.h> cbi DDRA,7 cbi PINA,7 loop: in r16,PINA andi r16,0x80 breq loop sbi DDRA,3 sbi PORTA,3 |
00000000 <loop-0x4>: 0: d7 98 cbi 0x1a, 7 ; 26 2: cf 98 cbi 0x19, 7 ; 25 00000004 <loop>: 4: 09 b3 in r16, 0x19 ; 25 6: 00 78 andi r16, 0x80 ; 128 8: 01 f0 breq .+0 ; 0xa <loop+0x6> a: d3 9a sbi 0x1a, 3 ; 26 c: db 9a sbi 0x1b, 3 ; 27 |
LED stays ON. Looking at the code the reason is the branch to loop back is actually not taking place!! Feels the assembly to hex code conversion could have been done manually. Else, there is a scope for a simple one, as far what I come across. The reason is the intermediate code generated is not resolving the address conversion. So a dummy linking is required. The posting by kroylar at stackoverflow link was of great help to get rid off this. Subsequently the file linker.x as below is created. SECTIONS { . = 0x0; .text : { *(.text) } } |
led2.1.S | #define __SFR_OFFSET 0 #include <avr/io.h> cbi DDRA,7 cbi PINA,7 loop: in r16,PINA andi r16,0x80 breq loop sbi DDRA,3 sbi PORTA,3 |
00000000 <loop-0x4>: 0: d7 98 cbi 0x1a, 7 ; 26 2: cf 98 cbi 0x19, 7 ; 25 00000004 <loop>: 4: 09 b3 in r16, 0x19 ; 25 6: 00 78 andi r16, 0x80 ; 128 8: e9 f3 breq .-6 ; 0x4 <loop> a: d3 9a sbi 0x1a, 3 ; 26 c: db 9a sbi 0x1b, 3 ; 27 |
Now the branching issue
is solved!! Commands issued. avr-gcc -c -mmcu=attiny44a led2.1.S avr-ld -Tlinker.x led2.1.o -o led2.o LED goes off Now button pressed and the LED glows. The expected result. |
File |
Code |
avr-objdump result |
Remarks |
led2.2.S |
#define __SFR_OFFSET 0 #include <avr/io.h> cbi DDRA,7 ; PA7 for button input cbi PINA,7 ; clear the input sbi DDRA,3 ; PA3 to led loop: cbi PORTA,3 ; led off poll: in r16,PINA ; reading input andi r16,0x80 ; checking input breq loop sbi PORTA,3; led on rjmp poll |
00000000 <loop-0x6>: 0: d7 98 cbi 0x1a, 7 ; 26 2: cf 98 cbi 0x19, 7 ; 25 4: d3 9a sbi 0x1a, 3 ; 26 00000006 <loop>: 6: db 98 cbi 0x1b, 3 ; 27 00000008 <poll>: 8: 09 b3 in r16, 0x19 ; 25 a: 00 78 andi r16, 0x80 ; 128 c: e1 f3 breq .-8 ; 0x6 <loop> e: db 9a sbi 0x1b, 3 ; 27 10: fb cf rjmp .-10 ; 0x8 <poll> [fab |
To light the LED as far
as the button is kept pressed. Compilation and loading. avr-gcc -c -mmcu=attiny44a led2.2.S avr-ld -Tlinker.x led2.2.o -o led2.o avr-objcopy -O ihex -S led2.o avrdude -p t44 -P usb -c usbtiny -U flash:w:led2.o Result: OK |
led2.3.S |
#define __SFR_OFFSET 0 #include <avr/io.h> ;Default = button released ->led on; Button pressed -> led off cbi DDRA,7 ; PA7 for button input cbi PINA,7 ; clear the input sbi DDRA,3 ; PA3 to led loop: sbi PORTA,3; led on poll: in r16,PINA ; reading input andi r16,0x80 ; checking input breq loop ; button not pressed cbi PORTA,3; led off rjmp poll |
00000000 <loop-0x6>: 0: d7 98 cbi 0x1a, 7 ; 26 2: cf 98 cbi 0x19, 7 ; 25 4: d3 9a sbi 0x1a, 3 ; 26 00000006 <loop>: 6: db 9a sbi 0x1b, 3 ; 27 00000008 <poll>: 8: 09 b3 in r16, 0x19 ; 25 a: 00 78 andi r16, 0x80 ; 128 c: e1 f3 breq .-8 ; 0x6 <loop> e: db 98 cbi 0x1b, 3 ; 27 10: fb cf rjmp .-10 ; 0x8 <poll> |
Button released ->led
on; Button pressed -> led off Compilation and loading. avr-gcc -c -mmcu=attiny44a led2.3.S avr-ld -Tlinker.x led2.3.o -o led2.o avr-objcopy -O ihex -S led2.o avrdude -p t44 -P usb -c usbtiny -U flash:w:led2.o Result: OK |
led.toggle.S |
#define __SFR_OFFSET 0 #include <avr/io.h> ;Buuton to toggle LED cbi DDRA,7 ; PA7 for button input cbi PINA,7 ; clear the input sbi DDRA,3 ; PA3 to led clr r17; for toggling poll: in r16,PINA ; reading input andi r16,0x80 ; checking input breq poll ; button not pressed com r17 breq ledon cbi PORTA,3; led off rjmp poll ledon: sbi PORTA,3; led on rjmp poll |
00000000 <poll-0x8>: 0: d7 98 cbi 0x1a, 7 ; 26 2: cf 98 cbi 0x19, 7 ; 25 4: d3 9a sbi 0x1a, 3 ; 26 6: 11 27 eor r17, r17 00000008 <poll>: 8: 09 b3 in r16, 0x19 ; 25 a: 00 78 andi r16, 0x80 ; 128 c: e9 f3 breq .-6 ; 0x8 <poll> e: 10 95 com r17 10: 11 f0 breq .+4 ; 0x16 <ledon> 12: db 98 cbi 0x1b, 3 ; 27 14: f9 cf rjmp .-14 ; 0x8 <poll> 00000016 <ledon>: 16: db 9a sbi 0x1b, 3 ; 27 18: f7 cf rjmp .-18 ; 0x8 <poll> |
To toggle the LED. You can't read PORTA. A register is complemented after every button press. Result: Ok |