You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

300 lines
13 KiB

3 years ago
  1. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >
  2. # Flashing guide
  3. Table of contents:
  4. * [Warning](#warning)
  5. * [Tools needed](#tools-needed)
  6. * [Opening the lamp, to expose the PCB](#opening-the-lamp-to-expose-the-pcb)
  7. * [Solder wires to the board](#solder-wires-to-the-board)
  8. * [Connect the wires to your serial to USB adapter](#connect-the-wires-to-your-serial-to-usb-adapter)
  9. * [When you only have one GND pin on your USB Adapter](#when-you-only-have-one-gnd-pin-on-your-usb-adapter)
  10. * [Make a backup of the current firmware](#make-a-backup-of-the-current-firmware)
  11. * [How to restore the backed up firmware](#how-to-restore-the-backed-up-firmware)
  12. * [Flash new ESPHome firmware](#flash-new-esphome-firmware)
  13. * [Troubleshooting flash](#troubleshooting-flash)
  14. ## Warning
  15. We have writen these instructions with care, but we will give absolutely no
  16. warranty. Perhaps you will destroy your lamp and your computer.
  17. ## Tools needed
  18. * Allen key (2mm, 5/64") or torx (T8) screw driver
  19. * Soldering Iron
  20. * A serial to USB adapter (for example FTDI) that can provide 3.3V RX/TX signals
  21. * Some wires
  22. * Optional: sticky tape, hot glue gun, magnifying glass
  23. ## Opening the lamp, to expose the PCB
  24. *Tip: you can click on all images from below to view them in full size.*
  25. Remove the rubber pads from the bottom of the lamp, to get access to 4
  26. screws that attach the bottom to the rest of the lamp.
  27. <img src="images/01_unboxed.jpg" width="200"><img src="images/02_remove_rubber_pads.jpg" width="200">
  28. Note that you don't have to remove these pads fully. Once you can access
  29. the screws, you've gone far enough.
  30. <img src="images/03_bolts_overview.jpg" width="200">
  31. Unbolt the 4 screws which were hidden under the rubber pads.
  32. <img src="images/04_remove_bolts.jpg" width="200"><img src="images/05_bolts.jpg" width="200">
  33. Detach the bottom from the rest of the lamp, exposing the PCB. This might
  34. take a bit of force. Just pull it off bit by bit, until it pops loose.
  35. <img src="images/06_pull_off_the_bottom.jpg" width="200"><img src="images/07_bottom_removed.jpg" width="200">
  36. <img src="images/08_board_exposed.jpg" width="400">
  37. ## Solder wires to the board
  38. The wires will be connected to the debug pads that are shown in the following image.
  39. <img src="images/09_debug_pads_for_soldering.jpg" width="400">
  40. Many of the serial to USB adapter have some header pins to which you can
  41. connect the wires of a device (no soldering required). Therefore, it might be
  42. useful to use dupont wire. Cut off one end, strip the wire, tin the wire and
  43. solder it to the board.
  44. *Note: Whether to use male or female dupont wires depends on how you want to connect
  45. the serial adapter. In this example, I have used male wires, so I could plug them
  46. into a breadbord.*
  47. <img src="images/10_stripped_dupont_wires.jpg" width="200">
  48. Solder the wires to the `RX`, `TX`, `GND` and `GPIO0` debug pads.
  49. *Note: The board has a debug pad that exposes 3.3V. Do not use this pad to power
  50. the board from your serial adapter. Always power the lamp using its own power supply.*
  51. A few tips:
  52. - Depending on the quality of your eyes, you might want to use a magnifying glass for the
  53. soldering work. Use one that is mounted on a stand, or you will quickly be left wishing
  54. that you could grow a third arm.
  55. - You could use some sticky tape to fixate the cables before soldering.
  56. - When you want to keep the wires attached after flashing the new firmware (e.g. for
  57. serial logging or for future firmware flashing), then you might want to apply some
  58. hot glue to fixate the wires. This prevents the wires from breaking off, due to
  59. excessive movement.
  60. <img src="images/11_soldered_wires.jpg" width="200"><img src="images/12_optional_hot_glue.jpg" width="200">
  61. ## Connect the wires to your serial to USB adapter
  62. Make sure that your adapter uses 3.3V for the pns that you will connect to the lamp.
  63. Some of these adapters allow you to switch between 3.3V and 5V using a switch or a jumper.
  64. Do not use an adapter that only provides 5V output. Reason for this, is that the ESP32 chip
  65. works at 3.3V. I have seen the chips accept 5V serial input, but I am not sure if they are
  66. actually 5V tolerant. Better safe than sorry in such case!
  67. The wires must be connected as follows:
  68. | Soldering point| Serial USB Adapter name |
  69. | -------------- |:------------------------:|
  70. | GND | GND |
  71. | TX | RX |
  72. | RX | TX (3.3V) |
  73. | GPIO0 | GND |
  74. To be able to flash the lamp, `GPIO0` must be connected to ground while the lamp boots up.
  75. Therefore, connect these wires *before* plugging in the lamp's power supply.
  76. Flashing will *not* work if you connect these wires *after* the lamp has already been booted up.
  77. ## When you only have one GND pin on your USB Adapter
  78. If your USB Adapter does not have multiple `GND` pins, then you'll have to
  79. find another way to attach `GPIO0` to ground. Some options:
  80. - **Use a breadbord**, so you can connect the USB Adapter `GND` pin to a row on
  81. the bread bord, and connect the `GND` and `GPIO0` wires of the lamp's
  82. board to that same row. The rest of this guide will show this method.
  83. [View example by @mmakaay](images/13_connect_to_serial_to_usb_adapter.jpg).
  84. - **Solder a button on the board** that connects `GPIO0` to `GND` when pressed.
  85. Then you can hold down this button while plugging in the lamp's power
  86. supply. After booting up, you can release the button (the serial console
  87. will also mention that flash mode is now enabled). This is not the most
  88. practical solution for most people (since only one such flash operation is
  89. needed, from then on OTA - Over The Air - updates are possible), but it
  90. was a great help to me during the initial reverse engineering and firmware
  91. development.
  92. [View example by @mmakaay](images/13_connect_to_serial_with_button.jpg) or
  93. [another example by @edwinschoonhoven](images/13_connect_to_serial_with_button_alternative.jpg).
  94. - **Manually hold a wire connected** to both a GND surface (e.g. the silver pad
  95. on the left of the board) and the `GPIO0` debug pad, while plugging in the
  96. power supply. After booting, the wire can be removed. This is very fiddly
  97. way of doing it (a third hand would be very welcome with this), but it can
  98. be done.
  99. - **Temporarily solder a lead between `GND` and `GPIO0` on the board**,
  100. making `GPIO0` pulled to ground permanently. It is a bit less flexible than
  101. some other options, but if you only need to do the initial backup and firmware
  102. flash of the lamp, then this can be all that you need. Remove the lead after
  103. flashing is done, otherwise the lamp won't boot in normal mode.
  104. [View example by @erwinschoonhoven](images/13_connect_to_serial_with_soldered_gnd.jpg).
  105. In the following images, you will see the first solution, using a breadboard.
  106. <img src="images/13_connect_to_serial_to_usb_adapter.jpg" width="400">
  107. In close up:
  108. <img src="images/14_connect_to_serial_to_usb_adapter_close_up.jpg" width="400">
  109. You can now connect the serial to USB adapter to you computer. Pay special attention
  110. to the cross-over of the TX/RX pair (TX connects to RX and vice versa).
  111. Start the [esphome-flasher tool](https://github.com/esphome/esphome-flasher) and
  112. select the COM port to use. Then click on "View logs".
  113. Now, plug in the lamp's power supply to boot up the lamp.
  114. <img src="images/15_power_up_for_flashing.jpg" width="400">
  115. Because GPIO0 is connected to GND, the device should start up in flashing mode.
  116. If all went well, the log output in esphome-flasher looks somewhat like this:
  117. <img src="images/16_serial_showing_download_mode.png" width="400">
  118. ## Make a backup of the current firmware
  119. Backing up the firmware makes it possible to revert to the original firmware,
  120. in case you have problems with the ESPHome firmware. The backup can be
  121. created using "esptool". Installation instructures can be found here:
  122. https://github.com/espressif/esptool/blob/master/README.md#installation--dependencies
  123. Here's an example on how to backup the original firmware from Linux.
  124. First, unplug your lamp's power supply, then start the esptool read_flash command:
  125. ```
  126. python esptool.py -p /dev/ttyUSB0 read_flash 0x0 0x400000 original-firmware.bin
  127. ```
  128. `/dev/ttyUSB0` is the port of the USB adaper on Linux. You can find what
  129. port is used by the adapter by running `dmesg` after plugging in the USB
  130. device. On Windows this is often `COM1`, `COM2` or `COM3`.
  131. Now plug back in the power supply. The output of esptool should now show that it
  132. connects to the lamp and downloads the firmware from it.
  133. **Caution**: You will find the WLAN SSID and Password of the last used
  134. WiFi network in this file. Therefore, keep this backup in a safe place.
  135. ## How to restore the backed up firmware
  136. In case you need to rollback to the lamp's original firmware at some
  137. point, here's an example of how to restore the original firmware from
  138. Windows, by fully flashing it back onto the lamp.
  139. First, unplug your lamp's power supply, then start the esptool write_flash command:
  140. ```
  141. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00 original-firmware.bin
  142. ```
  143. Make sure that `GPIO0` is connected to GND and plug in the power supply.
  144. The output of esptool should now show that it connects to the lamp and
  145. uploads the firmware to it.
  146. Be patient after the upload reaches 100%. The output is silent while
  147. esptool tool is verifying that the firmware was uploaded correctly.
  148. After the firmware upload completes, unplug the power, disconnect `GPIO0`
  149. from GND and reconnect the power supply to boot into the restored firmware.
  150. ## Flash new ESPHome firmware
  151. Setup an ESPHome Project (see [README.md](../README.md)), compile the firmware
  152. for the lamp and download the `firmware.bin` file to the device to which
  153. the serial adapter is connected.
  154. You can flash the lamp using esphome or esptool. I would strongly recommend using
  155. the [esphome-flasher](https://github.com/esphome/esphome-flasher) tool. This is
  156. a very easy to use GUI utility app for flashing ESPHome devices and for viewing
  157. serial console logging.
  158. - In the app, select the COM port of your serial adapter.
  159. - Then select the firmware.bin file to flash onto the lamp.
  160. - Power up the lamp with `GPIO0` connected to GND.
  161. - Click the "Flash ESP" button to flash the firmware.
  162. If all went well, the final log output in esphome-flasher looks somewhat like this:
  163. <img src="images/17_flash_ready.png" width="400">
  164. If you want to flash with esptool, you can use the following command.
  165. *Note: This is probably not correct to get the lamp fully operational. This
  166. does not update partition table and the bootloader, which are also needed to
  167. get a functioning ESPHome device. Unless you know exactly what you're doing
  168. with esptool here, I recommend to use the esphome-flasher instead.*
  169. ```
  170. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x1000 <path\to\yourfirmware.bin>
  171. ```
  172. *The following is a bit more in the direction of the required command
  173. for flashing. If you have some definitive info on how to handle this best,
  174. please let me know.*
  175. ```
  176. python esptool.py --chip esp32 \
  177. -p /dev/ttyUSB0 --baud 115200 \
  178. --before default_reset --after hard_reset \
  179. write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect \
  180. 0x1000 bootloader_dout_40m.bin \
  181. 0x8000 partitions.bin \
  182. 0xe000 boot_app0.bin \
  183. 0x10000 ~/Downloads/firmware.bin
  184. ```
  185. After flashing, power down the lamp, disconnect `GPIO0` from GND and
  186. reconnect the power to boot into the new ESPHome firmware.
  187. <img src="images/18_disconnect_GPIO0.jpg" width="200">
  188. The lamp should now be operational using the new firmware.
  189. <img src="images/19_test_run.jpg" width="200">
  190. From here on, it is possible to flash the lamp OTA (over the air, which
  191. means that the firmware is uploaded over WiFi) from ESPHome. Therefore, it
  192. is now time to tuck away or remove those soldered wires.
  193. Because I want to keep them around for future use, I tuck them away, making
  194. sure that the connectors don't touch each other or the board.
  195. <img src="images/20_tuck_away_wires.jpg" width="200">
  196. The bottom cover can now be put back on. The lamp is ready for use.
  197. <img src="images/21_reassemble_and_enjoy.jpg" width="200">
  198. ## Troubleshooting flash
  199. If you have **A fatal error occurred: MD5 of file does not match data in flash!**,
  200. then make sure you are powering the board using the lamp's own power adapter.
  201. We've seen these errors when trying to power the board using the 3.3V debug pad.
  202. After seeing this error, user @tabacha was able to successfully flash his
  203. lamp using the regular power adapter.
  204. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >