Hello Look at this code if i replace 1024 in array with more than 2048 compiler work fine but micro hang !! program work fine with 1024 or less. i use at91sam7x256 this have 64KB Ram. if i replace char with int then more than 256 have the same problem.
#include <at91sam7x256.h>
int main (void){
char buf[1024]="Hello World";
*AT91C_PMC_PCER = (1<<AT91C_ID_PIOB); *AT91C_PIOB_PER = (1 << 0) | (1 << 1); *AT91C_PIOB_OER = (1 << 0) | (1 << 1); *AT91C_PIOB_SODR = (1 << 1); *AT91C_PIOB_CODR = (1 << 0);
return 0;
}
.....is on the stack, as it is a local. Check stack size.
How well do you know C?
You have a local variable inside main(). This is called an auto variable, and it is stored on the stack. It doesn't matter how large RAM your processor has - a more interesting question is how large stack _you_ have configured.
Now, would you please tell us one more time why you think this is a Keil bug?
Another thing - also related to my original question: What do you think happen when main() ends? Do you think your processor will get back to a graphical desktop? Or to a command line prompt? What is the most important differences between writing a program for an embedded target, and writing a program for a PC?
thanks for your fast replay i used assembly before but i define this variable global too but nothing different. how can i solve this problem. can you tell me whats happen when program end ? how can define stack in c and keil compiler and all register that i define is on stack right! and stack is part of ram thats start from end so how much ram i can use?
hello to every one you right thats my bug not keil i found where can i change stack and after that my program work fine. excuse me for this mistake but can you told me how much stack that i can define without problem? if i increase this stack which problems occurs?
Thank you
You can consume almost all your memory as stack. But for embedded, you normall try to keep down the stack needs.
The stack is for varibles you only need a limited time. Local variables that can be thrown away when a function ends. Variables that you need for the full lifetime of the application, you would make global, i.e. place outside of your functions.
What happens when the program ends? Simple - your program should not end. You should create an infinite loop inside main(). The only time you would want a program to end, is if you want to force a reboot (often done by requesting a watchdog reset), or if the device is running on batteries, in which case you often design your equipment so that the microcontroller can request the battery to be disconnected (which would require the user to press a button to reconnect the battery again)
www.catb.org/.../smart-questions.html