sprintf or printf with float arguments gives bus fault exception!

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Not applicable
Hi,

I'm running DAVE-3.1.10, with ARM XMC4500.
When I call sprintf (or printf) with float arguments I get a bus fault exception, but only if the float arguments <> 0.

So this works:
char buf[64];
sprintf(buf, "%f", 0.0);


But this gives a bus fault exception:
char buf[64];
sprintf(buf, "%f", 1.0);


I get the bus fault exception even if I call sprintf in main, directly after the call to DAVE_Init, and before anything else is started.
Does the C-library functions sprintf and printf don't have support for floats?

And it is not a stack issue (I have plenty of stack), and everything else works, as far as I can tell...

According to the map file this is the C-library that is used:
c:/program files (x86)/dave-3.1.10/arm-gcc/bin/../lib/gcc/arm-none-eabi/4.7.4/../../../../arm-none-eabi/lib/armv7e-m\libg.a(lib_a-sprintf.o

Thanks for any help!
0 Likes
7 Replies
Not applicable
Hi Mikael,

Would you pls provide some more details on your project? For example, which Apps are you using etc.? If possible, could you share your project?

Best regards,
Sophia
0 Likes
lock attach
Attachments are accessible only for community members.
Not applicable
Hi Sophia,

I found out that if I revert to an older version of the project, with less amount of code, and add the same test sprintf there, then it works!
So I tried to successively add more code to that old version until it stopped working.
(Note however that the added code is never executed when there is an exception, since the failing debug sprintf is inserted directly after DAVE_Init in main, so the execution halts there).

I think perhaps this is because some memory segment spills over.
I runned objdump.exe to extract a memory map, but I am not sure exactly how to interpret it...
It seems both firmware/constants and ram are within boundaries, but what about all those .debug segments?
But if memory is exceeded, then why isn't there an error from the linker?

This is what objdump.exe says for the old .elf file that works.
(The debug sprintf has been inserted after DAVE_Init, and here it succeds, i.e. no exception is generated, and the value in the buf variable is 1.0 as expected):

D:\Temp\140528.1ok_pem2_freertos\PEM_FreeRTOS>"C:\Program Files (x86)\DAVE-3.1.1
0\ARM-GCC\arm-none-eabi\bin\objdump.exe" -h Debug\PEM_FreeRTOS.elf

Debug\PEM_FreeRTOS.elf: file format elf32-littlearm

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00023d34 08000000 08000000 00008000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .ARM.exidx 00000010 08023d34 08023d34 0002bd34 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .rodata 00004b50 08023d44 08023d44 0002bd44 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 Stack 00000800 20000000 20000000 00038000 2**0
ALLOC
4 .bss 0000d25c 20000800 20000800 00038000 2**2
ALLOC
5 .data 00001194 2000da60 080288a0 00035a60 2**3
CONTENTS, ALLOC, LOAD, DATA
6 .debug_aranges 00002418 00000000 00000000 00036bf8 2**3
CONTENTS, READONLY, DEBUGGING
7 .debug_info 000361e6 00000000 00000000 00039010 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_abbrev 00007421 00000000 00000000 0006f1f6 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_line 0005cfd7 00000000 00000000 00076617 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_frame 0000825c 00000000 00000000 000d35f0 2**2
CONTENTS, READONLY, DEBUGGING
11 .debug_str 000b1406 00000000 00000000 000db84c 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_loc 0000c3c8 00000000 00000000 0018cc52 2**0
CONTENTS, READONLY, DEBUGGING
13 .debug_ranges 00001ef0 00000000 00000000 00199020 2**3
CONTENTS, READONLY, DEBUGGING
14 .build_attributes 00001bac 00000000 00000000 0019af10 2**0
CONTENTS, READONLY
15 .debug_macro 00014620 00000000 00000000 0019cabc 2**0
CONTENTS, READONLY, DEBUGGING

D:\Temp\140528.1ok_pem2_freertos\PEM_FreeRTOS>


And here when a little more code is added (which is never executed), then I get the bus fault exception from the sprintf call:

D:\Temp\140528.2err_pem2_freertos\PEM_FreeRTOS>"C:\Program Files (x86)\DAVE-3.1.
10\ARM-GCC\arm-none-eabi\bin\objdump.exe" -h Debug\PEM_FreeRTOS.elf

Debug\PEM_FreeRTOS.elf: file format elf32-littlearm

Sections:
Idx Name Size VMA LMA File off Algn
0 .text 00024194 08000000 08000000 00008000 2**3
CONTENTS, ALLOC, LOAD, READONLY, CODE
1 .ARM.exidx 00000010 08024194 08024194 0002c194 2**2
CONTENTS, ALLOC, LOAD, READONLY, DATA
2 .rodata 000050c8 080241a4 080241a4 0002c1a4 2**3
CONTENTS, ALLOC, LOAD, READONLY, DATA
3 Stack 00000800 20000000 20000000 00038000 2**0
ALLOC
4 .bss 0000d660 20000800 20000800 00038000 2**2
ALLOC
5 .data 00001194 2000de60 08029270 00035e60 2**3
CONTENTS, ALLOC, LOAD, DATA
6 .debug_aranges 00002488 00000000 00000000 00036ff8 2**3
CONTENTS, READONLY, DEBUGGING
7 .debug_info 000369f4 00000000 00000000 00039480 2**0
CONTENTS, READONLY, DEBUGGING
8 .debug_abbrev 00007661 00000000 00000000 0006fe74 2**0
CONTENTS, READONLY, DEBUGGING
9 .debug_line 0006043c 00000000 00000000 000774d5 2**0
CONTENTS, READONLY, DEBUGGING
10 .debug_frame 00008384 00000000 00000000 000d7914 2**2
CONTENTS, READONLY, DEBUGGING
11 .debug_str 000b1554 00000000 00000000 000dfc98 2**0
CONTENTS, READONLY, DEBUGGING
12 .debug_loc 0000c58c 00000000 00000000 001911ec 2**0
CONTENTS, READONLY, DEBUGGING
13 .debug_ranges 00001f40 00000000 00000000 0019d778 2**3
CONTENTS, READONLY, DEBUGGING
14 .build_attributes 00001c1e 00000000 00000000 0019f6b8 2**0
CONTENTS, READONLY
15 .debug_macro 00015385 00000000 00000000 001a12d6 2**0
CONTENTS, READONLY, DEBUGGING

D:\Temp\140528.2err_pem2_freertos\PEM_FreeRTOS>


See also attached zip file with linker and map files.

Thanks for any help or suggestions! (And sorry for the delay in answering...)

/Mikael
0 Likes
Not applicable
Hi Mikael,

Perhaps you can get some hints from Forum Thread "printf"?

BR,
Zain
0 Likes
Not applicable
Hi Mikael,

Could you try the followings with your old project and see whether the problem still exists?
1) Install the CMSIS patch for DAVE v3.1.10 (DAVE_CMSIS_Patch _2014-05-09)
2) Use the latest startup file (V1.15,May, 05, 2014) & linker script template (V1.2, 05 May 2014)
3) Add "Lib" folder containing "System_LibcStubs.c" (V1.3, Jan 2014)

