Dave's Blog

My Collection of Hobbies, Code and Other Ramblings

Using Stm32f4-discovery With OS X + Built in St-link

In me previous post - I talked about using an STM32F103 based Cortex M3 with OS X. Since that post, I’ve ordered one of these - STM32F4-Discovery. I am thinking about porting the work done with smoothieware from the LPC17xx platform to the STM32xxxx platform. The STM32F4-Discovery is a relatively new development board that shows a lot of promise. At ~$15 it is a bargain platform with a lot of features.

As usual, I need all of my goodies to work on my Mac and Windows boxes since I go back and forth a lot. The following is a quick guide to getting this up and running with OS X Lion.

First, you’ll need to get the stlink software compiled from https://github.com/texane/stlink:

1
2
3
cd stlink # this is where you've cloned the stlink software
make
make install

You will also need to build the Mac driver:

1
2
3
4
5
cd stlink/stlinkv1_macosx_driver
tar xzvf osx.tar.gz

# Then, install the driver using:
sudo make osx_stlink_shield

make sure the gdbserver works:

1
2
cd stlink/gdbserver
./st_util

If it successfully connects - you should see something like this:

1
2
3
4
5
6
7
8
2012-04-03T13:51:50 INFO src/stlink-usb.c: -- exit_dfu_mode
2012-04-03T13:51:50 INFO src/stlink-common.c: Loading device parameters....
2012-04-03T13:51:50 INFO src/stlink-common.c: Device connected is: F4 device, id 0x20006411
2012-04-03T13:51:50 INFO src/stlink-common.c: SRAM size: 0x30000 bytes (192 KiB), Flash: 0x100000 bytes (1024 KiB) in pages of 16384 bytes
Chip ID is 00000413, Core ID is  2ba01477.
KARL - should read back as 0x03, not 60 02 00 00
init watchpoints
Listening at *:4242...

verify that you can load software through GDB (make sure you use a ARM gdb such as yagarto etc…) Run the following:

1
~/Downloads/STM32F4-Discovery_FW_V1.1.0 $ arm-none-eabi-gdb

You will get something like this if you successfully connect:

1
2
3
4
5
6
7
8
9
GNU gdb (GDB) 7.3.1
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=i386-apple-darwin10.8.0 --target=arm-none-eabi".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
1
(gdb) load /Users/draphael/Documents/workspace/TestDiscovery/TestDiscovery.elf
1
2
3
4
5
6
7
8
9
Loading section .isr_vector, size 0x188 lma 0x8000000
Loading section .text, size 0x6750 lma 0x8000188
Loading section .ARM, size 0x8 lma 0x80068d8
Loading section .init_array, size 0x4 lma 0x80068e0
Loading section .fini_array, size 0x4 lma 0x80068e4
Loading section .data, size 0x5d0 lma 0x80068e8
Loading section .jcr, size 0x4 lma 0x8006eb8
Start address 0x800676d, load size 28348
Transfer rate: 3 KB/sec, 3543 bytes/write.
1
2
3
4
(gdb) file /Users/draphael/Documents/workspace/TestDiscovery/TestDiscovery.elf
A program is being debugged already.
Are you sure you want to change the file? (y or n) y
Reading symbols from /Users/draphael/Documents/workspace/TestDiscovery/TestDiscovery.elf...done.

Using a Segger JLink With OS X

I wanted to work on some ARM Cortex M3 programming on my Mac…

In order to program my dev boards, I use a Segger J-Flash. At first glance, they don’t appear to support the hardware on OS X. However, after some digging I found that they offer a beta that includes OS X support here

Once I got that installed, I received the following error:

1
2
3
4
dyld: Library not loaded: /usr/local/lib/libusb-1.0.0.dylib
  Referenced from: /Users/draphael/JLink/./JLinkGDBServer
  Reason: image not found
Trace/BPT trap: 5

Well, of course that just means I need libusb installed. I use homebrew for my ports of linux to mac.

1
brew install libusb

This worked like a champ…except…now I get this error:

1
2
3
4
5
6
dyld: Library not loaded: /usr/local/lib/libusb-1.0.0.dylib
  Referenced from: /Users/draphael/JLink/./JLinkGDBServer
  Reason: no suitable image found.  Did find:
  /usr/local/lib/libusb-1.0.0.dylib: mach-o, but wrong architecture
  /usr/local/lib/libusb-1.0.0.dylib: mach-o, but wrong architecture
Trace/BPT trap: 5

D’OH! I’ve seen this before…time to edit the formula

1
brew edit libusb

I needed to add the i386 arch flag as shown in this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'formula'

