MS-I (908 MCU) Code Development How-To
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.
-
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
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...)
-
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
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
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
-
jsmcortina
- MegaSquirt Newbie
- Posts: 11
- Joined: Mon May 03, 2004 12:34 am
- Location: Birmingham, UK
- Contact:
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.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.
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
-
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
The 908 embedded code equivalent of printf is to put the data into an output variable and display it on a gauge or datalog...> 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.
--
Eric Fahlgren http://www.not2fast.com/
(posted by email)
-
muythaibxr
- MegaSquirt Newbie
- Posts: 11
- Joined: Thu Oct 14, 2004 11:48 am
- Location: Columbia, Maryland
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.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.
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:
Eric
-
EricR287
- MegaSquirt Newbie
- Posts: 1
- Joined: Sun Sep 12, 2004 4:38 pm
- Location: Wonder Lake, IL
- Contact:
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
That page does not exist anymore. Is it still available? I could not find it for free on the P&E page.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