1425bb815Sopenharmony_ci#### Preparation 2425bb815Sopenharmony_ci 3425bb815Sopenharmony_ci##### Accessories 4425bb815Sopenharmony_ci 5425bb815Sopenharmony_ciYou need, 6425bb815Sopenharmony_ci* 3.3V power supply. You can use bread board power (+5V, +3.3V). I used LM317 like this; 7425bb815Sopenharmony_ci * Use [LM317](http://www.ti.com/lit/ds/symlink/lm317.pdf) 8425bb815Sopenharmony_ci * R1 = 330 Ohm, R2 = 545 Ohm (1K + 1.2K in parallel) 9425bb815Sopenharmony_ci * 5V 2A adaptor 10425bb815Sopenharmony_ci* USB to RS-232 Serial + RS-232 Serial to Digital or USB-to-RS232 TTL converter 11425bb815Sopenharmony_ci 12425bb815Sopenharmony_ci#### Tools 13425bb815Sopenharmony_ci 14425bb815Sopenharmony_ciThe rest of this document will assume that you download all necessary tools into 15425bb815Sopenharmony_cia common directory structure. For the sake of simplicity, `$HOME/Espressif` will 16425bb815Sopenharmony_cibe used as the root of this structure. Feel free to deviate from this but then 17425bb815Sopenharmony_ciadapt all the paths accordingly. 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ci``` 20425bb815Sopenharmony_cimkdir $HOME/Espressif 21425bb815Sopenharmony_ci``` 22425bb815Sopenharmony_ci 23425bb815Sopenharmony_ci##### Toolchain 24425bb815Sopenharmony_ci 25425bb815Sopenharmony_ciDownload the [toolchain](https://github.com/espressif/ESP8266_RTOS_SDK/tree/v3.0.1#get-toolchain) 26425bb815Sopenharmony_cipre-built for your development platform to `$HOME/Espressif` and untar it. E.g., 27425bb815Sopenharmony_cion Linux/x86-64: 28425bb815Sopenharmony_ci 29425bb815Sopenharmony_ci``` 30425bb815Sopenharmony_cicd $HOME/Espressif 31425bb815Sopenharmony_citar xvfz xtensa-lx106-elf-linux64-1.22.0-88-gde0bdc1-4.8.5.tar.gz 32425bb815Sopenharmony_ci``` 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_ci##### Espressif SDK: use Espressif official 35425bb815Sopenharmony_ci 36425bb815Sopenharmony_ci``` 37425bb815Sopenharmony_cicd $HOME/Esprissif 38425bb815Sopenharmony_cigit clone https://github.com/espressif/ESP8266_RTOS_SDK.git -b v2.1.0 39425bb815Sopenharmony_ci``` 40425bb815Sopenharmony_ci 41425bb815Sopenharmony_ciThis version is tested and works properly. 42425bb815Sopenharmony_ci 43425bb815Sopenharmony_ci##### ESP image tool 44425bb815Sopenharmony_ci``` 45425bb815Sopenharmony_cicd $HOME/Espressif 46425bb815Sopenharmony_ciwget -O esptool_0.0.2-1_i386.deb https://github.com/esp8266/esp8266-wiki/raw/master/deb/esptool_0.0.2-1_i386.deb 47425bb815Sopenharmony_cisudo dpkg -i esptool_0.0.2-1_i386.deb 48425bb815Sopenharmony_ci``` 49425bb815Sopenharmony_ci 50425bb815Sopenharmony_ci##### ESP upload tool 51425bb815Sopenharmony_ci``` 52425bb815Sopenharmony_cicd $HOME/Espressif 53425bb815Sopenharmony_cigit clone https://github.com/themadinventor/esptool 54425bb815Sopenharmony_ci``` 55425bb815Sopenharmony_ci 56425bb815Sopenharmony_ci##### Set environment variables 57425bb815Sopenharmony_ci 58425bb815Sopenharmony_ciSet environment variables, might also go in your `.profile`: 59425bb815Sopenharmony_ci``` 60425bb815Sopenharmony_ciexport PATH=$HOME/Espressif/xtensa-lx106-elf/bin:$PATH 61425bb815Sopenharmony_ciexport SDK_PATH=$HOME/Espressif/ESP8266_RTOS_SDK 62425bb815Sopenharmony_ciexport ESPTOOL_PATH=$HOME/Espressif/esptool 63425bb815Sopenharmony_ciexport BIN_PATH=(to output folder path) 64425bb815Sopenharmony_ci``` 65425bb815Sopenharmony_ci 66425bb815Sopenharmony_ci#### Test writing with Blinky example 67425bb815Sopenharmony_ci 68425bb815Sopenharmony_ci##### Get the source 69425bb815Sopenharmony_ci 70425bb815Sopenharmony_cifound one example that works with SDK V1.2 (which is based on FreeRTOS, as of writing) 71425bb815Sopenharmony_ci 72425bb815Sopenharmony_ci* https://github.com/mattcallow/esp8266-sdk/tree/master/rtos_apps/01blinky 73425bb815Sopenharmony_ci 74425bb815Sopenharmony_ci 75425bb815Sopenharmony_ci##### Compile 76425bb815Sopenharmony_ci 77425bb815Sopenharmony_ciRead `2A-ESP8266__IOT_SDK_User_Manual_EN` document in 78425bb815Sopenharmony_ci[this](http://bbs.espressif.com/viewtopic.php?f=51&t=1024) link. 79425bb815Sopenharmony_ci 80425bb815Sopenharmony_ciIt's configured 2048KB flash 81425bb815Sopenharmony_ci``` 82425bb815Sopenharmony_ciBOOT=new APP=1 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make 83425bb815Sopenharmony_ciBOOT=new APP=2 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=5 make 84425bb815Sopenharmony_ci``` 85425bb815Sopenharmony_ci 86425bb815Sopenharmony_cior old way... this works not sure this is ok. 87425bb815Sopenharmony_ci``` 88425bb815Sopenharmony_cimake BOOT=new APP=0 SPI_SPEED=80 SPI_MODE=QIO SPI_SIZE_MAP=2 89425bb815Sopenharmony_ci``` 90425bb815Sopenharmony_ci 91425bb815Sopenharmony_ci##### Flashing 92425bb815Sopenharmony_ci 93425bb815Sopenharmony_ci* power off ESP8266 board 94425bb815Sopenharmony_ci* connect GPIO0 to GND, connect GPIO2 to VCC 95425bb815Sopenharmony_ci* power on 96425bb815Sopenharmony_ci* write 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_ci``` 99425bb815Sopenharmony_cisudo $HOME/Espressif/esptool/esptool.py \ 100425bb815Sopenharmony_ci --port /dev/ttyUSB0 write_flash \ 101425bb815Sopenharmony_ci 0x00000 $SDK_PATH/bin/"boot_v1.7.bin" \ 102425bb815Sopenharmony_ci 0x01000 $BIN_PATH/upgrade/user1.2048.new.5.bin \ 103425bb815Sopenharmony_ci 0x101000 $BIN_PATH/upgrade/user2.2048.new.5.bin \ 104425bb815Sopenharmony_ci 0x3FE000 $SDK_PATH/bin/blank.bin \ 105425bb815Sopenharmony_ci 0x3FC000 $SDK_PATH/bin/esp_init_data_default.bin 106425bb815Sopenharmony_ci``` 107425bb815Sopenharmony_ci_change `/dev/ttyUSB1` to whatever you have._ 108425bb815Sopenharmony_ci 109425bb815Sopenharmony_cior the old way...this works not sure this is ok. 110425bb815Sopenharmony_ci``` 111425bb815Sopenharmony_cicd $BIN_PATH 112425bb815Sopenharmony_cisudo $HOME/Espressif/esptool/esptool.py \ 113425bb815Sopenharmony_ci--port /dev/ttyUSB0 write_flash \ 114425bb815Sopenharmony_ci0x00000 eagle.flash.bin 0x40000 eagle.irom0text.bin 115425bb815Sopenharmony_ci``` 116425bb815Sopenharmony_ci 117425bb815Sopenharmony_ci* power off 118425bb815Sopenharmony_ci* disconnect GPIO0 so that it is floating 119425bb815Sopenharmony_ci* connect GPIO2 with serial of 470 Ohm + LED and to GND 120425bb815Sopenharmony_ci* power On 121