Dave's STM32 Page
Adventures with ARM Cortex M3 processors
Including the STM32 Design Challenge Project: Multi-Zone Stereo System
The Blog for this project


I haven't done much work with microprocessors for a while. At work we currently use Atmel ARM9, but my associate Kevin does pretty much all the microprocessor hardware work. We have trained software professionals and tight FDA approved design control for the embedded code. My last home project was a simple RS485 network based on AVR. In the past few years I have messed a bit with Arduino, NetBurner, ExpandIO, AVR32, and others. My home projects have been mostly one-off instruments run by a PC and a USB DAQ. It is time to dig in and do some 32 bit microprocessor work with USB, modern LCDs, a real network, SD cards.

The past year (2009-10) I looked at the Atmel XMEGA. Faster, more memory, better peripherals, DMA. But the I/O structure is different enough from AVR that code rewrite of the low level stuff is needed. It's new enough that there aren't many good hardware and code examples out there. I wasn't able to find the right combination of board, debug tool, compiler and demos or examples to get me started fast. The best I came up with is AVR Dragon ($60) JTAG debugger and programmer, and Atmel Xplain ($40). the Xplain has a bizarre combination of peripherals including audio and a 4 bit SDRAM(?!). It only brings out a few of the I/Os to connectors, and the other peripherals tie up many of the I/O pins I needed. I looked for other Xmega boards and considered laying out an ExpressPCB myself.
After all this, XMEGA is still an 8 bit processor.

I suspect that Atmel is spread a bit thin with too many processor families: AVR, XMEGA,
AVR32, Arm 7, 9 and M3. A bunch of other vendors have their own 32 bit solutions, but they seem to be scattered and either fully or semi proprietary. Other architectures out there: Microchip MIPS, Coldfire, lots of older ARM7 and ARM9, TI's OMAP (high end).

Recently eight or more IC vendors have adopted ARM Cortex M3: NXP, Atmel, ST, TI, Toshiba and others. The architecture has caught on for good reason. It is open, the variable-width Thumb instruction set is efficient, processors exceed one instruction per clock cycle. Fast,
hardware multiply and divide, low power, low cost, open tools,  a wide range of devices, lots of nice peripherals including DMA, high-everything-good, low-everything-bad.... ARM Cortex M3 looks like the best upgrade for an 8 bit architecture.
discovery
Kevin returned from the 2010 Boston Embedded Systems Conference with a couple of the STM32 Discovery modules (photo thanks to ST). I installed the Atollic TrueStudio software (lite version, nearly full functionality) and tried a few of the examples. Atollic is gcc and Eclipse based (good and good), and supports full source level debug (nice). I looked at the Discovery hardware: STM32F100RB processor, 24MHz ARM Cortex M3, 128K Flash, 8K RAM, gobs of I/O including 12 bit ADC and DACs. It has a 2-wire debug to save pins (vs. 4 wires for JTAG). The Discovery module is a decent form factor that brings out every processor I/O on a convenient DIP format. Then I looked up the Discovery module price: $12!!! OK, now I'm very interested.

This is an amazing deal compared even to the low-priced Arduino
($30) or anything that Atmel or Microchip offer. It beats mBed and other CortexM3's for cost of entry. I suspect the modules are built at a loss by ST, but we might as well enjoy them while they last. The core processor consists of only the STM32F100RB plus 2 crystals. The only on-board I/O is 2 LEDs and a push button. Perfect: their stuff won't get in the way of my applications. The current Digikey price for the processor IC is $3.50, qty100. The board also contains another smaller STM32 with USB, factory programmed as the debug interface. The two-wire debug interface is brought out to a 4 pin connector, allowing a Discovery to be used as a debug interface for other STM32 designs.

If that isn't enough, just for signing up for the new STM32 design contest, I received a new Discovery module with the STM32F103 chip for free. Same board, but the processor has 1MB of flash, 96K RAM, 72MHz and even more I/O. Yikes! The module isn't for sale yet, nor is the chip, so I don't know the chip or module price. (1/'11)

STM32 I/O Ports
Apparently while I wasn't looking, general purpose I/O ports (GPIO) evolved. The old style generally consisted of an output port register, a pin read port, and a port direction register, all 8 bits. Some ICs added open-drain mode or other features.

The STM32 has 16 bit ports, and each port has ODR (output data register), IDR (read pin register) and Direction, but the ODR and the direction registers each have separate Bit-Set  and
Bit-Clear registers. Why is this important? With the old ports, to set one or more bits required one to do a read / modify / write (R/M/W) cycle to the port. Simple enough, but this creates a problem when a main routine, multiple interrupt routines and and DMA all want to operate on different bits in the same register. The contents of the register can be corrupted if one routines R/M/W cycle is interrupted by another routine trying to set the same bits. A separate flag or other mechanism must be used to prevent this. It gets worse with 16 bit GPIO registers since it is more likely that multiple device drivers will want to access different bits in the same I/O port. And worse again with DMA. The solution is to use the separate bit set and bit clear registers. These do not require R/M/W cycles. Faster, too.

