{"action":"created","issue":{"url":"https://api.github.com/repos/micropython/micropython/issues/1336","labels_url":"https://api.github.com/repos/micropython/micropython/issues/1336/labels{/name}","comments_url":"https://api.github.com/repos/micropython/micropython/issues/1336/comments","events_url":"https://api.github.com/repos/micropython/micropython/issues/1336/events","html_url":"https://github.com/micropython/micropython/issues/1336","id":89183087,"number":1336,"title":"esp8266: Making esp.flash_id() more useful","user":{"login":"owens-bill","id":1128544,"avatar_url":"https://avatars.githubusercontent.com/u/1128544?v=3","gravatar_id":"","url":"https://api.github.com/users/owens-bill","html_url":"https://github.com/owens-bill","followers_url":"https://api.github.com/users/owens-bill/followers","following_url":"https://api.github.com/users/owens-bill/following{/other_user}","gists_url":"https://api.github.com/users/owens-bill/gists{/gist_id}","starred_url":"https://api.github.com/users/owens-bill/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/owens-bill/subscriptions","organizations_url":"https://api.github.com/users/owens-bill/orgs","repos_url":"https://api.github.com/users/owens-bill/repos","events_url":"https://api.github.com/users/owens-bill/events{/privacy}","received_events_url":"https://api.github.com/users/owens-bill/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-18T02:51:04Z","updated_at":"2015-06-18T10:33:35Z","closed_at":null,"body":"The esp8266 port exposes the SDK function that reads out the ID of the SPI flash module; it produces a result like this:\r\n```\r\n>>> esp.flash_id()\r\n1261768\r\n```\r\nUnfortunately, that's not terribly helpful because it isn't the representation of the ID that people actually use. To get that we can use esptool:\r\n```\r\n./esptool.py -p /dev/tty.usbserial flash_id\r\nConnecting...\r\nManufacturer: c8\r\nDevice: 4013\r\n```\r\nOr the code for the flash_id method could be enhanced to do some simple parsing and spit out the same thing. The question I have is whether this is useful. The different ESP8266 modules do have different sized flash, and it might be handy to know how big they are, but this result doesn't directly tell you that; instead, you have to search for the result, or know that you can go grab a big file of flash IDs (http://code.coreboot.org/svn/flashrom/trunk/flashchips.h) and grep through it, and then look up the manufacturer's datasheet. We could work around that by building in a table of the most-commonly-used SPI flash modules, but I could see that getting out of hand pretty quickly!\r\n\r\nIt would be nicer to have an SDK function that simply told you how big the flash is. There is a new SDK function in 1.1.0 called system_get_flash_size_map but it seems to report what was configured when the software was linked, not what is actually on the board. I added a simple wrapper for it and tested on modules with 512 KB, 2 MB and 4 MB, and it always reported map 0, which is 512 KB. Assuming I wrote the wrapper correctly, that is not helpful ;)\r\n\r\nSo the questions are these, IMO:\r\n - Is it useful to be able to retrieve the flash ROM size from within MicroPython, or will people just look up the spec sheet or use esptool?\r\n - Is the current flash_id method sufficient?\r\n - If not, should it parse the answer to display the manufacturer and device codes?\r\n - Or should it have a lookup table of known flash chips, so it can also report the size?"},"comment":{"url":"https://api.github.com/repos/micropython/micropython/issues/comments/113102699","html_url":"https://github.com/micropython/micropython/issues/1336#issuecomment-113102699","issue_url":"https://api.github.com/repos/micropython/micropython/issues/1336","id":113102699,"user":{"login":"dpgeorge","id":6187689,"avatar_url":"https://avatars.githubusercontent.com/u/6187689?v=3","gravatar_id":"","url":"https://api.github.com/users/dpgeorge","html_url":"https://github.com/dpgeorge","followers_url":"https://api.github.com/users/dpgeorge/followers","following_url":"https://api.github.com/users/dpgeorge/following{/other_user}","gists_url":"https://api.github.com/users/dpgeorge/gists{/gist_id}","starred_url":"https://api.github.com/users/dpgeorge/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dpgeorge/subscriptions","organizations_url":"https://api.github.com/users/dpgeorge/orgs","repos_url":"https://api.github.com/users/dpgeorge/repos","events_url":"https://api.github.com/users/dpgeorge/events{/privacy}","received_events_url":"https://api.github.com/users/dpgeorge/received_events","type":"User","site_admin":false},"created_at":"2015-06-18T10:33:35Z","updated_at":"2015-06-18T10:33:35Z","body":"The manufacturer and device can be obtained from flash_id() by using simple bit manipulation in Python, so I don't see that it's worth doing this on the C side.\r\n\r\nWhen do you need to know these things from a running script?  Knowing the flash size is not useful unless you can write to it.  The unused parts of the flash should eventually contain a filesystem, and the size of that filesystem is what's important (free and used bytes), and that information will come from some filesystem query function.\r\n\r\nSummary: I'd say flash_id() as it is provides just enough information to be useful, and not more.  Development time and bytes should be spent on other non-existent features like a filesystem :)"}}