Forum: Mikrocontroller und Digitale Elektronik Bootloader für den ATmega 168 macht Probleme


von H3ll G. (h3llghost)


Lesenswert?

Hallo Leute,

ich habe ein Problem mit meinem Bootloader, dieser soll für einen ATmega 
168 geschrieben werden.

Das ist die Hauptdatei:
1
/**************************************************
2
  -------->>>>> programm-doku siehe asm_main.s
3
***************************************************/
4
5
#include <avr/io.h>
6
7
8
int main(void)
9
{
10
  asm("rjmp asm_main");
11
  return(0);
12
}

asm_main.s:
1
#include <avr/io.h>
2
#include "def_asm.h"
3
4
5
6
  .section .text
7
  .global asm_main
8
9
asm_main:
10
11
12
  ;Baudrate 2400
13
  ldi     temp1,hi8(BAUDRATE)
14
  out    IO_REG(UBRR0H), temp1
15
  ldi    temp1,lo8(BAUDRATE)  
16
  out    IO_REG(UBRR0L),temp1
17
  ldi    temp1, (1<<RXEN0) | (1<<TXEN0)
18
  out    IO_REG(UCSR0B), temp1
19
20
21
  ldi     temp1,hi8(BAUDRATE)
22
  out    IO_REG(UBRR0H), temp1
23
  ldi    temp1,lo8(BAUDRATE)  
24
  out    IO_REG(UBRR0L),temp1
25
  ldi    temp1, (1<<RXEN0) | (1<<TXEN0)
26
  out    IO_REG(UCSR0B), temp1
27
28
init:
29
30
  ;Baudrate 2400
31
  ldi     temp1,hi8(BAUDRATE)
32
  out    IO_REG(UBRR0H), temp1
33
  ldi    temp1,lo8(BAUDRATE)  
34
  out    IO_REG(UBRR0L),temp1
35
  ldi    temp1, (1<<RXEN0) | (1<<TXEN0)
36
  out    IO_REG(UCSR0B), temp1
37
  
38
  ;Timer 2 für IR-CLK
39
  ldi   temp1, (1<<WGM21) | (1<<COM2A0)   // 36khz ir-clk mit timer2
40
  out    IO_REG(TCCR2A), temp1
41
  ldi     temp1, (1<<CS21) 
42
  out     IO_REG(TCCR2B),temp1
43
  ldi    temp1, 0x22
44
  out    IO_REG(OCR2A), temp1
45
46
  ;Dioden Status-LED IR-LED Front-LED
47
  ldi    temp1, (1<<PB3) | (1<<PB0)
48
  out    DDRB, temp1                  // ir-led-driver und status-led1
49
  ldi    temp1, (1<<PD2)                // status-led2              
50
  out    DDRD, temp1
51
  ldi   temp1, (1<<PD6)
52
  out    DDRD, temp1                  // rote front-led für batterie
53
54
  ; batt test5 init
55
56
  ;ADC Enable und ADC Prescaler auf 128
57
  ldi    temp1, (1<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADPS0)  // adc-clk = sys-clk/128 
58
  out    IO_REG(ADCSRA), temp1
59
  ;Reference Spannung auf Interne 2,56 Volt setzen und ADC5 als Input pin 
60
  ldi   temp1, (1<<REFS0) | (1<<REFS1) | (1<<MUX2) | (1<<MUX0);
61
  out    IO_REG(ADMUX), temp1
62
63
  ret
64
65
  rcall  init            // init com-port-verbindung mit 2400 baud
66
  ldi    ZL, lo8(wait_send);      // startstring senden
67
  ldi    ZH, hi8(wait_send);      
68
  rcall  com_put_string        // startstring senden
69
70
main_loop:
71
;Batt test
72
  sbi    IO_REG(ADCSRA), ADSC   
73
batt_loop:
74
  sbic  IO_REG(ADCSRA), ADSC
75
  rjmp  batt_loop
76
  clc
77
  in    INT_REG_L, ADCL
78
  in    INT_REG_H, ADCH
79
  subi  INT_REG_L, lo8(BATT_MIN)
80
  sbci  INT_REG_H, hi8(BATT_MIN) 
81
  brcc  batt_ok            
82
//  versorgungs-spannung zu gering
83
  sbi    IO_REG(PORTD), PD6
84
  rjmp ende
85
batt_ok:
86
87
;schleifen kopf
88
LDI r19,255
89
verzoeg111:
90
LDI r18,255
91
verzoeg11:
92
LDI r17,255
93
verzoeg1:
94
95
96
// Was da ?
97
rcall  wait_serial          // warte auf ein zeichen vom com-port
98
cpi    CHAR_GET_REG, STARTZEICHEN  // war es das startzeichen?
99
breq  start_rec          // ja, dann startet die datenübertragung
100
101
102
;Schleifen Fuß
103
DEC r17        
104
BRNE verzoeg1    
105
DEC r18
106
BRNE verzoeg11
107
DEC r19
108
BRNE verzoeg111
109
rjmp start_prog
110
  
111
// Speichern
112
start_rec:
113
  sbi    IO_REG(PORTB), PB0      // led on IR-Diode
114
  sbi    IO_REG(PORTD), PD2      // led on Status
115
  clr    temp1            
116
  sts    page_adr, temp1        // flash-page-adress mit 0 initialisieren
117
  sts    page_adr+1, temp1      // programm wird immer ab adresse 0 gespeichert
118
119
  rcall  flash_get          // flashdaten einlesen
120
121
  cbi    IO_REG(PORTB), PB0      // led off
