Forum: Compiler & IDEs Makefile Uart Korrekt?


von Theo (Gast)


Lesenswert?

hi,
ist der ausschnitt korrekt?:

F_CPU = 7372800

BAUD = 9600L

UBRR_VAL = ((F_CPU+BAUD*8)/(BAUD*16)-1)   // clever runden
BAUD_REAL = (F_CPU/(16*(UBRR_VAL+1)))     // Reale Baudrate
BAUD_ERROR = ((BAUD_REAL*1000)/BAUD-1000) // Fehler in Promille

von Falk B. (falk)


Lesenswert?

@ Theo (Gast)

>ist der ausschnitt korrekt?:

Nein.

>F_CPU = 7372800

Hier fehlt das L am Ende.

Und wieso ins Makefile? das kommt einfach in den Quelltext, so wie im 
Tutorial, wo du es herkopiert hast.

MFG
Falk

von Theo (Gast)


Lesenswert?

und wiso schreib ich den Takt in das makefile und den rest nicht?


Building target “Make” of project “GTR” with configuration “Development” 
— (10 errors)
      cd /Users/tuxianer/GTR
    setenv ACTION
    setenv APPLE_INTERNAL_DEVELOPER_DIR /AppleInternal/Developer
    setenv APPLE_INTERNAL_DIR /AppleInternal
    setenv APPLE_INTERNAL_DOCUMENTATION_DIR /AppleInternal/Documentation
    setenv APPLE_INTERNAL_LIBRARY_DIR /AppleInternal/Library
    setenv APPLE_INTERNAL_TOOLS /AppleInternal/Developer/Tools
    setenv BUILD_COMPONENTS "headers build"
    setenv BUILD_DIR /Users/tuxianer/GTR/build
    setenv BUILD_ROOT /Users/tuxianer/GTR/build
    setenv BUILD_STYLE Development
    setenv BUILD_VARIANTS normal
    setenv BUILT_PRODUCTS_DIR /Users/tuxianer/GTR/build/Development
    setenv CC /usr/bin/cc
    setenv CLASS_FILE_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build/JavaClasses
    setenv CLONE_HEADERS NO
    setenv CONFIGURATION Development
    setenv CONFIGURATION_BUILD_DIR /Users/tuxianer/GTR/build/Development
    setenv CONFIGURATION_TEMP_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development
    setenv COPY_PHASE_STRIP NO
    setenv DEBUGGING_SYMBOLS YES
    setenv DERIVED_FILES_DIR
    setenv DERIVED_FILE_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build/DerivedSource 
s
    setenv DERIVED_SOURCES_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build/DerivedSource 
s
    setenv DEVELOPMENT_LANGUAGE English
    setenv DO_HEADER_SCANNING_IN_JAM NO
    setenv DSTROOT /tmp/GTR.dst
    setenv ENABLE_HEADER_DEPENDENCIES YES
    setenv FILE_LIST 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build/Objects/LinkF 
ileList
    setenv FRAMEWORK_VERSION A
    setenv GCC3_VERSION 3.3
    setenv GCC_DYNAMIC_NO_PIC NO
    setenv GCC_GENERATE_DEBUGGING_SYMBOLS YES
    setenv GCC_OPTIMIZATION_LEVEL 0
    setenv GROUP tuxianer
    setenv HEADERMAP_INCLUDES_FLAT_ENTRIES_FOR_TARGET_BEING_BUILT YES
    setenv HEADERMAP_INCLUDES_FRAMEWORK_ENTRIES_FOR_ALL_PRODUCT_TYPES 
YES
    setenv HEADERMAP_INCLUDES_NONPUBLIC_NONPRIVATE_HEADERS YES
    setenv HEADERMAP_INCLUDES_PROJECT_HEADERS YES
    setenv INSTALL_DIR "/tmp/GTR.dst/(INSTALL_PATH)"
    setenv INSTALL_GROUP tuxianer
    setenv INSTALL_MODE_FLAG a-w,a+rX
    setenv INSTALL_OWNER tuxianer
    setenv INSTALL_ROOT /tmp/GTR.dst
    setenv JAVA_APP_STUB 
