Forum: Mikrocontroller und Digitale Elektronik Elm Chan FFT Linker Error? Atmega1284, C++


von David (Gast)


Lesenswert?

Hallo Zusammen,

ich arbeite gerade an einem Projekt, in dem ich auch gern nebenbei einen 
Frequenzanalyzer mit einbauen würde.

Leider bekomme ich die Software von Elm Chan nicht zum laufen.
(siehe http://elm-chan.org/works/akilcd/report_e.html)

Das Problem scheint mir mit dem Linker zusammen zu hängen, leider habe 
ich davon keine Ahnung und finde nichts passendes im Netz.

Ich arbeite mit Atmel Studio 6.0.1996 und schreibe mein Programm in C++.
Die ffft.h und ffft.S habe ich über <rechtsklick>/add/existing item im 
Solution Explorer hinzugefügt, die ffft.h ist mit
1
#include "ffft.h"
 includiert.
So wie ich die Ausgabe von Atmel Studio verstehe, scheint er die .o noch 
erstellen zu können und der Linker findet ein Problem. Stimmt das 
soweit?

Könnt Ihr mir bitte helfen und sagen, was ich falsch mache?
Vielen Dank!
David

Hier die Fehlermeldung aus dem Atmel Studio:
1
------ Build started: Project: led_table_1, Configuration: Debug AVR ------
2
Build started.
3
Project "led_table_1.cppproj" (default targets):
4
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
5
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\Vs\Compiler.targets" from project "C:\Users\David\Desktop\led_table\led_table_1\led_table_1\led_table_1.cppproj" (target "Build" depends on it):
6
  Task "RunCompilerTask"
7
    C:\Program Files (x86)\Atmel\Atmel Studio 6.0\make\make.exe all 
8
    Building target: led_table_1.elf
9
    Invoking: AVR8/GNU Linker : (AVR_8_bit_GNU_Toolchain_3.4.1_830) 4.6.2
10
    "C:\Program Files (x86)\Atmel\Atmel Studio 6.0\extensions\Atmel\AVRGCC\3.4.1.95\AVRToolchain\bin\avr-g++.exe" -o led_table_1.elf  berechnungen.o ffft.o animationen.o led_table_1.o   -Wl,-Map="led_table_1.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group  -mmcu=atmega1284p  
11
    led_table_1.o: In function `main':
12
C:\Users\David\Desktop\led_table\led_table_1\led_table_1\Debug/.././led_table_1.cpp(685,1): undefined reference to `fft_input(int const*, _tag_complex_t*)'
13
C:\Users\David\Desktop\led_table\led_table_1\led_table_1\Debug/.././led_table_1.cpp(686,1): undefined reference to `fft_execute(_tag_complex_t*)'
14
C:\Users\David\Desktop\led_table\led_table_1\led_table_1\Debug/.././led_table_1.cpp(687,1): undefined reference to `fft_output(_tag_complex_t const*, unsigned int*)'
15
    collect2: ld returned 1 exit status
16
    make: *** [led_table_1.elf] Error 1
17
  Done executing task "RunCompilerTask" -- FAILED.
18
Done building target "CoreBuild" in project "led_table_1.cppproj" -- FAILED.
19
Done building project "led_table_1.cppproj" -- FAILED.
20
21
Build FAILED.
22
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========

von Stefan E. (sternst)


Lesenswert?

Vermutlich 'extern "C"' vergessen.

von David (Gast)


Lesenswert?

Stefan E. schrieb:
> Vermutlich 'extern "C"' vergessen.

Hallo Stefan,

danke für den Hinweis...
Leider weiß ich nicht, wie ich das umsetzen muss.
Muss ich dieses im header hinzufügen? Weil ich aus c++ ein "c"-header 
einbinde? Ich habe bisher nur die Anzahl der Samples runter gesetzt.
Müsste ich also den kompletten oberen Teil (bis zu /*for asm module*/ in
1
extern "C"{
2
3
          }
 "einpacken"?

Die ffft.h sieht folgendermaßen aus:
1
#ifndef FFT_N
2
#define FFT_N  64    /* Number of samples (64,128,256,512). Don't forget to clean! */
3
//#define INPUT_NOUSE
4
//#define INPUT_IQ
5
6
7
#ifndef FFFT_ASM  /* for c modules */
8
9
typedef struct _tag_complex_t {
10
  int16_t  r;
11
  int16_t i;
12
} complex_t;
13
14
#ifndef INPUT_NOUSE
15
#ifdef INPUT_IQ
16
void fft_input (const complex_t *, complex_t *);
17
#else
18
void fft_input (const int16_t *, complex_t *);
19
#endif
20
#endif
21
void fft_execute (complex_t *);
22
void fft_output (const complex_t *, uint16_t *);
23
int16_t fmuls_f (int16_t, int16_t);
24
25
//extern const prog_int16_t tbl_window[];
26
extern const int16_t tbl_window[] PROGMEM;
27
28
29
#else        /* for asm module */
30
31
#define T0L  r0
32
#define T0H  r1
33
#define T2L  r2
34
#define T2H  r3
35
#define T4L  r4
36
#define T4H  r5
37
#define T6L  r6
38
#define T6H  r7
39
#define T8L  r8
40
#define T8H  r9
41
#define T10L  r10
42
#define T10H  r11
43
#define T12L  r12
44
#define T12H  r13
45
#define T14L  r14
46
#define T14H  r15
47
#define AL  r16
48
#define AH  r17
49
#define BL  r18
50
#define BH  r19
51
#define CL  r20
52
#define CH  r21
53
#define DL  r22
54
#define DH  r23
55
#define EL  r24
56
#define EH  r25
57
#define XL  r26
58
#define XH  r27
59
#define YL  r28
60
#define YH  r29
61
#define ZL  r30
62
#define ZH  r31
63
64
.macro  ldiw  dh,dl, abs
65
  ldi  \dl, lo8(\abs)
66
  ldi  \dh, hi8(\abs)
67
.endm
68
69
.macro  subiw  dh,dl, abs
70
  subi  \dl, lo8(\abs)
71
  sbci  \dh, hi8(\abs)
72
.endm
73
74
.macro  addw  dh,dl, sh,sl
75
  add  \dl, \sl
76
  adc  \dh, \sh
77
.endm
78
79
.macro  addd  d3,d2,d1,d0, s3,s2,s1,s0
80
  add  \d0, \s0
81
  adc  \d1, \s1
82
  adc  \d2, \s2
83
  adc  \d3, \s3
84
.endm
85
86
.macro  subw  dh,dl, sh,sl
87
  sub  \dl, \sl
88
  sbc  \dh, \sh
89
.endm
90
91
.macro  subd  d3,d2,d1,d0, s3,s2,s1,s0
92
  sub  \d0, \s0
93
  sbc  \d1, \s1
94
  sbc  \d2, \s2
95
  sbc  \d3, \s3
96
.endm
97
98
.macro  lddw  dh,dl, src
99
  ldd  \dl, \src
100
  ldd  \dh, \src+1
101
.endm
102
103
.macro  ldw  dh,dl, src
104
  ld  \dl, \src
105
  ld  \dh, \src
106
.endm
107
108
.macro  stw  dst, sh,sl
109
  st  \dst, \sl
110
  st  \dst, \sh
111
.endm
112
113
.macro  clrw  dh, dl
114
  clr  \dh
115
  clr  \dl
116
.endm
117
118
.macro  lsrw  dh, dl
119
  lsr  \dh
120
  ror  \dl
121
.endm
122
123
.macro  asrw  dh, dl
124
  asr  \dh
125
  ror  \dl
126
.endm
127
128
.macro  lslw  dh, dl
129
  lsl  \dl
130
  rol  \dh
131
.endm
132
133
.macro  pushw  dh, dl
134
  push  \dh
135
  push  \dl
136
.endm
137
138
.macro  popw  dh, dl
139
  pop  \dl
140
  pop  \dh
141
.endm
142
143
.macro  lpmw  dh,dl, src
144
  lpm  \dl, \src
145
  lpm  \dh, \src
146
.endm
147
148
.macro  rjne  lbl
149
  breq  99f
150
  rjmp  \lbl
151
99:
152
.endm
153
154
155
.macro  FMULS16  d3,d2,d1,d0 ,s1h,s1l, s2h,s2l  ;Fractional Multiply (19clk)
156
  fmuls  \s1h, \s2h
157
  movw  \d2, T0L
158
  fmul  \s1l, \s2l
159
  movw  \d0, T0L
160
  adc  \d2, EH ;EH: zero reg.
161
  fmulsu  \s1h, \s2l
162
  sbc  \d3, EH
163
  add  \d1, T0L
164
  adc  \d2, T0H
165
  adc  \d3, EH
166
  fmulsu  \s2h, \s1l
167
  sbc  \d3, EH
168
  add  \d1, T0L
169
  adc  \d2, T0H
170
  adc  \d3, EH
171
.endm
172
173
174
.macro  SQRT32  ; 32bit square root (526..542clk)
175
  clr  T6L
176
  clr  T6H
177
  clr  T8L
178
  clr  T8H
179
  ldi  BL, 1
180
  ldi  BH, 0
181
  clr  CL
182
  clr  CH
183
  ldi  DH, 16
184
90:  lsl  T2L
185
  rol  T2H
186
  rol  T4L
187
  rol  T4H
188
  rol  T6L
189
  rol  T6H
190
  rol  T8L
191
  rol  T8H
192
  lsl  T2L
193
  rol  T2H
194
  rol  T4L
195
  rol  T4H
196
  rol  T6L
197
  rol  T6H
198
  rol  T8L
199
  rol  T8H
200
  brpl  91f
201
  add  T6L, BL
202
  adc  T6H, BH
203
  adc  T8L, CL
204
  adc  T8H, CH
205
  rjmp  92f
206
91:  sub  T6L, BL
207
  sbc  T6H, BH
208
  sbc  T8L, CL
209
  sbc  T8H, CH
210
92:  lsl  BL
211
  rol  BH
212
  rol  CL
213
  andi  BL, 0b11111000
214
  ori  BL, 0b00000101
215
  sbrc  T8H, 7
216
  subi  BL, 2
217
  dec  DH
218
  brne  90b
219
  lsr  CL
220
  ror  BH
221
  ror  BL
222
  lsr  CL
223
  ror  BH
224
  ror  BL
225
.endm
226
227
#endif  /* FFFT_ASM */
228
229
#endif  /* FFT_N */

von Stefan E. (sternst)


Lesenswert?

1
extern "C" {
2
  #include "ffft.h"
3
}

von David (Gast)


Lesenswert?

Danke!

Jetzt kompiliert es :)

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.