Sooo… where was I?
Mostly just doing my own thing, building stuff, breaking stuff, etc., etc. Living the dream, as some might say.
Part of what I was doing was taking the long, winding road to creating cogsandsquigs/twiboot (not to be confused with orempel/twiboot, but that’ll be explained later). How I got here was long, tiring, and frankly too exhausting. So that’s where two (of the many previous) weeks of my life went!
Flashback to 2 weeks prior: I was sitting around, minding my own buisness, when my boss and I were having a discussion about what to do about our problem: The chips we were using for our internal project didn’t support OTA updates. They’re just tiny little ATmega328s, which we could possibly ship with buggy or outright broken code! Fortunately, these guys were controlled by a Particle Argon, which could connect to WiFi and did support OTA updates.
The question was, how do we get the ATmegas to be updated by the Argon? The answer was a bootloader, of course! A custom bootloader which could be controlled (for a split second) by the Argon, which could send it new firmware through a communication protocol (I2C/TWI was the one we were gonna use), and bam! updates! How hard could it be? Not worse than coding in C for the Argon and Arduino Uno (basically an ATmega + nice libraries + nice hardware), right?
As it turns out, it was awfully hard. Like, really, really, really hard. Low level programming with C is not for everyone (and definitely not for me!). Because I don’t want to provide too much detail, being a lazy blogger, here’s a step-by-step of what happened:
- Research.
- Start with low-level programming.
- Get a simple blink example to work on an ATmega328.
- Great, that works! Try doing stuff over UART/Serial.
- Very difficult, but manageable. Try I2C/TWI now?.
- Wow, that was awful, and it doesn’t work!.
- Repeat steps 1-6 a few more times.
- Stumble across orempel/twiboot.
- Try to get that to work.
- Suprise! It doesn’t :(.
- Repeat steps 1-6.
- Try to make just a bootloader, see if that can work.
- It works, just not for what we need.
- Repeat steps 1-6.
- Try twiboot in desperation again.
- Suprise! It works now. (I needed to send 128 bytes of flash per page at a time, nothing more or less. Silly me, just read the docs!)
- Make a particle library for it.
- Done! Eazy-peezy lemon-squeezy.
Yeah… those were an awful two weeks. But I’m done now, and you can find the library at the link above. Don’t confuse it for orempel’s library, though. That’s the actual bootloader.
So if you’re ever in my position, and need something to help you, maybe my work can make your life easier. Maybe. Or it could make it hell, I dunno how many bugs are in there (but I tried to squash them all, don’t worry :P).
So I guess the moral of the story is that you should do things the easier way, especially if someone has done them before, because otherwise you end up wasting weeks of your time and energy getting nearly nothing done, only for you to find out that someone else did what you tried to do better than you ever could.
See ya!