/System/Library/Frameworks/JavaVM.framework/Resources/MacOS/JavaApplicat 
ionStub
    setenv JAVA_ARCHIVE_CLASSES YES
    setenv JAVA_ARCHIVE_TYPE JAR
    setenv JAVA_COMPILER /usr/bin/javac
    setenv JAVA_FRAMEWORK_RESOURCES_DIRS Resources
    setenv JAVA_JAR_FLAGS cv
    setenv JAVA_SOURCE_SUBDIR .
    setenv JAVA_USE_DEPENDENCIES YES
    setenv JAVA_ZIP_FLAGS -urg
    setenv LOCAL_ADMIN_APPS_DIR /Applications/Utilities
    setenv LOCAL_APPS_DIR /Applications
    setenv LOCAL_DEVELOPER_DIR /Library/Developer
    setenv LOCAL_LIBRARY_DIR /Library
    setenv NATIVE_ARCH i386
    setenv OBJECT_FILE_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build/Objects
    setenv OBJROOT /Users/tuxianer/GTR/build
    setenv OPTIMIZATION_LEVEL 0
    setenv OS MACOS
    setenv PATH "/sw/bin/:/usr/local/bin/:/usr/bin:/bin:/usr/sbin:/sbin"
    setenv PATH_PREFIXES_EXCLUDED_FROM_HEADER_DEPENDENCIES "/usr/include 
/usr/local/include /System/Library/Frameworks 
/System/Library/PrivateFrameworks /Developer/Headers"
    setenv PRODUCT_NAME Make
    setenv PROFILING_CODE NO
    setenv PROJECT GTR
    setenv PROJECT_DERIVED_FILE_DIR 
/Users/tuxianer/GTR/build/GTR.build/DerivedSources
    setenv PROJECT_DIR /Users/tuxianer/GTR
    setenv PROJECT_FILE_PATH /Users/tuxianer/GTR/GTR.xcodeproj
    setenv PROJECT_NAME GTR
    setenv PROJECT_TEMP_DIR /Users/tuxianer/GTR/build/GTR.build
    setenv REMOVE_CVS_FROM_RESOURCES YES
    setenv REMOVE_SVN_FROM_RESOURCES YES
    setenv SDKROOT
    setenv SHARED_DERIVED_FILE_DIR 
/Users/tuxianer/GTR/build/Development/DerivedSources
    setenv SOURCE_ROOT /Users/tuxianer/GTR
    setenv SRCROOT /Users/tuxianer/GTR
    setenv STRIP_INSTALLED_PRODUCT YES
    setenv SYMROOT /Users/tuxianer/GTR/build
    setenv SYSTEM_ADMIN_APPS_DIR /Applications/Utilities
    setenv SYSTEM_APPS_DIR /Applications
    setenv SYSTEM_CORE_SERVICES_DIR /System/Library/CoreServices
    setenv SYSTEM_DEMOS_DIR /Applications/Extras
    setenv SYSTEM_DEVELOPER_APPS_DIR /Developer/Applications
    setenv SYSTEM_DEVELOPER_DEMOS_DIR 
"/Developer/Applications/Utilities/Built Examples"
    setenv SYSTEM_DEVELOPER_DIR /Developer
    setenv SYSTEM_DEVELOPER_DOC_DIR "/Developer/ADC Reference Library"
    setenv SYSTEM_DEVELOPER_GRAPHICS_TOOLS_DIR 
"/Developer/Applications/Graphics Tools"
    setenv SYSTEM_DEVELOPER_JAVA_TOOLS_DIR "/Developer/Applications/Java 
Tools"
    setenv SYSTEM_DEVELOPER_PERFORMANCE_TOOLS_DIR 
"/Developer/Applications/Performance Tools"
    setenv SYSTEM_DEVELOPER_RELEASENOTES_DIR "/Developer/ADC Reference 
Library/releasenotes"
    setenv SYSTEM_DEVELOPER_TOOLS /Developer/Tools
    setenv SYSTEM_DEVELOPER_TOOLS_DOC_DIR "/Developer/ADC Reference 
Library/documentation/DeveloperTools"
    setenv SYSTEM_DEVELOPER_TOOLS_RELEASENOTES_DIR "/Developer/ADC 
Reference Library/releasenotes/DeveloperTools"
    setenv SYSTEM_DEVELOPER_UTILITIES_DIR 
/Developer/Applications/Utilities
    setenv SYSTEM_DOCUMENTATION_DIR /Library/Documentation
    setenv SYSTEM_LIBRARY_DIR /System/Library
    setenv TARGETNAME Make
    setenv TARGET_BUILD_DIR /Users/tuxianer/GTR/build/Development
    setenv TARGET_NAME Make
    setenv TARGET_TEMP_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build
    setenv TEMP_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build
    setenv TEMP_FILES_DIR
    setenv TEMP_FILE_DIR 
/Users/tuxianer/GTR/build/GTR.build/Development/Make.build
    setenv TEMP_ROOT /Users/tuxianer/GTR/build
    setenv USER tuxianer
    setenv USER_APPS_DIR /Users/tuxianer/Applications
    setenv USER_LIBRARY_DIR /Users/tuxianer/Library
    setenv XCODE_APP_SUPPORT_DIR "/Library/Application 
Support/Apple/Developer Tools"
    /usr/bin/make

