nrf51288-DK storage #7308
Replies: 1 comment
-
Posted at 2019-04-12 by @fanoush nrf51288 has only 256KB of flash (and no EEPROM) so even the Espruino build had to be cut down on features so Flash and Storage modules are not present. See e.g. https://www.espruino.com/Reference#Storage "Note: This is not available in devices with low flash memory" I'd suggest to get nRF52832 for Espruino instead, it is better and not that much expensive, there are e.g very cheap <$5 nrf52 modules on aliexpress (like this one posibly with this adapter) . Or the DS-D6 smartwatch is currently $6.99 on gearbest and you also get battery+charger and display with the nrf52 chip :-) So IMO there in no reason to get nrf51 today if you target Espruino unless your needs are very, very basic. Arduino might be better fit for nrf51. Posted at 2019-04-12 by @gfwilliams Hi, You mean the nRF51822? That's not quite the way you'd use storage. You could try:
But I just checked and the 51822 build doesn't have it in, since it's got You could modify NRF51822.py to remove the debugger and tab complete, then edit Posted at 2019-04-12 by @fanoush Well, if you fit Flash/Storage code in like this, it is still a question if there is enough spare flash pages to actually use it. Adding cheap SPI flash might be a solution however Flash module may not support it? There was some conversation here http://forum.espruino.com/conversations/269195/ but I don't see it in list of current modules. Or i2c/spi eeproms might do, these are supported http://www.espruino.com/AT24 http://www.espruino.com/AT25 . Posted at 2019-04-13 by Vlad Thank you guys for your answers. I've got a bunch of those nrf51822 boards that I want to make use of to build some very basic sensors, e.g. water meter, pir, temperature, humidity etc. Effectively, scripts are going to be very basic and small in size, however I need to store a number, e.g. rotation count etc, this is just a small number to back up readings in case of any power outages. This is an experimental project as a part of Eclipse SmartHome/OpenHab Bluetooth binding and Java Bluetooth Manager development. I will definitely try to enable Flash module first, if this fails, I'll get some nrf52 boards. Or maybe someone has a better idea on how to store a small number/variable? Posted at 2019-04-13 by Vlad Hi @gfwilliams, thanks for your suggestion to comment out
This prints:
It seems to me 3072 bytes is more than enough for storing some basic backup data. BTW, could you please let me know what are these Posted at 2019-04-13 by @fanoush You also need some Storage space for your javascript code if you need it permanetly stored to run after poweron, this is saved into same space. Tab complete is used in interactive console to complete object methods/properties when you press tab key after dot. For debugger type 'debugger' in console to see it. Posted at 2019-04-13 by Vlad I see now, getting 896 bytes free space after saving a simple script. Is there anything else I could disable to free up some space? Update: JS minification helped a bit: 1312 bytes vs 896 (unminified) Posted at 2019-04-13 by @fanoush When checking https://github.com/espruino/Espruino/blob/master/boards/NRF51822DK.py try removing GRAPHICS library, then removing gpio as pin reset define could save some code (reset should still work as long as this code run at least once on this board). Also in same board file try to increase page constants '3' in saved_code section as the size and start of Storage is hardcoded there. If you set it too large the linker should fail. Posted at 2019-04-13 by @fanoush I just tried with bare 51822 module from ebay. I only removed debugger and tab complete added storage (and reduced RAM to 16KB and variables to 300 since my module only has 16kb) and while building I see
so I increased storage pages to 6 and while building I see
and in console I see
Posted at 2019-04-13 by Vlad Thanks @fanoush, I've pushed When I build a new FW, it prints this:
Does it mean that I still can allocate even more space for storage? E.g. tune that Posted at 2019-04-13 by @fanoush Yes. If you give it too much the build will fail. Removing GRAPHICS gives me similar numbers. Also when adding back tab complete (i.e just removing debugger and keep everything else in) I can still have 5 pages. This is not so bad after all :-) EDIT: Also if you would enable Flash module too you could keep some space for Storage and the rest is automatically available for Flash - which allows saving pages directly. For some use cases saving/erasing pages directly to store data might make better sense? See src/jswrap_flash.c the getFree method there should figure out free space automatically. Posted at 2019-04-14 by Vlad Perfect! Thank you. Just wondering why nrf51822-dk image is not available on the official image download page? There are only Micro:bit and nrf52 firmwares. Posted at 2019-04-14 by Vlad Alright... After doing this:
I'm getting:
Great success, I think it is more than enough. Thanks for your suggestion to look at the Flash module, I will soon. Posted at 2019-04-15 by @gfwilliams Great! Glad that's all working for you now. Since you are now using all available flash for
While Espruino is Open Source, it still takes effort to maintain the builds - and I can't afford to spend all by time working on supporting new hardware that I don't get paid for. As a result, builds generally only get put up if:
Posted at 2019-04-15 by @fanoush BTW Interesting info about flash endurance for both nrf51 and 52 is here https://devzone.nordicsemi.com/f/nordic-q-a/15798/flash-endurance-on-nrf52 it is 'only' 20/10K erase cycles, not 100K as I hoped. I like the idea there about rewriting previous data with zeroes (which comes free, it is the erase that counts) and finding first nonzero data. Posted at 2019-04-15 by @gfwilliams
That's basically what Interesting about the write endurance stats though. Posted at 2019-04-16 by Vlad Interesting... Thank you guys for your clarification. I'm trying to come to a conclusion if it is actually rational to use internal nrf5 flash for this king of things I wanted to use it for, e.g. backing up some readings (daily or hourly). Giving that:
Does it mean that I'll have about 10000 * (14 * 1024 (page size)) / 4 (bytes) = 35840000 write cycles for 1 word? Something tells me that it is not right or very hard to achieve giving that wear leveling won't be ideal. Also, I'm not quite sure if my assumption is correct - 10000 write/erase cycles is per 1 bit (e.g. not per page or minimum write operation length). If 10000 write/erase cycles is actually per 1 page (e.g. minimum write operation length is 1024 bytes), then it would be a different figure: 10000 * 14 = 140000 write cycles for 1 word. I also not quite sure if flash page size on low level is the same as page size of Espruino Flash module. Looks like ppl on that nordicsemi thread mention that page size is 512. What's your thoughts on that guys? If it is 35m write/erase cycles, then it is acceptable even if we store a figure every hour. If it is only 140000 write cycles, then it could be problematic. Posted at 2019-04-16 by Robin Mon 2019.04.15 Back in the eighties, when we had the luxury of doubling our NOVRAM capacity to a whopping 1024 bytes, we made sure we wrote an entire page to maximize the number of bytes that would get written in one cycle. For a 4 page 512 byte chip, four arrays of 32 bytes each made a page, so we would fill those over time in RAM, then write that page P0. On the second write, we advanced to the next page P1, and the third and fourth the same way P2 & P3. On the fifth page write, we started over, erasing the first page written P0. In this way, we used one cycle per write for a 128 byte page rather than 128 cycles for each of the individual 128 bytes. The rough rule of thumb was one page write each hour for one year, roughly ten thousand. 365 days in a year Therefore, for a ten hour work day, a three year life expectancy. Moore's law, doubling capacity while halving price every eighteen months, allowed obsolescence to force an upgrade to the hardware, an excuse to then greedily use that extra memory. ;-)
The 181 value indicates the number of writes before an erase must be performed. One then could write all 256 32 bit words, one by one with an intermediate erase. Posted at 2019-04-16 by @fanoush
Oh I got the numbers wrong. It looks like block is 512 bytes long, not 1024. So I can write it in 128 steps. This now makes sense. So I have 53 spare writes to rewrite some 32bit words second time. @vlad So as I understand it with nrf51822 you can write each 32bit word twice, then you need to erase whole page and this page erase counts as one from 20K per page. Posted at 2019-04-23 by Vlad Thanks everyone. Just a heads up, I've tried to enable full BLE API support for nrf51822 board (e.g. that are disabled atm by
Effectively nrf51822 boards are forced to be peripheral devices only. That's ok methink as to be "central" is not that important/common for this small devices. However, I must say I was able to read some data from other BT devices by using advertised services, for example I was able to hook up to a Xiaomi Temperature and Humidity sensor:
Perfectly working. Posted at 2019-04-23 by Robin Mon 2019.04.22 Congrats on your success @vlad ! As you have quite a nicely done snippet block of code there and it doesn't appear that the Espruino site currently has an interface solution for the 'Xiaomi Temperature and Humidity sensor', would it make sense to add that content with a few basic comments and some sample output data in a descriptive unique thread to assist others? Maybe a post such as 'Accessing data returned from a Xiaomi Temperature and Humidity sensor' beneath:
Having that content in this thread may get lost, and may never become searchable. Having a descriptive title would allow others that use the Xiaomi sensor to quickly find your solution. Posted at 2019-04-23 by Frida
You use the same dataset for both temp and humidity, is it correct? Posted at 2019-04-23 by Vlad Yes, it is correct. Depending on the flag field (11th element), payload contains temperature, humidity, both temp and hum, battery level. I've decoded and described Xiaomi protocol in the Gatt Parser project here and here. Most of Xiaomi devices follow this protocol, e.g. MiFlora sensor, Mi Kettle, Mi Scales etc Posted at 2019-04-26 by Vlad |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2019-04-12 by Vlad
Hello, I'm new to Espruino, however I really like it!
I've built nrf51288-DK Espruino image to play with an nrf51288 chip. It mainly works, e.g. Bluetooth stuff, reading digital analog pins etc. However I can't get it to store something in EEPROM. I'm following some example where you need to load a module, e.g. Storage, Flash etc but non of them actually loads...
I've got a simple code that does:
This print the following:
Does it mean that nrf581 chip does not support Storage?
PS. I've tried to load "Flash" module with the same result.
Beta Was this translation helpful? Give feedback.
All reactions