STM32F4. Read data from UART. ERROR: Out of Memory! #290
Replies: 9 comments
-
Posted at 2014-07-11 by user7265 Error:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-11 by @gfwilliams Ok, first check that you're using the latest version... Version 1v65 had a memory leak when receiving from Serial ports. And then, you should switch from using arrays to using a single string that you append.... Instead of Arrays in JavaScript are sparse, so each element has to store both the index and the value. In your case, it could be that for every character you are storing the index and a string, which will eat up the memory very quickly. It's much better to put all your information into one string - see http://www.espruino.com/Performance for more info. The reason it works at higher baud rates is that |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-11 by user7265 SUCCESS (9600 baudrate) ERROR (9600 baudrate) SUCCESS (115200 baudrate) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-11 by user7265 Thank you for answer! Be sure to tell about the results. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-11 by DrAzzy I think I see the problem - you're setting a timeout to read back the data EVERY TIME you read from the serial port, so you end up with a crapload of timeouts. The number of reads you get before it dies at 9600 baud is (based on a quick estimate) consistent with storing the data (in a simple array, so it wastes tons of memory) AND creating a timeout for every byte. The solution is to only set the timeout once.
For better memory usage, something like this would be a good start - by not creating the array and just building the string as it comes.
Also, if you want it to work when running from flash, you might have to put the Serial2.on(...); inside an onInit() function. I don't recall whether Espruino will remember callbacks like that on save() or whether you need to set them in onInit(). (Note: My code is untested, might have typo/etc in it. Edit: just fixed one of them) Edit: Even when it's "successful" in the case you've shown above, it looks like it's leaking oodles of memory.... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-14 by user7265 DrAzzy thank you. The problem is really in incorrect use of setTimeout. This function was spending a lot of memory, because i often called this. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-15 by user7265 Gordon can you explain why object setTimeout spend a lot of memory? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-15 by @gfwilliams You can probably see by typing That needs the function code itself (which is copied each time because it was defined inside the function), as well as the scope in which the function was originally defined. But either way I imagine you had lots of timeouts queued up. It's the kind of thing that would be really bad news even on a PC with loads of memory - it just becomes more of a problem more quickly on a constrained device. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2014-07-15 by user7265 Thank you very much for the detailed explanation. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2014-07-11 by user7265
Hi, Gordon, Hi all!
Working with the board STM32F4.
I have a problem when I try to transfer file from PC to UART (pins PA2, PA3).
If the file size small (less 200 bytes) all is well.
If the file size a bit more, then sometimes console shows the error memory.
If the file size like 2000 bytes, then always console shows the error memory.
I try change baudrate of UART from 9600 to 115200, and have a successful file transfer size in 2 528 bytes. But after a few hours situation with the problem persists.
STM32F4 has a lot of memory. Why this error occurs?
My project:
My File:
{
"crosstime": {
"1": [
1,
10,
3,
3
],
"2": [
1,
10,
3,
3
],
"3": [
1,
20,
3,
1
]
},
"racks": {
"1": {
"1": 1,
"2": 1,
"3": 0,
"4": 0,
"5": 5,
"6": 5
},
"2": {
"1": 2,
"2": 2,
"3": 0,
"4": 0,
"5": 5,
"6": 5
},
"3": {
"1": 1,
"2": 1,
"3": 0,
"4": 0,
"5": 5,
"6": 5
},
"4": {
"1": 2,
"2": 2,
"3": 0,
"4": 0,
"5": 5,
"6": 5
}
},
"groups": {
"1": {
"1": [
1,
3,
4,
5
],
"2": [
2,
2,
2,
2
],
"3": [
2,
2,
2,
2
]
},
"2": {
"1": [
2,
2,
2,
2
],
"2": [
1,
3,
4,
5
],
"3": [
2,
2,
2,
2
]
},
"3": {
"1": [
2,
2,
2,
2
],
"2": [
2,
2,
2,
2
],
"3": [
2,
3,
4,
2
]
}
},
"desc": {
"note": "\u041f\u0440\u043e\u0441\u0442\u0435\u0439\u0448\u0438\u0439 \u0441\u0432\u0435\u0442\u043e\u0444\u043e\u0440 \u0438\u0437 3 \u0433\u0440\u0443\u043f\u043f \u0438 3 \u0444\u0430\u0437.",
"phases": "3",
"name": "\u0422\u0435\u0441\u0442",
"groups": "3",
"addr": "\u0421\u0442\u0435\u043d\u0434"
}
}
Beta Was this translation helpful? Give feedback.
All reactions