MS-I (908 MCU) Code Development How-To

A forum for discussing the creation, modification, and loading of embedded code for B&G MS-I/MS-II.
Forum rules
Read the manual to see if your question is answered there before posting. Many users will not reply if the answer is already available in the manual.

If your question is about troubleshooting, configuration, or tuning, you MUST include your processor type (MS-I or MS-II) and code version in your post. If your question is about PCB assembly or modifications, you must also include the main board version number (1.01, 2.2 or 3.0).

If you have questions about MS1/Extra or MS2/Extra code configuration or tuning, please post them at www.msextra.com Such questions posted here will be moved to: a temporary MSextra sub-forum, where they will be removed after 7 days

The full forum rules are here: Forum Rules, be sure to read them all regularly.
Post Reply
efahl
Site Admin
Posts: 102
Joined: Mon Feb 16, 2004 3:15 pm
Location: San Clemente, California, USA
Contact:

MS-I (908 MCU) Code Development How-To

Post by efahl »

This thread is intended to get people started editing, assembling/compiling and downloading code to the original MS-I MC68HC908GP32 microcontroller. Please keep questions on this thread on-topic, and any specific questions not directly related to this topic should be asked on new threads. (I'll be deleting and consolidating posts as I see fit to keep this one thread as to-the-point as possible.) All of the following discussion assumes that you are using a Windows-based machine, there is no proven assembler that works on Linux, so you are stuck with Windows for 908 development.

Source Code
The official code releases for V2.000, V2.98 and V3.000 are at dload.php?action=category&cat_id=34. You can also find the "Boot_R12.asm" and header file "megasquirt.h" there as well. For other code version sources (such as MegaSquirtnSpark), please see the creator's web site.

Editors
If you are going to be a real programmer, you'll need to become familiar with real programming tools. First and foremost you will need a good text editor, wordpad just won't do. Acquire and learn to use either VI or Emacs. I personally use VI in the form of gvim (http://www.vim.org/download.php), hopefully some Emacs user will chime in with a good installation of that editor.

Assemblers
We really only have one choice for assemblers with this chip, the P&E (http://www.pemicro.com/) freeware version of their assembler, which includes an IDE (Integrated Development Environment). I have played with their IDE, but it forces use of their useless editor, which breaks it severely. Lance has a copy of the installer here: dload.php?action=file&file_id=84

Downloaders
Once you have run the assembler and produced an s19 file, you need to get that code into the 908's flash memory in order to run it. You have several options here, HyperTerm (a terminal emulator program supplied with windows), EasyTherm (Roger Enns's program intended to modify thermistor tables in existing s19 files, but which can be used to just download them) and download.exe (a command-line utility whose sole purpose in life is to send s19 files to MegaSquirt).

HyperTerm:
Pros: It's already on your machine, it's usually quite reliable if you use the correct commands.
Cons: Clunky, difficult and slow to use, the user interface is error prone.

EasyTherm: dload.php?action=category&cat_id=27
Pros: Easiest to learn to use, just open and send. Fair reliability. Source available.
Cons: Gui-based, requires manual operation.

Download: http://not2fast.com/megasquirt/tools/wi ... wnload.exe
Pros: Fastest, can be scripted so no manual intervention and hence no usage errors. Source available.
Cons: Uses winapi comm calls, so not as robust on some machines.

Instructions for downloading code are here

Tutorials
The following are tutorials and technical references written for the 68HC908 processor used in MegaSquirt. They are arranged in order from the simplest to follow, to the most complete and technically demanding:

Megasquirt Code: For those looking for an introduction to assembly language programming for MegaSquirt, there's some MegaSquirt specific advice here: http://www.megasquirt.info/Tutorial.htm

Motorola Reference Manual: The general guide to the 08 series of processors, which includes the MegaSquirt-I processor, is here: http://www.megasquirt.info/CPU08RM.pdf. This is the bible of the 908 processor, once you have some familiarity with assembly language programming read section 4 (Addressing Modes) and then pick through section 5 (Instruction Set) as needed. If you can only have one manual, this is the one to have.

MC68HC908 Microcontroller Technical data: The 'official' manual - it tells you everything you want to know about the 68HC908 processor used in MegaSquirt (but not always in easy to understand terms). If you are going to make serious changes to the MS code that will require using the timers, or programming IO ports or interrupts, or anything fancy like that, then you'll need to read this. Get it here: http://www.megasquirt.info/MC68HC908GP32.pdf

(more later...)
Last edited by efahl on Sat Nov 13, 2004 6:52 am, edited 1 time in total.
efahl
Site Admin
Posts: 102
Joined: Mon Feb 16, 2004 3:15 pm
Location: San Clemente, California, USA
Contact:

MS-I (908 MCU) Code Development How-To

Post by efahl »

This is sort of secondary information that my brother, Keith, dug up.

General DIY Resources
This site has a scattergun collection of programming resources, for all types of programming and application areas.

http://www.techbooksforfree.com/

Here's some good stuff on hardware design.

http://www.andamooka.org/reader.pl?section=liec

And some more on programming:

http://savannah.nongnu.org/download/pgubook/
renns
Helpful Squirter
Posts: 53
Joined: Fri Apr 02, 2004 5:12 pm
Location: Ontario, Canada

MS-I (908 MCU) Code Development How-To

Post by renns »

Here's an excellent on-line text that uses HC908GP32 throughout. Lots of sample code, and more detailed explanations and examples for those new to assembly programming.

http://www.hc08.cz/attachments/gp32.pdf

Lots of downloadable examples here as well:

http://www.hc08.cz/

Roger.
boost junkie
MegaSquirt Newbie
Posts: 3
Joined: Tue May 11, 2004 7:58 am
Location: dallas texas usa

Post by boost junkie »

Stupid question for the assembly coders. I code in C on embedded linux systems here at work. Debugging is pretty easy with a BDM tool or just using "printk()'s" but I don't understand how you guys debug the MS code. You can't really output any debug messages and there's no BDM tool or anything like that. I'm sure I could write some assembler code if I just just slap in a bunch of debug messages and figure out the program flows. Just staring at a page of assembly is just too hard for me to understand.
-shawn
msns-e controled turbo neon
sample msq's!
jsmcortina
MegaSquirt Newbie
Posts: 11
Joined: Mon May 03, 2004 12:34 am
Location: Birmingham, UK
Contact:

Post by jsmcortina »

boost junkie wrote:Stupid question for the assembly coders. I code in C on embedded linux systems here at work. Debugging is pretty easy with a BDM tool or just using "printk()'s" but I don't understand how you guys debug the MS code. You can't really output any debug messages and there's no BDM tool or anything like that. I'm sure I could write some assembler code if I just just slap in a bunch of debug messages and figure out the program flows. Just staring at a page of assembly is just too hard for me to understand.
There can be a bit of trial and error. On occaisions when something isn't working out I set/clear a spare output pin and monitor it on the scope.
Yes printf would be great...
If you can write embedded code then take your time and you'll be able to do assembler. No harder really, just lower level.

James
boost junkie
MegaSquirt Newbie
Posts: 3
Joined: Tue May 11, 2004 7:58 am
Location: dallas texas usa

Post by boost junkie »

Take the wheel decoder stuff for example. I'm having a REAL hard timing following the logic. I need a flow chart!!!! :lol:
-shawn
msns-e controled turbo neon
sample msq's!
efahl
Site Admin
Posts: 102
Joined: Mon Feb 16, 2004 3:15 pm
Location: San Clemente, California, USA
Contact:

MS-I (908 MCU) Code Development How-To

Post by efahl »

On Fri, February 11, 2005 12:45 pm, boost junkie said:
> systems here at work. Debugging is pretty easy with a BDM tool or just
> using "printk()'s" but I don't understand how you guys debug the MS code.
The 908 embedded code equivalent of printf is to put the data into an output variable and display it on a gauge or datalog...

--
Eric Fahlgren http://www.not2fast.com/



(posted by email)
milosch01
MegaSquirt Newbie
Posts: 2
Joined: Sun Aug 28, 2005 12:20 pm
Contact:

Post by milosch01 »

I have successfully used wine on linux to compile the default asm:
wine CASM08Z.EXE msns-extra.asm S L I M
muythaibxr
MegaSquirt Newbie
Posts: 11
Joined: Thu Oct 14, 2004 11:48 am
Location: Columbia, Maryland

Post by muythaibxr »

boost junkie wrote:Stupid question for the assembly coders. I code in C on embedded linux systems here at work. Debugging is pretty easy with a BDM tool or just using "printk()'s" but I don't understand how you guys debug the MS code. You can't really output any debug messages and there's no BDM tool or anything like that. I'm sure I could write some assembler code if I just just slap in a bunch of debug messages and figure out the program flows. Just staring at a page of assembly is just too hard for me to understand.
I typically debug the hard way... code inspection and watching bad behavior on the scope. I look at the bad behavior, then look at the places in the code that I think could cause the behavior. That's how I ended up getting the rotary stuff working. I just kept reading and re-reading the code until I knew how it worked, then it was obvious what was broken.

Took a long time though, and I got very frustrated at one point, but when I was done, it gave me a very good understanding of how the wheel decoder and spark code work. (Not to mention, taught me a lot about asm programming).

I originally came from a linux/freebsd sockets programming and kernel programming background... I think the hardest thing for me to get used to was not having a debugger. I never realized what a crutch it was until I didn't have it.

Ken
efahl
Site Admin
Posts: 102
Joined: Mon Feb 16, 2004 3:15 pm
Location: San Clemente, California, USA
Contact:

Post by efahl »

I'll create a bunch of extra output variables, then put them in gauges in MT; these are real-time printfs, you can see the intermediate values of computations as you twiddle knobs, which works very well. Of course if you have stuff like timing problems and lockups due to interrupt problems and the like, the you absolutely must get a scope like Ken says, and watch the traces.

Eric
EricR287
MegaSquirt Newbie
Posts: 1
Joined: Sun Sep 12, 2004 4:38 pm
Location: Wonder Lake, IL
Contact:

Post by EricR287 »

This link was broke, I got it off www.archive.org and have it stored on my website: http://b18c5.org/gp32.pdf
Here's an excellent on-line text that uses HC908GP32 throughout. Lots of sample code, and more detailed explanations and examples for those new to assembly programming.

http://www.hc08.cz/attachments/gp32.pdf
newtyres1
Helpful Squirter
Posts: 48
Joined: Mon Feb 06, 2006 7:32 pm
Location: Brisbane, Australia

Post by newtyres1 »

Lance,

I think your links above need updating, well it's been a couple of years...some good info there for sure.

Ian.
woh
MegaSquirt Newbie
Posts: 4
Joined: Sat Aug 27, 2005 1:19 am
Location: Colorado, USA
Contact:

Post by woh »

Lance wrote:Assemblers
We really only have one choice for assemblers with this chip, the P&E (http://www.pemicro.com/) freeware version of their assembler, which includes an IDE (Integrated Development Environment). I have played with their IDE, but it forces use of their useless editor, which breaks it severely. Lance has a copy of the installer here: dload.php?action=file&file_id=84
That page does not exist anymore. Is it still available? I could not find it for free on the P&E page.
woh
MegaSquirt Newbie
Posts: 4
Joined: Sat Aug 27, 2005 1:19 am
Location: Colorado, USA
Contact:

Post by woh »

Thanks Lance, Roger,

The files are now located here:
http://www.megamanual.com/files/code/
Post Reply