netbeans debug gdbserver: “Invalid argument”

I was trying to do some remote debugging via gdbserver the other day, using netbeans. I knew I’d had this working before, but I kept getting a rather bizarre (to my mind) error dialog:

I could connect happily via gdb on the command line, and on a whim I tried a different project in netbeans, which worked as expected. A bit more thought, and some comparison in the project properties showed up what was missing, the name of the binary output built for this project. After filling it in again everything works just fine :)

(This is with Netbeans 7.0.1, we won’t get into why it didn’t detect from the Makefile what the binary output was, when it runs quite fine in the non-cross configuration)

Taking quiet output to the next level

I don’t know who thought this was a good idea, but this is the output of a successful build for one of the examples in the libopencm3 project


karlp@tera:~/opencm3_f4$ make clean
karlp@tera:~/opencm3_f4$ make
karlp@tera:~/opencm3_f4$

Really? Realllly? Ok, concise output is good, but this is no output at all!

Probably the same people who think making a stdlib implementation that is GPL….

Updated MRF24J40 arduino driver

Thanks to pkarck my changes to improve the C library for Microchip’s MRF24J40 802.15.4 modules has been ported to the Arduino library. I’d written an Arduino library some time ago, but hadn’t been maintaining it as I don’t really deal with Arduino much these days. However, it’s gotten some love :) It’s now easier to use, and has support for the power amplifier on the MRF24J40MB modules, if you’re using those. It also makes some quirks I was dealing with in a mixed xbee/mrf24j40 module environment optional. In general, this collects up some of the various reported issues over the last year or so, and I didn’t have to do anything at all!

This is, “teh awesome”.

Downloads:

Getting started with ARM Cortex-M3 (STM32L1xxx) programming

So yeah, we fixed the linux development and programming tools for the STM32 series of ARM cortex M3 chips. And I spent quite a few weeks getting distracted by the tools, and never got around to actually developing for the platform.

Today I sat down to try and wire up a Microchip MRF24J40MA 802.15.4 module to the STM32L discovery board. Seemed straight forward enough, “what pins are for SPI”

“…..” What the… These pins could be anywhere! The reference manual doesn’t say, it refers to the datasheet, which has a table, “Table 5, Alternate function input/output” on page 35 of the actual device datasheet, revision 4. That table says that there are two SPI ports, and they can be made available on a variety of pins. Apparently, SPI1 and SPI2 can be made available on two separate sets of pins each!

All well and good, but how? That’s for another day :)

Solving the STM32 MCU datasheet maze

I’ve been hacking a lot on STM32 based microcontrollers recently. Not on any particularly useful code, but trying to make the support for the STLink v1 and STLink v2 SWD debuggers built into the various Discovery boards that ST makes really rock solid. It’s a bit of a battle, but it’s coming along

One of the things that has been causing some problems is the sheer volume of information spread across all the different datasheets and release notes. This is going to be particularly apparent as I try to fix the flash programming. Anyway, this afternoon I mapped out the relations between all the datasheets, and put them in a table that I think should help…. (This is based on latest datasheets as of today, some of the numbers changed recently)

The very very very rough version of the map is available here The html is disgusting, blame open office. The spreadsheet it came from is here too:
STM32 Datasheet map

Traps for new players, select() and FD_ISSET

So, you’re moving up into the world of multiple active tcp connections, and you know that you don’t want to poll them, but you haven’t learnt about libevent yet, or even heard of it perhaps. So you’re using select(), and it all seems pretty cool and groovy.

However, there’s a trap! when select returns, remember that it MODIFIES the fdsets, you need to reset the fd sets before each call to select(), and use FD_ISSET after the call to see which fd was hit.

Oh, and most importantly, more than one fd can trigger select to return. So don’t make any assumptions that FD_ISSET will only find a single fd.

Review of Íslandsbanki Android App

Íslandsbanki has started offering a smartphone app, with access to your accounts, make transfers, and a bunch of things they probably shouldn’t have bothered with. Having ran into issues once or twice where I wished I could just transfer some money on the spot, rather than having to find a computer, or remember some account numbers, I thought this had potential. Here’s my review of the android version, version 1.1.0. I wrote a review for the android market, or at least started to, but it requires reviews be twitter length. Here’s the full review…

