Difficulty linking in floating point functions

More
20 Jun 2016 16:40 #50863 by theseankelly
Hey Forum

I'm working on a protocol and adding some telemetry which requires floating point arithmetic to convert a VBat value. I'm taking an existing protocol (cflie, but it doesn't really matter which...) and I've added code to the effect of:
// Bytes 6, 7, 8, and 9 are the Vbat in float
float vBat;
memcpy(&vBat, &packet[5], sizeof(float));
Telemetry.value[TELEM_DSM_FLOG_VOLT1] = (s32)(vBat*10);
TELEMETRY_SetUpdated(TELEM_DSM_FLOG_VOLT1);

Which produces linker errors complaining about the floating point lib functions being used (mult, and float to int):
 + Compiling 'protocol/cflie_nrf24l01.c' as module
 + Building 'objs/devo7e/cflie_nrf24l01.bin'
objs/devo7e/cflie_nrf24l01.o_: In function `cflie_callback':
cflie_nrf24l01.c:(.text.cflie_callback+0x11a): undefined reference to `__aeabi_fmul'
cflie_nrf24l01.c:(.text.cflie_callback+0x11e): undefined reference to `__aeabi_f2iz'

I've spent a ton of time googling this sort of issue and best I can tell, it means I'm not linking in libgcc properly OR I need to be using gcc instead of ld for my linking (because apparently ld is notoriously bad at paths). However, no definitive solutions yet, and I've tried a variety of things. Converting the LD call to a CC call in the target/common/devo/Makefile.inc led me down a rabbit trail that I ultimately gave up on, but maybe that's the right way to go.

Anyway -- I imagine someone has got to have needed floats and tackled this problem before. Any ideas on the easiest solution -- preferably something that's portable and doesn't require a hard path to libgcc.a?

Thanks
Sean

Please Log in or Create an account to join the conversation.

More
20 Jun 2016 20:08 #50866 by theseankelly
Replied by theseankelly on topic Difficulty linking in floating point functions
Sure enough explicitly adding the path to libgcc.a works:
-L /usr/lib/gcc/arm-none-eabi/5.3.1/armv7-m/ -lgcc

But this doesn't really seem safe for a broad audience.

Please Log in or Create an account to join the conversation.

More
20 Jun 2016 22:30 #50880 by PhracturedBlue
Replied by PhracturedBlue on topic Difficulty linking in floating point functions
why do you need floating point? we do everything using integer code and that is what you should use as well. floating point is not well supported by the cortexM architecture, and should be avoided.

Please Log in or Create an account to join the conversation.

More
20 Jun 2016 22:34 #50881 by theseankelly
Replied by theseankelly on topic Difficulty linking in floating point functions
Perfect. I wasn't crazy about pulling in a whole lib just to multiply a float by 10, so this settles it.

As to why: The Crazyflie 2.0 exposes VBat as a float. It's trivial to extend the crazyflie F/W to expose a second telem variable for VBat in 1/10th volt units like other telemetry systems. Given your statement, it's a no brainer to go this route instead.

Thanks!

Please Log in or Create an account to join the conversation.

More
20 Jun 2016 22:40 - 20 Jun 2016 22:41 #50882 by PhracturedBlue
Replied by PhracturedBlue on topic Difficulty linking in floating point functions
I think there should already be routines that will convert a float to a int (i.e turn a float voltage into integer milli-volts), and if not, they're not hard to write. They may only work with BCD though.
Last edit: 20 Jun 2016 22:41 by PhracturedBlue.

Please Log in or Create an account to join the conversation.

Time to create page: 0.035 seconds
Powered by Kunena Forum