What is "bricking" and how to prevent and overcome it!Follow article
What is “bricking?”
Many of us have been there, developing on a new MCU and all of a sudden it become unresponsive. That feeling of dread flows through you and you think to yourself "did I just brick this device?" That is, is it possible to put the device into a state where it is unrecoverable, unable to be modified, or connected to with a debug adapter?
Yes, there are several ways in which this can happen. The primary cause is a lack of time for the debug adapter to access the device between reset and the device becoming unresponsive. The debug adapter will need a small amount of time where the device is responsive after reset in order to connect, so performing some action which halts the device immediately after reset can cause a device to become unrecoverable.
Primary means of performing this are:
- Switching to a non-functioning clock
- Going into a low power mode
- Issuing a reset
Preventing and dealing with “bricking” a device
In order to avoid this problem, it is advised to add a small delay at the beginning of user firmware, before any other code begins executing. The delay is dependent on the MCU but around 1ms should allow plenty of time for the debug adapter to connect to the device and halt it before the device can disable itself. This delay can be removed from tested and production-ready code.
A trap that I personally use is to halt the program near the very beginning of the code when a GPIO is toggled. This is easy if the development board you are working on has buttons. It is easy to implement and an example is below.
If the program is unresponsive you can hold the button down on reset and catch it in this loop, without a button you can power or ground the pin, depending on your code, which serves the same purpose.
If you have bricked your device there is hope. Most IDEs offer a flash utility that can erase the flash and bring it to a default state. Silicon Labs offers Simplicity Studio which is a free IDE with this flash utility that makes it very easy to either clear certain pages of flash or the entire thing. However, it’s probably best to never get to this point in the first place!
Hopefully this knowledge will prevent you from bricking your device and assist you in figuring out how to un-brick a device!