-------- begin --------
avr-gcc (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is 
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.




ich bekomme nun die errors:

In function 'main':
error: 'UBRRH' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: invalid suffix "LUL" on integer constant
error: 'UBRRL' undeclared (first use in this function)
error: invalid suffix "LUL" on integer constant
error: 'USR1C' undeclared (first use in this function)
error: 'URSEL' undeclared (first use in this function)
error: 'USBS' undeclared (first use in this function)
error: 'UCSZ1' undeclared (first use in this function)
error: 'UCSZ0' undeclared (first use in this function)
error: 'USR0C' undeclared (first use in this function)

von Flo S. (tuxianer)


Lesenswert?

mist hier war noch der Name von nem Freund drinne, der hier was 
geschrieben hat. Jetzt kann ichs nicht edieren. Das ganze oben ist 
quatsch!

um die errors geht es:




In function 'main':
error: 'UBRRH' undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: invalid suffix "LUL" on integer constant
error: 'UBRRL' undeclared (first use in this function)
error: invalid suffix "LUL" on integer constant
error: 'USR1C' undeclared (first use in this function)
error: 'URSEL' undeclared (first use in this function)
error: 'USBS' undeclared (first use in this function)
error: 'UCSZ1' undeclared (first use in this function)
error: 'UCSZ0' undeclared (first use in this function)
error: 'USR0C' undeclared (first use in this function)

von Falk B. (falk)


Lesenswert?

@ Florentin S. (tuxianer)

>um die errors geht es:

Da fehlt das inlcude von
1
#include <avr/io.h>

MFG
Falk

von Flo S. (tuxianer)


Lesenswert?

das ist ja drin das ist es ja. Ich bin leider absoluter Neuling in 
avr-gcc.

hier mal die .c:
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <inttypes.h>
4
5
#define BAUD 9600L                // Baudrate, das L am Ende ist wichtig, NICHT UL verwenden!
6
 
7
#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1)   // clever runden
8
#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1)))     // Reale Baudrate
9
#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD-1000) // Fehler in Promille
10
11
12
13
int temp, Data, Count;
14
15
int main (void) {
16
17
    UBRRH = UBRR_VAL >> 8;
18
    UBRRL = UBRR_VAL & 0xFF;
19
    
20
  USR1C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
21
  USR0C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
22
  
23
24
  UCSR1B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN); 
25
  UCSR1B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
26
  
27
  sei();
28
  
29
    
30
}


