Runtime memory corruption is one of the worst class of bugs a C/C++ application can have. I do not mean design problems like abuse of global variables, but seemingly correct code clobbering memory it should never touch (for example due to runaway pointers). Compared to “regular” crashes that are obvious and much simpler to fix (even if they are rare they leave a stacktrace), memory corruption is often silent. It can go unnoticed for a long period and manifest itself in subtle ways. For example: the application sometimes acts weirdly or a particular variable is sometimes wrong. Fortunately Cortex-M3 and M4 cores are equipped with special hardware that can assist in catching rogue memory accesses.
Continue reading “Cortex-M – Debugging runtime memory corruption”
Month: August 2018
Preserving debugging breadcrumbs across reboots in Cortex-M
Debugging embedded systems during development even with the best tools can be hard. Certainly a good debug probe makes life easier, but what do you do after the product is shipped? What if the customer complains that something strange is happening sometimes or a bug makes the device reboot, but only once a week? You make the firmware gather diagnostic information for you. This is the first post in series.
Continue reading “Preserving debugging breadcrumbs across reboots in Cortex-M”
Reducing firmware size by removing libc
The C standard library (libc) is a component that gets little attention. It is just there. However for embedded systems it brings some challenges and overhead in terms of code size. As firmware size is often critical, it sometimes makes sense to use a trimmed version of the standard library or to remove it entirely. I will focus on reducing the code size that may be beneficial for a small application like a bootloader.
Continue reading “Reducing firmware size by removing libc”
Fixing Cortex-M startup code for link-time optimization
Link-time optimization is a powerful output size reducing feature. Even though (as of 2018) still regarded as somewhat experimental, LTO is worth trying, if the binary size is very important and the application can be reliably tested afterwards, as link-time optimized code is hard to debug. A bootloader can be an ideal example. LTO is very easy to enable, but there are some small quirks that have to be taken care of. I will use GCC 7.2.1 from GNU Arm Embedded as an example.
Continue reading “Fixing Cortex-M startup code for link-time optimization”