2 Running algorithms
Clyne edited this page 3 years ago

Now that you've written your algorithm, it's time to upload it to your board and see how it runs.

1. Compile your algorithm

Your algorithm must be compiled before it can be uploaded. Compilation can be initiated either by clicking the "Compile" button seen below the menu toolbar, or by clicking the "Compile code" entry of the Code menu.

The log view at the bottom of the stmdspgui window will indicate if compilation succeeded. If it failed, error messages will be shown that will help you fix your code.

Compiling...
   text	   data	    bss	    dec	    hex	filename
    106	      0	      2	    108	     6c	/tmp/stmdspgui_build.o

Compilation succeeded.

Algorithm size limits

Above the "Compilation succeeded." message is information on the memory usage of your algorithm. As your algorithm grows in complexity, you will want to make sure you do not exceed the amount of available processor memory.

  • text: This is the total size (in bytes) of the processor instructions that make up your algorithm.
  • data: This is the number of bytes of uninitialized static memory your algorithm requires.
  • bss: This is the number of bytes of initialized static memory your algorithm uses.
  • dec/hex: These display the sum of text, data, and bss, in decimal and hexadecimal.

There are two size limits you need to be mindful of: binary size and stack size. Binary size is the total size of your compiled algorithm (the dec value from above); currently, the limit is 16 kilobytes or 16,384 bytes. If your algorithm exceeds this, stmdspgui will report an upload error.

Your algorithm's stack usage is not easily measured. Two things use up stack memory: function calls, and non-static variables (any variables that are not marked static). There is 15 kilobytes (15,360 bytes) of stack memory available.

As long as you are not declaring large stack-allocated variables (e.g. int myarray[1000]), you should not need to worry about the stack limit. If you do have large variables, consider marking some as static to keep them outside of the stack: static int myarray[1000].

2. Upload your algorithm

The next step is to upload your compiled algorithm. Provided that your algorithm compiled successfully, this is a straightforward step: click either the "Upload" button under the toolbar, or "Upload algorithm" in the Device menu. The log view will report if the upload is a success.

Note: stmdspgui uploads the most recently compiled algorithm. If you have edited your algorithm since the last compile, you need to re-compile before uploading; otherwise, you will upload an old or "stale" version of your algorithm!

If you ever need it, the Device menu also has an "Unload algorithm" entry, which can unload the algorithm that's currently on the device. It is not necessary to unload between uploads. If the device is told to run without a loaded algorithm, it will behave as if a passthrough algorithm is loaded.

3. Run your algorithm

Once an algorithm is uploaded, it can be run by clicking the "Start" entry of the Device menu. Once started, the status LED should change from a slow, green blink to a fast, blue blink. To stop the algorithm, click the now-visible "Stop" entry in the Device menu.

While running, the signal on the SIGNAL IN port of the add-on board is sampled, processed by your algorithm, then outputted through the SIGNAL OUT port. You may try connecting a simple signal source to SIGNAL IN, like a voltage or function generator, and using an oscilloscope to monitor the output on SIGNAL OUT.

If you do not have this lab equipment available, don't worry; stmdspgui and the add-on board can provide the same functionality. See stmdspgui without lab equipment.

stmdspgui also has multiple utilities available for analyzing your algorithm's performance. See Analyzing algorithms.