All posts by bsiever

SIGCSE 2016 IoT Workshop

Thanks for participating in our Workshop. Feel free to contact us at any time either via e-mail or connect with us on LinkedIn:

Bill Siever Michael Rogers
bsiever@gmail.com mprogers@mac.com
View Bill Siever's profile on LinkedIn View Bill Siever's profile on LinkedIn

Please download these files:

  1. SIGCSE.zip: SIGCSE Simblee Examples Library
    (GitHub Repository)
  2. Simblee-PulseSensorAmped.zip: Simblee Pulse Sensor Library
    (GitHub Repository)
  3. SimbleeForMobile-BarGraph.zip: Simblee Bar Graph Library
    (GitHub Repository)
  4. SIGCSE_IoT_Exercises.pdf: Guide to the exercises

Please help SIGCSE evaluate workshops by completing this survey at the end of our session:

https://www.surveymonkey.com/r/WFNRGJY

Experiments with JavaScript in Swift Playgrounds

In preparation for the SIGCSE 2015 I put together a demo showing ways to leverage Swift’s Playgrounds for a more immersive learning experience. They are:

01_WelcomeToThePlayground.playground.zip

02_While.playground.zip

The first example is an introduction to Swift Playgrounds. It gives a quick overview of the element of the Playground environment itself (the Results Sidebar, Assistant Editor, etc.). It concludes with some JavaScript multiple-choice self-test questions.

The second example introduces while-loops and the Assistant Editor. It also contains a “code building” component that uses a “Parsons problem” from Runestone Interactive. The Parson’s Problems are a powerful way to guide learners to proper logic and syntax. Rather than create code from scratch, it’s just a matter of dragging/dropping code in the correct order, as seen here:
ParsonsProblem
In the full while-loop playground example the learner should also type in the actual code and evaluate it in the playground.

Credits

  • Both examples were built with Jason Sandmeyer’s Playground builder (https://github.com/jas/playground).
  • The quizzes and Parsons problem use JavaScript and CSS from

Including interactive JavaScript in Playgrounds could be a great tool for improving their impact, but it requires some effort to set it up.

Logging events with on Nordic’s nRF series via Seger’s J-Link Real-Time Terminal

One of the most most common debugging techniques is “logging”, or creating a history of what happens while code runs.  Logging can be especially difficult in embedded systems, which often lack a natural way to log events, like a console.  Commonly UARTs are used to log messages via a serial port, but this approach can consume significant run-time that may undermine the timing constraints of the software. It also requires the use of additional pins to support development.

I’ve found it especially difficult to debug applications using Nordic’s Bluetooth Low Energy products (nRF family).  Fortunately, due to some helpful hints by fellow Nordic developers (Thanks Jeremy) and great products from Segger, I’ve got a solution that suits my needs fairly well. Segger’s Real-Time Terminal is a perfect solution to the problem. I’ve taken the example’s provided by Segger and made a package from them (easier to configure on multiple projects). I’ve also added some wrapper functions that provide additional data I find helpful when debugging.

The following explains how to setup a logger for the nRF series of chips, but assumes that:

  1. You are using a Segger J-Link (I’m using the J-Link CortexM)
  2. You are using Keil MDK v5 or later,which uses Software Packs.

This guide is broken into three distinct phases:

  1. Installing the Logging Package and updating the Keil’s IDE to easily connect to Segger’s Log Viewer
  2. Configuring a project to use the Logging functions
  3. A quick demo of actual use

 

Installing the Logging Package and updating the Keil

These steps should only need to be performed once.

    1. Install the latest version of Segger’s J-Link: https://www.segger.com/jlink-software.html?step=1&file=JLink_496a.

 

  1. Install the Software Package I created for Logging
    1. Download Siever.Segger_RTT_Logger.1.0.1.pack. (It works with any system that Segger’s RTT supports, not just Nordic)
    2. Double click on the package. It should automatically install via Keil’s Package Installer.
  2. Update Keil’s Tools menu to allow easy access to the Log Viewer (which is the window you will use to view log messages).
    1. Open Keil.
    2. Select Tools → Customize Tools Menu... from the menu:

      1_AddCustomEntry
    3. Add a new entry for the Log Viewer. When done it should look something like:
      2_LogViewerEntryDetails

      There are a few things to notice here:

      • I typed Log Viewer in the first available slot. This will be the name of the new item on the Tools menu.
      • The Command is the JLinkRTTViewer.exe. Verify that the path is correct for your installation.
      • Note that Run Independent is checked.

    The Tools menu should now have a new item that will be used to launcher the Log Viewer.


Configuring a project to use the Logging functions

You will need to do this for each project on which you want to use these logging functions.

    1. Open the Project
    2. Select the Logger Package for inclusion in the project. Select Project → Manage → Select Software Packs...:

      1_AddPack
    3. Select the newly added Logger Package and set the version to fixed:

      2_SelectPackToAdd_1.0.1

 

  1. Add the Pack to the Run-Time Environment. Select Project → Manage → Run-Time Environment...:

    3_AddPackToRunTime
  2. Ensure that the package will be included at Run-Time. Expand it and make sure it is selected:

    4_ExpandLoggerPackAndSelect_1.0.1
  3. The package will need to be enabled via a define. Add the define to the project’s Preprocessor Symbols.
    1. Select Project → Options For Target...:

      OptionsForTarget
    2. Navigate to the C/C++ tab and add RTT_LOG_ENABLED to the Defines:

      AddDefine

Demo of Use

In order to use the logging functions you will need to add calls to the logging functions to your code. You can use primitive functions provided by Segger, but I choose to use my own wrappers. In order to use my wrappers you will need to include the header file:


6_AddIncludeWhereNeeded

and insert calls into your code. I’ve provided three functions that each have printf semantics (and each call Segger’s SEGGER_RTT_vprintf()). My functions are:

loge(…)
Used for logging run-time errors (shown in red)
logw(…)
Used for logging warnings (shown in yellow)
logi(…)
Used for logging general information (shown in white)

Here are some examples in code:


7_AddLogMessages
I generally start a debugging session and then launch the Log Viewer via the item added to the Tools menu:


3_UpdatesMenu Launching

The Log Viewer you will ask how it should connect to a debugger session. When being run with an existing debugging session just indicate it should connect to the debugging session:


4_LaunchSettings

Here’s an example of the log generated by the three examples shown above:


RunAndDebug

Notice that:

  • The different warning styles are color coded.
  • The log macros I’ve created insert the file name and line number. This does consume additional flash memory, so don’t get too carried away with log messages.
  • Currently I have all log messages going to the tab for Terminal 0. It would be easy to update the approach to include different messages to different terminal tabs for different modules.

Disclaimers

This work is provided as-is with no warranty or guarantee of any sort. I’m new to Segger’s RTT and haven’t done any review of performance issues. I’m also new to CMSIS Packages and haven’t verified that I’ve followed all appropriate package conventions. At this point this is an alpha version, but any input or suggestions are welcome. The log macros were made for my needs when I developed them and may not suite other’s needs. The formatting used for them could certainly be improved.

Credits

The package includes unmodified code provided by Segger at: http://download.segger.com/J-Link/RTT/RTT_Implementation_141217.zip. Code by Segger includes a copyright notice, but they have given me permission to share the package.