Friday 13 April 2012

Booting up

Edited: 20120413 to add images and fix some errors.

OK, so today was fun, I received my Olimexino-STM32 that I talked about yesterday and I was able to do a few things with it:
  1. Set it up so that I could use it with the Maple integrated development environment ('IDE') - a simple IDE that allows a 'fast-start' and that comes with quite a few 'example' programmes to show the capability of the device, and also provide a basis for one's own projects.
  2. Programmed it to make some LEDs flash on and off in different sequences
  3. Set it up so that I could use it with the Eclipse IDE - a much more powerful IDE that provides more flexibility (at the cost of more risk of doing something that can't be easily undone)
  4. Programmed it again using Eclipse to make the LEDs flash on and off, using a JTAG interface
  5. Worked out how to return the board to being able to work with the Maple IDE (since using the Eclipse IDE to download code removed the bootloader that the Maple tool requires)

This last bit was  quite tricky and not all that obvious!  So a description follows for anyone out there trying to work out how to make this work... especially as most of the instructions I could find are Linux-based, so I made sure I could do this using the Eclipse IDE on my windows machines too!

Note that all of this assumes that you've already set up Eclipse, the various drivers and other software required and have a JTAG interface to hand!

Firstly you need to make sure that you have copied the OpenOCD files and the Olimex examples into a folder structure that mimics that found under your 'Program Files' folder, and make this your workspace (short paths with no spaces are better, mmm-kay?):


Next, go download the Maple bootloader source and unzip it.  Move the folder named something like 'leaflabs-maple-bootloader-d1234348' (yours will have a different name) into your workspace folder and rename it to something a little shorter, I called mine, 'stdBoot' (you can see this in the image above).

In Eclipse right-click in the projects pane and select 'Import', click on 'C/C++' and then select 'Existing Code as Makefile Project' and click 'Next':


For the 'existing code location' browse to the 'stdBoot' (or whatever you called it) folder, and select just this folder:


Click on 'Finish'.  The folder and contents should then appear in the projects pane.  'Borrow' (copy and paste) the stm32.cfg and openocd.cfg project.cfg files from one of the other STM32 projects for your 'stdBoot' folder:


OK, almost there!  If you've not done so already then hook up your board to your computer via the JTAG.  You also need to power the board - to do this I use a USB lead that is broken and supplies only power (otherwise the PC will try to load the USB drivers that the JTAG needs and reserve them!).

Try clicking the 'Run external tool' entry in Eclipse that matches your JTAG interface (for me this is the ARM-USB-TINY-H), if you get an error like this:



Then just click in the pane holding 'main.c' and try again, what you should see is this:


Which appears in the console panel end finishes something like:  "stm32.cpu: hardware has 6 breakpoints, 4 watchpoints".  This is good and means that everything is running,  


Ensuring that you're in the C/C++ perspective of Eclipse, expand your 'stdBoot' project and open the 'Makefile' - on my PC the make action failed to make some folders, so look through for 'mkdir' commands and create the folders that make will require.  Unless you know exactly what you are doing, DO NOT EDIT THE MAKEFILE!  In my Makefile, the mkdir commands are:



Now right click on the 'stdBoot' project and select 'Build as...' 'Make Targets'/'Build', in the dialog that appears, click on 'Add', then in the top text entry box type 'all' (without the ''), then click 'OK':


Now select the 'all' entry in the 'Make Targets' window and click on 'Build'.

If your setup is OK then you'll see a successful build occur.  Warnings are undesirable, but survivable - 'Errors' though are a big problem!  Check the console carefully - if you've had a successful build then you will receive a report of the file sizes created.  If you see errors, then Google is your friend!  A good outcome looks like this (just cancel any errors from 'mkdir.exe' as we've already circumvented these):


Now, right-click your project and under 'Debug as...' select the 'Debug configuration' option.  In the new window select 'Zylin Embedded Debug (Native)' and click the 'New launch configuration icon' button:


Fill out the Debug configuration name and there are now some tabs to fill out:
  • On the first tab, 'Main', in the C/C++ application box type: build/stdBoot.bin

  • On the second tab, 'Debugger', in the 'GDB debugger' box type: arm-none-eabi-gdb (if you've not added the yagarto/bin folder to your path then browse to that file)

  • On the third tab, in the 'Run' commands type:
target remote localhost:3333
monitor gdb_breakpoint_override hard
monitor soft_reset_halt
symbol-file build/stdBoot.bin
break main


target remote localhost:3333
monitor reset halt
monitor wait_halt
monitor sleep 100
monitor poll
monitor flash probe 0
monitor flash write_image erase main.bin 0x08000000


  • On the 4th and 5th tabs do nothing (you can 'add to favourites' on the 6th tab if you want to)
Next click 'Apply' and then 'Debug' - you should see the console window show a load of information (again check it for errors, of which there should be none) and you have just flashed your board back to the Maple bootloader.  Save everything.  You can now use this project to restore your Olimexino back to the standard bootloader if you ever have any problems, or if after using Eclipse you decide that you want to go back to the Maple IDE.

I know this is quite long, so if I can I'll add some explanatory images I hope the images are useful!

Tuesday 10 April 2012

Stay on target!

OK so I'm now into the implementation phase of my MSc project - see my previous post on the fuzzy transform for what I was doing a while ago. Because my end-result is for a device to go into a vehicle I need to work in an embedded environment (my target environment) to accurately determine the capability of my system.  If you're interested the target platform I'll be using it's called the Olimexino-STM32 and it's made by Olimex.

Over the last few weeks I've found that there's an active community developing small systems using this and other devices, which is useful since it means there are other people doing things that I can learn from and also ensure that I don't inadvertently replicate anything that's already being worked on.

As part of my project I need to do some prediction work, one way of doing this is the method of least squares, and I've described an approach to it in the linked PDF:  Using least squares with a linear system

Whether this is the approach I'll end up with is debatable, as the fuzzy transform may still have a few treats in store for me!

Creative Commons Licence
'Using least squares with a linear system' by Iain Cunningham is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.