cancel
Showing results for 
Search instead for 
Did you mean: 

stm32 rand() problem

lucabe90
Associate II
Posted on August 24, 2012 at 16:23

hi 

i have a problem with the stm32w  mb851a 

i would generate a random number. i have try to use the function rand() and I include header file

but when i execute the program it jump at 

void __attribute__ ((weak)) Default_Handler()

{

               

/* Hang here */

               

while(1)

               

{

               

}

}

why?

this is my include files

#include PLATFORM_HEADER

#include BOARD_HEADER

#include ''hal/hal.h''

#include ''hal/micro/cortexm3/uart.h''

#include ''hal/micro/micro-common.h''

#include ''hal/micro/cortexm3/micro-common.h''

#include ''include/phy-library.h''

#include ''hal/error.h''

#include <stdio.h>

#include <stdlib.h>

#include ''hal/micro/temperature_sensor.h''

#include <time.h>

#include <math.h>

...

int main()

{

int a=0;

.....

   a=rand();

....

}
7 REPLIES 7
Posted on August 24, 2012 at 17:43

With WHAT compiler/toolchain?

Most likely cause of a Hard Fault is that you have linked a library with ARM 32-bit code, which doesn't run on the Cortex-M3

Use your debugger to look at the faulting instruction, and perhaps use a fault handler that can decode the condition, rather than a while(1) loop. Joseph Yiu has published a book, and web examples of such.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
lucabe90
Associate II
Posted on August 24, 2012 at 19:58

thanks for the answer

i use atollic 3.0. 

when i use a debugger i can't see the exectly point when the code jump in the default heandler because when i try to step into the function the execution jump in the default heandler. i search on internet and i think the problem could be that i haven't link the stdlib with the compiler but i haven't idea to resolve that. how can do?

thanks

Luca

Andrew Neil
Chief III
Posted on August 24, 2012 at 20:12

 

 

''i would generate a random number''

Remember that rand() does not generate true random numbers - just pseudo-random...

Andrew Neil
Chief III
Posted on August 24, 2012 at 20:14

Stupid forum insists on hiding text as ''quoted message''

 

 

''i would generate a random number''

Remember that rand() does not generate true random numbers - just pseudo-random...

lucabe90
Associate II
Posted on August 24, 2012 at 20:27

yes i need a pseudo-random number

thanks for the detail

alaa_06
Associate
Posted on February 09, 2013 at 04:00

what this problem ???

It appears unrelated to this thread. That BOARD_HEADER isn't resolving to a quoted file name in the preprocessor?
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..