Hi guys,
A pleasure to finally partake in a forum I've browsed for such a long time. As a general EE enthusiast and hobbyist I've worked with half a dozen of microcontrollers over the years. I consider myself experienced, and almost like an old fart. However what I experienced recently really surprised me and also demused me at the same time. I came here to ask if someone else has remotely the same experience, and what they would do about it..
My design: I'm built this kit that does videorecording and logging based on a pi5 (video processing, saving.. Linux system obviously) and a microcontroller for the buttons.. nice for PWM LEDs (I never trusted Raspberry Pi PWM, although I hear it's getting better). Both are connected with a 230kbps UART connection (2 traces on the PCB). The microcontroller is a SAMD21. This little bugger is cost efficient, and since I always was charmed by Arduino, of course it had to be an Atmel..
Here it comes. So I build a number of these kits.. and most just work fine. Then I had one and after a couple of power cycles it just failed? Wut? Then I opened GDB and guess what? The code section was corrupted in a number of places. A bunch of bit flips? But this is flash memory?? How is that possible? I googled like mad, and all I could find is that you need a good dose of X-rays (more than an airport scan) or a hammer. It seemed to be impossible. But.. after a while it happened again on this same unit! I then replaced the MCU and after a few weeks it happened .. AGAIN!?! .. Everytime in a slightly different area in the flash memory..
Then I started to suspect power spikes, and to be honest the startup transients didn't look clean on the scope. But while they seemed to exceed the 3.3V it only happened for a very short time. I don't know how much damage is done if you exceed 3.6V for a matter of microseconds? And how well is my oscilloscope calibrated? Those sort of things cross my mind. As a last resort I just reached out to Atmel (now Microchip) and asked if they could understand what was going on here. Their answer: you need to have a monotonically increasing power supply transient and it needs to ramp up to 100% in about 1 millisecond. If not, then the flash controller can become unstable and yes, even get its memory banks corrupted! I've certainly never heard about this before..
Well, in my case that wasn't what happened. The Pi powers the MCU with its 3v3, and it has this little spike at the beginning.. and then after 10 millisecond it finally ramps up to 3v3. And I suspect this is what causes the problem. The thing totally browns out.
I read this blog post about brown out detection:
https://blog.thea.codes/sam-d21-brown-out-detector/This blogger seems to have experienced the same issues...
However, some people say that brown out detection and reset won't cut it. You just need to have a good power up sequence... The irony is. I actually do power sequencing to avoid backpowering the Pi. Would the MCU activate its UART lines too early it could potentially mess up the Raspberry Pi process. Seems like the chicken or the egg.
Ok, long story. Sorry guys. Does anyone have a similar experience. Should I just ditch the SAMD21? Should I hold the NRST pin low for a long time using an RC circuit? Curious what you think.