Things that are just bad, silly or outright wrong

  • Requires camera permissions. This seems to be for the built in QR code reader.
    1. There’s no need for building in a QR code reader! I have a separate app for that! This is a banking app!
    2. It crashes on my phone, (vodafone 845, android 2.1)
  • Requires directly call permissions. This seems to be for the “connect me to a branch” feature. This is a common feature, that is commonly done badly. Instead of requesting permissions to directly call numbers, (which allows you to call any number anytime) the app should simply fire the android intent to request a call. This has the benefit for the user that a) they see what call is about to be made, b) they can choose to complete the call with a different service, such as skype, rather than the regular dialer, and c) it properly integrates with any other phone call apps, that might record, or track for the user.
  • It’s an iPhone app? This is my only explanation for the UI. The back button and the menu button do nothing at all. There are UI buttons if you scroll down, and a cog wheel settings type icon that you have to press. Likewise, the currency converter section uses a custom built UI, rather than the built in android input methods. This means it looks different, the cursors are messed up, and the backspace button behaves weirdly. Really, use the built in input methods! Just make it a text box, with the numeric hints!
  • The login screen has a font problem with the password
  • The login screen doesn’t switch to numeric for the “auðkennisnumer” field
  • Not all my accounts are shown! “Mína siða” only shows the top 2 accounts, plus the first credit card account. I have an empty account in position 2, so it doesn’t show the main account. (It does show up in my list of accounts)
  • The screen showing the list of transactions is badly scaled and centered.
  • The list of transactions doesn’t allow showing the full transaction details

The rest

Well, it does mostly work though. That’s something I guess. However, a half decent mobile stylesheet for the general website would probably have done just as well or better, and been a whole lot less work. If you’re going to make it native, it should be done properly.

C UnitTests with Check, and reporting in Jenkins/Hudson

Update 20110910 – This is now available as a standard feature in the current xUnit plugin for Jenkins/Hudson.

I’ve gotten quite spoilt over the years with things like Jenkins/Hudson, and automated test tools magically creating output that Jenkins understands, and magically creating pretty graphs and charts. But that is working in Java and python, where unit tests are common and easy. Working in raw C, this isn’t quite so common, nor quite so easy. I’ve been wanting to add unit testing to my C code for a while, and with a new task at hand, and having finally gotten Jenkins set up, it was time to get this done

I found http://stackoverflow.com/questions/65820/unit-testing-c-code and given the number of votes, gave Check a go. I had a few niggles with makefiles and library load paths and so on, (Isn’t C coding fun?) but then it was beautifully and happily giving me nice output on the command line.

XML output for Jenkins was another story. Check supports XML output, with just a single line of config in the test suite, but it’s yet another format. The regular standard JUnit plugin didn’t recognise it, and the xUnit plugin, depsite supporting almost a dozen other tools outputs, didn’t support Check. So much for Check being big and popular. However, the xUnit plugin does support applying a custom XSL stylesheet to your tool’s results. So I made a basic XSL for converting Check’s results into something compatible. And now I have pretty charts and graphs for my raw C code too. Whee

 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ck="http://check.sourceforge.net/ns"
exclude-result-prefixes="ck"> 
   <xsl:output method="xml" indent="yes"/> 
 
<xsl:variable name="checkCount" select="count(//ck:suite/ck:test)"/>
<xsl:variable name="checkCountFailure"
select="count(//ck:suite/ck:test[@result='failure'])"/>
<xsl:variable name="suitename" select="//ck:suite/ck:title"/>
 
<xsl:template match="/"> 
      <testsuite> 
         <xsl:attribute name="errors">0</xsl:attribute>
         <xsl:attribute name="tests"> 
          <xsl:value-of select="$checkCount"/> 
         </xsl:attribute> 
         <xsl:attribute name="failures"> 
          <xsl:value-of select="$checkCountFailure"/> 
         </xsl:attribute> 
         <xsl:attribute name="name"> 
            <xsl:value-of select="$suitename" /> 
         </xsl:attribute> 
         <xsl:apply-templates /> 
      </testsuite> 
   </xsl:template> 
 
<xsl:template match="//ck:suite/ck:test">
    <testcase>
      <xsl:attribute name="name">
        <xsl:value-of select="./ck:id"/>
      </xsl:attribute>
      <xsl:attribute name="classname">
        <xsl:value-of select="$suitename" /> 
      </xsl:attribute>
      <xsl:attribute name="time">0</xsl:attribute>
      <xsl:if test="@result = 'failure'">
        <error type="error">
          <xsl:attribute name="message">
            <xsl:value-of select="./ck:message"/>
          </xsl:attribute>
        </error>
      </xsl:if>
    </testcase>
</xsl:template>
 
<!-- this swallows all unmatched text -->
<xsl:template match="text()|@*" /> 
</xsl:stylesheet>

Known issues:

  • Check reports the duration of the entire testsuite. Junit expects a time per test. I tried putting the duration element from Check on the top level suite, but Jenkins ignored it.
  • The “classname” is a bit funky, but so be it.