class Libusb < Formula
  url 'http://downloads.sourceforge.net/project/libusb/libusb-1.0/libusb-1.0.8/libusb-1.0.8.tar.bz2'
  homepage 'http://www.libusb.org/'
  md5 '37d34e6eaa69a4b645a19ff4ca63ceef'
  head 'git://git.libusb.org/libusb.git'

  def options
    [["--universal", "Build a universal binary."]]
  end

  if ARGV.build_head? and MacOS.xcode_version >= "4.3"
    depends_on "automake" => :build
    depends_on "libtool" => :build
  end

  def install
    ENV.universal_binary if ARGV.build_universal?
    # Added flag to compile libusb for i386
    ENV["CFLAGS"] += " -arch i386"
    system "./autogen.sh" if ARGV.build_head?
    system "./configure", "--prefix=#{prefix}", "--disable-dependency-tracking"
    system "make install"
  end
end

Once that was complete…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
~/JLink $ ./JLinkGDBServer
SEGGER J-Link GDB Server V4.43c (beta)

JLinkARM.dll V4.43c (DLL compiled Feb 22 2012 20:13:03)

The server has been started with the following settings:
---Server related settings---
GDBInit file:              none
Listening port:            2331
SWO thread listening port: 2332
Accept remote connection:  yes
Logfile:                   off
Verify download:           off
Init regs on start:        on
Silent mode:               off
Single run mode:           off
---J-Link related settings---
J-Link script:             none
Target interface:          JTAG
Host interface:            USB
Target endian:             big
Target interface speed:    5kHz

Waiting for J-Link connection...
J-Link is connected.

Success!!!

New Blog Engine!

I have deliberated for a while now on what to do with my blog. I have not been particularly active in my blogging, but I have definitely been thinking about a number of things I need to blog about. However, I found that my blogging engine (Typo) was very limiting for me. It turns out, that most blogging engines are limiting to me. I am not very comfortable using a web UI for my workflow! I am a coder that uses SVN, git etc…day in and day out for my daily work. So I asked my friend, Glenn Vanderburg, if he had any ideas - and he suggested Octopress.

So far, it seems that Octopress really fits the bill. I generally like using a text editor and version control for everything - including documentation. I am somewhat of a fan of wikis, but I prefer having raw access to my source trees. So Octopress really allows you to hack away at your blog, and then push and deploy just like you would any other software.

Migration was easy since I didn’t really have that much content to begin with. I simply cut and pasted my blog content into new articles generated through rake. I’ll recap the steps I took:

  1. First, I forked Octopress from github
  2. Next, I edited _config.yml to reflect my site configuration…this is pretty self explanatory.
  3. Then, I generated new posts via rake new_post["..."]
  4. I edited those posts to reflect the original publication date from my former blog
  5. Finally, I tested everything using rake preview
  6. Once everything was to my liking, I edited my remote server nginx configuration to point at a directory I created to hold my content.
  7. Restarted nginx on my remote server
  8. ran rake deploy
  9. BAM! It was done.

I absolutely love this new approach to my blog so far. It is static content!!! No database…at least not for now. I hope that this can stay as static as possible. I really just want a place to call my home page where I can rant and write about my hobbies and code etc… without thinking about another web application that I have to manage. Not to mention - I don’t like working through a web based workflow to being with, so this really lends itself to a hacker style blog! I’ll just have to get up to speed with all of the various formatting options…

Using Git With a Proxy

Some of us are stuck behind a corporate firewall, but need to access all the great little github plugins through git! So what do you do?

Create the following wrapper:

( ~/bin/proxy-wrapper ):
1
2
3
4
5
6
7
8
!/bin/sh

Put your own values

PROXY_IP=127.0.0.1
PROXY_PORT=1090

nc -x${PROXY_IP}:${PROXY_PORT} -X5 $*
add this to your ~/.profile or ~/.bash_rc etc…
1
export GIT_PROXY_COMMAND=~/bin/proxy-wrapper

I stole this solution from http://blogs.gnome.org/juanje/2009/07/17/git_behind_proxy/

Cheers, Dave

0% Interest for 6 Months

Rapid Application Development is not a technology, but it is a mindset that is prevalent in a very small percentage of developers. This mindset involves an obsession with code quality and never letting the code base get out in front of the developers. It’s the same mentality that “The Millionaire Next Door” preaches - save money, don’t accumulate debt, live below your means, etc…

We win the race of great software through diligent unit testing, refactoring, coding standards and frequent releases. Any tool or toolset that doesn’t allow us to manage the source code at a source code level will only detract from this ability to deliver great software. Sure, we can use RAD tools that generate copious amounts of code. But that code becomes stale, and it doesn’t evolve with our software. It’s a lot like 0% interest financing. It’s a way to get something that doesn’t have a fiscal impact in the first 6 months of ownership. But those payments are due after the 6 months pass - with accrued interest.

Coding Without Unit Tests Is Like Using a Credit Card

Occasionally I find myself a few days (or sometimes weeks) into some piece of code that I’ve been working on without good test coverage. I just realized that it’s the same feeling I get when I use a credit card. I know I’ll be in trouble if I don’t take care of it ASAP.