BTW the same is true of any peripheral on any processor and requires programmer awarenes sand care. If the main routine wants to read an ADC channel and an interrupt routine or DMA channel wants to read another channel of the same ADC, the state of the peripheral will be corrupted. For the ADC, The STM32 has a separate set of registers to permit this possibility.

1/12/2011
I am looking for a good blog about STM32. I found a 3 year old Yahoo group at http://tech.groups.yahoo.com/group/stm32/ This group has been idle for a while,  but I'll see if I can revive it a bit.
Update: As of 1/18/11, only one response to my posting there, pointing me to a better group at http://www.stm32circle.com/forum/index.php

On the original Discovery I have a test program running with basic ADC, DACs (using DMA), USART / sprintf() and GPIO. It is a combo of some of the STM32 demos. I separated out the demo board specific code since the Discovery code didn't provide much interesting stuff. I'm willing to share my code in the 'files' area of the Yahoo group. Let me know if you would like it.

Next is to get an alphanumeric LCD, and a 128x64 LCD working, using GPIOs for the 8 bit bus plus the control lines.  Anyone willing to share code for either of these?
breadboard

Here is the discovery module mounted to a 4" x 6" proto-board from Vector. The colored ribbon cable connects to the LCD. In retrospect I should have just mounted the LCD on the empty part of the board. It can be
mounted straight or right-angled using a simple .1" right angle header header.

I'm planning to write a simple ADC routine, getAdc(chan), using programmed I/O only (no interrupts or DMA). Has anyone written this yet? It's a bit tricky because the ADC is designed to measure a list of channels, but there is just one register to deposit the result. This works fine with DMA or a fast interrupt. My plan is to ADC a 'list' of just one channel.


1/18/2011

I spent too much time last weekend looking for LCDs for the house-wide audio project. It was a slog opening and reading dozens of data sheets. What I am looking for is a simple low cost, lo-res monochrome display to display text, and simple graphics. I have old C libraries from my FPGA controllers on BoatBus, but my old controllers were overly complicated and were not 3.3V compatible. They required an FPGA/CPLD plus a RAM, plus DC-DC converter... Too much like work. All I ask is:
Unfortunately the older / surplus LCDs are mostly low contrast, green or yellow LEDs or worse, electro-luminescent, and 5V only devices The old Samsung KS108 controllers require 5V logic. I have a few of these panels lying around. The newer 3.3V displays are mostly Chip-on-glass (COG) and require high pinout (40-50 pin) fine pitch connectors and a bunch of external capacitors for the DC-DC.
NewHaven Displays seems to have the displays I want and their products are in stock at Digikey and Mouser as well as others.  I like the
NHD-12864WG-BTFH-V#N. This part uses 5V power, and the Vih (Input Voltage high) spec is 2.0V, so 3.3V logic is good. The Voh spec is 2.4V at low current. These are TTL compatible specs which are 3.3V / 5V tolerant compatible. Unloaded the outputs will go to to 5V, but STM32s I/Os are 5V tolerant. So life is good. If you are using a non-5V-tolerant chip, you may be able to use series resistors and Schottky diodes to +3.3V on the 8 bit data bus to protect the CPU inputs. Or some other 3/5V translation trick.

2/12/2011
After a few weeks, I have the 128x64 LCD code working nicely. Low level reads and writes to the LCD,  5x7 font and lcd_string(), putpix, linedraw and ellipse drawing are all working. See the LCD page for the details and to download the current code.

lcd working

3/21/2011
The STM32 design contest deadline was extended a week to Monday 3/21. This was just enough time to allow me to sprint to the finish. On the previous weekend I finished the 2 board designs: the crosspoint and quad preamp boards. On Monday 3/14 I ordered the 2 boards and the parts. On Thursday and Friday, the boards and parts arrived and a soldering frenzy ensued, followed by a coding frenzy over the weekend of the 19th.
See the
Multi-Zone Preamp Page for details.


STM32 Documents
The STM32 Processor Reference Manual RM0041 for the STM32F100xx family details all the I/O, memory, and debug devices. Very well organized, this is the STM32 F100 bible.
The STM32F100x4 STM32F100x6 STM32F100x8 STM32F100xB is the data sheet for the Low & medium-density value line products. It has the device pinouts and package specific specs.
The Discovery UM0919 User Manual has the pinouts and schematic for the Discovery Module.


The Blog for this project
Multi-Zone Preamp Page
LCD 128x64 Page
Main STM32 Page (Here)
BoatBus and AVR Projects

Last Updated: 2/16/2012