Computing stuff tied to the physical world

Uploading from Mac OSX

In a way, Apple Macintosh computers running OSX are a curious – some might say schizophrenic – mix of technologies: out of the box, you get an appliance full of icons and windows, ready to go and operated primarily through a mouse or trackpad:

Mac screen

But underneath sits a POSIX-compliant operating system which is every bit as much like Unix as Linux and FreeBSD – you know, that invention from the 1970’s, decades ago. Some things are so timeless and able to evolve to meet new needs, that they tend to last virtually forever. Like wheels, the written word, transistors, the C programming language, Unix?

The gateway to this hidden world is the Terminal app (it’s buried in the Utilities folder):

Mac shell

Transitioning from that first screen to the second is like moving to the next game level – turning from a consumer to a creator of software. The terminal, or more exactly the “command shell” inside it, unlocks great powers. With this power comes responsibility, but it’s actually a very safe and robust playground, as long as you take some precautions:

  • under the hood, a Mac OSX disk often has over a million files: yes, it’s complex
  • don’t mess with it, try not to change anything outside your home directory
  • with one exception: install Homebrew to manage all the files in /usr/local/...
  • and also: try not to mess with the Library folder inside your home directory
  • only use “sudo” (to get superuser privileges) if you know what you’re doing

This way it’s very unlikely that you’ll interfere with what the Mac and its “apps” are doing.

Homebrew

Homebrew is a package manager. It lets you install (and uninstall!) packages prepared by others and made freely available. It’s actually much more than that: in the long run, it also takes care of your sanity. With brew, as the command is called once installed, you gain access to a wide range of software tools (some 3,000 at last count) – to install, try out, update, or remove at will. The key is that it also manages all package dependencies, and that it goes out of its way to let know know how to solve problems if anything goes wrong.

With Homebrew, life is good. Without, your Mac is a ticking bit-rotting time-bomb.

The installation instructions are on brew’s home page. You will be asked to install Xcode as well, which is Apple’s development environment. The reason for this is that it includes a base collection of command-line utilities, most of which are essential during development.

Once installed, life is easy. These commands are really all you ever need to deal with:

  • brew search ... – find out what packages Homebrew knows about
  • brew home ... – open the homepage associated with a specific package
  • brew install ... – install the specified package and all its dependencies
  • brew uninstall ... – uninstall the specified package and its dependencies
  • brew update – get brew’s latest list of packages and versions from the web
  • brew upgrade – download updated versions of the packages you’re using
  • brew cleanup – remove files belonging to obsolete or outdated packages
  • brew doctor – verify that all is well, report any potential troublespots

That’s a bunch of commands to get used to, but you can always type brew for a summary.

Packages are added to Homebrew all the time. Most packages get updated shortly after a new release is out, so Homebrew is also a fine way to keep your tools up to date. With Homebrew, it’s easy to keep a Mac running well, up to date, and in good shape for years. In fact, the adage “nothing gets installed, other than as Apps or via Homebrew” is a fine one.

For anything experimental, be it the code you are developing or code from others which is not production-ready, your safest bet is to keep all that inside your own home directory.

lpc21isp

One reason for that whole brew stuff, was to get access to an open source utility called lpc21isp. This tool knows about the protocol used by the serial boot loader of the LPC810, and is able to upload to it as well as manage a serial connection for debugging.

Getting this tool on your Mac couldn’t be easier now – brew install lpc21isp

After that, you can type lpc21isp as command to see a brief summary of how to use it.

In our case, assuming you have a copy of the firmware.bin code you want to upload to the LPC810, the steps to send a firmware image to the LPC810 are as follows:

  • plug in the (modified) FTDI board, with the breadboard setup described earlier
  • type: lpc21isp -control -bin firmware.bin /dev/tty.usb* 115200 0

Here is what a successful upload looks like:

$ lpc21isp -control -bin firmware.bin /dev/tty.usb* 115200 0
lpc21isp version 1.97
File firmware.bin:
        loaded...
        image size : 400
Image size : 400
Synchronizing (ESC to abort). OK
Read bootcode version: 4
13
Read part ID: LPC810M021FN8, 4 kiB FLASH / 1 kiB SRAM (0x00008100)
Will start programming at Sector 1 if possible, and conclude with Sector 0 to ensure that checksum is written last.
Erasing sector 0 first, to invalidate checksum. OK 
Sector 0: ..|.
Download Finished... taking 0 seconds
Now launching the brand new code

So much for uploading on the Mac – it’s all Unix with a lot of 21st century lipstick, really.

[Back to article index]