JENKINS-10909 is tracking this as a feature over on their issue tracker.

As a friend said, “xml is just like violence. if it’s not solving your problem, use more.”

OpenSSL PEM_read_RSA_PUBKEY vs PEM_read_RSAPublicKey

File this in the “Everybody hates OpenSSL’s API” category. From the expansive documentation:

The RSAPublicKey functions process an RSA public key using an RSA structure. The public key is encoded using a PKCS#1 RSAPublicKey structure.

The RSA_PUBKEY functions also process an RSA public key using an RSA structure. However the public key is encoded using a SubjectPublicKeyInfo structure and an error occurs if the public key is not RSA.

Seeing as I’m in the “PEM” functions, so at least in theory, I’m using methods for processing files that look like this:

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxKMFS0eoDxn6YltlCM4P
uIHK1bp3+7Lt0aWZ9rimjd4uvx49ZYT1DKrUZi96rUkzdJuCqtYbFtUVAy0V5AtZ
EtQGRoZBN5JQ9u80I8NNS4jhtHZU2i6CY9Aeb6KHY790ceD+lMCbXCgrtl1yPUVE
s8pFwEwO2Vqjim2pO0iVsAzUJAyppjn/7FjxyqOHZHL+OPi7vNule1V9OdVrb9m3
mHVy3u9LWdA+3Ch/YJe8FgenRncQEVrDbA/0wHlRE5fH+nQ9OwPTDYP6A6pphAbk
ZUhc9VjIDKrTCQP2o4RDLz0OKyBs5xZc7vjGXpHG+kL3OVpHxpSrK9EVGIX65ofN
9QIDAQAB
-----END PUBLIC KEY-----

I’ve got no idea where the PKCS#1 vs SubjectPublicKeyInfo comes into it when I’m just trying to load that file. Regardless, the only one that works is PEM_read_RSA_PUBKEY()

Early impressions with PyDev 2.2 and Eclipse 3.7

I’ve been happily using netbeans for C/C++ and python work, which works well enough to not really complain much. Mostly, I want IntelliJ for C code. I find eclipse big and clunky and awkward on the keyboard, and just generally a pain. No Eclipse, I do NOT want to have some sort of “workspace” I want you to just leave things where they are on the disk. Anyway, in Oracle’s infinite wisdom, they are continuing to destroy things that Sun built, and python support has been dropped in netbeans 7. A pity, as netbeans 7 added some nice debugging support for C/C++, and netbeans is much more tightly integrated than eclipse. Still a pale shadow of IntelliJ, but I digress.

So, I had to go and look for some alternative python editors. I’m currently trying out PyDev 2.2 with Eclipse 3.7. It mostly works ok too. It’s capable of running some unit tests, and has the basic highlighting and so on. However, it’s completion is not as good as I would like, nor think it should be. Take this for example.

def something(self):
    self.mylist = []
    # on this line, self.mylist. will give me the full builtin completion for lists
    self.otherlist = "blah blah".split()
    # split returns a list, but self.otherlist. has no completion here

It seems this can be worked around by “pre declaring” the type.

def something(self):
  self.somelist = []
  self.somelist = "blah blah".split()
  # self.somelist. produces full completion for list here....

This is…. odd?

Possibly related is that in python unit tests, I at least, normally use the self.assertEquals(left, right, msg) form, probably because I came from Java. However, self.assertEquals in PyDev doesn’t give me any completion guidance on the parameters at all. It turns out that in the implementation of python’s unittest, assertEquals is simply an alias for another function (assertEqual = assertEquals = failUnlessEqual) For whatever reason, this means that I get full completion and parameter help if I use the _real_ implementation, failUnlessEqual but no advice/help whatsoever if I use the assertEquals form.

Google says this is unhelpful.

  • “self.assertEquals python” returns 74300 results
  • “self.failUnlessEqual python” returns 35800 results

Update: this assertEquals vs failUnlessEqual is apparently only a problem for python < 2.7. Unfortunately debian stable (squeeze) at present still uses python 2.6 :( In more mundane items, I would _really_ like to know how to get IntelliJ's "ctrl-W" shortcut, for expanding a selection. (From the cursor in the middle of "karl" in the following line, 'self.wop = "this is karl in python".split()', pressing ctrl-w once would highlight 'karl', once more would select 'this is karl in python' (without the quotes), once more with the quotes, and then on to the entire rvalue, then the entire line. This stackoverflow post mentions a solution, but it doesn’t seem to work in PyDev windows, even after getting into the keymap and adding a “Select Enclosing Element” for the PyDev views (or the editor scope? the difference being?) it still doesn’t work.

Oh well, life goes on.