Thanks for your reply. The watchdog is disabled and I'm not using any semihosting libraries as described. I am debug printf through UART.

The full part number is K21FN1M0VMC12 and K60DN512ZVLL10. I want to convert from a K60 project to K21. Is there any safe way to share the project with you?
An update to the problem. When I make some changes to the code and debug on the target, the hardfault handler is triggered. Looking closely at the handler, there is a bus fault and the rogue address is saved in the Bus Fault Address Register (BFAR). This address is assigned as a value to a pointer variable in my code.

Memory settings of the target:

If I debug a gain with the same code, the micro (or sth else) seems to realise the problem and assign a more appropriate value to the pointer. Now I know where the problem is actually is.
The question really is why the correct behaviour is observed in debug mode?
Many thanks.