BrainFPV / TauLabs

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

stack aligment issue for floating point prints #40

Open droney opened 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) {'.

(I attempted to perform a pull request to brainfpv, but it wound up in the taulabs base. Attached is the corrected printf2.c file.) printf2.zip