Please post more details on your case (share the entire debug log), so that it will be easier to understand the root cause.
Otherwise, I advise you to check the Debug configuration in the CubeIDE and make sure to select the adequate external loader. Check also your board stack size.
In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. Thanks