Search This Blog

May 18, 2015

Time lapse of clouds in a sunny day

Some days clouds just look amazing, and in such a day it is so difficult not to photograph them. However this time I shoot about 1400 photos in about 1.25 hour to see how beautiful they move, change their shape and dissipate.

May 12, 2015

How to log debug data in TI CCS?

* This topic is based on experience with Texas Instruments (TI) Code Composer Studio (CCS) version 5.5

Let's say we have pressed the green bug button in order to debug our project when it is running on a target device. We add some variables of our interest, e.g. temperature sensors, to the CCS' Expressions view for watching them during the debug session. Here, assume we only use JTAG. What if we want to log these data in a file for analyzing it in a later time? Obviously to halt the program and do a copy and paste from the Expressions view to a text file manually is a burden! Good news is that there is a better way to do this, and the key is to use Scripting Console within CCS. To see the Scripting Console view follow this menu steps: "Window -> Show View -> Scripting Console". Let's denote Scripting Console by SC in the rest of this text.

Scripting Console in CCS v5.5

The scripting language of SC is JavaScript. To see the already existing functions and definitions in SC press the "Tab" button. To view help for each of the listed items type "help item_name". To serve our logging purpose the "saveData" command is the right tool for us. Let's see the help for it: 

 js:> help saveData
Description: Save a block of target memory to a data file format
Syntax: saveData(address,page,filename,length,IOFormat,append)
  address - the first address in the block
  page - the memory page, use one of the PAGE_X constant
  filename - specifies the name of the file that store the target data
  length - defines the number of words to store
  IOFormat - Specifies the format in which memory words will be written to the output file. Use one of the IOMEMORY_X constant
  append - true to append to an existing file, false to overwrite. Note: append is not supported for COFF formatted files.
 It is pretty clear what to do now. So if we stick to our example of logging temperature sensors we need to know where in memory these values exist. If the variables are in a structure and we add that structure to the Expressions view, the address of that structure is already shown under the Value column. Another way to find the address for any variable is to right click on its name in the Expressions view and select "View Memory", and voila!, you find the address highlighted in the left column, e.g. something like 0x0000BA10. Note that if you change your code which manipulates data storage, then you want to check the addresses again.

 Next in the line is 'page', and in our example we need PAGE_DATA, which is a predefined variable in the SC, just it. Then the filename is where the log file is stored. We have to give the filename as string and note that a windows path like "C:\MyProjects\hemnik\logs\temp.log" will not work, because \ (backslash) is used as escape notation in JavaScript which is used to encode special characters. Find more about JavaScript string here, and if you want to know moew about JavaScript here is a great reference. So to make this path work we need to support each \ with another \ and our example path becomes "C:\\MyProjects\\hemnik\\logs\\temp.log". Remember to keep the quotes around the string, both single or double quotes work.

 The length is dependent on the number of variables we want to store at once, let's say we have 3 temperature sensors, so we write 3. We choose IOFormat based on the data type. If we want to log data as a float value we use IOMEMORY_FLOAT, if integer we choose IOMEMORY_INT and like that. Take care about the length and IOFormat, they are interrelated. The last parameter, append, is a Boolean and based on our need we choose either true or false. All said, let's see the example command in one line:

 js:> saveData(0x0000BA10, PAGE_DATA, "C:\\MyProjects\\hemnik\\logs\\temp.log", 3, IOMEMORY_FLOAT, false)

 Press enter, and we get an error that says 'Could not open file', so we need to make the file before running the command. Now it works and we are done with the basic logging! But still it is not convenient to type this command for different variables and in different times one by one in the SC. A better choice is to use "loadJSFile" command in SC: 

 js:> help loadJSFile                                                                               
Description: Load a JavaScript file or all the JavaScript files in the directory. Example: loadJSFile c:\myDirectory\myJavaScript.js
Syntax: loadJSFile(file,store)
  file - the JavaScript file or a directory.
  store - [optional] true, store the file(s) to the preference, the script will auto reload the next time the view is open.
This is our key to a better automated logging process. We write all the desired logging commands in a JavaScript file and only by loading that file in SC all the logging process is done. This way, we can write logging commands for any number of variables we need at different memory locations with different IOFormats only once and in one file. Another great possibility is that we can even include the whole process of starting the debug session and running the code on the target in our script and control the steps. Let's see all these in a simple example script, e.g. saved as C:\MyProjects\hemnik\ccs_run_test_log.js:

Then we only need to run this script in SC as following:

js:> loadJSFile C:\MyProjects\hemnik\ccs_run_test_log.js

That's it! Good luck with your projects.

Mar 18, 2015

Tronheim's smoking

A strong northern lights, Aurora Borealis, happened over Trondheim, and it was amazing, all around and moving fast. It was so beautiful.

Feb 28, 2015

11 p.m. Trondheim

Days are getting longer here and I am waiting for the beautiful long summer days. Look at this sunset at 11p.m. from before. Norway's summers are charming.

Feb 24, 2015

All sharpened

I have sharpened some colour pencils for my children and collected the pencil shavings in a glass. I started taking some macro shots where I broke the glass in the process and it become sharp same as the pencils ;) And all that resulted in this shot.

Update: Now I enjoy this as my desktop background :-)