Page 1 of 1

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

Posted: Thu Nov 11, 2004 7:19 am
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...)

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

Posted: Sat Nov 13, 2004 6:37 am
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/

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

Posted: Sat Nov 13, 2004 7:25 am
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.

Posted: Fri Feb 11, 2005 9:45 am
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.

Posted: Fri Feb 11, 2005 11:08 am
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

Posted: Fri Feb 11, 2005 1:17 pm
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:

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

Posted: Fri Feb 11, 2005 1:27 pm
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)

Posted: Sun Mar 26, 2006 5:01 am
by milosch01
I have successfully used wine on linux to compile the default asm:
wine CASM08Z.EXE msns-extra.asm S L I M

Posted: Sun Mar 26, 2006 11:13 am
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

Posted: Sun Mar 26, 2006 1:01 pm
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

Posted: Thu Jun 08, 2006 3:51 pm
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

Posted: Wed Oct 18, 2006 11:54 pm
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.

Posted: Tue May 08, 2007 9:23 am
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.

Posted: Tue May 08, 2007 10:38 am
by woh
Thanks Lance, Roger,

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