You swapped the tenses of do and of come. The tense of do is relevant to your question, but you don't need to change the tense of 'come' to change the meaning in the way that you describe. I have therefore simplified your two statements by replacing the "you were coming" and "you came" by "on your way".
do has several meanings. The two that are relevant are:
- to perform (an act, duty, role, etc.). This is an activity that takes some time, so you would use a continuous tense to imply this meaning.
- to accomplish; finish; complete: This is an event, so you would use a simple tense to imply this meaning.
Did you do your homework on your way to school?
"Did you do" is a simple tense, so you are asking whether the student finished their homework on their way to school.
Were you doing your homework on your way to school?
"Were you doing" is a continuous tense, so you are asking the student whether thew were working on their homework on the way to school.