BrainFPV / TauLabs

http://www.brainfpv.com
Other
27 stars 9 forks source link

stack aligment issue with floating point print #39

Closed droney closed 8 years ago

droney commented 8 years ago

For all EABI ARM implementations, an eight byte stack alignment is required for floating point printf/sprintf calls. Please see https://wiki.debian.org/ArmEabiPort#Stack_alignment.

This alignment is performed when the USE_NEWLIB define is set in flight/PiOS/Common/printf2.c. Without setting this define, luck of the draw will decide which floating point prints display the correct value and which ones do not, depending on the arguments passed to printf/sprintf.

Unfortunately, printf2 alignment code is flawed and must be addressed in addition to enabling the define. Here is the code snip...

ifdef USE_NEWLIB

        char *cptr = (char *) varg ;  //lint !e740 !e826  convert to double pointer
        uint caddr = (uint) cptr ;
        if ((caddr & 0xF) != 0) {
           cptr += 4 ;
        }
        double *dblptr = (double *) cptr ;  //lint !e740 !e826  convert to double pointer

else

        double *dblptr = (double *) varg ;  //lint !e740 !e826  convert to double pointer

endif

Notice the argument pointer is adjusted if any of the lower four bits are set. The correct test to be performed should be 'if ((caddr & 0x4) != 0) {'.

Please update the printf file and add the define to be enabled in the brain make process. I will submit my osd_menu.c code which adds OSD altitudehold and vtol_pathfollower settings change capability if the brainfpv developers are interested.

droney commented 8 years ago

closing issue since pull request submitted