Code that seems to "hang":
Possible causes:
* Any loop (those that do not simply count, but look at changing conditions): breaking conditions are not satisfied as you expect
* Stack corruption
* Wrong/corrupted function pointers
* ISR that gets retriggered infinitely
By far, #1 reason for stack corruption is over/underindexing an array. Just search for [ in your code to find every indexing, add range checking as shown above, and chances are high you catch the problem! Just call the customer, ask how many times the LED is blinking, and voila, you have a fix within a day! (Remember that if you index with signed types, negative indexes will cause a problem, too!)
Of course pointer arithmetic can go wrong, too, but people usually do less of it, and are more cautious when they do, which is why I mention [] indexing as the most probable cause.
If you handle strings, make sure you use the strncpy, snprintf type functions and further, read very carefully how they actually work regarding the n parameter (do they add terminating zero or not, and if they do, is it included in the n?)
I mention this stack corruption first, because when you rule it out first (or, reduce the likelihood by safeguarding the most usual suspects), this either fixes the problem, or leaves:
* Any loop (those that do not simply count, but look at changing conditions): breaking conditions are not satisfied as you expect
* Wrong/corrupted function pointers
* ISR that gets retriggered infinitely
Function pointers are easily checked because you either have none, or have just a few, or you are an experienced C wizard who makes no mistakes with them.
This leaves retriggered ISRs, and loop conditions. For ISRs, make sure you understand the clearing conditions of peripherals, and maybe you have unexpected interrupt sources turned on, like an error interrupt coming from EMI/ESD event, which you fail to check and clear, keeping it repeating?
This leaves you with just loop conditions, and instead of going full-blown instrumentation first, maybe you can just go through all of your loops, looking for assumptions such as some peripheral setting a status flag like you expect, but not do that? You can probably rule out 90% of your loops as trivial enough, and instrument the rest; add a timeout and report an error.
I despise of STM32 HAL code where every freaking function can return a failure or a timeout. Talk about cargo cult engineering! The problem here is, there is already enough instrumentation, error checking and recovery work to do where a failure can actually happen. You don't need to check every operation which, by design, cannot fail, and STM32 designers should know the best which can fail, and which can't.