This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

RTX error using sprintf

At the moment we are using C51 + a realtime CMX kernel.
We are evaluating the ARM platform and are looking how this new platform reacts to parts our existing (little modified) programs in therms of code size and speed.
We modified a little existing CMX program to transmit a string.

With our first atempt we already run into trouble.

Problem is unknown amount of stack for sprintf with vars without warning.
Next example has 3 parts.
1st part runs fine.
2nd part seems to run fine (but at the moment it looks like it corrupts the stack)
3nd part crashes as soon as os_tsk_self(); is called from within SendBlockTimed(,,)
crash result => os_error (with err_code=1)
How can this happen (al vars are int)?

for (Counter = 0; Counter <250; Counter++)
{
   NumChars = sprintf(ConsoleBuffer, "Console. 00000");
   if (NumChars == 14)
   {
      OK_Count++;
      SendBlockTimed(ConsoleBuffer, strlen(ConsoleBuffer), CONSOLE_SEND_TIMEOUT);
   }
   else
   {
      Error_Count++;
   }
}
for (Counter = 0; Counter <250; Counter++)
{
   NumChars = sprintf(ConsoleBuffer, "Console. %05u",Counter);
   if (NumChars == 14)
   {
      OK_Count++;
   }
   else
   {
     Error_Count++;
   }
}
for (Counter = 0; Counter <250; Counter++)
{
   NumChars = sprintf(ConsoleBuffer, "Console. %05u",Counter);
   if (NumChars == 14)
   {
      OK_Count++;
      SendBlockTimed(ConsoleBuffer, strlen(ConsoleBuffer), CONSOLE_SEND_TIMEOUT);
   }
   else
   {
      Error_Count++;
   }
}

.

Parents
  • All is clear after reading the reply of Per Westermark

    One way or another i mixed two things up (allocating memory an stack usage).
    I thougth the sprintf() routine allocated memory and corrupted stack and memory beacause of that and didn't free up all memory on exit, making the next part of the program crash.

    But the answer is very simple it's stack usage and a stack must always be large enough.
    This was the same on a 8051 platform and will be the same on an ARM platform
    We did all the calculation and testing for routines on the 8051 and "just" forgot and didn't think about it on the ARM.

    Now we can continue to evaluate the controller with development platform.

Reply
  • All is clear after reading the reply of Per Westermark

    One way or another i mixed two things up (allocating memory an stack usage).
    I thougth the sprintf() routine allocated memory and corrupted stack and memory beacause of that and didn't free up all memory on exit, making the next part of the program crash.

    But the answer is very simple it's stack usage and a stack must always be large enough.
    This was the same on a 8051 platform and will be the same on an ARM platform
    We did all the calculation and testing for routines on the 8051 and "just" forgot and didn't think about it on the ARM.

    Now we can continue to evaluate the controller with development platform.

Children
No data