If you press the 'Pause' button, the system will schedule a pause for the end of the trial. From the paused state, you can press stop.
Before you try it, make sure that the following lines are at the end of your main loop to ensure that data is saved before the pause:
HandlePauseCondition; % If the protocol is paused, execution waits here until user resumes.
if BpodSystem.Status.BeingUsed == 0