und das makefile:
1
# Hey Emacs, this is a -*- makefile -*-
2
#----------------------------------------------------------------------------
3
# WinAVR Makefile Template written by Eric B. Weddington, Jˆrg Wunsch, et al.
4
#
5
# Released to the Public Domain
6
#
7
# Additional material for this makefile was written by:
8
# Peter Fleury
9
# Tim Henigan
10
# Colin O'Flynn
11
# Reiner Patommel
12
# Markus Pfaff
13
# Sander Pool
14
# Frederik Rouleau
15
#
16
#----------------------------------------------------------------------------
17
# On command line:
18
#
19
# make all = Make software.
20
#
21
# make clean = Clean out built project files.
22
#
23
# make coff = Convert ELF to AVR COFF.
24
#
25
# make extcoff = Convert ELF to AVR Extended COFF.
26
#
27
# make program = Download the hex file to the device, using avrdude.
28
#                Please customize the avrdude settings below first!
29
#
30
# make debug = Start either simulavr or avarice as specified for debugging, 
31
#              with avr-gdb or avr-insight as the front end for debugging.
32
#
33
# make filename.s = Just compile filename.c into the assembler code only.
34
#
35
# make filename.i = Create a preprocessed source file for use in submitting
36
#                   bug reports to the GCC project.
37
#
38
# To rebuild project do "make clean" then "make all".
39
#----------------------------------------------------------------------------
40
41
42
# MCU name
43
MCU = atmega162
44
45
46
# Processor frequency.
47
#     This will define a symbol, F_CPU, in all source code files equal to the 
48
#     processor frequency. You can then use this symbol in your source code to 
49
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
50
#     automatically to create a 32-bit value in your source code.
51
F_CPU = 7372800L
52
53
# Output format. (can be srec, ihex, binary)
54
FORMAT = ihex
55
56
57
# Target file name (without extension).
58
TARGET = GTR
59
60
61
# List C source files here. (C dependencies are automatically generated.)
62
#SRC += ADC.c 
63
SRC += $(TARGET).c
64
65
66
# List Assembler source files here.
67
#     Make them always end in a capital .S.  Files ending in a lowercase .s
68
#     will not be considered source files but generated files (assembler
69
#     output from the compiler), and will be deleted upon "make clean"!
70
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
71
#     it will preserve the spelling of the filenames, and gcc itself does
72
#     care about how the name is spelled on its command-line.
73
ASRC = 
74
75
76
# Optimization level, can be [0, 1, 2, 3, s]. 
77
#     0 = turn off optimization. s = optimize for size.
78
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
79
OPT = s
80
81
82
# Debugging format.
83
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
84
#     AVR Studio 4.10 requires dwarf-2.
85
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
86
DEBUG = stabs
87
88
89
# List any extra directories to look for include files here.
90
#     Each directory must be seperated by a space.
91
#     Use forward slashes for directory separators.
92
#     For a directory that has spaces, enclose it in quotes.
93
EXTRAINCDIRS = 
94
95
96
# Compiler flag to set the C Standard level.
97
#     c89   = "ANSI" C
98
#     gnu89 = c89 plus GCC extensions
99
#     c99   = ISO C99 standard (not yet fully implemented)
100
#     gnu99 = c99 plus GCC extensions
101
CSTANDARD = -std=gnu99
102
103
104
# Place -D or -U options here
105
CDEFS = -DF_CPU=$(F_CPU)UL 
106
107
108
# Place -I options here
109
CINCS =
110
111
112
113
#---------------- Compiler Options ----------------
114
#  -g*:          generate debugging information
115
#  -O*:          optimization level
116
#  -f...:        tuning, see GCC manual and avr-libc documentation
117
#  -Wall...:     warning level
118
#  -Wa,...:      tell GCC to pass this to the assembler.
119
#    -adhlns...: create assembler listing
120
CFLAGS = -g$(DEBUG)
121
CFLAGS += $(CDEFS) $(CINCS)
122
CFLAGS += -O$(OPT)
123
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
124
CFLAGS += -Wall -Wstrict-prototypes
125
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
126
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))
127
CFLAGS += $(CSTANDARD)
128
129
130
#---------------- Assembler Options ----------------
131
#  -Wa,...:   tell GCC to pass this to the assembler.
132
#  -ahlms:    create listing
133
#  -gstabs:   have the assembler create line number information; note that
134
#             for use in COFF files, additional information about filenames
135
#             and function names needs to be present in the assembler source
136
#             files -- see avr-libc docs [FIXME: not yet described there]
137
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
138
139
140
#---------------- Library Options ----------------
141
# Minimalistic printf version
142
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
143
144
# Floating point printf version (requires MATH_LIB = -lm below)
145
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
146
147
# If this is left blank, then it will use the Standard printf version.
148
PRINTF_LIB = 
149
#PRINTF_LIB = $(PRINTF_LIB_MIN)
150
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
151
152
153
# Minimalistic scanf version
154
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
155
156
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
157
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
158
159
# If this is left blank, then it will use the Standard scanf version.
160
SCANF_LIB = 
161
#SCANF_LIB = $(SCANF_LIB_MIN)
162
#SCANF_LIB = $(SCANF_LIB_FLOAT)
163
164
MATH_LIB =
165
#MATH_LIB = -lm
166
167
168
169
#---------------- External Memory Options ----------------
170
171
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
172
# used for variables (.data/.bss) and heap (malloc()).
173
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
174
175
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
176
# only used for heap (malloc()).
177
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
178
179
EXTMEMOPTS =
180
181
182
183
#---------------- Linker Options ----------------
184
#  -Wl,...:     tell GCC to pass this to linker.
185
#    -Map:      create map file
186
#    --cref:    add cross reference to  map file
187
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
188
LDFLAGS += $(EXTMEMOPTS)
189
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
190
191
192
193
#---------------- Programming Options (avrdude) ----------------
194
195
# Programming hardware: alf avr910 avrisp bascom bsd 
196
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
197
#
198
# Type: avrdude -c ?
199
# to get a full listing.
200
#
201
AVRDUDE_PROGRAMMER = butterfly
202
203
# com1 = serial port. Use lpt1 to connect to parallel port.
204
AVRDUDE_PORT = /dev/cu.usbserial    # programmer connected to serial device
205
206
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
207
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
208
209
210
# Uncomment the following if you want avrdude's erase cycle counter.
211
# Note that this counter needs to be initialized first using -Yn,
212
# see avrdude manual.
213
#AVRDUDE_ERASE_COUNTER = -y
214
215
# Uncomment the following if you do /not/ wish a verification to be
216
# performed after programming the device.
217
#AVRDUDE_NO_VERIFY = -V
218
219
# Increase verbosity level.  Please use this when submitting bug
220
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
221
# to submit bug reports.
222
#AVRDUDE_VERBOSE = -v -v
223
224
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
225
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
226
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
227
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
228
229
230
231
#---------------- Debugging Options ----------------
232
233
# For simulavr only - target MCU frequency.
234
DEBUG_MFREQ = $(F_CPU)
235
236
# Set the DEBUG_UI to either gdb or insight.
237
 DEBUG_UI = gdb
