Loading...
 

Zephyr project on STM32

   Zephyr Workbench, a VSCode extension to manage Zephyr on STM32.
It enables users to easily create, develop, and debug Zephyr applications.
Main features:
  • Install host dependencies.
  • Import toolchain and SDK.
  • Create, configure, build and manage apps.
  • Debug STM32.
You can directly download it from the VSCode marketplace
For more details, visit the Zephyr Workbench

System Workbench for STM32


FPU float in functions calls

Hello,

I recently started with OpenSTM32 to program my STM32F4 Discovery board. I’ve already programmed it under Windows with CooCox IDE. So I had some program examples to test under Linux and sw4stm32. But, I was surprised that one of them didn’t run correctly and hanged. After spending some time with the debugger, I noticed that the problem was due to float variable declaration and function call with float variables as parameters. The program went in an infinite loop.
First, I took a look at the compiler options in order to verify that the FPU was correctly set, and yes it was. Second, I searched on internet about this problem and found some ideas like changing float to double. So I did it but it wasn’t sufficient : the FPU was in fact not activated !

Here what the original code looks like :

factor(float, float);
int main(void)
{
float a = 10.0f, b = -1.5f;

while(1)
{
factor(a, b);
}
}



This code needs the corrections below to run correctly :

factor(double, double); // float -> double
int main(void)
{
// NOTE: Important: Enable full access to FPU:
SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2)); /* set CP10 and CP11 Full Access */

double a = 10.0f, b = -1.5f; // float -> double

while(1)
{
factor(a, b);
}
}

Another thing to do in factor() is to cast the double variable to float because there is a slowdown in the calculation using double. Why ? Does the FPU only compute float numbers in simple precision ?

So, can someone explain what’s the difference between my original program and the modified one ? Is it a normal behaviour of OpenSTM32 or GCC compiler ?
Thanks

After taking a look to the STM32F4 documentation redface, I can confirm that the FPU only supports float variables in simple precision. That explains the slowdown with double variables I had before. rolleyes. But what can explain the fact that it is impossible to use float vaiables as parameters in a function call ?

 

Newest Forum Posts

  1. Монтаж камина с грилем в Москве - установка и барбекю by KpddomErorb, 2025-05-10 18:28
  2. SPI on Nucleo_STMH533RE by royjamil, 2025-05-04 20:13
  3. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-25 07:37
  4. SPI on Nucleo_STMH533RE by royjamil, 2025-03-23 11:31
  5. SPI on Nucleo_STMH533RE by higginsa1, 2025-03-23 09:33
  6. Configuring DMA for ADC in SW? by sam.hodgson, 2025-03-04 12:58
  7. Build a project in "release" mode by info@creosrl.it, 2025-02-20 18:12
  8. Build a project in "release" mode by info@creosrl.it, 2025-02-20 17:05
  9. Build a project in "release" mode by tang, 2025-02-20 10:36
  10. Build a project in "release" mode by info@creosrl.it, 2025-02-19 17:35

Last-Modified Blogs