Saturday, April 26, 2014

Presenting the F3 Gizmo

Today I present the F3 Gizmo. A firmware solution for the STM32F3 Discovery board.

Motivation

The STM32F3 Discovery board is a fantastic board full of features that ST  sells at a very low cost. In includes a STM32F303 ARM Cortex M4 32bit microcontroller running at 72 MHz, 8 LEDs, one Gyroscope and one combined Accelerometer/Magnetometer. The microcontroller itself includes several communication ports: Serial, SPI, I2C, CAN, USB... as well as a lot of other peripherals like GPIOs, timers, Operational Amplifiers and Comparators.
The problem is that it is not easy to program. At least not as easy as an Arduino for instance.

STM32F3 Discovery Board


There are software solutions that ease the use of this board. One case is the ChibiOS/RT Real Time Operating System (RTOS) that provides all the board initialization code, a Hardware Abstraction Layer (HAL) and and a mutithreaded operating system.
There are other solutions aside from ChibiOS/RT but this is the one I use.

Building a software solution for the STM32F3 Discovery board using ChiBiOS/RT as its foundation is much easier that trying to build from scratch or from the verbose libraries that ST provides but it is still complex. Not only that, but you have to piece together a development environment with compiler, editor, debugger, and so on although ChibiStudio eases this process.

Sometimes you have an idea to test quick and dirty and you don't need a fully featured development environment. Or you have a new SPI or I2C chip to check. In those cases you need to develop a small test program, compile it, flash it on the microcontroller and run it.


What is the F3 Gizmo

The F3 Gizmo tries to ease quick tests of ideas by providing a Forth like development environment in the STM32F3 board.

You only need to burn the F3 Gizmo firmware on a STM32F3 Discovery board, connect it to a PC using one USB cable and stablish a serial over USB connection using an emulator terminal .

F3 Gizmo Console
In the above figure we see the start of the F3 Gizmo as shown in the PuTTY terminal emulator. 
Just writing 0 LedSet in the console one LED (Number 0) in the board is lit. 
Just writing AccelRead we get the X, Y and Z readings on the acceleromenter.

Do you want to blink the led? Write:

: blink begin 0 ls 300 ms 0 lc 300 ms again ;
blink

The new  blink user word definition can be used just like the built-in  LedSet  word and it can be used in any new user word definition making the system perfect for incremental development.

What to check the addresses of an I2C device?  
Connect it and call  ISCAN

Do you want to access the internal microcontroller registers?
You also can:

0x48001000 CONSTANT gpioe  \Start of GPIOE
0x14 CONSTANT odr          \Offset of ODR register
gpioe odr +                \ODR register of port E
DUP @                      \Get current ODR value
1 9 LSHIFT OR              \OR with bit 9
SWAP !                     \Store new ODR


It is fast and it is interactive. You don't need anything on the host PC aside from the terminal emulator.
And it's Forth like.

And all operates in RAM. You can create new words (something like functions), erase them, rewrite them and you don't need to touch the flash memory of the microcontroller.
If any time you want to store the current RAM status you can use save it on the flash to recover it on the next reboot.

If you want to test a system that don't use the console, you can set a function to start when the board boots, save the RAM in flash and make it work standalone.

The F3 Gizmo don't pretend to be the next great development environment. It just tries to be a quick and easy access to the STM32F3 Board features.

Features

The F3 Gizmo makes a fixed assignment of several board pins. The following figure shows each allocated pin.
F3 Gizmo Pins
Currently the F3 Gizmo manages the following Board /MCU elements:
  • 8 User LEDs
  • 10 Digital I/O pins
  • 3 PWM digital outputs
  • 6 Analog input channels
  • 1 Analog DAC output channel
  • 2 General use Timers
  • 1 SPI Bus
  • 1 I2C Bus
  • 1 Giroscope
  • 1 Combined Accelerometer/Magnetometer
It also provides some features provided by the underlying ChibiOS/RT operating system:
  • Mutithreaded execution
  • Binary Semaphores
  • Mutexes
In the future I plan to include at least:
  • Two asyncronous serial lines
  • 2 Operational Amplifiers
  • 2 Comparators
  • 1 CAN bus
 

 Components

The F3 Gizmo is composed by three elements:
  • ChibiOS/RT : Provides the Board and MCU Start routines, the HAL for several of the microcontroller peripherals and all OS services.
  • CForth engine: Provides the basic machine independent programing and interpreter language.
  • F3 Gizmo port for the CForth engine. Provides the link between CForth and all MCU or board specific features. It also includes the low level code for the features that don't use the ChibiOS/RT HAL.

Installing the F3 Gizmo

To install the F3 Gizmo you just need its firmare file that is available in bin and hex formats and the STLink utility that ST provides.
You only need the bin file. The  hex is not necesary for the STLink utility.

F3Gizmo_V1.0(2014-04-25).bin

F3Gizmo_V1.0(2014-04-25).hex.zip

Of course you can also build it from its sources but you'll need an ARM toolchain:

F3Gizmo_V1.0(2014-04-25) Source.zip


Manuals

To learn how to use the F3 Gizmo you have two manuals:

The F3 Gizmo Manual explains how to install the firmware and use all STM32F3 Discovery Board Functionalities.

F3 Gizmo Manual v1.0 (2014-04-25).pdf

As the F3 Gizmo implements a Forth like language called CForth, you will also need the CForth manual as the F3 Gizmo manual don't explain the operations of the CForth engine.

CForth Manual v1.0 (2014-04-20).pdf

That's all for now. Just try it if you like.
In the future I will post more entries about the F3 Gizmo use.


13/5/2014 Update

The project is now on Github:

https://github.com/R6500/STM32F3_Gizmo


No comments:

Post a Comment