Issue with sprintf in STR9 IAR project

soufien
2013-01-24
2013-09-16
  • soufien
    soufien
    2013-01-24

    I have an issue where sprintf sometimes printing an unexpected string. The call: sprintf(str_my_string, "%#.1f", 0.0); is made from inside a function called from a task. Most of the time, the expected string is printed (0.0) and it only occurs every minute or two. This issue started occurring after adding the FreeRTos to our existing project and has never happened before. What might cause this issue? How should I go about troubleshooting this?
    Thanks for you help

     
  • soufien
    soufien
    2013-01-25

    I did some more troubleshooting and found that it only occurs when I have a 1ms timer interrupt enabled and that if I let the same code run in a while loop, it happens so often (seems to be more than 2 times a second). Then, I switched from the version that we are using V5.0.2 to the newer version V7.3.0 and it works fine so far.
    I am still not sure what caused the issue but I am starting to think that it has to do with saving and restoring the context although the save/restore context assembly macros of the two versions are the same.
    I am still concerned that somehow the new version is masking other problems somewhere else.
    I will keep working on it.

     
  • soufien
    soufien
    2013-01-25

    Problem solved!!! It was caused by a bug in version V5.0.2 that was not handling memory alignment properly in xCreateTask function. Version V7.3.0 works.
    V5.0.2 create task function does this:
    pxTopOfStack = pxNewTCB->pxStack + ( usStackDepth - ( unsigned short ) 1 );
    It should also do this:
    pxTopOfStack = ( portSTACK_TYPE * ) ( ( ( portPOINTER_SIZE_TYPE ) pxTopOfStack ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK  ) );