0

I have a problem with using log from math.h library on stm32f411ret6. when i pass a value normally to log eg.

double var = log(2.0); 

than i get 0.69314718056 in var. When i pass a value using variable than stm32 go to HardFault_Handler eq.

double var1 = 2.0;
double var2 = log(var1);

My code.

#include "main.h"

int main(void)
{


    double val = 2.0;
    double cos = log(2.0);
    double result = log((double)val);
    Board_Init();

    for(;;);
}

same problem even for custom function that calculate log.

int main(void)
{


    double val = 2.0;
    double cos = log(2.0);
//  double result = log((double)val);
    double result = Math_Log(2.0, 2.7182);
    Board_Init();

    for(;;);
}

double Math_Log(double number , double base)
{
    double low = 0, high = number;
    double epsilon = 0.000001;
    while (high - low > epsilon) {
        double mid = (low + high) / 2;
        double power = 1;
        for (int i = 0; i < mid; ++i) {
            power *= base;
        }
        if (power < number) {
            low = mid;
        } else {
            high = mid;
        }
    }
    return low;
}

I use stm32cubeIDE and i have marked option "Use C math library"

It would be nice to know what is causing this problem

1 Answer 1

0

I got it. The problem was with access privileges for coprocessors. fix:

SCB->CPACR |= 0x0F << 20;

Add this in start of main;

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.