Recently, I had a few embedded system projects I wanted to do with the MCF52221 ColdFire MCU, including controlling my toaster oven to do SMT reflow soldering... In addition to that, one of my dreams for a long time has been to make these kinds of projects more accessible to high-school and college age hobbyists, like I believe they used to be in the past.
Anyway, one thing led to another and we ended up writing an entire resident “StickOS BASIC” embedded system programming environment that runs entirely within the MCF52221 ColdFire MCU, including an easy-to-use editor, compiler, flasher, and debugger, where external pins are mapped to special “pin variables” for manipulation or examination, and internal peripherals are managed by BASIC control statements and BASIC interrupt handlers.
And we finally have a website up!!! (But now we need to redesign the graphics so the text is not clipped on windows narrower than 1024 pixels...)
If anyone wants to try it out, StickOS BASIC runs as-is on an M52221DEMO board with the CLK0 jumper installed (or basically any board using an MCF52221 ColdFire MCU and either an 8MHz crystal or the internal relaxation oscillator enabled). Download information, including the S19 ColdFire binary image and full documentation, is below.
You can log into the MCF52221 from any USB host computer that supports an FTDI Serial Port (including Windows and Linux) and then control it by a terminal emulator program, with no additional software or hardware required on the host computer.
By its very nature, StickOS supports in-circuit emulation when it is running in the MCF52221 -- all you need is three (USB) wires connecting the MCF52221 to a USB host computer, and you have full control over the target embedded system! The USB host computer may then be disconnected for standalone operation. (Or it may be left attached if you just want to use the MCF52221 as a slave data acquisition device!)
When you initially log in you’ll see a command prompt in the terminal emulator window like:
Welcome to StickOS for Freescale MCF52221 v1.01!
Copyright (c) CPUStick.com, 2008; all rights reserved.
If anyone remembers the old HP-2000 TimeShare BASIC systems from the 1970’s, that’s what inspired me to do this... In StickOS BASIC, however, the CPU and filesystem, not to mention the I/O system, are all on a single chip! You talk directly from the terminal emulator to the MCF52221!
So what does the “Hello world!” program look like in StickOS BASIC?
Well, if the baseline goal for an embedded system is to configure an I/O pin and get an LED to blink, such as LED1 on pin DTIN0 of the M52221DEMO board, then the “Hello world!” program looks like this (entered text is in bold):
> 10 dim led1 as pin dtin0 for digital output
> 20 while 1 do
> 30 let led1 = !led1
> 40 sleep 500
> 50 endwhile
STOP at line 40!
Line 10 declares a “pin variable” named “led1”, then configures the general purpose I/O pin “dtin0” for digital output, and finally binds the pin variable to the corresponding pin (in traditional BASIC, the “dim” statement is used to “dimension” the shape of a variable prior to use). From then on, any modification of the pin variable is immediately reflected at the I/O pin. Line 20 starts an infinite loop. Line 30 inverts the state of the dtin0 digital output pin. Line 40 delays the program for 500 ms. And finally line 50 ends the infinite loop. Press <Ctrl-C> to stop the program.
Of course, if you really *just* wanted to print “Hello world!” to the terminal (assuming it was still connected , you could just do:
> 10 print "Hello world!"
If you want to read analog input pins in StickOS BASIC, it’s just as easy...
To control and monitor the accelerometer on the M52221DEMO board, you could use the following program:
> 10 dim x as pin an4 for analog input
> 20 dim y as pin an5 for analog input
> 30 dim z as pin an6 for analog input
> 40 dim gsel1 as pin utxd1 for digital output
> 50 dim gsel2 as pin urxd1 for digital output
> 60 dim wake as pin ucts1* for digital output
> 70 let gsel1 = 0
> 80 let gsel2 = 0
> 90 let wake = 1
> 100 while 1 do
> 110 print "x =", x, "; y =", y, "; z =", z
> 120 sleep 1000
> 130 endwhile
x = 1583 ; y = 1656 ; z = 2456
x = 1576 ; y = 1662 ; z = 2458
x = 1593 ; y = 1655 ; z = 2465
x = 1572 ; y = 1656 ; z = 2455
STOP at line 120!
Lines 10-30 declare “pin variables” named “x”, “y”, and “z”, then configure I/O pins “an4”, “an5”, and “an6” for analog input, and finally bind the pin variables to the corresponding pins. From then on, examination of the pin variables results in the current ADC values being read. Lines 40-90 control the gsel1, gsel2, and wake (actually sleep*) pins of the accelerometer (see the M52221DEMO board schematic). Lines 100-130 poll the accelerometer every second and print the results to the terminal, in millivolts (mV). Press <Ctrl-C> to stop the program.
Hello Toaster Oven!!!
What if you want to use interrupts? StickOS BASIC supports them also! You can configure timers to interrupt periodically and UARTs to interrupt on character transmit or receive.
The following program illustrates the use of a timer interrupt (at lines 50-60 and 130-190), and controls my toaster oven with a convenient SMT reflow temperature profile, when hooked to a K-type thermocouple thru a 100:1 op-amp!
> 10 dim target, secs
> 20 dim thermocouple as pin an0 for analog input
> 30 dim relay as pin an1 for digital output
> 40 data 512, 90, 746, 105, 894, 20, -1, -1
> 50 configure timer 0 for 1000 ms
> 60 on timer 0 gosub adjust
> 70 while target!=-1 do
> 80 sleep secs*1000
> 90 read target, secs
> 100 endwhile
> 110 let relay = 0
> 120 end
> 130 sub adjust
> 140 if thermocouple>=target then
> 150 let relay = 0
> 160 else
> 170 let relay = 1
> 180 endif
> 190 endsub
> autorun on
> autoreset on
Note that if terse code were our goal, lines 60 and 130-190 could have all been replaced with the single statement:
> 60 on timer 0 let relay = thermocouple<target
“Save” saves the program to non-volatile flash memory, “autorun on” sets the program to run automatically when the CPUStick is powered up, and “autoreset on” sets the CPUStick to automatically reset itself when it is awakened from a sleep (as opposed to continuing running the saved BASIC program from where it left off). Finally, “reset” resets the CPUStick as if it was just powered up.
Using frequency output pins bound to the DMA timers whose value can be set in hertz (Hz), you can play scales or music or whatever else you might dream up, such as:
> 10 dim oct
> 20 dim freq as pin dtin0 for frequency output
> 30 let freq = 440
> 40 for oct = 1 to 8
> 50 sleep 500
> 60 let freq = freq*105946/100000
> 70 if oct!=3&&oct!=7 then
> 80 let freq = freq*105946/100000
> 90 endif
> 100 next
> 110 let freq = 0
Which plays a single octave of the musical scale starting at A-440 (Hz).
Other StickOS features...
* on-line help
* ansi terminal line editing
* transparent line-by-line compilation and de-compilation
* full-featured debugger with breakpoints, assertions, and even edit-and-continue
* load and save up to three BASIC programs in flash
* prolong flash lifetime by storing incremental updates in RAM
* StickOS firmware self-upgrade over USB
* MCU-to-MCU flash cloning over QSPI/EzPort
Who is StickOS for?
Our main target audience for StickOS is folks doing low-volume hobbyist and educational work. Or more specifically, our main target audience is folks for whom “ease of development” (and even ease of re-development!) is significantly more important than “production cost”. Obviously, for hobbyist and educational use, there is no production!
Who is StickOS *not* for?
StickOS simply doesn’t make sense for high-complexity, high-performance, high-volume, or cost-sensitive applications. By pushing the development environment to the MCU, you end up using a $6 MCU where you could have gotten by with a $1 MCU, from a performance and resource usage perspective. Likewise for high-volume applications, development costs (and “ease of development”) are nearly moot, since they are amortized over large number of production units.
Where is more information on StickOS?
See http://www.cpustick.com . You can download the S19 ColdFire binary image to flash to your M52221DEMO board, as well as a full set of documentation. There are also C source code examples for the “general purpose” parts of StickOS I thought folks would find useful, including the FTDI/USB transport device driver, S19 file parsing and self-upgrading, flash programming, QSPI/EzPort flash cloning, etc. These source files are available with no restrictions; however, we ask you don’t republish them so we c an fix bugs in the originals.
The “CPUStick” part of the website is the other half of the equation for making these projects more accessible to high-school and college age hobbyists -- it is a small (0.9” by 1.8”) PCB with the MCF52221 running StickOS, with 0.1” header pins suitable for use in either a solderless breadboard or wirewrap environment. You can download Gerber files if you want to make your own PCB.
For now, we can produce a limited number of CPUSticks for folks who want to help with beta test. We are especially seeking educators! Also, if you have other platforms you'd like us to port StickOS to, let us know that, too, as the code is easily portable!
PS The next project we’re just starting is to add a zigbee wireless daughter card (also 0.9” by 1.8”) based on the MC13201 to the CPUStick so you can remotely log in from one CPUStick to another, eliminating the need for the USB connection for all but the first CPUStick! And we’ll add QSPI support to StickOS at the same time, since that’s the MC13201 interface. I’m also considering a port to the (LQFP44) 51JM128, to save $2 and some board real estate.