238
#DEBUG_UI = insight
239
240
# Set the debugging back-end to either avarice, simulavr.
241
DEBUG_BACKEND = avarice
242
#DEBUG_BACKEND = simulavr
243
244
# GDB Init Filename.
245
GDBINIT_FILE = __avr_gdbinit
246
247
# When using avarice settings for the JTAG
248
JTAG_DEV = /dev/cu.usbserial
249
#JTAG_OPTS = --erase
250
251
# Debugging port used to communicate between GDB / avarice / simulavr.
252
DEBUG_PORT = 4242
253
254
# Debugging host used to communicate between GDB / avarice / simulavr, normally
255
#     just set to localhost unless doing some sort of crazy debugging when 
256
#     avarice is running on a different computer.
257
DEBUG_HOST = localhost
258
259
260
261
#============================================================================
262
263
264
# Define programs and commands.
265
SHELL = sh
266
CC = avr-gcc
267
OBJCOPY = avr-objcopy
268
OBJDUMP = avr-objdump
269
SIZE = avr-size
270
NM = avr-nm
271
AVRDUDE = avrdude
272
REMOVE = rm -f
273
COPY = cp
274
WINSHELL = cmd
275
276
277
# Define Messages
278
# English
279
MSG_ERRORS_NONE = Errors: none
280
MSG_BEGIN = -------- begin --------
281
MSG_END = --------  end  --------
282
MSG_SIZE_BEFORE = Size before: 
283
MSG_SIZE_AFTER = Size after:
284
MSG_COFF = Converting to AVR COFF:
285
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
286
MSG_FLASH = Creating load file for Flash:
287
MSG_EEPROM = Creating load file for EEPROM:
288
MSG_EXTENDED_LISTING = Creating Extended Listing:
289
MSG_SYMBOL_TABLE = Creating Symbol Table:
290
MSG_LINKING = Linking:
291
MSG_COMPILING = Compiling:
292
MSG_ASSEMBLING = Assembling:
293
MSG_CLEANING = Cleaning project:
294
295
296
297
298
# Define all object files.
299
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
300
301
# Define all listing files.
302
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
303
304
305
# Compiler flags to generate dependency files.
306
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
307
308
309
# Combine all necessary flags and optional flags.
310
# Add target processor to flags.
311
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
312
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
313
314
315
316
317
318
# Default target.
319
all: begin gccversion sizebefore build sizeafter end
320
321
build: elf hex eep lss sym
322
323
elf: $(TARGET).elf
324
hex: $(TARGET).hex
325
eep: $(TARGET).eep
326
lss: $(TARGET).lss 
327
sym: $(TARGET).sym
328
329
330
331
# Eye candy.
332
# AVR Studio 3.x does not check make's exit code but relies on
333
# the following magic strings to be generated by the compile job.
334
begin:
335
  @echo
336
  @echo $(MSG_BEGIN)
337
338
#
339
# a couple of hacks were added here by NAL to help with Xcode debugging
340
# ie give some kind of valid executable file.
341
end:
342
  chmod 755 $(TARGET).elf
343
  @echo $(MSG_END)
344
  @echo
345
  
346
347
# Display size of file.
348
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
349
ELFSIZE = $(SIZE) -A $(TARGET).elf
350
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
351
352
sizebefore:
353
  @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
354
  $(AVRMEM) 2>/dev/null; echo; fi
355
356
sizeafter:
357
  @if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
358
  $(AVRMEM) 2>/dev/null; echo; fi
359
360
361
362
# Display compiler version information.
363
gccversion : 
364
  @$(CC) --version
365
366
367
368
# Program the device.  
369
program: $(TARGET).hex $(TARGET).eep
370
  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
371
372
373
# Generate avr-gdb config/init file which does the following:
374
#     define the reset signal, load the target file, connect to target, and set 
375
#     a breakpoint at main().
376
gdb-config: 
377
  @$(REMOVE) $(GDBINIT_FILE)
378
  @echo define reset >> $(GDBINIT_FILE)
379
  @echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
380
  @echo end >> $(GDBINIT_FILE)
381
  @echo file $(TARGET).elf >> $(GDBINIT_FILE)
382
  @echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
383
ifeq ($(DEBUG_BACKEND),simulavr)
384
  @echo load  >> $(GDBINIT_FILE)
385
endif  
386
  @echo break main >> $(GDBINIT_FILE)
387
  
388
debug: gdb-config $(TARGET).elf
389
ifeq ($(DEBUG_BACKEND), avarice)
390
  @echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
391
#  @$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
392
  $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
393
#  @$(WINSHELL) /c pause
394
  @avarice --jtag $(JTAG_DEV) $(JTAG_OPTS) --program --file \
395
  $(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT) &
396
  
397
else
398
  @$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
399
  $(DEBUG_MFREQ) --port $(DEBUG_PORT)
