How to use the HCS12 T-board stand-alone with the use of functions in main.c file.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to use the HCS12 T-board stand-alone with the use of functions in main.c file.

Jump to solution
3,096 Views
dan23
Contributor III

Hi,

I have a problem using a HCS12 T-board with CodeWarrior for HCS12 V4.7. There is a MC9S12DP512 chip placed on the HCS12 T-board.

I want to use my HCS12 T-board stand-alone and it can be done by placing a jumper on MODA and MODB (connector X6B pin 1 and 2). With this setting the chip will start after reset at address $8000 (0x208000).

I write my code in C and when I put a function above my main the HCS12 T-board won’t start stand-alone (without a PC attached). When I use a function in my main and it is initialized above my main, my main doesn’t start on address 0x208000 but my function (delayms) starts there. This means that my HCS12 T-board won’t start stand-alone because he calls address 0x208000 after reset and this is my function (delayms).

Below is a copy of a little piece of my .map file from codewarrior.   

VECTOR-ALLOCATION SECTION

    Address     InitValue   InitFunction

------------------------------------------------------------------------------------

     0xFFFE        0xC000   _Startup

 

*****************************************************************************************

OBJECT-ALLOCATION SECTION

     Name               Module                 Addr   hSize   dSize     Ref    Section   RLIB

------------------------------------------------------------------------------------

MODULE:                 -- main.c.o --

- PROCEDURES:

     delayms                                 208000      12      18       2   .text      

     main                                    208012      2D      45       2   .text      

- VARIABLES:

MODULE:                 -- Start12.c.o --

- PROCEDURES:

     Init                                    20803F      29      41       2   .text      

     _Startup                                  C000       B      11       0   .init      

- VARIABLES:

     _startupData                              C00B       6       6       3   .startData 

- LABELS:

     __SEG_END_SSTACK                           900       0       0       1              

MODULE:                 -- mc9s12dp512.c.o –

 

 

How could I say to codewarrior that he has to put my main always first on address 0x208000?

Or is there another way to say to codewarrior that he has to start at my main after reset?

 

I use the terminal oc-console and I align the s19 file with SRecCvt.exe to a linear s19 file.

When I use the generated s19 file from codewarrior in SRecCvt.exe and I load the output from it to the chip with oc-console I get the error

 

Loading . . .

**********

Write error at BFF0

20>

 

If I use the .phy file from codewarrior and align it with SRecCvt.exe to a linear s19 file. I get no errors.

 

My .s19 file after I used SRecCvt.exe with the input .s19 file from codewarrior:

 

S2140800003BEE80096E80CE0A630435FDEC8026F14F

S2140800103A0A10EFC6FF5B015B03C6FA873BC601C8

S214080020070E5826FBC640070754C10122F920EEE2

S21408003037515B01EC83C300644A800020333DFEE1

S214080040C00DFDC00B270E35ED31EC316970043458

S214080050FB310326F2FEC00FEC31270BED31180AF0

S21408006030700434F920F10AFFFFFFFFFFFFFFFF9F

S2140FC000CF09004A803F204A8012200000C011C08E

S2140FC01015000000000000FFFFFFFFFFFFFFFFFF00

S2140FFFF0FFFFFFFFFFFFFFFFFFFFFFFFFFFFC0003B

S9030000FC

 

My .s19 file after I used SRecCvt.exe with the input .phy file from codewarrior:

 

S2140800003BEE80096E80CE0A630435FDEC8026F14F

S2140800103A0A10EFC6FF5B015B03C6FA873BC601C8

S214080020070E5826FBC640070754C10122F920EEE2

S21408003037515B01EC83C300644A800020333DFEE1

S214080040C00DFDC00B270E35ED31EC316970043458

S214080050FB310326F2FEC00FEC31270BED31180AF0

S21408006030700434F920F10AFFFFFFFFFFFFFFFF9F

S9030000FC

 

I’ve noticed that the last 3 s2 lines from the first file aren’t in the second file. Further is there no difference between them.

 

Maybe this info will help when it is possible when I want to say to codewarrior that he has to start at my main after reset?

 

I’ll be very pleased if anyone could help me.
Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
980 Views
CrasyCat
Specialist III
Hello
 
OK if the goal is to get function main allocated at address 0x208000, just do the following:
  1- Specify that main should be stored in a user defined code section.
      This is done adding a #pragma CODE_SEG as follows:
       #pragma CODE_SEG MyMainSeg
       void main(void) {
        /* Your code here */
       }
       #pragma CODE_SEG DEFAULT
 
  2- Change the placement block in your application PRM file to get the user defined code section allocated first.
      This is done changing the lines
      DEFAULT_ROM       INTO  PAGE_20, PAGE_21, PAGE_22, PAGE_23, PAGE_24, PAGE_25, PAGE_26, PAGE_27,
                              PAGE_28, PAGE_29, PAGE_2A, PAGE_2B, PAGE_2C, PAGE_2D, PAGE_2E, PAGE_2F,
                              PAGE_30, PAGE_31, PAGE_32, PAGE_33, PAGE_34, PAGE_35, PAGE_36, PAGE_37,
                              PAGE_38, PAGE_39, PAGE_3A, PAGE_3B, PAGE_3C, PAGE_3D                  ;