122
  cbi    IO_REG(PORTD), PD2      // led off
123
  sbi    IO_REG(PORTD), PD6      // led on
124
  rcall  wait_serial          // wartezeit eine sekunde
125
  cbi    IO_REG(PORTD), PD6      // led off
126
  ldi    ZL, lo8(flash_ok);      // startstring senden
127
  ldi    ZH, hi8(flash_ok);      
128
  rcall  com_put_string        // startstring senden
129
130
131
start_prog:
132
clr    ZL              // adresse 0 = reset vector
133
clr    ZH
134
ijmp                 // indirect jump zum reset vector
135
136
137
 *** END *** 
138
ende:
139
rjmp ende

def_asm.h:
1
#define BIT(n) (1<<(n))
2
#define IO_REG(n) _SFR_IO_ADDR(n)
3
4
#define sbi(p,b) p|=(1<<(b))
5
#define cbi(p,b) p&=(~(1<<(b)))
6
7
/*************************
8
  registerdefinitionen
9
**************************/
10
#define CHAR_GET_REG r24  // register für char-rückgabe 
11
#define CHAR_PUT_REG r25  // register für char-übergabe
12
#define CHAR_RET_REG r24  // register für char-rückgabe 
13
14
#define INT_REG_H r25    // register für int high byte
15
#define INT_REG_L r24    // register für int low  byte
16
17
#define temp1 r16      // arbeitsregister
18
#define temp2 r17
19
#define temp3 r18
20
#define temp4 r19
21
22
#define STARTZEICHEN ':'  // startzeichen für einen record
23
#define SEKUNDE 2      // für zeitschleife
24
25
#define MAXRECORDS 17    // wert für maximale anzahl daten im record
26
27
#define BATT_MIN 810      // minimalster batterie-wert ca. 4,5V
28
#define BAUDRATE 520    // UBRR Wert für Baudrate 2400

Wenn ich auf kompilieren gehe kommt folgende Message:
gcc plug-in: Error: Object file not found on expected location D:\Eigene 
Dateien\schule\elektro\Asuro\c-programme\bootloader\default\bootloader.e 
lf

Und folgendes Buildprotokoll:
Build started 23.2.2008 at 17:35:14
avr-gcc.exe  -mmcu=atmega168 -mmcu=atmega168 -Wall -gdwarf-2  -O0 
-fsigned-char -MD -MP -MT asm_main.o -MF dep/asm_main.o.d  -x 
assembler-with-cpp -Wa,-gdwarf2 -c  ../asm_main.s
../asm_main.s: Assembler messages:
../asm_main.s:14: Error: number must be less than 64
../asm_main.s:16: Error: number must be less than 64
../asm_main.s:18: Error: number must be less than 64
../asm_main.s:22: Error: number must be less than 64
../asm_main.s:24: Error: number must be less than 64
../asm_main.s:26: Error: number must be less than 64
../asm_main.s:33: Error: number must be less than 64
../asm_main.s:35: Error: number must be less than 64
../asm_main.s:37: Error: number must be less than 64
../asm_main.s:41: Error: number must be less than 64
../asm_main.s:43: Error: number must be less than 64
../asm_main.s:45: Error: number must be less than 64
../asm_main.s:59: Error: number must be less than 64
../asm_main.s:62: Error: number must be less than 64
../asm_main.s:112: Error: number must be less than 32
../asm_main.s:114: Error: number must be less than 32
../asm_main.s:117: Error: number must be less than 64
../asm_main.s:118: Error: number must be less than 64
../asm_main.s:177: Error: junk at end of line, first unrecognized 
character is `*'
make: *** [asm_main.o] Error 1
Build succeeded with 0 Warnings...

Ich habe keine Idee, was ich machen kann.
Habt ihr noch eine Idee?

von Peter D. (peda)


Lesenswert?

Ja, man kann Punkt 5 der Regeln ignorieren, muß sich dann aber nicht 
über das Resultat wundern.

Und eine Hauptdatei gibt es nicht, es gibt nur einen kompletten 
Dateianhang.

Wie soll denn jemand die Fehlermeldungen dem Codeschnipsel zuordnen?


Ich vermute mal, Du verwendest IN/OUT auf Adressen, die außerhalb des 
erlaubten Bereichs sind. Dann muß man LDS/STS nehmen.


Peter

von H3ll G. (h3llghost)


Angehängte Dateien:

Lesenswert?

Danke erstmal für deine Hilfe!

Aber ich habe nun ein anderes Problem ...
Ich kann meinen selbst geschrieben Bootloader einfach nicht starten bzw. 
er wird nicht gestartet.

Meine Fuse-Bits sind wie folgt:

http://palmavr.sourceforge.net/cgi-bin/fc.cgi?P_PREV=ATmega168&P=ATmega168&V_LOW=B7&V_HIGH=DD&V_EXTENDED=F8&M_LOW_0x3F=0x37&M_LOW_0x40=0x00&M_LOW_0x80=&M_HIGH_0x07=0x05&M_HIGH_0x08=&M_HIGH_0x10=&M_HIGH_0x20=0x00&M_HIGH_0x40=&M_HIGH_0x80=&M_EXTENDED_0x01=0x00&M_EXTENDED_0x06=0x00&B_SPIEN=P&B_CKSEL3=P&B_BOOTSZ1=P&B_BODLEVEL1=P&B_BOOTSZ0=P&B_BOOTRST=P&O_BITS=Apply+fuse+bits

Den Bootloader habe ich als Anhang angefügt.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.