The Woes of Debugging DMA on the STM32 Platform

I spent a good chunk of today getting frustrated with my AVC code. I have custom firmware on my GPS so that it sends a fixed-length binary sentence to my microcontroller. Rather than polling the USART, or handing an interrupt every time a character comes in, I figured this is a perfect application for the DMA controller... tell the DMA controller how many characters there are, and have it wake up my code when I receive a full GPS sentence.

Well, during debugging, I found that my DMA IRQ was being handled once, but I couldn't get it to trigger a second time. After wrestling with this for hours, I finally thought, what if the second DMA interrupt really is happening, but because I've got the CPU stopped at a breakpoint, I'm missing it?

So, I took out my breakpoint and instead threw a character out the USART every time the DMA IRA was called. And lo and behold, I got a DMA IRQ five times a second, which is just how often the GPS is sending me data.

Embedded programming can be so frustrating.

AVC Replacement Parts Finally Arrived!

Despite selecting 'air mail' at checkout, Hobby King apparently found the absolute slowest shipping method to get replacement parts for my R/C car to me.

Well, I finally got them and I replaced the front right "C" bracket and took the car for a test drive today. I've never owned a hobbyist-grade R/C car before so some things seemed a bit weird to me. First, the car would go much faster in reverse than it would going forward. I solved this by swapping 2 of the 3 leads to the brushless motor (thus reversing the motor's direction), and inverting the throttle signal on my transmitter. I'm not sure if that's the right solution or not, but it worked.

The other thing is that the car seems to have no problem going from reverse to forward, but it insists on pausing when going from forward to reverse. I have no idea if that's normal or not. At least the car works.

In any case, I now have a platform for my AVC robot. I'm still cleaning up code to interface with my GPS module, and I'm writing a separate subsystem to drive some LED indicators to tell me the internal state of the software. I don't know how useful that will be in the final product, but at the moment, it seems like it's going to be useful for debugging.

I'm almost finished with parts selection. I'm going to have a GPS receiver and at least one 9DOF IMU chip on my vehicle. I'm still debating whether or not to include odometry sensors, IR distance sensors, and/or ultrasonic ranging sensors.

I've started designing the schematic for my controller board in Eagle.

Using the FAT filesystem on SD cards with the STM32F4 Processor: Part II

In part I of this tutorial, we created a project for our STM32F4DISCOVERY board that read and wrote sectors to an SD card. In today's installment, we'll add a filesystem on top of that. Continue reading Using the FAT filesystem on SD cards with the STM32F4 Processor: Part II

Using the FAT filesystem on SD cards with the STM32F4 Processor: Part I

The other night I was able to get my STM32F4DISCOVERY board to read and write files on an SD card formatted with the FAT filesystem. While I haven't done extensive testing of my code, I'm comfortable enough to share what I have with the world. Writing to a filesystem is obviously a convenient feature in many projects. Here's how you can do it with an STM32F4 processor. What follows is the long story; you can find my code at the end of the post. Continue reading Using the FAT filesystem on SD cards with the STM32F4 Processor: Part I

Selecting Crystal Load Capacitors

When designing a circuit recently, I was faced with selecting appropriate load capacitors for the crystal oscillator on my microcontroller. While in the end this selection is rather straightforward, finding the relevant information can be a challenge. My Google searches weren't as helpful as I'd hoped they'd be, and I had to pull together information from several sources. I wrote this blog post to pull together all of the information I found into a single page that hopefully can serve as a reference for others.

So let's begin: what are load capacitors and why are they needed? Continue reading Selecting Crystal Load Capacitors

A system_stm32f4xx.c File for STM32F4DISCOVERY Projects

Because HSE_VALUE (that is, the speed of the high frequency clock crystal) is defined as 25MHz in stm32f4xx_conf.h, and the STM32F4DISCOVERY board actually has an 8MHz crystal fitted, any clock speed calculations done based on the files in the Standard Peripheral Library are going to be wrong. Continue reading A system_stm32f4xx.c File for STM32F4DISCOVERY Projects

USART woes on the STM32F4DISCOVERY board

Now that I have the ability to use a FAT filesystem on an SD card (post to come shortly), my next task was to write some code to allow me to send debug spew to a serial port. My plan is to use an Adafruit Bluefruit EZ-Link bluetooth link to send debug data to my laptop computer while debugging my AVC code. So yesterday I sat down to bang out the code. I mean, how hard can it be, right? Configure a USART with the proper baud rate, parity, data and stop bits, and pump data into the TX register. Piece of cake, right?

In about a half hour I had some code built and running. But I was getting garbage on my laptop over the FT232 cable I was testing with. I figured maybe I'd miscalculated the baud rate, or the clock speed, or something, so I tried doubling the bitrate on the microcontroller. Same problem, so I tried halving the original bitrate. No good.

I whipped out my Saleae Logic logic analyzer and took a gander at what was happening on the wire. The data simply made no sense. The width of each bit was not only not what I calculated it should be, but successive bit times weren't even an integer multiple of each other! The bit time was all over the map.. some short, some long, and very, very few were what they were supposed to be. Continue reading USART woes on the STM32F4DISCOVERY board

FAT and SDIO on the STM32F4: Early Experiments

I've been trying to marry the FatFS filesystem driver with a modified version of ST's SDIO sample code in order to read/write a FAT filesystem on an SD card for logging on my AVC robot.

It's been a frustrating few days. I've had intermittent results and I'm not sure why. I think there's some uncertainty with the DMA completion interrupts in my current lash-up. Moving from ST's library to Lukasz Iwaszkiewicz's software helped. I don't know the differences between the two codebases. Clocking the SD card at 25MHz (I think that's the clock speed in use) at the end of 12" jumper wires surely isn't helping anything. I also think that stopping the debugger and relaunching my code without powering off the SD card may leave its internal state machine confused. All of this is just conjecture, though, based largely on my wholescale ignorance of how the SD interface and the code I'm using actually work.

Currently, I'm able to read a file from the SD card but I'm having problems writing a file. (I started my attempt at writing this morning and only had 45 minutes to work on it before I had to leave for work.)

First experiments with the STM32F4DISCOVERY and an SD card.
First experiments with the STM32F4DISCOVERY and an SD card.

I'm designing a circuit board for my robot's brain that will solve the long wire problem when it's built, but I'm still a ways out from sending that off to be fabbed.

The Saleae logic analyzer that's barely visible in the picture has been worth its purchase price many times over. Many thanks to Supermodel Wife who bought it as a Christmas present for me despite knowing absolutely nothing about what it was!

AVC Parts from Hobbyking and Adafruit Arrived

AVC Parts have Arrived!

I got a box from Adafruit and a box from Hobbyking over the past couple of days, which should be all the parts I need to start developing my autonomous vehicle.

First the Hobbyking stuff. Despite several horror stories that I've read, the box that I received was a sturdy box in undamaged condition. I opened the box to find the contents were equally well packed and contents were all in good shape. Continue reading AVC Parts from Hobbyking and Adafruit Arrived