Building the STM32F4 DISCOVERY Toolchain For Mac OS X

The STM32F4 DISCOVERY is a very neat development board for the STM32 F4 series microcontroller. Not only is it neat, but also cheap. As in $14.55. Here’s the link to buy one from Mouser.

I have some radio related projects that I plan on implementing with this unit. But first I had to get the Open Source development tools installed. And while there are numerous webpages that describe how to do this, none of them actually worked. Such is the world of Open Sores.

With a bit of help, I was able to get things up and running. To save others grief, I’m documenting what I did to get things working. First, a brief description of what goodies you get with this development board.

Here’s a datasheet for the development board.

Some of the Features:
■ STM32F407VGT6 microcontroller featuring 32-bit ARM Cortex-M4F core, 1 MB Flash, 192 KB RAM in an LQFP100 package
■ On-board ST-LINK/V2 with selection mode switch to use the kit as a standalone ST- LINK/V2 (with SWD connector for programming and debugging)
■ Board power supply: through USB bus or from an external 5 V supply voltage
■ External application power supply: 3 V and 5 V
■ LIS302DL, ST MEMS motion sensor, 3-axis digital output accelerometer
■ MP45DT02, ST MEMS audio sensor, omni-directional digital microphone
■ CS43L22, audio DAC with integrated class D speaker driver
■ Eight LEDs:
– LD1 (red/green) for USB communication
– LD2 (red) for 3.3 V power on
– Four user LEDs, LD3 (orange), LD4 (green), LD5 (red) and LD6 (blue)
– 2 USB OTG LEDs LD7 (green) VBus and LD8 (red) over-current
■ Two push buttons (user and reset)
■ USB OTG FS with micro-AB connector
■ Extension header for all LQFP100 I/Os for quick connection to prototyping board and easy probing

Now for the gory details of actually getting all this to work:

First, my system:

I installed this on a Mac Book Pro running Mac OS X 10.6.8. I wanted it on a laptop so I could take it to my basement workshop to do the actual development work. You can do this under linux and Windows as well. I don’t have any information on doing that, you’re on your own. Good luck.

I installed Xcode 4.2, which is the latest version that will run on 10.6 Snow Leopard. I understand that Xcode 4 is required to get the development stuff up and running, I do not know that for a fact, however.

First you need to install a bunch of stuff:
brew install mpfr gmp libmpc texinfo libusb-compat libftdi wget

This uses Homebrew, which you must install if you don’t already have it.

This toolchain script was used as the base: https://github.com/ehntoo/summon-arm-toolchain

As I said earlier, it does not quite work out of the box.

A big thanks to Gwynne who came up with a patch.

So all you need to do is:

cd && git clone git://github.com/ehntoo/summon-arm-toolchain.git && cd summon-arm-toolchain && wget -O - http://darkrainfall.org/build-openocd.patch | patch -p1 && ./summon-arm-toolchain

Then… wait. A while. It takes 20-30 minutes to build everything. Go have lunch.

All of the dev tools are put into ~/sat so make sure that is in your $PATH variable:
export PATH="$HOME/sat:$PATH"

Plug in the dev board and connect to it with the On Chip Debugger:
openocd -f board/stm32f4discovery.cfg

if all goes well, a bunch of text is spit out into the terminal window, ending with:
Info : stm32f4x.cpu: hardware has 6 breakpoints, 4 watchpoints

Then open up another terminal window and connect to the On Chip Debugger:
telnet localhost 4444

Next I grabbed the STM32 Discovery firmware files, to get some sample code:
git clone https://github.com/nabilt/STM32F4-Discovery-Firmware.git

I decided to try the IO_Toggle project first, which turns some digital outputs, connected to LEDs on the board, on and off. Toggling LEDs is the microcontroller version of a Hello World program.

Building the project did not go completely smoothly. I needed to change a line in the Makefile dealing with floating point:
MCFLAGS = -mcpu=$(MCU) -mthumb -mlittle-endian -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb-interwork
to
MCFLAGS = -mcpu=$(MCU) -mthumb -mlittle-endian -mfpu=fpv4-sp-d16 -mfloat-abi=softfp -mthumb-interwork

I don’t yet have a good explanation as to the need to make the change, but I saw it mentioned on many websites while searching for a solution to the problem.

The result is a demo.elf file which gets downloaded to the dev board.

Open up yet another terminal window (while in the directory containing demo.elf) and run gdb via:
arm-none-eabi-gdb

In the OCD telnet window, stop the program currently running on the microcontroller:
reset halt

Then in the window running gdb:
target extended localhost:3333
load demo.elf

Then in the OCD telnet window run the program:
reset run

I was rewarded with blinking LEDs. I then edited the main.c source code to change their toggle rate, and re-built the project, as a test, which all worked.

Next step, some radio related programming!

mySdrPlayback – Mac OS X App to Play Back SDR I/Q Recording Files

I use an RFSpace netSDR to record the 43 meter (6800-7000 kHz) pirate radio band, overnight and often in the daytime as well. I then go back and check the recordings, to see what stations have been on the air. This lets me catch lots of broadcasts even when I am away from the shack.

Going through the recordings with traditional SDR software can be extremely tedious. You literally have to play the recordings at a real time rate, hoping to stumble across a transmission. Even being able to skip ahead and back is not much better.

So I ended up writing my own app to make the process of analyzing SDR recordings for interesting transmissions much easier and faster. I’ve just recently made this app available for others to download and use. It’s called mySdrPlayback (although it could probably use a more catchy name).

