What code issues could persist past a reset? (STM32F103)
Maybe something is being clobbered that you are not initializing in your code and that is not automatically initialized by the reset. When the power is removed it may take on a random value that happens to be okay. 

250 lines of code is not very much, but maybe you can further reduce it to try to isolate the problem. If you have a debugger attached to the system when it hangs, the cause could be related to the external system.