YAGARTO/Eclipse kein float to string per sprintf

Gast #2300922
Lesenswert?

Hallo,

Ich bin grade dabei mich mit YAGARTO/Eclipse auseinander zusetzen 
(Arbeite mit einem NXP LPC2468). Eigentlich funktioniert alles bis mir 
gestern aufgefallen ist das ich keine float-Werte über sprintf umwandeln 
kann – Integer funktionieren. Eclipse gibt mir keine Fehler oder 
Warnings aus, kommt ich im Programm aber an die Stelle
1
sprintf(Buffer, "Version %f", x);

hängt sich das Programm auf.

Ich habe über google/Forum Suche ähnliche Fehler gefunden aber nichts 
was mir helfen würde. Hab die Toolchain neu installiert, alle Settings 
überprüft aber nix gefunden. Schreibe ich mit Eclipse eine einfache exe 
funktioniert sprintf  ganz normal. Gleicher Programmcode funktioniert 
auch unter Keil.

Irgendeine Idee an was es liegen kann?
1
# Start of default section
2
#
3

4
TRGT = arm-none-eabi-
5
CC   = $(TRGT)gcc
6
CP   = $(TRGT)objcopy
7
AS   = $(TRGT)gcc -x assembler-with-cpp
8
BIN  = $(CP) -O ihex 
9

10
MCU  = arm7tdmi
11

12
# List all default C defines here, like -D_DEBUG=1
13
DDEFS =  
14

15
# List all default ASM defines here, like -D_DEBUG=1
16
DADEFS = 
17

18
# List all default directories to look for include files here
19
DINCDIR =  ./../../../yagarto/arm-none-eabi/include \
20
      ./../../../yagarto/lib/gcc/arm-none-eabi/4.6.0/include \
21
      ./../../../yagarto/lib/gcc/arm-none-eabi/4.6.0/include-fixed \
22

23

24
# List the default directory to look for the libraries here
25
DLIBDIR =
26

27
# List all default libraries here
28
DLIBS =
29

30
#
31
# End of default section
32
##############################################################################################
33

34
##############################################################################################
35
# Start of user section
36
#
37

38
# Define project name here
39
PROJECT = Start_LPC2468
40

41
# Define linker script file here
42
LDSCRIPT_RAM   = ./Setup/LPC2468_RAM.ld
43
LDSCRIPT_FLASH = ./Setup/LPC2468_FLASH.ld
44

45
# List all user C define here, like -D_DEBUG=1
46
UDEFS =  -DDEBUG=1 
47

48
# Define ASM defines here
49
UADEFS = 
50

51
# List C source files here
52
SRC  =  \
53
./Application/Main.c \
54
./Application/LED.c \
55

56
# List ASM source files here
57
ASRC =  \
58
./Setup/LPC2468_Startup.S          \
59
./Setup/JLINKDCC_HandleDataAbort.S \
60
./Setup/JLINKDCC_Process_ASM.S
61

62
# List all user directories here
63
UINCDIR =  ./../../Inc \
64
      ./Inc \
65
 
66
# List the user directory to look for the libraries here
67
ULIBDIR =
68

69
# List all user libraries here
70
ULIBS =  ./../../Lib/libosA4LNDP.a 
71

72
# Define optimisation level here
73
OPT = -O1
74

75
#
76
# End of user defines
77
##############################################################################################
78

79

80
INCDIR  = $(patsubst %,-I%,$(DINCDIR) $(UINCDIR))
81
LIBDIR  = $(patsubst %,-L%,$(DLIBDIR) $(ULIBDIR))
82
DEFS    = $(DDEFS) $(UDEFS)
83
ADEFS   = $(DADEFS) $(UADEFS)
84
OBJS    = $(ASRC:.S=.o) $(SRC:.c=.o)
85
LIBS    = $(DLIBS) $(ULIBS)
86
MCFLAGS = -mcpu=$(MCU)
87