400
endif
401
#  @$(WINSHELL) /c start 
402
  sleep 10
403
  avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
404
  
405
406
407
408
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
409
COFFCONVERT=$(OBJCOPY) --debugging \
410
--change-section-address .data-0x800000 \
411
--change-section-address .bss-0x800000 \
412
--change-section-address .noinit-0x800000 \
413
--change-section-address .eeprom-0x810000 
414
415
416
coff: $(TARGET).elf
417
  @echo
418
  @echo $(MSG_COFF) $(TARGET).cof
419
  $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
420
421
422
extcoff: $(TARGET).elf
423
  @echo
424
  @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
425
  $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
426
427
428
429
# Create final output files (.hex, .eep) from ELF output file.
430
%.hex: %.elf
431
  @echo
432
  @echo $(MSG_FLASH) $@
433
  $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
434
435
%.eep: %.elf
436
  @echo
437
  @echo $(MSG_EEPROM) $@
438
  -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
439
  --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
440
441
# Create extended listing file from ELF output file.
442
%.lss: %.elf
443
  @echo
444
  @echo $(MSG_EXTENDED_LISTING) $@
445
  $(OBJDUMP) -h -S $< > $@
446
447
# Create a symbol table from ELF output file.
448
%.sym: %.elf
449
  @echo
450
  @echo $(MSG_SYMBOL_TABLE) $@
451
  $(NM) -n $< > $@
452
453
454
455
# Link: create ELF output file from object files.
456
.SECONDARY : $(TARGET).elf
457
.PRECIOUS : $(OBJ)
458
%.elf: $(OBJ)
459
  @echo
460
  @echo $(MSG_LINKING) $@