Best regards,
Sophia
0 Likes
Not applicable
sophia wrote:
Hi Mikael,

Could you try the followings with your old project and see whether the problem still exists?
1) Install the CMSIS patch for DAVE v3.1.10 (DAVE_CMSIS_Patch _2014-05-09)
2) Use the latest startup file (V1.15,May, 05, 2014) & linker script template (V1.2, 05 May 2014)
3) Add "Lib" folder containing "System_LibcStubs.c" (V1.3, Jan 2014)

Best regards,
Sophia


Where do I get this patch?

I pressed "Help|Check for updates" in the DAVE3 Eclipse editor, but it only says "There are no update sites to search. Do you wish to open the 'Available Software Sites' preferences?", but that window is also blank...
Also, if I press "Help|Check for DAVE App Updates" it says "Library Updates not found".

Is the new startup file (v1.15) and linker script (v1.2) something that comes with the patch?
My current assembler startup file (startup_XMC4500.s) is v1.13 (Jul, 29, 2013).
My current C startup file (startup_XMC4500.c) is v3.0.1 Alpha (September 17, 2012).
My current liker script file (<myproject>.ld) is v1.1 (Aug 26, 2013).

Would it be possible to get the source code for sprintf, so I can override the default library version?
Then perhaps the exact line where the error appears could be found in the debugger...

Best Regards,
/Mikael
0 Likes
Not applicable
Hi Mikael,

1) Have you installed DAVE v3.1.10? In DAVE Forum thread "Information about Updates" May 16th post, you are requested to install CMSIS patch for DAVE v3.1.10. Details can be found by clicking "More details and Instructions to perform the update". At the same time, you can also refer to "DAVE TIP of the day: How to install the CMSIS patch for DAVE v3.1.10" for the procedure.
2) The startup_XMC4500.s & XMC4500.ld are located under C:\DAVE-3.1.10\CMSIS\Infineon\XMC4500_series\Source\GCC
The "System_LibcStubs.c' is located under C:\DAVE-3.1.10\CMSIS\Infineon\Lib
Frankly speaking, I am unable to reproduce your problem. I'm not sure whether it is related to the memory usage, so i would like you to try this. Or you can try your code in DAVE v3.1.10 directly.

Best regards,
Sophia
0 Likes
Not applicable
sophia wrote:
Hi Mikael,

1) Have you installed DAVE v3.1.10? In DAVE Forum thread "Information about Updates" May 16th post, you are requested to install CMSIS patch for DAVE v3.1.10. Details can be found by clicking "More details and Instructions to perform the update". At the same time, you can also refer to "DAVE TIP of the day: How to install the CMSIS patch for DAVE v3.1.10" for the procedure.
2) The startup_XMC4500.s & XMC4500.ld are located under C:\DAVE-3.1.10\CMSIS\Infineon\XMC4500_series\Source\GCC
The "System_LibcStubs.c' is located under C:\DAVE-3.1.10\CMSIS\Infineon\Lib
Frankly speaking, I am unable to reproduce your problem. I'm not sure whether it is related to the memory usage, so i would like you to try this. Or you can try your code in DAVE v3.1.10 directly.

Best regards,
Sophia


Hi Sophia,

Sorry for the late answer, but now I finally got around to fix the update problem I had...
(For some reason all the update URL's under "Window | Preferences | Install/Update | Available Software Sites" were lost in my DAVE3 installation, so that's why I got the "there are no update sites to search" message I mentioned before, but after I imported the URL's from an installation on another computer I could perform the update via the "Help | Check for Updates" menu).

This is the versions I got after the update:
646.attach

At this stage in the update procedure I still got the exception, but then I applied the separate CMSIS patch (which wasn't included in "Check for Updates") and copied "startup_XMC4500.s",
"XMC4500.ld" and "System_LibcStubs.c" to their respective locations in my project, and - voilà - I don't get the exception any more!
(I must test with some more code to be 100% sure, but it looks like the problem is fixed now!)

Thank you for your help!

Best Regards,
/Mikael
0 Likes