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.

287 lines
13 KiB

  1. < [Configuration guide](configuration.md) | [Index](../README.md) | [Technical details](technical_details.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 warranty. Perhaps you
  16. 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 screws that attach the bottom
  26. 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 the screws, you've gone far
  29. 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 take a bit of force. Just
  34. 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 connect the wires of a
  41. device (no soldering required). Therefore, it might be useful to use dupont wire. Cut off one end,
  42. strip the wire, tin the wire and solder it to the board.
  43. *Note: Whether to use male or female dupont wires depends on how you want to connect the serial
  44. adapter. In this example, I have used male wires, so I could plug them into a breadbord.*
  45. <img src="images/10_stripped_dupont_wires.jpg" width="200">
  46. Solder the wires to the `RX`, `TX`, `GND` and `GPIO0` debug pads.
  47. Beware not to use too much solder on the GPIO0 pad, because that might flow onto the pad that is right
  48. next to it, permanently putting the device in flash mode as a result.
  49. *Note: The board has a debug pad that exposes 3.3V. Do not use this pad to power the board from your
  50. 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 soldering
  53. work. Use one that is mounted on a stand, or you will quickly be left wishing that you could grow
  54. 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 serial logging
  57. or for future firmware flashing), then you might want to apply some hot glue to fixate the wires.
  58. This prevents the wires from breaking off, due to excessive movement.
  59. <img src="images/11_soldered_wires.jpg" width="200"><img src="images/12_optional_hot_glue.jpg" width="200">
  60. ## Connect the wires to your serial to USB adapter
  61. Make sure that your adapter uses 3.3V for the RX/TX pins that you will connect to the lamp. Some of
  62. these adapters allow you to switch between 3.3V and 5V using a switch or a jumper. Do not use an
  63. adapter that only provides 5V output. Reason for this, is that the ESP32 chip works at 3.3V. I have
  64. seen the chips accept 5V serial input (I did flash the lamp successfully like that), but I am not
  65. sure if they are actually 5V tolerant. Better safe than sorry in such case!
  66. The wires must be connected as follows:
  67. | Soldering point| Serial USB Adapter name |
  68. | -------------- |:------------------------:|
  69. | GND | GND |
  70. | TX | RX |
  71. | RX | TX (3.3V) |
  72. | GPIO0 | GND |
  73. To be able to flash the lamp, `GPIO0` must be connected to ground while the lamp boots up.
  74. Therefore, connect these wires *before* plugging in the lamp's power supply. Flashing will *not*
  75. work if you connect these wires *after* the lamp has already been booted up.
  76. ## When you only have one GND pin on your USB Adapter
  77. If your USB Adapter does not have multiple `GND` pins, then you'll have to find another way to
  78. attach `GPIO0` to ground. Some options:
  79. - **Use a breadbord**, so you can connect the USB Adapter `GND` pin to a row on the bread bord, and
  80. connect the `GND` and `GPIO0` wires of the lamp's board to that same row. The rest of this guide
  81. will show this method.
  82. [View example by @mmakaay](images/13_connect_to_serial_to_usb_adapter.jpg).
  83. - **Solder a button on the board** that connects `GPIO0` to `GND` when pressed. Then you can hold
  84. down this button while plugging in the lamp's power supply. After booting up, you can release the
  85. button (the serial console will also mention that flash mode is now enabled). This is not the most
  86. practical solution for most people (since only one such flash operation is needed, from then on
  87. OTA - Over The Air - updates are possible), but it was a great help to me during the initial
  88. reverse engineering and firmware development. Some example implementations:
  89. [a crude one by @mmakaay](images/13_connect_to_serial_with_button.jpg),
  90. [one by @edwinschoonhoven](images/13_connect_to_serial_with_button_alternative.jpg) and
  91. [one by @mmakaay, inspired by Erwin's](images/13_connect_to_serial_with_button_alternative2.jpg).
  92. - **Manually hold a wire connected** to both a GND surface (e.g. the silver pad on the left of the
  93. board) and the `GPIO0` debug pad, while plugging in the power supply. After booting, the wire can
  94. be removed. This is very fiddly way of doing it (a third hand would be very welcome with this),
  95. but it can be done.
  96. - **Temporarily solder a lead between `GND` and `GPIO0` on the board**, making `GPIO0` pulled to
  97. ground permanently. It is a bit less flexible than some other options, but if you only need to do
  98. the initial backup and firmware flash of the lamp, then this can be all that you need. Remove the
  99. lead after flashing is done, otherwise the lamp won't boot in normal mode.
  100. [View example by @erwinschoonhoven](images/13_connect_to_serial_with_soldered_gnd.jpg).
  101. In the following images, you will see the first solution, using a breadboard.
  102. <img src="images/13_connect_to_serial_to_usb_adapter.jpg" width="400">
  103. In close up:
  104. <img src="images/14_connect_to_serial_to_usb_adapter_close_up.jpg" width="400">
  105. You can now connect the serial to USB adapter to you computer. Pay special attention to the
  106. cross-over of the TX/RX pair (TX connects to RX and vice versa). Start the
  107. [esphome-flasher tool](https://github.com/esphome/esphome-flasher) and select the COM port to use.
  108. Then click on "View logs".
  109. Now, plug in the lamp's power supply to boot up the lamp.
  110. <img src="images/15_power_up_for_flashing.jpg" width="400">
  111. Because GPIO0 is connected to GND, the device should start up in flashing mode. If all went well,
  112. the log output in esphome-flasher looks somewhat like this:
  113. <img src="images/16_serial_showing_download_mode.png" width="400">
  114. ## Make a backup of the current firmware
  115. Backing up the firmware makes it possible to revert to the original firmware, in case you have
  116. problems with the ESPHome firmware. The backup can be created using "esptool". Installation
  117. instructures can be found here:
  118. https://github.com/espressif/esptool/blob/master/README.md#installation--dependencies
  119. Here's an example on how to backup the original firmware from Linux. First, unplug your lamp's
  120. power supply, then start the esptool read_flash command:
  121. ```
  122. python esptool.py -p /dev/ttyUSB0 read_flash 0x0 0x400000 original-firmware.bin
  123. ```
  124. `/dev/ttyUSB0` is the port of the USB adaper on Linux. You can find what port is used by the adapter
  125. by running `dmesg` after plugging in the USB device. On Windows this is often `COM1`, `COM2` or
  126. `COM3`.
  127. Now plug back in the power supply. The output of esptool should now show that it connects to the
  128. lamp and downloads the firmware from it.
  129. **Caution**: You will find the WLAN SSID and Password of the last used WiFi network in this file.
  130. Therefore, keep this backup in a safe place.
  131. ## How to restore the backed up firmware
  132. In case you need to rollback to the lamp's original firmware at some point, here's an example of how
  133. to restore the original firmware from Windows, by fully flashing it back onto the lamp.
  134. First, unplug your lamp's power supply, then start the esptool write_flash command:
  135. ```
  136. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00 original-firmware.bin
  137. ```
  138. Make sure that `GPIO0` is connected to GND and plug in the power supply. The output of esptool
  139. should now show that it connects to the lamp and uploads the firmware to it.
  140. Be patient after the upload reaches 100%. The output is silent while esptool tool is verifying that
  141. the firmware was uploaded correctly.
  142. After the firmware upload completes, unplug the power, disconnect `GPIO0` from GND and reconnect the
  143. power supply to boot into the restored firmware.
  144. ## Flash new ESPHome firmware
  145. Setup an ESPHome Project (see [README.md](../README.md)), compile the firmware for the lamp and
  146. download the `firmware.bin` file to the device to which the serial adapter is connected.
  147. You can flash the lamp using esphome or esptool. I would strongly recommend using the
  148. [esphome-flasher](https://github.com/esphome/esphome-flasher) tool. This is a very easy to use GUI
  149. utility app for flashing ESPHome devices and for viewing serial console logging.
  150. - In the app, select the COM port of your serial adapter.
  151. - Then select the firmware.bin file to flash onto the lamp.
  152. - Power up the lamp with `GPIO0` connected to GND.
  153. - Click the "Flash ESP" button to flash the firmware.
  154. If all went well, the final log output in esphome-flasher looks somewhat like this:
  155. <img src="images/17_flash_ready.png" width="400">
  156. If you want to flash with esptool, you can use the following command.
  157. *Note: unless you know exactly what you're doing with esptool here, I recommend to use the
  158. esphome-flasher instead.*
  159. ```
  160. python esptool.py --chip esp32 -p /dev/ttyUSB0 --baud 115200 \
  161. write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect \
  162. 0x1000 bootloader_dout_40m.bin \
  163. 0x8000 partitions.bin \
  164. 0xe000 boot_app0.bin \
  165. 0x10000 firmware.bin
  166. ```
  167. The required .bin files can be found in the following locations:
  168. - **bootloader_dout_40m.bin**: [from arduino-esp32 package](https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc/blob/v1.0.6/tools/sdk/bin/bootloader_dout_40m.bin) in `tools/sdk/bin/`
  169. - **partitions.bin**: from `<config dir>/<device name>/.pioenvs/<device name>/partitions.bin`
  170. - **boot_app0.bin**: [from arduino-esp32 package](https://github.com/mmakaay/arduino-esp32-unicore-no-mac-crc/blob/v1.0.6/tools/partitions/boot_app0.bin) in `tools/partitions/`
  171. - **firmware.bin**: from `<config dir>/<device name>/.pioenvs/<device name>/firmware.bin`
  172. After flashing, power down the lamp, disconnect `GPIO0` from GND and reconnect the power to boot
  173. into the new ESPHome firmware.
  174. <img src="images/18_disconnect_GPIO0.jpg" width="200">
  175. The lamp should now be operational using the new firmware.
  176. <img src="images/19_test_run.jpg" width="200">
  177. From here on, it is possible to flash the lamp OTA (over the air, which means that the firmware is
  178. uploaded over WiFi) from ESPHome. Therefore, it is now time to tuck away or remove those soldered
  179. wires.
  180. Because I want to keep them around for future use, I tuck them away, making sure that the connectors
  181. don't touch each other or the board.
  182. <img src="images/20_tuck_away_wires.jpg" width="200">
  183. The bottom cover can now be put back on. The lamp is ready for use.
  184. <img src="images/21_reassemble_and_enjoy.jpg" width="200">
  185. ## Troubleshooting flash
  186. If you have **A fatal error occurred: MD5 of file does not match data in flash!**, then make sure
  187. you are powering the board using the lamp's own power adapter. We've seen these errors when trying
  188. to power the board using the 3.3V debug pad.
  189. After seeing this error, user @tabacha was able to successfully flash his lamp using the regular
  190. power adapter.
  191. < [Configuration guide](configuration.md) | [Index](../README.md) | [Technical details](technical_details.md) >