We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
hello
I write program in one kind of RTOS. But some times all the data in RAM are corrupt since I add some code
in functions, if continue add some code in the function, the data in RAM is OK.
Does MDK assign memory for local data since compile in stack? I know stack is first in last out, is it suitable to pass a local pointer to a function as argument like the following code?
TASK(TASK_1) { UIP_UCHAR appBuf[APP_MSG_SIZE]; while(1) { if(WaitEvent(APP_EVENT_TASK_1) == E_OK) { ClearEvent(APP_EVENT_TASK_1); ReceiveMessage(MSG_ID_1, &appBuf[0]); UIP_writeSdo(0x80,appBuf); test1++; } } }
Yes, virtually every 'C' compiler puts automatic variables on the stack.
Sure, you can have a pointer to an auto variable - but you have to be certain that it will only ever be used while it remains valid.
Once the function where the auto variable was defined returns, the pointer will no longer be valid.
Google "lifetime" of variables in 'C' ...
I found that my code cause data in RAM corrupted during startup. I know CORTEX-M3 could copy RW DATA and ZI data from flash to RAM ,it means my code in thread has damage this procedure, I want inquire to how data in flash copy to RAM?
JackShan said:it means my code in thread has damage this procedure
No, it most certainly doesn't mean that, because that procedure has finished long before any code in your thread gets executed. What can happen is if you overflow the stack wildly enough, your code may overwrite any variable of the entire program. Which is why you really have to take care not to do that. Ever.
hello broeker
I operate like the following procedure, open debugger window and then click next step. I found the data has been modified before enter main function. so I suspect my code influnce the procedure that CORTEX-M3 copy data from flash to RAM, I do not know much about that, so I want to inquire you that.
does the data copy from FALSH to RAM by linker? I think my code has impact on linker