STM32F0, DRV8840 and GPIO Problems
Ok I have the answer...

It was due to encoder interrupts. My motor is coupled with an encoder and when I disconnect the motor, I also disconnect the encoder. I tested my program with disabling the interrupt and it is ok.