-
Notifications
You must be signed in to change notification settings - Fork 13.3k
sqrt() causing reboot #233
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Make sure val1*val1 doesnt return a negative. |
sqrt really doesn't work with the current version of toolchain. |
@chadouming when you multiply two negative values, the result is positive. Therefore, there is no way of multiplications are negative. @igrr How can I use this change? |
I know basic law of maths :P I saw strange things happen on esp8266 so this https://github.com/chadouming/hardware/commit/f1db56c4f97d1876d4311cd20ea5b5522cc47cfb On Wed, May 13, 2015, 12:16 Leandro Gomes [email protected] wrote:
|
@chadouming sorry if I was rude :| I'll take a look at your link... |
I have updated the toolchain yesterday but unfortunately the issue is not fixed. |
Meanwhile, you could try pow(value,0.5). Ugly hack, but it could work. |
Something weird just happened... I made a scketch from zero, and it worked. But on my original project it continues rebooting ESP8266
|
Compiler optimized away that sqrt call because the argument is a constant.
|
I'm not sure how the sqrt function is implemented but I replaced my calls to it with: #define sqrt(x) exp(log(x) / 2.f) and the call still hung causing the watchdog timer to end and reboot the chip. I then tested calls to exp(x) and log(x) separately with the same result. Hopefully this information assists the debugging effort. |
+1 |
Any news? Just ran into the same issue. Interestingly, I can do a sqrt in the setup but it fails in the loop. See https://github.com/tomn46037/SQRTTesting I also had it crash when I tried to to an atan2. |
Same here just using the log(x) function... |
Any progress related to this issue? @igrr, please tell me where I can start looking to help you guys. |
No progress here (working on other issues). |
I just tested by replacing the libm.a file from NodeMCU with the one in: Arduino\hardware\esp8266com\esp8266\tools\windows\xtensa-lx106-elf\xtensa-lx106-elf\lib There was no difference in the behavior and the ESP locked and then reset itself. I noticed that the libm.a file for linux and windows are very different sizes (about 1 meg). Not sure if that is an issue, just something I saw. I did not see a libhal.a in NodeMCU. Can someone run this test but in Linux? I don't have access to that development environment at the moment. |
I can't read the assembler from objdump -S so not much help there. However it looks to me like the implementation of sqrt(), log(), etc. are iterative algorithms. I am wondering if the watchdog times out before the function returns and causes the reset. I did find a separate implementation of a square root algorithm. I wrote up a quick sketch with it and it provides results without crashing the ESP:
Does anyone have something like this for log()? :) |
I'm also stuck since all the math libs stopped working. There are many basic functions and algorithms that make use of that lib (graphics, servo , stepper, pid, etc). As a fast patch, embedding an adhoc function might work, but I don't think is a good idea for long term for such basic need. |
the math libs are from the compiler and not from the SDK. #include <Arduino.h>
#define DEBUG_SERIAL Serial1
void setup() {
DEBUG_SERIAL.begin(115200);
DEBUG_SERIAL.println();
DEBUG_SERIAL.println();
DEBUG_SERIAL.println();
DEBUG_SERIAL.print("[SETUP] Reset Info: ");
DEBUG_SERIAL.println(ESP.getResetInfo());
delay(100);
}
void loop() {
DEBUG_SERIAL.println("[LOOP] sqrt:");
DEBUG_SERIAL.flush();
double test = sqrt(random(100));
DEBUG_SERIAL.println(test);
} not even the reset info is filled. |
@Links2004 According to your point, then the problem is related to device overhead with other tasks? If not, seems that the only way to go are the adhoc solutions. Other optimizations: any function using precomputed tables https://forums.adafruit.com/viewtopic.php?f=25&t=62598 @quezadaminter this should help .. but other option |
Fixed in the esp8266 branch. |
@igrr I just tested it and ESP keeps rebooting. |
could you please share your sketch? with the latest version in the esp8266 On Fri, Jun 19, 2015, 22:09 Leandro Gomes [email protected] wrote:
|
I noticed this version only uploads my sketch. Maybe I'm using an old firmware... |
Are you building the IDE from git, or using a boards manager package? In On Sun, Jun 21, 2015, 13:53 Leandro Gomes [email protected] wrote:
|
@igrr I am trying to build the IDE from the esp8266 branch but it fails when running the checksum for win32-xtensa-lx106-elf-gb404fb9.tgz. The file downloads and opens in winzip ok but fails the checksum in ant. Any chance you forgot to update this value in the build file in the esp8266 branch? UPDATE: The checksum is now fine. Seems like a bad download on my part but now I get this error when untaring the archive:
UPDATE 2: I was able to bypass the above issue by copying the directories manually from dist to work and commenting out the section of the build file to skip this target and continue. Now I have a zip of the arduino-1.6.5 IDE built. Ready to test. |
Good news! The log() function is working and so is the sqrtf() function. However the sqrt() function does not link and fails with the following error:
However the compiler optimization does seem to find it as the following sketch builds and runs successfully when calling sqrt() with a constant:
I ran out of time before I could test other functions, such as the trig and exp() calls. Can someone else try those? Else I'll try them later this week. @igrr Thanks! |
The remaining issue is that on Windows, libm.a was not built with those functions enabled. I will update the windows toolchain to fix this. |
Sounds good. I look forward to the update. Will you be meging these changes into the SDK branch? |
sdk-1.0 branch will just be removed because sdk 1.1 is stable enough now. |
Where is sdk 1.1 located? Is it the esp8266 branch? |
@nicjohnston yes, esp8266 branch is currently on 1.1.something. |
Thanks. |
Is there any way to upload a new SDK using IDE? I'm building it from git source and only my sketch is been uploaded to the board. |
This issue appears to be fixed when building on Linux (Ubuntu 14.04). |
the sdk is part of the sketch upload. |
the log() function seems to be still causing the wdt reset issue on OS X build 1.6.6 |
I have those three values
-83.00 | -181.00 | -243.00
and i'm trying to do this:Every time my code reach this line, ESP8266 reboots...
The text was updated successfully, but these errors were encountered: