Don't stop the clock before turning it off.

Stopping the clock pauses until the clock is low. If the clock is no longer running then stop clock might pause forever. It is perfectly valid to turn off a running clock so just remove the call to stop_clock().

See http://www.xcore.com/forum/viewtopic.php?f=26&t=2772 for someone who has hit this problem.

I haven't tried this on hardware but app_spi_loopback_demo still passes in the xsim.