8 years, 10 months ago.

Setting the time from a 32 bit int causes CPU lockup

I'm attempting to simply set the time from a number, but when I do, the CPU locks up (a debug session stepping into set_time just freezes). The code I'm using is:

char *TmpPoint;
time_t NewTime = strtoul(&TempData[2], &TmpPoint, 10);
set_time(NewTime);

TempData is a char array { 'T', 'M', '1', '4', '5', '1', '3', '9', '6', '7', '7', '5', '\r', '\n' } which is correctly converted into 1451396775, so I can't see why such a simple operation would lock the CPU up. Using set_time() with a static number works fine. Any ideas/suggestions or is this CPU a write off?

Question relating to:

Affordable and flexible platform to ease prototyping using a STM32F401RET6 microcontroller.

What about the \r and \n are these being passed to set_time? I have had something similar, I could not see these on a printf.

posted by Paul Staron 29 Dec 2015

I would call it really unlikely that it would be a CPU writeof. Can you do printf on the NewTime var, if you didn't already do so, to see what is in it.

posted by Erik - 29 Dec 2015

I don't think it's caused by a stray \r or \n, neither can be represented in an int and strtoul() stops at the first non-valid number it finds, http://linux.die.net/man/3/strtoul : 'The remainder of the string is converted to an unsigned long int value in the obvious manner, stopping at the first character which is not a valid digit in the given base.'

I printed out the number both using printf and using print from gdb, both displayed just the (valid) number and no newline characters.

posted by Bob Seque 30 Dec 2015
Be the first to answer this question.