88
ASFLAGS       = $(MCFLAGS) -gdwarf-2 $(ADEFS)
89
CPFLAGS       = $(MCFLAGS) $(OPT) -gdwarf-2 -fomit-frame-pointer -Wall -Wstrict-prototypes -fverbose-asm -Wa,-ahlms=$(<:.c=.lst) $(DEFS)
90
LDFLAGS_RAM   = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT_RAM) -Wl,-Map=$(PROJECT)_RAM.map,--cref,--no-warn-mismatch $(LIBDIR)
91
LDFLAGS_FLASH = $(MCFLAGS) -nostartfiles -T$(LDSCRIPT_FLASH) -Wl,-Map=$(PROJECT)_FLASH.map,--cref,--no-warn-mismatch $(LIBDIR)
92

93

94
# Generate dependency information
95
CPFLAGS += -MD -MP -MF .dep/$(@F).d
96

97
#
98
# makefile rules
99
#
100

101
all: FLASH
102

103

104
RAM: $(OBJS) $(PROJECT)_RAM.elf $(PROJECT)_RAM.hex
105

106
FLASH: $(OBJS) $(PROJECT)_FLASH.elf $(PROJECT)_FLASH.hex
107

108
%o : %c
109
  @echo "Compiling $<"
110
  @$(CC) -c $(CPFLAGS) -I . $(INCDIR) $< -o $@
111

112
%o : %s
113
  @echo "Assembling $<"
114
  @$(AS) -c $(ASFLAGS) $< -o $@
115

116
%RAM.elf: $(OBJS)
117
  @echo "Linking $@"
118
  @$(CC) $(OBJS) $(LDFLAGS_RAM) $(LIBS) -o $@
119

120
%FLASH.elf: $(OBJS)
121
  @echo "Linking $@"
122
  @$(CC) $(OBJS) $(LDFLAGS_FLASH) $(LIBS) -o $@
123

124
%hex: %elf
125
  @echo "Create $@ from $<"
126
  @$(BIN) $< $@
127

128
clean:
129
  -rm -f $(OBJS)
130
  -rm -f $(PROJECT)_RAM.elf
131
  -rm -f $(PROJECT)_RAM.map
132
  -rm -f $(PROJECT)_RAM.hex
133
  -rm -f $(PROJECT)_FLASH.elf
134
  -rm -f $(PROJECT)_FLASH.map
135
  -rm -f $(PROJECT)_FLASH.hex
136
  -rm -f $(SRC:.c=.c.bak)
137
  -rm -f $(SRC:.c=.lst)
138
  -rm -f $(SRC:.c=.o)
139
  -rm -f $(ASRC:.S=.S.bak)
140
  -rm -f $(ASRC:.S=.lst)
141
  -rm -f $(ASRC:.S=.o)
142
  -rm -fR .dep
143

144
# 
145
# Include the dependency files, should be the last of the makefile
146
#
147
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
148

149
# *** EOF ***
Gast #2300967
Lesenswert?

Du musst eine Version der libc linken, die sprintf mit float Formaten 
unterstützt.
Standardmässig tun das manche/einige/viele embedded libcs nicht.

Die Doku der verwendeten Lib sollte dazu Auskunft geben.

ZiZi.
Gast #2307764
Lesenswert?

Yagarto verwendet newlib, und die braucht für float in sprintf() leider 
ein funktionierendes malloc(). Das habe ich dann auch nicht hinbekommen. 
:-(

Ich habe dann halt die Nachkommastellen als Integer berechnet. Das 
klappt ganz gut, wenn der Wertebereich des Float nicht allzu allzu groß 
ist.

Aus
1
sprintf(Buffer, "Version %f", x);
wird dann
1
  int i=x*1000;
2
  siprintf(Buffer,"Version %d.%3.3d",i/1000, i%1000);
Gast #2316440
Lesenswert?

Danke erstmal.

Ja es liegt eindeutig am malloc. Habs bis jetzt auch noch nicht zum 
laufen gebracht aber jetzt weiß ich zumindest wo genau es harkt.

Das mit der Integer Ausgabe ist leider keine Alternativ da ich später 
einige Hundert bis Tausend Gleitkommazahlen ausgeben muss...

Ich versuch es mal weiter...

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren