Sunday, April 27, 2014

Bare bones CForth

The F3 Gizmo includes a Forth line engine that I call CForth.  Its name is related to the fact that is a Forth like engine developed in C. CForth is machine independent. That way I could develop the engine without needing to use the ARM cross compiler nor needing to flash the STM32 F3 Discovery board.

The bare bones CForth is a simple CForth port that can be compiled in most 32 bit systems that provide a GCC compiler and the basic I/O LIBC functions. Currently I have tested it under MinGW on Windows XP and 7 and under Linux Ubuntu.
It should also compile in 64 bit operating systems but you could run into problems using CForth pointer operations.

As current win command windows don't support the ANSI escape sequences, I use Ansicon to create the console that runs CForth.

MinGW executable


The link below points to the executable MinGW CForth port. Just run the contained cforth.exe file.

 MinGW cforth executable v1.0(2014-04-27).zip

Upon start you should get into the CForth console:

CForth start on Ansicon
The CForth manual can be obtained from the reference below:

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



CForth Sources

If you want to run CForth in other system different from windows you would need to compile from its sources. The link below points to the bare bones CForth sources:


You can also use the sources to expand the CForth built-in word dictionary using your own C functions. 
CForth is different from normal Forth implementatios because all its built-in words are created in C, not in Forth.
The information about how can it be done is on the included _CForth API.txt file.


CForth Limitations

CForth was never developed to run on a PC. It tragets medium size microcontrollers. The PC bare bones port was develop to ease the CFoth engine development as it doesn't neeed to access a real microcontroller. That's the reason why you don't get any file operation words. The only file operations that this port implements are the ones needed to create and read the userDict.bin file that is used to implement the SAVE and LOAD words.

13/5/2014 Update

The project is nowat Github:

https://github.com/R6500/MinGW_CForth

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


Friday, August 30, 2013

Visual inspection repair

This is short article about a low budget TV DVB decoder I just repaired today. An AXIL RT160.

AXIL RT160 Decoder

The decoder stopped working some days ago. As it didn't work at all a fail in the power supply was the expected problem.
After opening, the case, nothing was seen to be burnt on the switched mode power supply.

It could be the transformer, but I suspected of the electrolytic capacitors. It is a budget model and the manufacturer surely cut corners on the caps. Moreover, electrolytic capacitors are quite delicate devices and don't age well under stress.

Board View

There are a lot of capacitors on the board, but not so many on the power supply section. 
On a closer look it was evident that one capacitor was different that the others. You can see the difference between it an a normal one on the following photo:

Bad Capacitor on the right
The suspected bad capacitor is somewhat inflated. The top is bumped out. As in jam pots, a bumped out lid means it's bad. Something is probably wrong with the electrolyte inside the capacitor.

It was a 1000uF 16V cap. As I had no similar cap at hand, I replaced it with two parallel 470uF 16V caps. Quite close to the correct value.

Cap substitution
As you can see from the figure it's a quick and dirty solution as there was no place to put the two capacitors on the same place as it was the original.

After that the decoder is working as a charm.

It's interesting to see how a cheap capacitor can ruin the operation of the whole device.
It's also interesting to see how a bad cap can be located by visual inspection. It's not always so easy.








Monday, May 20, 2013

Welcome to R6500

Welcome to the R6500 blog. This is a blog about electronics in general and microcontrollers (MCU) in particular.
Why the R6500 name?
This is a follow-up of my AIM65 blog, same thematics, but spanish language.
The Rockwell AIM-65 is a classic computer from when computers were home built as kits. This was my first contact with computers so long ago back at school time.
Rockwell AIM65
The processor in  the AIM65 was the Rockwell R6502. A second source of the classic MOS 6502 of the 65xx family of processors. R6500 is, in fact, the family name of the Rockwell 65xx family of processors.
The 6502 processor was very popular at its time. It powered the Atari VCS 2600 the Apple II computer and the Commodore computer models VIC20 and Commodore 64.

My first owned computer was a Sinclair ZX81, but the second one was the VIC20. With the VIC20 i learned assembler and, in fact, created a 6502 assembler in Basic. From there i learned about resident programs and other computer hacks.

R6502 CPU

So that's it, the R6500 name of the blog is all about how it all started a long time ago.