Monday, July 7, 2014

Using the mBuino with Linux

mBuino is a powerful tiny circuit for all your needs... ARM® Cortex™ 50Mhz, UART, SPI, I2C...programmed using the mbed™ online compiler IDE

It currently (as of July 7, 2014) has 9 days left on kickstarter.

I was given one to test out using linux, as it seems that the NXP LPC11U24 has some issues with linux. Namely firmwares get written to the wrong space on the flash drive. They seem to be 4 blocks off.

With some googling and search a solution was found, and I can verify that with a slight modification the solution works.

My initial testing, coping the mBuino Firmware (just in case something happens), I will have a copy of the firmware that was installed by The OutrageousCircuits team at GHI Electronics.

But I can confirm that it will work with linux, using the DD command.
There are a couple of things you'll need to be aware of before you get started, and a couple of WARNINGS!

Until, I or someone else can get a script written to automate this process, you'll need to know the mount point of the drive.
 One of the easier ways to find this is the DF command:

lfmiller@lfmiller-Inspiron-One-2330 ~/Downloads $ df -h | grep "CRP DISABLD"

/dev/sdb         32K   32K     0 100% /media/lfmiller/CRP DISABLD
lfmiller@lfmiller-Inspiron-One-2330 ~/Downloads $

You could also grep "32K" if you want anyways you'll need the mount point, in my case it's "/dev/sdb" this time around. Also make a note of the directory, you'll need this to erase the current firmware.bin file, and that is what we will do
next. Erase the firmware.bin file that is on the drive, ***WARNING*** THIS STEP CAN NOT BE SKIPPED, if you skip it it will cause problems * See my notes below *

rm "/media/lfmiller/CRP DISABLD/firmware.bin"

So now you have a blank (empty) device. Now we want to put a new firmware on it.
issue this command:
sudo dd if=firmwaretoupdate.bin of=/dev/sdb seek=4

lfmiller@lfmiller-Inspiron-One-2330 ~/Desktop $ sudo dd if="mbunio factory firmware.bin" of=/dev/sdb seek=4
[sudo] password for lfmiller:
64+0 records in
64+0 records out
32768 bytes (33 kB) copied, 0.014345 s, 2.3 MB/s
lfmiller@lfmiller-Inspiron-One-2330 ~/Desktop $

 The very last step is to wait, I've found that there is a very large write delay, and it takes a while for the firmware to update. This seems to be a limitation of linux, as when I tried this with a Windows box, I did not have a delay issue.

2nd ***** WARNING *****
I have had to wait anywhere from 20 secs to 45 secs.
if you don't wait, it will fail, and the old firmware will still be on the device.

If you forget the sudo in the dd command you'll get something like this:
lfmiller@lfmiller-Inspiron-One-2330 ~/Desktop $ dd if="mbunio factory firmware.bin" of=/dev/sdb seek=4
dd: opening ‘/dev/sdb’: Permission denied
lfmiller@lfmiller-Inspiron-One-2330 ~/Desktop $

Bash Shell script:
  1. This is a quick dirty script, run it with the sudo command IE: sudo ./
    run it in the directory that the new firmware is in. Make sure it has execute rights
  2. It doesn't do a whole lot of error checking at this point, and my brain is getting to tired to figure it. It will fail if the mBuino is not plugged in, or not in upload mode
  3. It will not ask you to confirm, it will just do it, so be sure.
  4. It will look for the newest firmware (bin file), that is the file it will upload.
  5. It will tell you the mount points that you need if something does go wrong
  6. It was tested on a few different firmwares, and worked, each time.
  7. It has a sleep delay of 30 seconds, and prompts you to not remove the device before hand, see my blog for details on that.
  8. Fork this and fix it up :-)


 Here are a few things I've found that are a bit quirky, but could cause issues.

I forgot to erase the old firmware once (and then I did it again to duplicate the results) - What ended up happening, is my linux box couldn't decide what the device was, and didn't mount it, thou it did show it in the drives list, it did not show it as "CRP DISABLD", and refused to do anything with it.
I ended up rebooting the computer, holding the reset button again, and the drive appeared as it should. Erased the firmware, and put a new firmware on it,
 I still had to wait for a while, but this time the reset button didn't work, I had to remove power and plug it back in. This worked at least for me.

It's very important to note that this also happened to me when I put a firmware that had an error on it, I did this on purpose as well, Something similar happened, but this time I was able to remount the device and make changes.

I've done limited tested so far, and hope to update this more over time.  And I hope to get a more automated way to update written soon.

No comments:

Post a Comment