{"id":42,"date":"2017-11-21T15:04:41","date_gmt":"2017-11-21T15:04:41","guid":{"rendered":"http:\/\/wp.spoton.cz\/?p=42"},"modified":"2017-11-21T15:04:41","modified_gmt":"2017-11-21T15:04:41","slug":"bricking-and-flashing-esp-01s-8266","status":"publish","type":"post","link":"https:\/\/spoton.cz\/index.php\/2017\/11\/21\/bricking-and-flashing-esp-01s-8266\/","title":{"rendered":"Bricking and flashing ESP-01s &#8211; (8266)"},"content":{"rendered":"<p>A powerfull tool, delicate hardware and the simplicity of use. That is the Espressif ESP-01s with the 8266EX chip. Sometimes, you can bring it to an unusable state. Such as I did, with a factory reset (AT+RESTORE, or AT+RST in some cases). Now, how to bring it back to life?<!--more--><\/p>\n<h2>The status<\/h2>\n<p>Simply put, screwed. No matter the Baud rate used, or commands chucked at it, the ESP did not even boot into it&#8217;s AT command program. Pretty much bricked, time to bring it back to life, hopefully.<\/p>\n<p>I should stress, the ESP8266 HAS TO USE 3.3V under all circumstances. This is true for Vin, as well as Rx, Tx! If standard, 5V TTL signals are being used for communication, the behavior is unpredictable.<\/p>\n<h2>The setup<\/h2>\n<p><a href=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-57 size-large\" src=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843-1024x601.jpg\" alt=\"\" width=\"480\" height=\"282\" srcset=\"https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843-1024x601.jpg 1024w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843-300x176.jpg 300w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843-768x451.jpg 768w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_141843.jpg 1200w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>First the pins and what they mean:<\/p>\n<ul>\n<li><strong>TX<\/strong> &#8211; Transfer, serial send pin<\/li>\n<li><strong>EN<\/strong> &#8211; ENABLE, or SELECT, or&#8230; it has multiple names. This pin needs to be set high (read logical 1 &#8211; ~3 &#8211; 3.3V) for the module to work, send and receive data. Putting it high with Vcc \/ Vin throgh a resistor or directly is a good idea<\/li>\n<li><strong>RST<\/strong> &#8211; RESET. We&#8217;re going to use this one. If set LOW, device reset is initiated, but for the device to boot and actually reset, you must take the GND off this pin. In normal operation this should be set HIGH. Leaving it &#8220;in the air&#8221; is not a good idea.<\/li>\n<li><strong>3V3<\/strong> &#8211; Vcc \/ Vin &#8211; call it as you like &#8211; Input voltage. Mind you, 3.3V max!<\/li>\n<li><strong>GND<\/strong> &#8211; GROUND. doh!<\/li>\n<li><strong>IO2<\/strong> &#8211; General purpose I\/O pin #2<\/li>\n<li><strong>IO0<\/strong> &#8211; General purpose I\/O pin #0, we&#8217;ll need this one for flashing as well<\/li>\n<li><strong>RX<\/strong> &#8211; Receive, serial receive pin<\/li>\n<\/ul>\n<p>If you are using an FTDI programmer, USB dongle, or other interface, make sure it is 3.3V capable. If you start chucking 5V signals at it, it misbehaves. People have reported the ESP8266 to be 5V tolerant, but I found it far less stable at 5V logical levels. And how long it takes to get damaged at that rate? Who knows.<\/p>\n<p>Pay the extra buck and get one of these (switchable 5V \/ 3.3V logic):<\/p>\n<p><a href=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-60 size-large\" src=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232-1024x444.jpg\" alt=\"\" width=\"480\" height=\"208\" srcset=\"https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232-1024x444.jpg 1024w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232-300x130.jpg 300w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232-768x333.jpg 768w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142232.jpg 1200w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>For sheer lack of due diligence, I had to use an Arduino Nano as a voltage stabilizer. Please don&#8217;t do this, it is utter nonsense. I know however, that for testing purposes and flashing, the current supplied by the Nano is sufficient, so, leave me alone with this.<\/p>\n<p><a href=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-61 size-large\" src=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303-1024x741.jpg\" alt=\"\" width=\"480\" height=\"347\" srcset=\"https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303-1024x741.jpg 1024w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303-300x217.jpg 300w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303-768x556.jpg 768w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_142303.jpg 1200w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>You should however think about using one of these (at least) for voltage stabilization:<\/p>\n<p><a href=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1.jpg\"><img loading=\"lazy\" class=\"aligncenter wp-image-68 size-large\" src=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1-1024x627.jpg\" alt=\"\" width=\"480\" height=\"294\" srcset=\"https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1-1024x627.jpg 1024w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1-300x184.jpg 300w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1-768x470.jpg 768w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/20171121_150124-1.jpg 1200w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<p>This power supply is cheap, tolerant to 5V-12V (some say 24V is OK &#8211; gonna test it :-)) and has 4 pinouts, so can power 4 arduinos.<\/p>\n<p>Connect like this. If you are not lazy, nor stupid, don&#8217;t use the arduino as a voltage regulator. \ud83d\ude09<\/p>\n<p><a href=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema.png\"><img loading=\"lazy\" class=\"aligncenter wp-image-70 size-large\" src=\"http:\/\/wp.spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema-1024x724.png\" alt=\"\" width=\"480\" height=\"339\" srcset=\"https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema-1024x724.png 1024w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema-300x212.png 300w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema-768x543.png 768w, https:\/\/spoton.cz\/wp-content\/uploads\/2017\/11\/8266_schema.png 1052w\" sizes=\"(max-width: 480px) 100vw, 480px\" \/><\/a><\/p>\n<h2>The pain of finding out how<\/h2>\n<p>I thought, that there is only one firmware, and only one way to do things with the ESP-01s. Turns out, there are multiple firmwares available, AT commands, Python derivates&#8230; ehm, let&#8217;s concentrate on how to bring the ESP back to factory (AT firmware) setup. Great resource for FWs and documentation, of course:\u00a0<a href=\"http:\/\/esp8266.net\/\">http:\/\/esp8266.net\/<\/a>.<\/p>\n<h3>How to flash<\/h3>\n<p>You need PYTHON installed. Flash software:\u00a0<a href=\"https:\/\/github.com\/espressif\/esptool\">https:\/\/github.com\/espressif\/esptool<\/a>\u00a0&#8211; I like to use GIT, so:<\/p>\n<pre>https:\/\/github.com\/espressif\/esptool\ncd .\/esptool\/<\/pre>\n<p>The basic commands to flash a .bin file is as follows (Don&#8217;t forget to set up correct privileges &#8211; i.e. add yourself to &#8220;dialout&#8221; group or &#8211; use sudo).<\/p>\n<pre>sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0xFE000 .\/ESP8266_AT\/bin\/blank.bin \nesptool.py v2.2-dev\nConnecting........_\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 4096 bytes to 26...\nWrote 4096 bytes (26 compressed) at 0x000fe000 in 0.0 seconds (effective 4743.5 kbit\/s)...\nHash of data verified.<\/pre>\n<p>Now that we know how to destroy things, write crap to the controller, let&#8217;s do something useful&#8230;<\/p>\n<h3>Gather the firmware!<\/h3>\n<p>AT firmware:\u00a0<a href=\"https:\/\/github.com\/espressif\/ESP8266_AT\/tree\/master\/bin\">https:\/\/github.com\/espressif\/ESP8266_AT\/tree\/master\/bin<\/a>\u00a0&#8211; this is stock, AT firmware, that came with the ESP-01s preinstalled. I want that!<\/p>\n<pre>git clone https:\/\/github.com\/espressif\/ESP8266_AT<\/pre>\n<p>It says to flash these bins to the specified address (which I later found out it is wrong on my ESP).<\/p>\n<pre>Bin Address\nboot_v1.1.bin----------------&gt;0x00000 (reset)\nuser1.bin--------------------&gt;0x01000 (reset)\nesp_init_data_default.bin----&gt;0x7C000 (no reset)\nblank.bin--------------------&gt;0x7E000 (reset)\n\n<\/pre>\n<p>Let&#8217;s see&#8230; (how to observe ESP8266 boot sequence? later! Just take it as a fact, read on)<\/p>\n<pre>...\nSPI Speed : 40MHz\nSPI Mode : QIO\nSPI Flash Size : 8Mbit\njump to run usererror user bin flag, flag = 6\nuser code done<\/pre>\n<p>Nope. Dead. A spark of hope though, this clearly shows, that it is not fried, just misconfigured somehow.<\/p>\n<p>The way I read the documentation, there is a boot code and a user code (more on the boot later on). The user code should contain the AT commands functionality, but here it seems it doesn&#8217;t even run, or errors out. Might this be a problem of a mis-fired, wrongly placed user.bin?<\/p>\n<h3>Go back in line, repeat again<\/h3>\n<p>Again, but this\u00a0 time\u00a0<a href=\"https:\/\/www.allaboutcircuits.com\/projects\/flashing-the-ESP-01-firmware-to-SDK-v2.0.0-is-easier-now\/\">https:\/\/www.allaboutcircuits.com\/projects\/flashing-the-ESP-01-firmware-to-SDK-v2.0.0-is-easier-now\/<\/a>\u00a0helped me out, so I found the corect memory addresses to flash the files to.<\/p>\n<p>These values worked for me.<\/p>\n<pre>boot 00000\nuser 01000\nblank FB000\ninit_data_default FC000\nblank 7E000\nblank FE000<\/pre>\n<p><strong>Go.<\/strong><\/p>\n<ol>\n<li>Press and hold the Reset button\u00a0(SW1) on your flashing circuit.<\/li>\n<li>Press and hold the Flash button (SW2) on your flashing circuit.<\/li>\n<li>Release the Reset button.<\/li>\n<li>Release the Flash button.<\/li>\n<li>run the appropriate command.<\/li>\n<li>Or any freakin combination of the above. In general, the IO0 must be pulled down and pulldown of reset pin is sometimes needed, just wait for init, and if it doesn&#8217;t do anything, just press reset.<\/li>\n<\/ol>\n<p>In my case, all of the commands used to flash the ESP-01s were as follows:<\/p>\n<pre>$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0x00000 ESP8266_AT\/bin\/boot_v1.1.bin \nesptool.py v2.2-dev\nConnecting...\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nFlash params set to 0x0020\nCompressed 1712 bytes to 1295...\nWrote 1712 bytes (1295 compressed) at 0x00000000 in 0.1 seconds (effective 116.0 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...\n\n$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0x01000 .\/ESP8266_AT\/bin\/newest\/user1.bin \nesptool.py v2.2-dev\nConnecting........_____....._____.....\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 222376 bytes to 141270...\nWrote 222376 bytes (141270 compressed) at 0x00001000 in 12.4 seconds (effective 143.0 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...\n\n$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0xFB000 .\/ESP8266_AT\/bin\/blank.bin \nesptool.py v2.2-dev\nConnecting........_____....._\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 4096 bytes to 26...\nWrote 4096 bytes (26 compressed) at 0x000fb000 in 0.0 seconds (effective 4739.4 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...\n\n$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0xFC000 .\/ESP8266_AT\/bin\/esp_init_data_default.bin \nesptool.py v2.2-dev\nConnecting........_____....._\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 128 bytes to 72...\nWrote 128 bytes (72 compressed) at 0x000fc000 in 0.0 seconds (effective 93.0 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...\n\n$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0x7E000 .\/ESP8266_AT\/bin\/blank.bin \nesptool.py v2.2-dev\nConnecting........_\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 4096 bytes to 26...\nWrote 4096 bytes (26 compressed) at 0x0007e000 in 0.0 seconds (effective 4691.9 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...\n\n$ sudo .\/esptool.py --port \/dev\/ttyUSB2 write_flash 0xFE000 .\/ESP8266_AT\/bin\/blank.bin \nesptool.py v2.2-dev\nConnecting........_\nDetecting chip type... ESP8266\nChip is ESP8266EX\nUploading stub...\nRunning stub...\nStub running...\nConfiguring flash size...\nAuto-detected Flash size: 1MB\nCompressed 4096 bytes to 26...\nWrote 4096 bytes (26 compressed) at 0x000fe000 in 0.0 seconds (effective 4743.5 kbit\/s)...\nHash of data verified.\nLeaving...\nHard resetting...<\/pre>\n<p>Check! And hope that not Mate!<\/p>\n<p>Go to console (minicom, arduino monitor, whatever that can read serial), disconnect the IO0 pin from ground, press reset button&#8230; and don&#8217;t forget to set your console speed to 74880 baud!<\/p>\n<p>After a boot, with a nice value of 74880 baud rate, I got a full Boot, except for the last part, BUT this is expected, as there the baud rate changes, or should change to 115200.<\/p>\n<pre>ets Jan 8 2013,rst cause:2, boot mode:(3,6)\n\nload 0x40100000, len 612, room 16 \ntail 4\nchksum 0x12\nload 0x3ffe8000, len 788, room 4 \ntail 0\nchksum 0x50\nload 0x3ffe8314, len 264, room 8 \ntail 0\nchksum 0x4a\ncsum 0x4a\n\n2nd boot version : 1.1\n SPI Speed : 40MHz\n SPI Mode : QIO\n SPI Flash Size : 8Mbit\njump to run user1\n\n\n\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\u2e2e\n<\/pre>\n<p>Now, change your baud rate to 115200 and go for AT commands:\u00a0<a href=\"https:\/\/www.espressif.com\/sites\/default\/files\/documentation\/4a-esp8266_at_instruction_set_en.pdf\">https:\/\/www.espressif.com\/sites\/default\/files\/documentation\/4a-esp8266_at_instruction_set_en.pdf<\/a><\/p>\n<pre>AT\n\nOK\nAT+CWMODE? \n+CWMODE:2\n\nOK\nAT+CWMODE=1\n\nOK\nAT+CWLAP \n+CWLAP:(3,\"Bastart netgear 24\",-37,\"b0:7f:b9:9b:43:30\",3)\n+CWLAP:(4,\"Kvasnicovy_Synanet\",-87,\"c4:6e:1f:0b:e6:ae\",6)\n+CWLAP:(3,\"BastArt\",-40,\"bc:75:74:03:9f:23\",11)\n\nOK\nAT+CWJAP=\"Bastart netgear 24\",\"xyz\"\n\nOK\nAT+CIFSR \n+CIFSR:STAIP,\"192.168.0.171\"\n+CIFSR:STAMAC,\"18:fi:34:xa:6e:52\"\n\nOK<\/pre>\n<p>If this works for you, let me know.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A powerfull tool, delicate hardware and the simplicity of use. That is the Espressif ESP-01s with the 8266EX chip. Sometimes, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":59,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,8,9],"tags":[22,36,40,58,68],"_links":{"self":[{"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/posts\/42"}],"collection":[{"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/comments?post=42"}],"version-history":[{"count":0,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/posts\/42\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/media\/59"}],"wp:attachment":[{"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/media?parent=42"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/categories?post=42"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spoton.cz\/index.php\/wp-json\/wp\/v2\/tags?post=42"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}