Developing for Freescale Kinetis microcontrollers with Eclipse on a Linux host

April 27th, 2014

In this post I'll detail some things I ran into when trying to set up a development environment for Freescale's Kinetis parts on my Linux machine. There is some excellent information scattered around the Internet, this post just puts it all together for my own future reference and in case anyone else may find it useful.


Gnome Shell + Dual screen + NVidia = Frustration

December 19th, 2011

Being a geek and all that, I try to keep up with the latest developments in Linux land. One new development as of late is that there are two new desktop shells on the block: Gnome Shell and Ubuntu's Unity. Personally, I've fallen in love with the way Gnome Shell works, but Unity seems to rub me completely the wrong way. I had previously switched my Ubuntu install to Gnome 2 (to avoid Unity), but with the 11.10 release, Gnome 2 was removed and Gnome 3 (with Shell) was available in the repositories, so I decided to upgrade.


Ricoh Aficio MP C4501 and Linux

September 28th, 2011

A couple of days ago, I saw someone wheeling a new copier/printer/scanner into our office. Turned out it ended up here in Engineering to replace the Canon unit that used to be here. I never had managed to get the Canon to work on my Linux laptop, but this new Ricoh unit caught my attention because of the "Adobe Postscript 3" decal on it. If this thing understood Postscript, there was a chance... So I decided to give it a try.


Faster than light neutrinos?

September 27th, 2011

The response of the "public" to the faster than light neutrinos has been quite amusing, but also sort of sad to me. It is amazing how everyone seems to have an opinion even if they don't have the slightest understanding of what was done in the experiment. To some, Einstein's theory of relativity has now been definitively proven to be wrong, and the whole field of physics goes with it. Others seem to think a 750 km long tunnel exists between Switzerland and Italy. After all, how could you send subatomic particles from one place to another if there was no such tunnel, right? :-)


Rate This Spot

April 11th, 2011

For a while I've been working quietly on a new project called "Rate This Spot". The basic idea is simple: Providing an instant way to rate all kinds of stuff based on its location. I think this is a powerful concept, in that it does not try to put ratings into little cubbyholes based on what it is you're rating. Instead, it relies on the human user to provide context and interpret the data to filter what is relevant to them at the time. The nice thing is: humans tend to be very good at doing exactly that.


Nokia: The Long Road Down

February 14th, 2011

I have been both a Nokia user and a Linux user for quite a while. So when Nokia started to do Linux devices, I was thrilled. I was one of the few people that got a Nokia N800 Internet Tablet with Maemo when it first came out, and it was a great device. Browsing was two steps ahead of everyone else. Then when they finally put Maemo into a phone, I pre-ordered the Nokia N900 before it was even released. Awesome device too, way ahead of the curve at the time. A full-blown Linux computer in my pocket! I immediately started developing an app for it. I could use Python and GTK, and development was fun. There was good documentation, and development was going well in the little amount of spare time I could set aside for it.


Pulseaudio is great, so why do many people hate it?

December 10th, 2010

I keep noticing in forum comments that many people using Linux seem to hate Pulseaudio, the default audio subsystem in most modern Linux distributions. I seem to be in the minority with my sentiment toward it, but I actually think Pulseaudio has been the best thing to happen to audio in Linux in a long time. Before Pulseaudio, I was always having problems with one program grabbing the audio device and other programs not being able to play sounds. How stupid is that? I know that there is some kind of mixer plugin for ALSA, but it was hardly ever working or set up on distributions I tried before Pulseaudio was adopted. Pulseaudio finally provided a sane way to share audio devices and mix audio streams so several programs could have access to audio at the same time, including the ability to set audio levels for each program separately.


Django's wonderful permalink decorator

November 29th, 2010

First a quick disclaimer: I want to make clear that I am by no means an expert on Django. I think it is an awesome web development framework, using an awesome programming language, but I have only been using it off and on for a couple of years now and consider myself still a newbie. So what I'm talking about here is probably blatantly obvious to the seasoned Django developer, but since it was a new insight for me, I'm posting it here in case it might be of benefit to other Django newbies like me. :) So if you see something that needs correcting or could be done in a better way, please don't hesitate to add your insights in a comment.

With that out of the way, let's get down to business.

Everyone familiar with Django probably knows (or should know) about the permalink decorator. It provides a great way to tie your web app's model views to links you may create for them in your templates, without having to worry about the actual URL's involved (other than in your of course).

I had been using them as described in the tutorials, to create 'get_absolute_url' methods for my models like this:

from django.db.models import *

