gmtime() function is frozing after PSoC Creator 3.1 upgrade

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Is somebody else having problem with the gmtime() function after the PSoC Creator 3.1 upgrade? The code below is not completing as the gmtime() function is never returning. It used to work fine before the update...

   
#include <project.h> #include <time.h>  /*!  * Starts the Application.  */  int main() {     time_t seconds = 1420663532;     struct tm *ts = gmtime(&seconds);      return 0; }  
0 Likes
8 Replies
JeCo_264681
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

It is always difficult to answer a question unless we see your whole project. Do a File >> Create Workspace Bundle >>
and attach the zip file.

   

Of course, it is also helpful to strip out non-relevant parts of the project. And we do understand that you do not want to share proprietary code.

   

Also, share what platform you are using PSoC 3 or PSoC5.

   

kind regards,

   

Jerry
 

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Another question: how do you determine that the function doesn't return? There is no effective code after its call, so you might just run into the debugger not showing the next step. Try to do something meaningful afterwards (e.g. toggling a LED).

0 Likes
Anonymous
Not applicable

 More info about the problem:

   

I had the gmtime() call running in some place deep in my code. Using the debug I was able to determine that when the function was not returning. Actually, it got stuck into a call to a internal function called the mktm_r(). The code I sent is not my real code, its just to illustrate the problem. If you create a PSoC5 project and put that code in the main(), the issue will happen all the same.

   

Anyway, to anyone who is having the same problem, I've found a workaround. You just have to change the gmtime() function to the gmtime_r() function like the code below:

   
#include <project.h> #include <time.h>  /*!  * Starts the Application.  */  int main() {     time_t seconds = 1420663532;     struct tm ts;     gmtime_r(&seconds, &ts);      return 0;} 
0 Likes
JeCo_264681
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

 Thank you for sharing your solution. That's what this forum is about. Sharing our knowledge. I learned something from you.

0 Likes
JeCo_264681
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

@hli, Could he have used the debugger's Step Into instead of Step Over to get inside the function? I did not actually try this code but I find that when I use (other projects) the Step Into or the equivalent function key, I can see what's going on inside the function.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

Since the gmtime function is just available from a library, there is no source code available. So you cannot step into it while using the C code, you would need to step through the assembler code.

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

One change in Creator 3.1 that might cause this is the reduction of the default heap size. It was mentioned in another thread that the reduction from 256 to 128 bytes caused problems with printf().

   

Since gmtime() uses a shared memory structure, maybe its allocating heap memory on the first call? gmtime_r uses memory provided by the caller, so in your code thats memory from the stack. You can try to increase the heap and see whether it works now.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Additionally you could check where the program freezes. There is an infinite loop executed when any severe error occurs. Run the program and then stop execution in debugger. Have a look at the code and the call stack.

   

 

   

Bob

0 Likes