I'm using an STM32F4 discovery board for a project and am wondering if I'm approaching the problem correctly. When I press a button, an external interrupt is triggered which runs a routine; without using a delay, this part works fine. As the routine moves a servo then returns it to its original position, a delay is added to allow the servo to catch up with the new PWM output before returning to the original position. When I run the new interrupt routine with the delay, the board locks up. In debug the code appears to stall at the delay loop.
The delay is a simple systick routine. Is it bad practice (thus the reason for my crashes) to put this inside my interrupt, and should I use a different method? For example setting a one shot timer inside the external interrupt routine which returns the servo after a set time?
Thanks!
As you've discovered, interrupt routines are intended to perform quick handling of an external event, and defer additional work to other facilities. This is why, in your case, the delay loop causes the board to lock up: no other work is being performed while the code is sleeping inside the interrupt handler. That is a typical characteristic of all interrupt handlers.
If you need to perform a separate task (moving the servo again), schedule it just like you described: