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.

224 lines
9.5 KiB

  1. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >
  2. # Flashing guide
  3. ## Tools needed
  4. * Allen key (2mm, 5/64") or torx (T8) screw driver
  5. * Soldering Iron
  6. * A serial to USB adapter (FTDI)
  7. * Some wires
  8. * Optional: sticky tape, hot glue
  9. ## Warning
  10. We have writen these instructions with care, but we will give absolutely no
  11. warranty. Perhaps you will destroy your lamp and your computer.
  12. ## Opening the lamp, to expose the PCB
  13. Remove the rubber pads from the botton of the lamp, to get access to 4
  14. screws that attach the bottom to the rest of the lamp.
  15. <img src="images/01_unboxed.jpg" width="200"><img src="images/02_remove_rubber_pads.jpg" width="200">
  16. Note that you don't have to remove these pads fully. Once you can access
  17. the screws, you've gone far enough.
  18. <img src="images/03_bolts_overview.jpg" width="200">
  19. Unbolt the 4 screws which were hidden under the rubber pads.
  20. <img src="images/04_remove_bolts.jpg" width="200"><img src="images/05_bolts.jpg" width="200">
  21. Detach the bottom from the rest of the lamp, exposing the PCB. This might
  22. take a bit of force. Just pull it off bit by bit, until it pops loose.
  23. <img src="images/06_pull_off_the_bottom.jpg" width="200"><img src="images/07_bottom_removed.jpg" width="200">
  24. <img src="images/08_board_exposed.jpg" width="400">
  25. ## Solder the wires
  26. The wires will be connected to the debug pads that are shown in the following image.
  27. <img src="images/09_debug_pads_for_soldering.jpg" width="400">
  28. Many of the serial to USB adapter have some header pins to which you can
  29. connect the wires of a device. Therefore, it might be useful to take some
  30. dupont wires, cut off one end, and solder the stripped end to the board.
  31. *Note: Whether to use male or female dupont wires depends on how you want to connect
  32. the serial adapter. In this example, I have used male wires, so I could plug them
  33. into a breadbord.*
  34. <img src="images/10_stripped_dupont_wires.jpg" width="200">
  35. Solder the wires to the `RX`, `TX`, `GND` and `GPIO0` debug pads.
  36. *Note: The board has a debug pad that exposes 3.3V. It is not required to
  37. solder a wire to this debug pad. For that reason, I have not marked this debug
  38. pad in the images. This pad is not directly connected to the 3.3V Vin of the
  39. ESP32 chip, making it a less than optimal candidate for powering the board
  40. during flashing. Instead, powering the lamp using its own power supply works best.*
  41. You could use some sticky tape to fixate the cables before soldering.
  42. When you want to keep the wires attached after flashing the new firmware,
  43. then you might want to apply some hot glue to fixate the wires. This prevents
  44. the wires from breaking off, due to excessive movement.
  45. <img src="images/11_soldered_wires.jpg" width="200"><img src="images/12_optional_hot_glue.jpg" width="200">
  46. ## Connect the wires to your serial to USB adapter
  47. The wires must be connected as follows:
  48. | Soldering point| Serial USB Adapter name |
  49. | -------------- |:------------------------:|
  50. | GND | GND |
  51. | TX | RX |
  52. | RX | TX |
  53. | GPIO0 | GND |
  54. To be able to flash the lamp, `GPIO0` must be connected to ground while
  55. the lamp boots up. Therefore, connect these wires *before* plugging in
  56. the lamp's power supply. Flashing will not work if you connect these
  57. wires after the lamp has already been booted up.
  58. ## When you only have one GND pin on your USB Adapter
  59. If your USB Adapter does not have multiple `GND` pins, then you'll have to
  60. find another way to attach `GPIO0` to ground. Some options:
  61. - Use a breadbord, so you can connect the USB Adapter `GND` pin to a row on
  62. the bread bord, and connect the `GND` and `GPIO0` wires of the lamp's
  63. board to that same row.
  64. - Solder a button on the board that connects `GPIO0` to `GND` when pressed.
  65. Then you can hold down this button while plugging in the lamp's power
  66. supply. After booting up, you can release the button (the serial console
  67. will also mention that flash mode is now enabled). This is not the most
  68. practical solution for most people (since only one such flash operation is
  69. needed, from then on OTA - Over The Air - updates are possible), but it
  70. was a great help to me during the initial reverse engineering and firmware
  71. development.
  72. - Manually hold a wire connected to both a GND surface (e.g. the silver pad
  73. on the left of the board) and the `GPIO0` debug pad, while plugging in the
  74. power supply. After booting, the wire can be removed. This is very fiddly
  75. way of doing it (a third hand would be very welcome with this), but it can
  76. be done.
  77. - You could opt for temporarily soldering a lead between `GND` and `GPIO0`
  78. on the board, making `GPIO0` pulled to ground permanently. It is a bit
  79. less flexible than some other options, but if you only need to do the
  80. initial backup and firmware flash of the lamp, then this can be all
  81. that you need. Remove the lead after flashing is done, otherwise the
  82. lamp won't boot in normal mode.
  83. In the images below, you can see the first solution, using a breadboard.
  84. <img src="images/
  85. 13_connect_to_serial_to_usb_adapter.jpg" width="200"><img src="images/14_connect_to_serial_to_usb_adapter_close_up.jpg" width="200">
  86. ## Make a backup of the current firmware
  87. Backing up the firmware makes it possible to revert to the original firmware,
  88. in case you have problems with the ESPHome firmware. The backup can be
  89. created using "esptool". Installation instructures can be found here:
  90. https://github.com/espressif/esptool/blob/master/README.md#installation--dependencies
  91. Here's an example on how to backup the original firmware from Linux. First,
  92. unplug your lamp's power supply, then start the esptool read_flash command:
  93. ```
  94. python esptool.py -p /dev/ttyUSB0 read_flash 0x0 0x400000 original-firmware.bin
  95. ```
  96. `/dev/ttyUSB0` is the port of the USB adaper on Linux. You can find what
  97. port is used by the adapter by running `dmesg` after plugging in the USB
  98. device. On Windows this is often `COM1`, `COM2` or `COM3`.
  99. Now plug in the power supply. The output of esptool should now show that it
  100. connects to the lamp and downloads the firmware from it.
  101. **Caution**: You will find the WLAN SSID and Password of the last used
  102. WiFi network in this file. Therefore, keep this backup in a safe place.
  103. ## Restore the backed up firmware
  104. In case you need to rollback to the lamp's original firmware at some
  105. point, here's an example of how to restore the original firmware from
  106. Windows, by fully flashing it back onto the lamp.
  107. First, unplug your lamp's power supply, then start the esptool write_flash
  108. command:
  109. ```
  110. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x00 original-firmware.bin
  111. ```
  112. Make sure that `GPIO0` is connected to GND and plug in the power supply.
  113. The output of esptool should now show that it connects to the lamp and
  114. uploads the firmware to it. Be patient after the upload reaches 100%. The
  115. output is silent for a while, but esptool tool is verifying if the firmware
  116. was uploaded correctly.
  117. After the firmware upload completes, unplug the power, disconnect `GPIO0`
  118. from GND and reconnect the power supply to boot into the restored firmware.
  119. ## Flash new ESPHome firmware
  120. Setup an ESPHome Project (see [README.md](../README.md)),compile the firmware
  121. for the lamp and download the `firmware.bin` file to the device to which
  122. the serial adapter is connected.
  123. You can flash the lamp using esphome or esptool. I would recommend using
  124. the [esphome-flasher](https://github.com/esphome/esphome-flasher) tool,
  125. which is a very easy to use GUI utility app for flashing ESPHome devices:
  126. - In the app, select the COM port of your serial adapter.
  127. - Also select the firmware.bin file to flash onto the lamp.
  128. - Power up the lamp with `GPIO0` connected to GND.
  129. - Click the "Flash ESP" button to flash the firmware.
  130. If you want to flash with esptool, you can use:
  131. ```
  132. python.exe .\esptool.py --chip esp32 --port COM3 --baud 115200 write_flash 0x1000 <path\to\yourfirmware.bin>
  133. ```
  134. After flashing, power down the lamp, disconnect `GPIO0` from GND and
  135. reconnect the power to boot into the new ESPHome firmware.
  136. From here on, it is possible to flash the lamp OTA (over the air, which
  137. means that the firmware is uploaded over WiFi) from ESPHome. Therefore, it
  138. is now time to tuck away or remove those soldered wires and add the bottom
  139. cover back on.
  140. ## Troubleshooting flash
  141. If you have **A fatal error occurred: MD5 of file does not match data in
  142. flash!**, then make sure you are powering the board using the lamp's own
  143. power adapter. We've seen these errors when trying to power the board using
  144. the 3.3V debug pad.
  145. After seeing this error, user @tabacha was able to successfully flash his
  146. lamp using the regular power adapter and the tasmota boot loader using
  147. the following command:
  148. ```
  149. python esptool.py --chip esp32 -p /dev/ttyUSB0 --baud 115200 --before default_reset --after hard_reset write_flash -z --flash_mode dout --flash_freq 40m --flash_size detect 0x1000 bootloader_dout_40m.bin 0x8000 partitions.bin 0xe000 boot_app0.bin 0x10000 ~/Downloads/schlafzimmerbedlight.bin
  150. ```
  151. You will find the missing tasmota boot files here:
  152. https://github.com/arendst/Tasmota/tree/firmware/firmware/tasmota32/ESP32_needed_files
  153. *Note: user @tabacha was not able to use tasmota with the Bedside Lamp 2.*
  154. (remember that the [esphome-flasher](https://github.com/esphome/esphome-flasher)
  155. will give you a bit less of a hard-core experience during flashing)
  156. < [Configuration guide](configuration.md) | [Index](../README.md) | [Known issues](known_issues.md) >