461
  $(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
462
463
464
# Compile: create object files from C source files.
465
%.o : %.c
466
  @echo
467
  @echo $(MSG_COMPILING) $<
468
  $(CC) -c $(ALL_CFLAGS) $< -o $@ 
469
470
471
# Compile: create assembler files from C source files.
472
%.s : %.c
473
  $(CC) -S $(ALL_CFLAGS) $< -o $@
474
475
476
# Assemble: create object files from assembler source files.
477
%.o : %.S
478
  @echo
479
  @echo $(MSG_ASSEMBLING) $<
480
  $(CC) -c $(ALL_ASFLAGS) $< -o $@
481
482
# Create preprocessed source for use in sending a bug report.
483
%.i : %.c
484
  $(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
485
486
487
# Target: clean project.
488
clean: begin clean_list end
489
490
clean_list :
491
  @echo
492
  @echo $(MSG_CLEANING)
493
  $(REMOVE) $(TARGET).hex
494
  $(REMOVE) $(TARGET).eep
495
  $(REMOVE) $(TARGET).cof
496
  $(REMOVE) $(TARGET).elf
497
  $(REMOVE) $(TARGET).map
498
  $(REMOVE) $(TARGET).sym
499
  $(REMOVE) $(TARGET).lss
500
  $(REMOVE) $(OBJ)
501
  $(REMOVE) $(LST)
502
  $(REMOVE) $(SRC:.c=.s)
503
  $(REMOVE) $(SRC:.c=.d)
504
  $(REMOVE) .dep/*
505
506
507
508
# Include the dependency files.
509
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
510
511
512
# Listing of phony targets.
513
.PHONY : all begin finish end sizebefore sizeafter gccversion \
514
build elf hex eep lss sym coff extcoff \
515
clean clean_list program debug gdb-config

von Flo S. (tuxianer)


Lesenswert?

wenn ich bei mcu atmega 32 eingebe kommen weniger errors. Also muss es 
daran liegen!

von holger (Gast)


Lesenswert?

>>F_CPU = 7372800
>Hier fehlt das L am Ende.

Blödsinn. Der Compiler erkennt von sich aus das das 'L' ist.
Was soll er sonst mit einer so großen Definition machen ?
Das sind "Urban Legends". Ich hatte noch nie Probleme ohne 'L'.

>Und wieso ins Makefile? das kommt einfach in den Quelltext, so wie im
>Tutorial, wo du es herkopiert hast.

Das ist ja wohl der größte Schwachsinn den ich je gelesen habe !

von Stefan B. (stefan) Benutzerseite


Angehängte Dateien:

Lesenswert?

Du versuchst laut Makefile für die MCU atmega162 zu übersetzen. Die hat 
ZWEI UARTs, die in dem Sourcecode auch spezifisch angesprochen werden 
müssen.

Also statt
1
    UBRRH = UBRR_VAL >> 8;
2
    UBRRL = UBRR_VAL & 0xFF;

könnte es heissen
1
    UBRR0H = UBRR_VAL >> 8;
2
    UBRR0L = UBRR_VAL & 0xFF;

wenn du UART0 benutzen willst.

Das Problem zieht sich wahrscheinlich durch den kompletten Sourcecode.
1
-------- begin --------
2
avr-gcc (GCC) 4.1.2 (WinAVR 20070525)
3
Copyright (C) 2006 Free Software Foundation, Inc.
4
This is free software; see the source for copying conditions.  There is NO
5
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
6
7
8
Compiling: GTR.c
9
avr-gcc -c -mmcu=atmega162 -I. -gstabs -DF_CPU=7372800LUL  -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=GTR.lst  -std=gnu99 -MD -MP -MF .dep/GTR.o.d GTR.c -o GTR.o
10
GTR.c: In function 'main':
11
GTR.c:17: error: 'UBRRH' undeclared (first use in this function)
12
GTR.c:17: error: (Each undeclared identifier is reported only once
13
GTR.c:17: error: for each function it appears in.)
14
GTR.c:17:13: error: invalid suffix "LUL" on integer constant
15
GTR.c:18: error: 'UBRRL' undeclared (first use in this function)
16
GTR.c:18:13: error: invalid suffix "LUL" on integer constant
17
GTR.c:20: error: 'USR1C' undeclared (first use in this function)
18
GTR.c:20: error: 'URSEL' undeclared (first use in this function)
19
GTR.c:20: error: 'USBS' undeclared (first use in this function)
20
GTR.c:20: error: 'UCSZ1' undeclared (first use in this function)
21
GTR.c:20: error: 'UCSZ0' undeclared (first use in this function)
22
GTR.c:21: error: 'USR0C' undeclared (first use in this function)
23
GTR.c:24: error: 'RXCIE' undeclared (first use in this function)
24
GTR.c:24: error: 'RXEN' undeclared (first use in this function)
25
GTR.c:24: error: 'TXEN' undeclared (first use in this function)
26
GTR.c:30:2: warning: no newline at end of file
27
GTR.c: At top level:
28
GTR.c:30: fatal error: opening dependency file .dep/GTR.o.d: No such file or directory
29
compilation terminated.
30
MAKE.EXE: *** [GTR.o] Error 1

Du solltest dir die Definitionen in avr/include/avr/iom162.h anlesen und 
den Sourcecode abändern. Dann sehen wir weiter.

Im Anhang noch das handkorrigierte Makefile. Beim Einfügen in den 
Nachrichtentext sind wohl die essentiellen TAB vor den Kommandos 
(@echo...) verloren gegangen und das Makefile wurde dadurch 
funktionsunfähig.

Wie gesagt im Anhang eine Korrektur mit TABs ansonsten ungeändert und 
funktionsfähig.

von Flo S. (tuxianer)


Lesenswert?

gut danke das mit den 2 uarts habe ich korrigiert. Dummer Fehler in 
meiner ASM Umsetzung ist es ja richtig. Jetzt kommt noch 1 Fehler:

.
.
.
Support/Apple/Developer Tools"
    /usr/bin/make

-------- begin --------
avr-gcc (GCC) 4.1.1
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is 
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR 
PURPOSE.

make: *** No rule to make target `GTR.o', needed by `GTR.elf'.  Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
    make: *** No rule to make target `GTR.o', needed by `GTR.elf'. 
Stop.
Build failed (1 error)

von Stefan B. (stefan) Benutzerseite


Angehängte Dateien:

Lesenswert?

Ich würde je die korrigierte Source gerne durch meinen avr-gcc schicken, 
aber du hast sie nicht beigefügt...

Ich habe stattdessen einen Rumpf (die folgende Datei GTR.c) kompiliert:
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <inttypes.h>
4
5
#define BAUD 9600L                // Baudrate, das L am Ende ist wichtig, NICHT UL verwenden!
6
7
#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1)   // clever runden
8
#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1)))     // Reale Baudrate
9
#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD-1000) // Fehler in Promille
10
11
int temp, Data, Count;
12
13
int main (void) {
14
#if 0
15
    UBRRH = UBRR_VAL >> 8;
16
    UBRRL = UBRR_VAL & 0xFF;
17
18
  USR1C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
19
  USR0C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
20
21
22
  UCSR1B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
23
  UCSR1B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
24
25
  sei();
26
#endif
27
}

Das funktioniert (s. Anhang).

ADD: Ich muss jetzt in die Falls; schaue aber morgen sicher in den 
Thread rein.

von Flo S. (tuxianer)


Lesenswert?

ich hab den:
1
#include <avr/io.h>
2
#include <avr/interrupt.h>
3
#include <inttypes.h>
4
5
#define BAUD 9600L                // Baudrate, das L am Ende ist wichtig, NICHT UL verwenden!
6
 
7
#define UBRR_VAL ((F_CPU+BAUD*8)/(BAUD*16)-1)   // clever runden
8
#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1)))     // Reale Baudrate
9
#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD-1000) // Fehler in Promille
10
11
12
13
int temp, Data, Count;
14
15
int main (void) {
16
17
    UBRR0H = UBRR_VAL >> 8;
18
    UBRR0L = UBRR_VAL & 0xFF;
19
  
20
  UBRR1H = UBRR_VAL >> 8;
21
    UBRR1L = UBRR_VAL & 0xFF;
22
    
23
  UCSR1C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
24
  UCSR0C |= (1<<URSEL)|(1<<USBS)|(1<<UCSZ1)|(1<<UCSZ0);
25
  
26
27
  UCSR1B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN); 
28
  UCSR0B |= (1<<RXCIE)|(1<<RXEN)|(1<<TXEN);
29
  
30
  sei();
31
  
32
    
33
}


deiner geht aber auch nicht also liegts am compiler...

von Stefan B. (stefan) Benutzerseite


Angehängte Dateien:

Lesenswert?

OK, ich stehe hier schon mit Zahnpasta im Mund.

Du hast noch nicht alle Fehler korrigiert s. Anhang.

PS: Zeigt deine Fehlerausgabe keine Zeilennummern. Die sind ziemlich 
wichtig beim korrigieren!

Beispiel:
GTR.c:17:14: error: invalid suffix "LUL" on integer constant

Zeile 17 in GTR.c ist
    UBRR0H = UBRR_VAL >> 8;

Es kann sich bei Spalte 14 nur um das UBRR_VAL handeln und das wird 
durch ein Define gebildet. Die Zutaten dafür kommen teils aus der Source 
(die sieht OK aus) und aus dem Makefile.

Das Vermaledeite LUL kommt aus dem Makefile. Dort steht in einer Zeile

F_CPU = 7372800L

und in einer anderen Zeile

CDEFS = -DF_CPU=$(F_CPU)UL

Das

L + UL ergibt LUL ;-(

Lass beim definieren von F_CPU das L weg (so wie es für UL im 
darüberstehenden Kommentar steht)

F_CPU = 7372800

Die verbleibenden Fehler hängen mit den beiden UARTs zusammen. Hier auch 
mit 0/1 arbeiten.

von Flo S. (tuxianer)


Lesenswert?

also irgendwas ist komisch.

Mit meinem Code in meinem einen Projekt kommt der Besagte fehler. Aber 
kein anderer. Mit deinem genau so. In einem Neuen Projekt geht deiner, 
aber meiner nicht. Wobei ich seh jetzt eigentlich keinen Unterschied.

von Stefan B. (stefan) Benutzerseite


Lesenswert?

Ich verstehe deine Nachricht nicht, so oft ich sie auch lese (war 
gestern spät ;-). Versuche, es mir besser zu erklären.

Aber zunächst zum alten Problem:

In meinem Projekt mit deiner letzten Beispielsource (00:34) kommt der 
besagte LUL-Fehler nicht mehr, seit ich die oben vorgeschlagene 
Änderung (F_CPU = 7372800L ändern zu F_CPU = 7372800) im Makefile 
gemacht habe.

Der oben angehängte Fehlertext (error2.txt) ist der Zustand vor meiner 
Änderung (ein Fehler der weg ist, kann ich schlecht als Fehler zeigen).

Die anderen Fehler (unbekanntes 'URSEL', 'USBS', 'UCSZ1', 'UCSZ0', 
'RXCIE',
'RXEN', 'TXEN') hatte ich als triviale Fehler eingestuft. Ich dachte, du 
hättest nur vergessen, diese zu beheben. Vielleicht ist es aber anders:

In meiner AVR-GCC Distribution (WinAVR 20070525) "fehlen" diese 
Makrosymbole im entsprechenden Includefile (avr/include/avr/iom162.h). 
Aber dort sind aber andere, funktional entsprechende Makrosymbole. Diese 
sind jeweils mit dem 0 bzw. 1 für eine der beiden UARTs des Atmega162 
gekennzeichnet (Beispiel #define URSEL1  7 und #define URSEL0 7).

Wenn jetzt die Namen der Makrosymbole bei deiner Distribution anders 
sind oder wenn deine Makrosymbole eventuell zusätzlich definiert sind, 
sei es so. Im Hinterkopf behalten: Es kann zu Verständnisproblemen 
führen, wenn du wie in dieser Diskussion Source austauschst.

Jetzt zum neuen Problem.

Wie sieht das neue Projekt aus? Makefile? Sourceode? Fehlertext beim 
Kompilierversuch?

von Flo S. (tuxianer)


Lesenswert?

Die probleme sind soweit behoben. Ich hab nen neunen Thread 
aufgemacht...


ALSO HIER BITTE NICHT MEHR ANTWORTEN!!!! IM NEUEN GEHTS WEITER!!!

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.