Hello,
I am writing a program with using RTX. I want to convert ascii buffer into a float using atof in a task. But this function works unreliable, program hang. If I try to debug this situation with jtag, problem never happen. I have replaced atof to atoi and then program start working, but I need some solution for converting string to float.
microcontroller - ARM7, LPC2368 Keil - 3.80
May someone give me an idea?
It's possible that you allocated too little stack space for the task and atof() overflows your stack. It could be something else entirely, of course.
But this function works unreliable, program hang
the only thing unreliable here is your program. it sounds like you did not spend enough time to determine the cause (and effects!) of your problem. nobody can help you without more information.
I have replaced atof to atoi and then program start working, but I need some solution for converting string to float.
Just wanted to clarify. Most likely, abandoning atof() will not eliminate the bug. It will just remove this particular trigger of the underlying bug. The bug could still be triggered by something else, like a rare, hard to reproduce event. That would make it far more difficult to debug. You are lucky to have an easily reproducible bug. As Tamir suggested, you should spend some time collecting information about the problem. Debugging, basically... So far, the problem description is too vague to give much useful advice.
Thanks Mike Kleshov, with the big stack it works. My problem is that I do not know how to estimate stack size.
I like the following way of measuring stack utilization. In your startup code, fill the stack space with a known pattern (like 0xDEADBEEF or whatever.) With the in-circuit debugger attached, run your application, try to induce maximum stack usage. After a while, stop the application and inspect stack space in the memory window of the debugger. This will give you the exact stack space requirement for this application run. The maximum theoretical stack space requirement will likely be greater, of course. Some compilers can estimate that, by the way. Nevertheless, it's a direct measurement.