Skip to main content
Graduate
February 6, 2024
Solved

STm32F401RE: FPU not working

  • February 6, 2024
  • 2 replies
  • 1453 views

Hi guys,

I really need your help.

I'm trying to divide two numbers.. But the result is still 0. Analyzind the disassembling the commands are not those of FPU unit. I enable the FPU in the  Properties/MCU Setting.

Here the simple code:


uint32_t A = __HAL_TIM_GET_CLOCKDIVISION(&htim3)+1; // result is 1

uint32_t B = HAL_RCC_GetPCLK2Freq(); // result is 84000000

float D = A/B; // result is 0

double E = A / B; // result is 0

long double F = A / B; // result is 0

double G = 1 / 5; // result is 0

uint32_t H = 10/3; // result is 3

double I = 10/3; // result is 3

FAJOL1_0-1707217206273.png

Any ideas

Thanks

    This topic has been closed for replies.
    Best answer by AScha.3

    Hi,

    You have to learn about C , not the cpu is the problem here.

    If you want float, you have to use float - or "tell" the compiler about your desire : casting .

    + double is not calculated in hardware, on F401 is just (single) float unit.

    try :

    float D = (float) A/B;

    float D = (float) A/ (float) B;

     

    read...ie:

    https://www.tutorialspoint.com/cprogramming/c_type_casting.htm

     

    2 replies

    AScha.3Answer
    Super User
    February 6, 2024

    Hi,

    You have to learn about C , not the cpu is the problem here.

    If you want float, you have to use float - or "tell" the compiler about your desire : casting .

    + double is not calculated in hardware, on F401 is just (single) float unit.

    try :

    float D = (float) A/B;

    float D = (float) A/ (float) B;

     

    read...ie:

    https://www.tutorialspoint.com/cprogramming/c_type_casting.htm

     

    FAJOL.1Author
    Graduate
    February 6, 2024

    Thanks

    Super User
    February 6, 2024

    Use this button to properly post source code:

    AndrewNeil_0-1707223572312.png

     

    To get that extra row of icons, press this button:

    AndrewNeil_1-1707223572335.png