cancel
Showing results for 
Search instead for 
Did you mean: 

STm32F401RE: FPU not working

FAJOL.1
Associate II

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

1 ACCEPTED SOLUTION

Accepted Solutions
AScha.3
Chief II

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

 

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

3 REPLIES 3
AScha.3
Chief II

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

 

If you feel a post has answered your question, please click "Accept as Solution".
Andrew Neil
Evangelist III

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

Thanks