Knowledge Base

Serial debugging: Getting back control (with SPLat/PC)

Once the serial port has been switched to “user protocol” mode, it is impossible for SPLat/PC to command the controller to stop. This means SPLat/PC cannot connect to the controller (referring here to the “classic” SPLat/PC debug functions, which require the SPLatLink protocol.

There are two ways around this:

  1. Power cycle the board. You then have a 10-second window to connect.
  2. Get the board out of user protocol programmatically.

The second methods requires some way of signalling to your program that you want to get back control, and then having your program do something to make it happen. The easy way is to have a dedicated task watching a spare input, and then crash the program with a subroutine that calls itself. Example:

           LaunchTask  KillTask
           ...
           RunTasksForever
           ...

KillTask:  WaitOnK     iKillSwitch
           iiPrintText 251,'0D,'0A,"Terminating with extreme prejudice."
Die:       Gosub Die

This is quick and easy, if somewhat brutal. It will always report a runtime error when you do connect. You still have to connect within 10 seconds.

A more subtle way is to switch back to SPLatLink.

           LaunchTask  GracefullyRetire
           ...
           RunTasksForever
           ...

GracefullyRetire:
           WaitOnK    iRetireSwitch
Retire:
           iiPrintText 251,'0D,'0A,"Retiring gracefully"
#          Open_Serial SPLatLink(9600)
           GoTo       GracefullyRetire
           ...

Which method you use is up to you.