This is what the program window looks like (click on it for an enlarged image):

When the app loads, it reads in a list of all the recording files from the directory you have told it they are stored in. Clicking on a file loads it. A waterfall of the entire file is created, that is what you see in the large area on the right side of the window. The x axis is frequency, the y axis is time. Any transmissions are immediately obvious, such as a pirate on 6925 in AM mode, as well as WWCR, also in AM mode, on 6875 kHz. SSB and the various digital modes also have distinctive visual appearances. In no time, you can tell what type of transmission it is just by looking at it.

Files created by SpectraVue, the SDR app that RF Space supplies with their radios, SdrDx, the third party app also for RF Space radios, as well as files created by Perseus can be read. Other file types could probably also be added, if their exact format is known.

Selecting a portion of the recording file to play back could not be easier. Just drag select with the mouse by drawing a rectangle around it. Select the mode, and click Play. The frequency and time limits are displayed in the Secs Start/End and Demod fields when you drag select, you can also edit them in the boxes by hand if needed, to fine tune things.

The buttons to the left and right of Play let you skip playback behind or ahead by 10, 30, or 60 second increments, or even by 5 minutes. This makes it easy to jump around, looking for an ID. An S meter updates during playback, showing the signal strength in dBm.

The Demod To File button will demodulated the entire selected transmission to a WAVE file. You can then feed that into a decoding program, such as MultiMode if you want to decode an SSTV or other digital mode. You can also convert it to an mp3 file using your own utility, if you want to post it for others to download.

mySdrPlayback is only available for Mac OS X. There is no windows or linux version, and there never will be one. It’s written in objective-c and uses the extremely powerful and feature rich cocoa API. That makes development extremely easy, but is only available for the Mac. It can be downloaded from the program page: http://www.blackcatsystems.com/software/sdr_iq_recording_playback_program.html

Lies, Damned Lies, and Receiver Images

I have my SDR-14 receiver online, for some listeners to use. The other day, there was a logging of Trenton military aviation weather on 6950 kHz. I had not seen other reports of Trenton aviation weather on this frequency. And, since 6950 is a very popular frequency for pirate radio in the USA, this could cause some concern, as QRMing military stations is generally bad karma for pirates.

Here is a recording of Trenton Aviation as received on the SDR-14.

As it turns out, I had been running a recording of 6800-7000 kHz via another SDR, my netSDR. So I went back, and checked that recording at the same time the SDR-14 had picked up Trenton on 6950. Nothing. Nothing at all. And the netSDR is connected to a much better antenna than the SDR-14. Hmm. This is strange.

Last night, I was alerted that Trenton was again being heard on the SDR-14 on 6950 kHz. So I went and tuned in on the netSDR, and again heard nothing. I then decided to look for a schedule of frequencies used by Trenton, and found that they should be on 6754 kHz. I tuned in, and sure enough, there they were. Coming in very well, about S9+30 dB or so. Hmm… I did a quick calculation, and the difference between 6950 kHz and 6754 kHz is 196 kHz. 196 kHz, that sounds familiar. Why yes, that’s the I/Q sample rate of the SDR-14!

Now it all makes sense – the received signal on 6950 kHz is an image, a false signal generated by the receiver. It turns out that even SDRs are not immune to images. (Shhh… don’t anyone tell Al Fansome)

Images have been the bane of DXers for decades. They often manifest themselves as a particularly strong signal that is picked up on other frequencies. With an analog receiver, these frequencies are often offset from the actual frequency by the IF frequency of the receiver. With VHF/UHF radios and scanners, this is often 10.7 MHz, or close to that. In the case of the SDR-14, the image was located at an offset equal to the I/Q data rate. It was probably being heard on 6558 kHz (6754 kHz – 196 kHz) as well.

If you’re hearing an unexpected signal, one suggestion is to try another radio, ideally one with a different IF frequency. If you don’t hear the signal on the second radio, then it is most likely an image. Or your other radio is broken. But it’s probably an image. Ask another DXer if they can hear it, as well.

There’s a ham in Erie, PA that has been harassing the local club that runs a 2 meter repeater with claims of interference to the VHF marine band. The FCC has investigated, and found no interference. Multiple hams have contacted the Coast Guard and they have not had any interference issues. The only person who reports interference is the previously mentioned ham, who lives a few hundred yards from the building housing the repeater. I’ll close by noting that the VHF marine band is about 10.7 MHz above the 2 meter band frequency used by the repeater – 146.610 MHz.

New version of SdrDx available, now for Windows also

There’s a new version of SdrDx, the free app for RF Space SDRs (SDR-IQ, SDR-14, netSDR, etc): http://fyngyrz.com/?p=915

This version includes a lot of new features, including recording I/Q data directly to disk, so you can then play it back. Think of it as a VCR. You can, for example, record the entire 43 meter band (6800-7000 kHz or so, depending on your SDR model) and then go back later and run the I/Q recording back through SdrDx again. It’s awesome! Previously I’ve had to run SpectraVue under vmware to do this, now I can do it natively on the Mac.

I use a program I’ve written myself, that reads in the I/Q data file, and plots a waterfall for the entire file. I can then selectively demodulate what signals I want. I can record all of 43 meters overnight, then check in the morning to see who was on, and listen in. I don’t miss anything, nor do I have to choose if there’s two, or even three pirates on at the same time. I can listen to all of them. At some point I may release this for others to use (Mac OS X only) but it’s still pretty crude right now.

There’s lots of other new features and improvements to SdrDx, so if you have an RF Space SDR, go download a copy to try out.