This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

compatible floating point flags for library built with GCC and used in Keil (nRF52)

I'm using the nRF52832 +SDK11.0.0 +s132. I am making a making a library with floating point calculations and compiling it with GCC. A couple of test functions are:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#define NUMAPPLES 25
float getNumApples(void)
{
return (float)NUMAPPLES;
}
float testFunc2(void) {
return roundf(25.0f / (float)NUMAPPLES);
}
float testFunc3(void) {
return roundf(25.0f / getNumApples());
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I noticed that enabling the floating hardware in uVision/Keil sets --cpu=Cortex-M4.fp. I see that Cortex-M4.fp defaults to vfpv4-spvfpv4_sp_d16 from here. In a newer version of the doc, I only see Cortex-M4 or Cortex-M4.fp.sp listed. Cortex-M4.fp.sp defaults to FPv4-SP.

If I use the compile flags -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=soft in GCC and disable floating point hardware in uVision/Keil, then both functions give the correct value when calling them.

If I use the compile flags -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=softfp in GCC, and enable the floating point hardware and explicitly use "--fpu=softvfp+fpv4-sp" in uVision/Keil, then both functions give the correct value when calling them.

If I use the compile flags -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard in GCC, and enable floating point hardware and explicitly use "--fpu=fpv4-sp" or do not set the --fpu option explicitly in uVision/Keil, then I get an incorrect result from testFunc3 but testFunc2 gives the correct result.

How can I get the "hard" option to work?

Parents
  • Hello,

    Just to be clear, are you trying to import a GCC project to Keil, or do you use them separately? The reason I ask is that I don't understand why you use both the GCC compile flags and the uVision/Keil?

    If you are trying to import a GCC project to Keil, you have to be careful with the different types. Keil and GCC uses different sizes. Please check out this link:

    https://answers.launchpad.net/gcc-arm-embedded/+question/249073

    Best regards,

    Edvin

Reply
  • Hello,

    Just to be clear, are you trying to import a GCC project to Keil, or do you use them separately? The reason I ask is that I don't understand why you use both the GCC compile flags and the uVision/Keil?

    If you are trying to import a GCC project to Keil, you have to be careful with the different types. Keil and GCC uses different sizes. Please check out this link:

    https://answers.launchpad.net/gcc-arm-embedded/+question/249073

    Best regards,

    Edvin

Children
  • I have a library with floating point operations that was complied in GCC. I am trying to link it into my Keil project, but the floating point operations give bad results. Hence I am attempting to debug this issue by compiling some simple test functions into a GCC static library and linking that into my Keil project.

    Thanks for the link; it seems to be a similar issue to mine, but there wasn't a solution posted there. I have fixed the --wchar difference as described here, so that is not the issue.

  • Do you get any warnings when you compile your project? Please check if you run "rebuild all targets" to see if there are any warnings. Some compilers tend to strip away warnings if there weren't any changes in the file since the last compile. 

  • No, I don't get any warnings either from GCC or Keil. Attached is the source and Makefile for the GCC library. Would you kindly be able to compile in GCC and link to a nRF52 app using Keil (my Keil project is based on SDK11.0.0 + s132, + ble_app_hrs example)? Thanks

    floatTest.7z