Setting port pin high

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

Setting port pin high

995 Views
bengtandersson
Contributor III

I wish to set PB[2] to high using assembly code only. Can anyone provide me with a code snippet for this?

My MCU is MPC5602B.

Labels (1)
8 Replies

752 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

the best way, how to get assembly code is to write the functionality using C language and then disassembly C file. Right click to the window with C code and select disassembly.

Regards,

Martin

752 Views
bengtandersson
Contributor III

Thanks for the help!

I have another question. When disassembling the code I get assembler code like this:

00000034: E2EF      se_bne   *-34                    ; 0x00000012

The ";0x00000012 at the end of the line confuses me. If reading the document "MCU_Power-Architecture_compiler.pdf" it says

"

Anything following a ; character is considered to be a comment, except in GNU

compatibility mode, where ; is a statement separator.

"

Becauase this line gives the compilation error  ">end of line expected" it's is probably another statement. If this "statement" is removed there are no problems when compiling but it would probably not work since some code has been removed.

Is the disassembler doing something wrong? How should the statement look like instead of " ; 0x00000012"

0 Kudos

752 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

I wrote simple example for you. Use the following function:

asm void function()

{

    /*SIU.MCR[18] = 0x0200

   * load value to r0, load register address to r5, store value to register

   **/

      e_li       r0,0x0200       

      e_lis    r5,0xc3f9

      e_or2i   r5,0x0064   

      e_sth    r0,0(r5)

   

/*SIU.GPDO[18] = 0x1*/

      se_li    r0,1

      e_lis    r5,0xc3f9

      e_or2i   r5,0x0612   

      e_stb    r0,0(r5)

}

Call this function in your main function. You can check correct register settings using debugger.

Btw, semicolon means comment in assembly language.

Regards,

Martin

0 Kudos

752 Views
bengtandersson
Contributor III

Hi again!

Thanks!!  This works fine in the debugger when singel-stepping the line:

     e_sth    r0,0(r5)

but if a break-Point is set at the next line:

      se_li    r0,1

and then singel-stepping from this line the output is not set. It seems like the OBE bit is not set in the last case.

Is there a smart way to make sure that the OBE bit is set?

I better mention that if this should work at all for me I have to start with setting ME_RUN_PC0  DRUN = 1 and ME_PCTL68 RUN_CFG = 0. All this modifications are done in MPC5604B_Startup.c

0 Kudos

752 Views
martin_kovar
NXP Employee
NXP Employee

Hi,

at first, check Peripheral Status Register 2 in mode entry module. SIU module has to be enabled, otherwise it is not possible to write to the module.

Also you can look at the following function.

void InitModesAndClks(void) {                                                                                                             

      ME.MER.R = 0x0000001D;        /* Enable DRUN, RUN0, SAFE, RESET modes */                                          

      CGM.FMPLL_CR.R = 0x02300100;  /* 8MHz xtal: Set PLL0 to 48 MHz */                                                       

      ME.RUNPC[0].R = 0x000000FE;/* enable peripherals run in all modes */                                                    

      ME.RUN[0].R = 0x001F0074;     /* RUN0 cfg: IRCON,OSC0ON,PLL0ON,syclk=PLL */                                

      /*Mode Transition to enter RUN0 mode:*/                                                                                                            

      ME.MCTL.R = 0x40005AF0;       /* Enter RUN0 Mode & Key */                                                         

      ME.MCTL.R = 0x4000A50F;       /* Enter RUN0 Mode & Inverted Key */                                                       

      while (ME.GS.B.S_MTRANS) {} ;  /* Wait for mode transition to complete */                                                          

while(ME.GS.B.S_CURRENTMODE != 4) {};/* Verify RUN0 is the current mode */                                                                                                                  

  }      

                  

Could you please tell me, which debugger you use? I tested in Lauterbach, but it works correct. Also in this case, breakpoints should not affect code execution. Could you please also provide me some screens of your problem? I am not able to reproduce it.

Regards,

Martin                                                                                                               

0 Kudos

752 Views
bengtandersson
Contributor III

Hi Martin!

Sorry, I should have provided you with this information from the beginning. I'm using Code Warrior for MCU version 10.6.

Some explanation of my problem. I have to set an input to another unit also containing a uC (This unit is from another Company). I have to set it very fast since it must be done before the uC on the other unit is awake. The first try was to set it as early as possible in main after the run-mode settings but this turned out to not be fast enough. Then I tried to do it as soon as possible after boot and this is where I'm struggling now. I made the assumption that Everything written between boot and main() has to be written in assembler since this is how it looks like in the platform code. Is this assumption right??

Here some screens from the debugger:

First I'm singel-stepping the line where OBE is set and there you can see in Registers that this bit has been set.

OBE_set.png

second try I set the break-Point at the next line and now OBE is not set.

OBE_not_set.png

The entire code in MPC5604B_Startup.c now looks like this:

asm void __startup(register int argc, register char **argv, register char **envp)
{
    nofralloc  /* explicitly no stack */
    /* frame allocation */
   
  
// Enable SIUL in DRUN mode
//ME.RUNPC[0].B.DRUN = setBit;
se_li    r0,1
e_lis    r9,0xc3fe
e_lwz    r8,-16256(r9)
e_insrwi r8,r0,1,28              ; e_rlwimi   r8,r0,3,28,28
e_stw    r8,-16256(r9)

//ME.PCTL[68].B.RUN_CFG = 0;
se_li    r0,0
e_lis    r9,0xc3fe
e_lbz    r8,-16124(r9)
e_insrwi r8,r0,3,29              ; e_rlwimi   r8,r0,0,29,31
e_stb    r8,-16124(r9)



   /*SIU.MCR[18] = 0x0200

    * load value to r0, load register address to r5, store value to register

    **/

       e_li       r0,0x0200       

       e_lis    r5,0xc3f9

       e_or2i   r5,0x0064   

       e_sth    r0,0(r5)

    

/*SIU.GPDO[18] = 0x1*/

       se_li    r0,1

       e_lis    r5,0xc3f9

       e_or2i   r5,0x0612   

       e_stb    r0,0(r5)

   
    // call standard application initialization
    bl __start
}

Regards Bengt

0 Kudos

752 Views
martin_kovar
NXP Employee
NXP Employee

Hi Bengt,

I tested your code and you are correct about the behavior. It seems, there is some synchronization problem. So the only idea which I have is to do mode transition after you set RUNPC and PCTL. So add the following code under the RUNPC and PCTL settings:

            e_lis         r9,0x3000

       e_add16i r9,r9,0x5AF0

       e_lis         r8,0xC3FE

       e_stw         r9,-0x3FFC(r8)

      

       e_lis         r9,0x3001

       e_add16i      r9,r9,-0x5AF1

       e_lis         r8,0xC3FE

       e_stw         r9,-0x3FFC(r8)

This code is equivalent to:

     ME.MCTL.R = 0x30005AF0;       /* Enter DRUN Mode & Key */

     ME.MCTL.R = 0x3000A50F;       /* Enter DRUN Mode & Inverted Key */

Try this solution and eventually write me back if it is usable for you.

Regards,

Martin

0 Kudos

752 Views
bengtandersson
Contributor III

Hi!

Now it finally works! Thanks for all help!

Regards

Bengt

0 Kudos