Sunday, May 24, 2009

Bringing up Baby: (a new-to-me) Cortex-M3 board

First sign of life from my Cortex-M3 processor board

24 May 2009

After some struggles with stupid errors, I finally got a sign of life from my little Cortex M3 (a fairly new ARM processor) board (ET-STAMP-STM32, purchased from futurlec.com)   
FYI, here's where I ordered the board from:

http://www.futurlec.com/ET-STM32_Stamp.shtml
US$ 24.90 (+shipping)  

So, it's around the same price as an Arduino, but much more CPU firepower. memory and better I/O (including 16 channels of 12-bit AtoD and two ch of DtoA – real D2A, not just PWM {which it also has plenty of.})   This is why several reprappers are working with this chip.  (NXP says they'll have a similar chip out, the LCP17xx "real soon now," but I haven't seen it orderable andywhere.)

The futurlec folks don't get parts to you nearly as fast as digikey (took a couple weeks), but their prices are good, and they had this goodie in stock when I ordered it (and Sparkfun was out of their Cortex boards; though they've now got some in.)






This board's .pdf manual (English translation from Thai), isn't perfectly clear, but is OK after some study. Certainly better than my (nonexistent) Thai, so I shouldn't complain.

They don't include (or describe) how to set up a compiler toolchain, but that info seems to be available online. I followed the steps outlined in:

http://wiki.fosstronics.com/arm_cortex-m3/stm32/minimal-c-program

except that I downloaded the code to my board using UART1 on the board, and the two boot lines to invoke the serial downloader.

See also, “A Free Toolchain for ST-ARM uC” online (as of 5/2009) at:

http://www.binaryconstruct.com/index.php?option=com_weblinks&view=category&id=44&Itemid=72

and

http://www.danielecaltabiano.com/wwm/ST-ARM_toolchain/files/ST-ARM_toolchain_1.2.pdf


First problem:

I ,finally> found that my first jury-rigged +5 supply (tapped off of an Arduino clone) was misbehaving (slight overvoltage, strange --- looks like a solder joint came loose on the regulator), so I rigged up a separate 7805 and a wall wart, ditto a 3.3 v regulator for the STM32.

(We're in the middle of a remodeling project, and I'm working on a folding table in my bedroom, instead of my usual electronic-ing benches in the basement – that's all torn up/boxed up during construction. And my bench supply is hiding in some box. (Mistake!)


Problem 2:  Needs true RS232 levels (not TTL levels)

My best guess is that Desktop PCs, that still have a serial port, are the norm where this board is built (Thailand.)  As a result, it expects true RS232 levels, and comes with a DB9 cable.   As a result, I ended up creating a four-step Rube Goldberg interface to get it to talks to my (serial-portless) laptop:

  • My Laptop (USB port)  

  • FTDI USB to serial cable (at 5V TTL levels)

  • MAX233 on my protoboard (5V ttl to RS232 level transceiver)

  • On-the-board RS232 to 3.3V ttl level translator (can't read the P/N, suspect MAX3232)

  • STM32's UART1

I wish the designers of this module had put in a jumper between their level translator and the processor pins. (I have another FTDI based device that can be switched to do either 3.3 V or 5 V TTL levels, the USB BUB board from http://moderndevice.com/connect.shtml -- BTW, this costs less than a FTDI cable, and IMHO more versatile, e.g. the voltage level jumper-ability.) Since board is surface mount, I was leery of attempting surgery, so I protoboarded the above hack to get it talking.

There are two hardware items that need to be set correctly for the CPU to respond to the STM Flash Loader:

  • The boot0 pushbutton must be depressed (not crystal clear in the manual.)  

  • The jumper to the right of the pushbutton should be on the outermost two pins (position marked ISP.)

With that, I now get signs of life (target is readable!), when I push the reset switch, WOOT:




 Look at all that memory -- half a meg of flash, and 64K of ram.  Not too shabby!


Getting a blink program running:


I adapted the (great) example from

http://wiki.fosstronics.com/arm_cortex-m3/stm32/minimal-c-program

The main difference is that that example assumes the use of JTAG, which my board lacks.  (And I don't have a JTAG probe yet, either.)

Following those instructions, I downloaded the latest GCC toolchain for the Cortex, from http://www.codesourcery.com/sgpp/lite/arm/portal/release830

I selected current (2009q1 release) as of this writing, IA32 Windows Installer.

I also grabbed new download of cygwin (linux like env. for windows), from: http://www.cygwin.com/ 
and set that up

I was able to use the example .c and linker-script files verbatim (always helpful when trying something new), and jumpered/protoboarded an LED/resistor onto portB/pin9.

The example was especially helpful to me, because it gave exact “what to type to Cygwin's bash shell” lines, complete with all the options needed to compile, link, convert to a plain binary file to download to the STM32 chip.  The end result was a plain binary file (in may case blink_flash.bin), which is just what the serial bootloader wants.





One thing that wasn't quite clear to me was whether to leave my code .org'ed at 0x000000, or relocate it to 0x8000000. The STM documentation isn't crystal clear on how the FLASH is addressed in the various boot modes. I think it's addressable as either address when the boot1/boot0 are both set to zero (but I won't swear to that.)

In any case, the .bin file downloaded without error: 

----

For this little board, the magic configuration info is the following:

Leave the boot1 jumper in the ISP position always.

The boot0 switch (to the left of the boot1 jumper: should be:

  • Depressed during code dowload (which lights the green LED)

  • Out to execute the code from FLASH (green light off)

Once the code has been downloaded (using STM's flash loader demonstrator {v 1.1}), pop the boot0 switch out, and either press the reset button, or power cycle the board.


A blinking LED! 
It doesn't take that much to make me happy.

Now, on to studying the myriad I/O configuration registers.....

I'd take a photo of my messy (but working!) protoboard, but my camera seems to be hiding. 
But it is blinking.

More later (and fingers crossed that I can find the camera amid all our remodelling chaos),

Larry




2 comments:

  1. Have you tried the low power savings modes
    of "stop" and "standby"?
    I had to do a slight modification on three
    items on the board to get it within (close)
    to specs.

    ReplyDelete
  2. You cannot put the STM32 in the low power saving modes of sleep/stop/standby! Check
    your running ma. and you will see that it is
    extremely high instead the normal room temperature @ 36 ma. per specs. I found a solution to fix this excessive current draw -lift zener D2!
    Also, remove the red power LED (2 ma)
    Note: The green LED still shows power when switched.
    Also, remove the RS232 IC (saves 5 ma with the cable plugged in) then bridge the SOIC pins 11-14 and 12&13. Then you could use the
    USB BUB by cutting the RS232 cable and installing the wires in the BUD Rx-TX and TX-Rx and ground. Hope this helps.

    ReplyDelete

Comment form msg. ursine@gmail.com