Hello Gianni,
of course, we try to help you.
If I understood the situation correctly, the error happens only if the additional code is part of the project - but it is never called. Just the changed location of the other code causes the problem.
Two ideas:
1.) Can you try to switch off the compiler optimization? Does this change the effect? Btw: What compiler are you using?
2.) Please check the MPU settings - within version 8.30 of the Build Environment we changed the MPU settings according ST application note AN4861.
Please find the necessary configuration for STM32F746 within the following file ew_bsp_system.c.
Generally, it might be good to update to the latest version (8.30 at the moment)...
Best regards,
Manfred.