Back to Basic(s) with the Freedom Board


If you think that my LED tutorial is too complicated to program a simple LED, then this article might be of interest for you. Because there is an easy and basic way: And I mean it: really basic. And the name is the program(ming language) ;-).

One of my very first contact with computers was the Commodore C64: this was a very successful home computer system back in the 1980′s: a 8bit machine with 64 KByte of RAM and a built-in Basic Interpreter in ROM:

Commodore C64 Startup Screen

The great thing with the build-in BASIC ROM was that you immediately can start programming: no compiler or special IDE needed: simply type in your program and run it! Awesome simple and intuitive, especially for beginners. And of course there was plethora of software and game available too.

Now the cool thing is: there is the CoreBASIC interpreter for the FRDM-KL25Z Freedom board created by SolderCore. :-)

CoreBASIC startup

CoreBASIC startup

Freedom MSD Bootloader

First, I need to load the MSD bootloader on my Freedom board to use OpenSDA as mass storage bootloader (skip this step if the MSD bootloader is already running):

  1. Plug in the board using the SDA USB port, with the reset button pressed
  2. Small green LED nearby of the OpenSDA K20 toggles
  3. Device enumerates as Mass Storage Device/Drive named ‘Bootloader’
  4. Drag&drop (or copy) the MSD_FRDM_KL25Z_Pemicro_v*.SDA from P&E’s OpenSDA firmware (latest and greatest, registration needed) or from Freedom Quick Start the to the Bootloader drive (:!: unzip the files first, and then copy!)
  5. Unplug the USB cable and power the board again with the USB cable
  6. Small green LED is on, and device reports as ‘FRDM-KL25Z’ device
  7. Now the Freedom board can be programmed with an application file

Programming the CoreBASIC application

Next step is to program the board with the BASIC firmware:

  1. Download the CoreBasic Freedom Board CoreBASIC firmware (binary file).
  2. Copy the freedom.bin file to Freedom board device (drive letter on your system)
  3. Be patient as it takes a while to flash the application
  4. Repower the board

Connecting with Tera-Term

A terminal program capable to emulate VT100 or later because CoreBASIC is using control character sequences e.g. for color information. A good choice in my view is TeraTerm.

Connect to the board with 115200 baud:

TeraTerm Connection settings

TeraTerm Connection settings

After connecting to the OpenSDA serial port, I press the reset button, and I get:

CoreBASIC startup

CoreBASIC startup

BASIC stuff

To print out something is easy, simply type in

print "Hello World!"

and voilà:

Hello World

Hello World

There are other cool things: turning on the red RGB LED is as simple as:

core.led = %red

And you guess it right:

core.led = %blue
core.led = %green
core.led = %black

turns the RGB led to blue, then to green and finally to black (well: off). Other colors are accepted too (see below or the CoreBASIC manual).

A LED Blinking Loop

Creating a program on the fly is simple: it is entered line by line.

:idea: Each line starts with a line number. To insert new lines, it is a good idea to increment line numbers by 10 (so I have enough lines as space in the program).

So I enter the following lines, one after each other:

10 for i = 1 to 5
20   print i
30   core.led = %magenta
40   pause 0.5
50   core.led = %black
60   pause 0.5
70 next i

:idea: Simply copy-paste the source lines into TeraTerm!

The list command lists my program:

list my program

list my program

Notice the %magenta in yellow color: here I have made spelling error. To correct a line I simply enter that line again.

to delete a line: I use the delete command followed by the line number.

The command to run a program is: of course run:

running the program

running the program

:idea: The video on the SolderPage shows the usage of the accelerometer.

Using the edit command opens an editor to edit multiple lines:

Edit Mode

Edit Mode

:idea: make sure the TeraTerm view is big enough, otherwise the top line(s) of the source might not be visible.

To exit the edit mode, use CTRL+D.

Summary

It is a great feeling: feels like I was young and programming with the Commodore C64. Maybe because of the blue background ;-). It is really fun to quickly type in something and to see how it goes. The only consideration is that there is not much RAM left, and that does not allow big things. SolderCore demonstrates on larger devices with more RAM that a BASIC system can work with file system, ethernet and all the other goodies an embedded systems offers. On the CoreBasic site there is a cool demo video, plus www.soldercore.com/manual/ for the documentation, plus code examples I can try out.

Happy Back to BASIC :-)

About these ads

One thought on “Back to Basic(s) with the Freedom Board

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s