class Something(Model):
    slug = CharField(max_length=50)
    title = CharField(max_length=100)
    text = TextField(blank=True)

    def get_absolute_url(self):
        return ('views.view_something', (), {'slug': self.slug})

This works great provided there is a url declaration in your pointing to a 'view_something' function that takes a slug argument and you defined that 'view_something' view function. In some template you can now create a link to a specific 'something' object by doing:

<a href="{{ something.get_absolute_url }}">{{ something.title }}</a>

This is all pretty basic stuff, and explaining it is not the point here. If you don't get what I'm talking about, I suggest you read the Django tutorial first.

Being a newbie, and not understanding how Django does all of its magic in the background, I thought for quite a while that there was something special about the method name 'get_absolute_url'. It turns out there isn't. As far as I have been able to determine, it seems the only special thing about it is that if you use the Django admin infrastructure, specifying a 'get_absolute_url' function for your model gives you a 'View on site' link in the model's admin page, which is pretty cool. But other than that, you could use any old name you wanted for this function (not that I recommend doing that, using the standard name adds clarity and that's a good thing). What is special though, is that you put the @permalink decorator in front of the method, whatever you end up calling it. This decorator is what provides the magic for looking up the specified view function and constructing a correct URL for the object based on the information found in

What was a new insight to me (and probably was always clear to most people) is that you can have as many methods with a @permalink decorator as you like for a model. This provides a convenient way to transparently create links for many different ways of 'view'ing your model. Let's say you have a model for data you want to display using a normal HTML page, and you have a view to edit the model data, and you have a view for a machine interface that generates JSON data from your model, and you have a view that generates partial HTML you load into a page using AJAX. You could create a model like this:

from django.db.models import *

class Something(Model):
    slug = CharField(max_length=50)
    title = CharField(max_length=100)
    text = TextField(blank=True)

    def get_absolute_url(self):
        return ('views.view_something', (), {'slug': self.slug})
    def get_edit_url(self):
        return ('views.view_something_edit', (), {'slug': self.slug})
    def get_json_url(self):
        return ('views.view_something_json', (), {'slug': self.slug})
    def get_html_chunk_url(self):
        return ('views.view_something_ajax', (), {'slug': self.slug})

After you implement the view functions to spit out the appropriate data and tying them to URL's, you can use template code like this and get links to pages to view and edit objects using this model:

<h1>{{ something.title }}</h1>
<li><a href="{{ something.get_absolute_url }}">View</a></li>
<li><a href="{{ something.get_edit_url }}">Edit</a></li>

Or you could generate JavaScript to get to your raw data this way (using jQuery):

$.getJSON('{{ something.get_json_url }}', function(something) {
    // The variable 'something' now received your data

Or if you dynamically want to update a div on your page with id 'something', you could generate this piece of JavaScript to do it (again using jQuery):

$('#something').load('{{ something.get_html_chunk_url }}');

The cool thing is that you do not need to worry at all about what the actual URL is for any of these examples. If you ever want to change your URL layout, you only need to edit your and you don't have to worry about updating URL's all over the place, which is great.


Windows USB troubles, again

November 2nd, 2010

The new custom USB device we're using in production is causing us problems. The software seems to be losing the connection to the device and is unable to reconnect. The operator has to unplug and replug it, and sometimes quit the program or even reboot the computer to make it work again. Of course, since it is used in a factory environment, the immediate suspect was ESD (electrostatic discharge). But we had tested the design quite thoroughly for ESD performance. In fact, since ESD damage was one of the major problems we were having with the system that was replaced by this new device, ESD performance was high on the list of requirements. Of utmost importance was that the device would survive ESD events undamaged. It also had to be capable of transparently reconnecting to the system, in case an ESD event caused the device to get into a confused state.


Windows drivers and getting output from programs into batch variables

October 26th, 2010

Recently I found myself stuck with the unpleasant task of making a custom USB device work under Windows. The USB device in question would be used in a factory environment and it had the ability to have its firmware updated automatically. During the update process, the device would be enumerated with a different vendor and product ID, and required a different device driver. The biggest problem was that Windows has the nasty habit of bothering the user more than it should. I didn't want the operators to be stuck with a driver installation wizard during production, so I needed a way for a technician to pre-install the drivers, both those used for the application and those needed during the firmware update process.

Anyone who knows me knows that Windows is far from my favorite environment to work in. The Windows command line and batch file environment must be one of the most rudimentary and opaque scripting environments in existence. So to be clear: I don't claim to be an expert on any of this stuff, far from it. I am just documenting some of the things I learned during this painful process, in case it might be of help to some other poor individual stuck with a similar task. :)

I first decided that I should just find a way to pre-install the drivers into Windows, and things would work automatically and without user intervention after that. I had a set of .inf, .sys and .dll files, and I could point the driver wizard to the correct place to find them when I plugged in the device or switched it to firmware update mode. But I did not want the technician to have to do this. I wanted him to be able to install the drivers by running a simple wizard, and then they would be automatically loaded when needed. After some searching, I found out about Microsoft's DPInst program, which seemed to do exactly what I wanted. With this piece of software, you write an XML file describing where your driver files are and it will generate the wizard screens to install the drivers. Cool.

Only, it turned out it didn't do what I wanted after all. After the drivers were installed, Windows still didn't just use them when the device was plugged in, but required a Next/Next/Next sequence the first time. Only after that was done, would it behave the way I wanted it to the following times. (If anyone knows how to make Windows just use the driver immediately, without requiring user interaction the first time, I would greatly appreciate the info!)

Still, DPInst solved part of the problem. The technician would not have to go hunt for the driver files, he could just have Windows find them automatically. I decided that in addition to this, I had to make a program that would switch the device into its different modes after the drivers were installed, so the technician could go through the initial Next/Next/Next sequences as part of the setup procedure. After this was done, the device would then transparently switch and the factory operators would be left alone. I decided to do this job using a batch file, some small executables for managing and reprogramming the device, and the Wizard's Apprentice software to put up some friendly screens.

The Wizard's Apprentice has an interesting way of returning user input to the calling batch file. It will generate a temporary file with content like this:

set waoutput= ...some value...
set waoutnum= ...some other value...

This file can then be called from your own batch file, which will set the waoutput and waoutnum variables to the ones defined in the batch file.

I decided I could use a similar system to get data I needed from the tools I was using to manage and program the USB device. The problem was that these tools, unlike the Wizard's Apprentice tool, weren't intended to return values to a batch file, so they didn't output nice set variable=value statements. So I figured I could do this instead:

echo set variable=> tempfile
mytool parameters >> tempfile
call tempfile

Only, instead of:

set variable=value

this produced a tempfile that contained:

set variable=

This isn't valid code to be called from your batch file. I found out that Windows' brain-dead implementation of echo doesn't provide any way to suppress a linefeed. You can download replacement echo.exe files in various places that support this basic option, but I didn't really want to go there. I found another solution: the caret ^. In many programming languages, one can use the backslash \ at the end of a line to indicate the statement continues on the next line. Since Windows uses the backslash \ as path delimiter (one of Microsoft's many dumb ideas), they use the caret ^ as an escape character instead. So in a batch file you use the caret ^ for the same purpose.

So I changed my code to:

echo set variable=^^> tempfile
mytool parameters >> tempfile
call tempfile

Note the double caret ^^. We want to print a single caret ^ to the file, but since the caret ^ is the escape character, in the batch file we need to escape it with another caret ^ to indicate we want to output the actual character. This code produces a tempfile that contains:

set variable=^

On calling this file, the batch command interpreter sees the caret at the end of the line and it continues the statement on the next line, producing a valid set command.

This is not the cleanest solution for retrieving data from other programs though. I only mention it because having a batch statement generated from the output of external programs and split over multiple lines might be useful in some particular circumstances. A better way to assign the output of a program to a variable is this:

mytool parameters > tempfile
set /p variable= < tempfile

Much cleaner.

After the project was already implemented I found yet another way. This method avoids using a temporary file, which might be very useful if there is no good place where a file can be written:

for /f %%a in ('mytool parameters') do set variable=%%a

A little explanation is in order here. The for command is kind of unusual in that it seems to be playing in another league than most other batch commands. Most batch commands are very rudimentary, missing even the most basic options (like echo missing the option to suppress newlines). The for command on the other hand is quite powerful. The details are beyond the scope of this article, a great resource for finding out more about it (plus other batch commands and even other command line languages) can be found at What I'll mention here is that this statement executes the command between single quotes and then parses its output and saves parsed out data to variables. The case shown in my example is pretty much the simplest parser possible (just assigns all the output to a variable), the for command is capable of parsing much more complicated output to extract information from it.

I hope some of this post may be helpful to someone not familiar with the details of Windows drivers and batch programming, like I was. As for myself, I will resume trying to stay away from it as much as possible. :)


My name is Patrick Van Oosterwijck. Welcome to my spot on the web where I will hopefully regularly dump some of my brain content for the benefit of whomever may find it useful.

Search for Posts
Popular Tags
© 2010 Patrick Van Oosterwijck.

Using technoblog blog engine by Will McGugan