Adjusting variables when building custom firmware #3412
Replies: 12 comments
-
Posted at 2020-07-28 by parasquid Hm I might be conflating RAM and Flash here. I'm guessing that variables would be related to RAM and the firmware size would be related to Flash. And I'm guessing if I can somehow get the constants in that library be a lookup table located in storage, I should be able to free up more memory for actual code. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by @gfwilliams Ahh - yes, so you can remove libraries and then adjust the I've just taken a look at that module and there's a load of room for improvement (for instance it stores the data in RAM even though it's only used on initialisation). So, I made some changes. I don't have one here to test with so haven't made it live yet, but please could you try:
Then ensure that module minification is on (the default) and that you're saving to flash. The minified file is down from 11k to 7k and RAM usage should be down massively. If that works I'll make the modified file live on the website. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid Ah the heatshrink technique is nice! :) I'm still getting memory issues though.
and that's with the minification options Esprima(offline) for both modules and editor. Enabling mangling gives me:
and turning on pretokenise:
I'll try playing around with the closure minifiers as well |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid Here's the code I'm using btw (the same as in the docs, just the I2C options and trigger changed)
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid closure with simple optimizations gives
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid setting both editor and module to closure simple optimizations works!
I guess it just barely gets it. However, I'm planning to use this to stream accelerometer data over BLE so I'm afraid even if the example works, adding more of my own code might take me over the memory limit :( I'll see what I can do in the meantime :) Thanks! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid I might have spoken too soon; closing and then reopening the Espruino editor gives me a memory error again:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by @gfwilliams Ahh - can you check "Modules uploaded as functions" is checked under communication settings, and that you're definitely uploading to flash? I just uploaded your code to a Pixl here and it went fine (up to the point that I2C failed because I didn't have an MPU6050 attached) with only ~900 vars used. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid Strangely, trying to upload the code again after the memory problem works. I guess I'll work with this for now :) |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid Ah I was uploading to RAM. Uploading to flash works :) (I didn't upload to flash because I had to reset the Pixl when the memory issues came up during upload) And yeah, modules uploaded as functions is checked. The module seems to be working, and is quite performant :) Thanks again for the help! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by @gfwilliams No problem. Can you try moving back to the website modules now?
I also found out that the MPU6050 module wasn't minifying quite right, so now it should be a bit faster and use a bit less space too! |
Beta Was this translation helpful? Give feedback.
-
Posted at 2020-07-28 by parasquid Works well! :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2020-07-28 by parasquid
I'm trying to get https://www.espruino.com/MPU6050 working on my Pixl.js and I'm running into memory issues when doing the MPU6050_DMP example. Looking at https://www.espruino.com/modules/MPU6050_DMP.js and the minified version https://www.espruino.com/modules/MPU6050_DMP.min.js it seems that I'll need to cut down on the unnecessary libraries included in the firmware.
I've removed many of the libraries and only left BLUETOOTH and PIXLJS and have reduced the size of the DFU zip to just 312k but it looks like I also would need to adjust the
variables
section to actually make use of the freed space.How do I calculate the actual amount of variables I can set?
process.memory()
gives me this:so does that mean 524288 - 446464 = 77824 variables I can use for the
variables
section? (it was originally set to 2500) or should I just do a trial and error to find the thresholds?Beta Was this translation helpful? Give feedback.
All reactions