into
 
      MyMainSeg , DEFAULT_ROM       INTO  PAGE_20, PAGE_21, PAGE_22, PAGE_23, PAGE_24, PAGE_25, PAGE_26, PAGE_27,
                              PAGE_28, PAGE_29, PAGE_2A, PAGE_2B, PAGE_2C, PAGE_2D, PAGE_2E, PAGE_2F,
                              PAGE_30, PAGE_31, PAGE_32, PAGE_33, PAGE_34, PAGE_35, PAGE_36, PAGE_37,
                              PAGE_38, PAGE_39, PAGE_3A, PAGE_3B, PAGE_3C, PAGE_3D                  ;
This should allocate main at 0x208000.
Note
In order for the main function to be started you need to make sure the TwinPEEKs monitor is setting the PPAGE register to 0x20. Not sure whether this is the case.
 
CrasyCat

View solution in original post

0 Kudos
Reply
4 Replies
980 Views
dan23
Contributor III

Hello CrasyCat,

 

Thank you for your answer it is very useful for me.

 

I’ve tried it and my main is placed at address 0x208000 and after reset my program will automatically start when I use the HCS12 T-board jumper selection (MODA connected with MODB).

 

Now I can use the board for its purpose were I want to use it for.

 

thanks a lot.

 

Greetings Danny    

0 Kudos
Reply
980 Views
dan23
Contributor III

hi CrasyCat,

 

thank for your repley,

 

> How are you telling your board to start at address 0x208000?

 

After reset, the TwinPEEKs monitor checks, whether port pins PE5 (MODA) and PE6 (MODB) are connected (use X6B pins 1+2). If this is the case, the monitor immediately jumps to address $8000.

 

> Do you have a bootloader which is then forcing the application to start there?

 

On the MC9S12DP512 chip there is a TwinPEEKs Monitor (in the MCU's Flash Memory).  The reset vector points to the start of this monitor software. As a result, the

monitor will start immediately after reset.

 

>Are you skipping the whole startup code (initialization of stack pointer, initialization of >global variables) on purpose?

 

After reset the stack pointer jumps to the TwinPEEKs monitor program. When I use     oc-console (without jumper, MODA and MODB aren’t connected) to upload my .s19 file I’ve to type g <address void main(void)> to start my program. In my case it is

20> g 8012

 

>Are you initializing all your global variables with assignment in your C source code?

 

Yes, a normal initializing.

Example:  unsigned int a;

 

>Are you initializing the stack pointer in your application?

 

I don't know how to initializing the stack pointer. Is it possible to initializing the stack pointer after reset to my "void main(void)"  were ever the address of this function is located. 

 

 

 

I just want use the HCS12 T-board stand-alone. After the MCU reset it automatically has to begin with my void main(void).   

 

danny

0 Kudos
Reply
981 Views
CrasyCat
Specialist III
Hello
 
OK if the goal is to get function main allocated at address 0x208000, just do the following:
  1- Specify that main should be stored in a user defined code section.
      This is done adding a #pragma CODE_SEG as follows:
       #pragma CODE_SEG MyMainSeg
       void main(void) {
        /* Your code here */
       }
       #pragma CODE_SEG DEFAULT
 
  2- Change the placement block in your application PRM file to get the user defined code section allocated first.
      This is done changing the lines
      DEFAULT_ROM       INTO  PAGE_20, PAGE_21, PAGE_22, PAGE_23, PAGE_24, PAGE_25, PAGE_26, PAGE_27,
                              PAGE_28, PAGE_29, PAGE_2A, PAGE_2B, PAGE_2C, PAGE_2D, PAGE_2E, PAGE_2F,
                              PAGE_30, PAGE_31, PAGE_32, PAGE_33, PAGE_34, PAGE_35, PAGE_36, PAGE_37,
                              PAGE_38, PAGE_39, PAGE_3A, PAGE_3B, PAGE_3C, PAGE_3D                  ;
into
 
      MyMainSeg , DEFAULT_ROM       INTO  PAGE_20, PAGE_21, PAGE_22, PAGE_23, PAGE_24, PAGE_25, PAGE_26, PAGE_27,
                              PAGE_28, PAGE_29, PAGE_2A, PAGE_2B, PAGE_2C, PAGE_2D, PAGE_2E, PAGE_2F,
                              PAGE_30, PAGE_31, PAGE_32, PAGE_33, PAGE_34, PAGE_35, PAGE_36, PAGE_37,
                              PAGE_38, PAGE_39, PAGE_3A, PAGE_3B, PAGE_3C, PAGE_3D                  ;
This should allocate main at 0x208000.
Note
In order for the main function to be started you need to make sure the TwinPEEKs monitor is setting the PPAGE register to 0x20. Not sure whether this is the case.
 
CrasyCat
0 Kudos
Reply
980 Views
CrasyCat
Specialist III
Hello
 
I am a little bit confused here.
In order to start Standalone, the HCS12 CPU is retrieving the start address from the last entry in the vector table (at address 0xFFFE, 0xFFFF).
 
That means the entry point from an application as well as all interrupt function should be allocated in non-banked memory.
How are you telling your board to start at address 0x208000?
Do you have a bootloader which is then forcing the application to start there?
Are you skipping the whole startup code (initialization of stack pointer, initialization of global variables) on purpose?
Are you initializing all your global variables with assignment in your C source code?
Are you initializing the stack pointer in your application?
 
CrasyCat
0 Kudos
Reply