Using ESP/Tasmota for OTA programming of STM32 microcontrollers #21068
Replies: 3 comments 6 replies
-
Tasmota is already able to do OTA update of STM32 via serial, like in the Shelly Dimmer 2 where the Tasmota setup includes replacing the firmware of the STM32. To be clear, I've not looked closely at your suggestion here, or how things differ, and am not trying to say anything about how to handle the "overlap", but it seems to plausibly make sense to have some unification. |
Beta Was this translation helpful? Give feedback.
-
Oh, cool, I had no idea. I'll have to look at the existing code then. But based on the docs alone, a major difference is that Tasmota is driving the bootloader protocol there, given a firmware file upload. In my implementation, Tasmota is acting like a dumb serial to TCP bridge, relying on another project to handle the bootloader protocol. Arguably the latter is more flexible, since it also allows readback and option byte programming, etc. I also don't really know if there are big differences in the STM bootloaders across the many STM32 variants out there, but I could imagine some corners having been cut in existing code considering it only has to work for one target device. My gut feeling is that unifying the two would probably be a lot of work due to how different the approach is. ETA: reading that again, I sound like I don't like the existing approach -- of course the existing method is much more user-friendly! It would probably be good enough for my use case too, if it works with the chip I'm using. |
Beta Was this translation helpful? Give feedback.
-
Yes, you are correct in your assumption that most Tasmota users does not touch the code. |
Beta Was this translation helpful? Give feedback.
-
Short version: I just made a Tasmota driver to use an ESP-01S for OTA updating of STM32 microcontrollers. Is there any interest in a pull request?
Long version:
I'm currently working on some DIY home automation stuff, but after having tried Tasmota and ESPHome for a while I'm not convinced about power consumption, latency, stability, etc... WiFi just isn't for me. So back to wired serial ports I went.
One thing I immediately missed from the WiFi stuff though, is OTA. You just can't really do that over DIY serial busses running at 2400 baud, not to mention that writing bootloaders yourself is hard. At some point I moved to Teensy-based stuff (back when that was a tenth of the price) so I at least wouldn't need more than a long USB cable, but the really old stuff is a bunch of ATtiny microcontrollers that are so far embedded I need to flip my breaker, disassemble stuff, and then flip my breaker again to, you know, power my computer. Rinse and repeat for every test... Ain't nobody got time for that. Counterpoint: that system has been working flawlessly without any updates or repairs for over a decade now. Meanwhile Home Assistant + ESPHome seems to catch fire for an entirely new reason every time it updates, power goes out, or there is a full moon. Really, the only thing my own system misses thus far is reasonable extensibility, which, due to all the DIY point-to-point serial connections, usually requires recompilation.
So I had the following idea: what if STM32 microcontrollers (which have a serial bootloader, similar to ESP, but are much less power-hungry and have much more I/O and peripherals), but with an ESP-01S tied to its primary serial port, BOOT0, and nRST pins, with its power gated by a switch controlled by the STM32? Then whenever I want debug serial or OTA updates, I can give it a command to enable power to the ESP-01S over whatever low-speed wired protocol I want. Or I can just push a button to do the same if that fails, which is more work, but still doesn't require disassembly and such. A complete ESP-01S module is literally cheaper than a single STM32 in my BOM (Asia vs the West and all), so it seems worth the investment.
I found the existing TCP to serial bridge driver in Tasmota, and initially figured I'd just use that. However, I didn't immediately see a good way to automate driving BOOT0 and nRST without setting up and maintaining a whole MQTT environment again just for that. What I wanted, really, is for it to just reset the STM32 into its bootloader automatically when connecting via TCP, and reset it into application code when the connection closes. I figured I could just script it, but the ESP-01S board I designed for is an ESP8266, so no berry scripting. D'oh. To be honest I know little more about berry than that it exists, so I don't really know if it would have been possible anyway.
In the end I bit the bullet and started hacking away at Tasmota itself. The result is a clone of the TCP to serial driver, with some light modifications to make it do what I want. It differs from the existing TCP bridge as follows:
Combined with a modification to stm32loader that allows it to connect via TCP instead of a serial port, I have everything I need: just point it to the bootloader TCP server and it can program the connected STM32. In the meantime I can keep netcat/telnet open to the virtual COM port server for debug messages and commands.
So, as I stated in the tl;dr, my question is if there is interest in a PR for this, or if it's out of scope. After all, I think Tasmota is more intended for people who can't or don't want to program microcontrollers themselves, which you'd still have to do for STM32s. Not to mention that there's some circuitry involved in tying the two together, at least if you don't want the ESP32 to always be powered. I'm guessing the answer is "out of scope," and I don't want to spend time testing and cleaning up beyond "works on my machine" for a dead-on-arrival PR, so hence the question.
Beta Was this translation helpful? Give feedback.
All reactions