Skip to content

Latest commit

 

History

History
45 lines (25 loc) · 3.74 KB

File metadata and controls

45 lines (25 loc) · 3.74 KB

Chapter 9: Getting Into Trouble

This is a companion repository for Making Embedded Systems, 2nd Ed. by Elecia White.

Following Along in the Book

Compiler Explorer is a web tool lets you look at the assembly that your code becomes after compilation. In the book, there is an example with an interrupt that needs a volatile. You can see that at Compiler Explorer here. If you change the compiler options from -O3 (optimized) to -O0 (unoptimized), the while loop returns to the assembly Alternatively, if you make the global variable volatile, the while loop remains because the volatile keyword lets the compiler know other piece of code may modify the variable.

Rubber duck debugging is when you explain your issue to an inanimate object. It is surprisingly effective.

Debugging Hard Faults (Arm Cortex-M)

In Ending the Embedded Software Dark Ages: Let’s Start With Processor Fault Debugging!, Phillip at Embedded Artistry goes through the whole process of debugging from manually walking through the hardfault to creating good handlers to making a mini-core dump for later use. He also writes about using Memfault's services to track hard fault issues.

That links to Interrupt Blog’s How to Debug a Hard Fault on an Arm Cortex-M MCU which is the most tactical hands-on resource.

More information about hardfaults

Arm Documentation: Configurable Fault Status Register - Cortex-M3

Profiling Firmware on Cortex-M from Interrupt provides an code to create a sample Profiling with GBD and awk on a Cortex-M processor. (It also shows other profiling methods.)

Linker Files

Miguel Young de la Sota’s post about Everything You Never Wanted to Know About Linker Script is an excellent and thorough post about linker files.
Another great resource is Thea Flowers’ post on the most thoroughly commented linker script (probably). Finally, Phillip Johnston’s Linker-Generated Variables in Libc shows how to use and set linker variables.

Memory

Extended and excellent video instruction on Memory and Pointers in C / C++

Code For This Chapter

hardfaults.c shows the code used in the book. It was developed using an STM32 L4.

stackoverflow.c shows two ways to overflow the stack. See Smashing The Stack For Fun And Profit: buffer vulnerabilities and why stacks and heaps are important

Final Note

If you like what's here, please consider buying the book: Making Embedded Systems, 2nd Ed. by Elecia White