AnsweredAssumed Answered

Hard fault when calling sprintf with floating point numbers from .cpp file

Question asked by Daniel Hurowitz on Jan 16, 2018
Latest reply on Jan 16, 2018 by Erich Styger

Hi,

I have been having trouble using sprintf for floats. 

I read all of the posts I could find on the topic and failed to resolve the problem.

I am using KDS 3.2 with processor expert with a K26F processor.

 

The current state of my program is as follows:

when I call 

sprintf((char*)s,"Event;\t  %f\r\n ",1.5);

from main.c, It works fine.

The exact call from a .cpp file results in a hard fault. 

I have several other uses of sprintf with integers, without any problems. 

 

Please note that I have already tried the following (this is the current state of my project):

1. Enlarging the heap and stack.

2. In the cross ARM C++ Linker settings, I checked

"use float with nano printf (-u _printf_float)" and "use float with nano scanf (-u _scanf_float)"

3. In Cross ARM C Compiler Preprocessor definitions I defined "PRINTF_FLOAT_ENABLE=1"  and  "SCANF_FLOAT_ENABLE=1".

4. Called  the following after startup:

void vPortEnableVFP(void) {

 

/* The FPU enable bits are in the CPACR. */

 

__asm volatile (

 

" ldr.w r0, =0xE000ED88 \n" /* CAPCR, 0xE000ED88 */

 

" ldr r1, [r0] \n" /* read CAPR */

 

" orr r1, r1, #(0xf<<20) \n" /* Enable CP10 and CP11 coprocessors */

 

" str r1,[r0] \n" /* store to new value back */

 

: /* no output */

 

: /* no input */

 

: "r0","r1" /* clobber */

 

);

 

}

 

Do you have any further suggestions?

Thanks!

Outcomes