when I used PIT0 and SWI interrupts the program can't run,【ILLEGAL_BP】

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

when I used PIT0 and SWI interrupts the program can't run,【ILLEGAL_BP】

1,850 Views
xianyu
Contributor II

Recently I am transplanting ucosii on xs128.When I use PIT0 or SWI respectively, each of them could enter thier blackette,but use them at the same time the program running out of truck. By the way, there is no question if I used TIM7 and swi at the same time. How can I use PIT and swi at the same time ?

Labels (1)
0 Kudos
7 Replies

1,567 Views
RadekS
NXP Employee
NXP Employee

Hi 崇锐 卢,

That is strange. Please share here your code for PIT0 initialization, PIT0 and SWI interrupt routines.

Did you enable COP watchdog? – is it possible that execution of PIT0 and SWI ISRs increased interval between watchdog triggering?

Illegal_BP means that debugger got lost.

Typical issues are:

  1. Unexpected interrupt. Attached is interrupt catcher (catch unexpected interrupts) example code.
  2. Watchdog reset. Please check RESET signal on oscilloscope during debugging.
  3. Illegal address reset
  4. Any other reset like Low Voltage reset,…
  5. Inconsistency between debugger data and code in flash (for example when code rewrites himself).
  6. The lost of BDM connection could be sometimes caused also by any extreme change of PLL clock (typically when we stepping over PLL init code)


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,567 Views
xianyu
Contributor II

Last night I download a uCOSii source for XS128,

I replaced the TIMer Interrupt and enable PIT Interrupt this program run regular.

Can I get a answer that My code of PIT0 initialization, PIT0 and SWI interrupt routines don't have bug.

Something wrong in another plance?

by the way , there doesn't apply to uploading my program?

0 Kudos

1,567 Views
RadekS
NXP Employee
NXP Employee

Hi 崇锐 卢,

I could not see anything wrong in your INIT_PIT() function.

But your code in PIT_ISR is strange.

You used “asm cli” command for enable other interrupts prior you cleared PITTF_PTF0 flag. Since there is 1-cycle (bus clock) delay in the clearing mechanism for the I bit, PITTF_PTF0 flag will be cleared anyway. However exact time of OSTimeTick() function execution depends on number of pending interrupts… This does not make sense for me. OS tick time based on Periodic interrupt should be accurate and without any necessary jitter. Why did you clear I bit in middle of PIT ISR?

The strange is also your code in OSCtxSw.

I suppose that you used SWI for some “context switching”, but your implementation is quite insufficient.

If I understood correctly - You saved PPAGE, modify stack pointer and restore back PPAGE. This could “work” only when all functions will be in non-paged flash. When you want execute some code from banked flash, you have to change stack pointer and PPAGE. Additionally, context switch should modify also basic CPU registers…

I would like to apologize, but I don’t have experiences with uCOSii OS.

For now I suppose that there will be probably some issue with inconsistency between modified stack pointer and PPAGE.

There should not be any connection between SWI and PIT0 on hardware side.

Just for sure: SWI interrupt vector number is 4, PIT0 interrupt vector number is 66. Please check your prm file whether you defined it correctly.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,567 Views
xianyu
Contributor II

with my best grateful.

       yes,when I debug my code, It went wrong.

       After watching your receive, I try to chek my XS128 register.

       some code is doing when pending interrupts is come to “context switching” ,code is follow,

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

#pragma TRAP_PROC

void OSIntCtxSw(void)    //中断级任务切换子程序

{

    #if OS_CPU_HOOKS_EN > 0

    OSTaskSwHook(); /* 4~, Invoke user defined context switch hook */                                        

  #endif                    

__asm{   

    ldx    OSTCBHighRdy               ;  3~, OSTCBCur  = OSTCBHighRdy

    stx    OSTCBCur                   ;  3~                       

    ldab   OSPrioHighRdy              ;  3~, OSPrioCur = OSPrioHighRdy                       

    stab   OSPrioCur                  ;  3~

    ldx     OSTCBCur

    lds    0,x                        ;3~, Load SP into 68HC12

    pula

    staa  $15                          

    nop                   

  }

}

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

        I  try to replace it to  OSCtxSw(), let PPAGE and stack pointer  be saved before switch context,the program run correctly.

   So I think there is some wrong when PIT interrupt  come,perhaps some registers couldn't be saved correct,When this code

   delay is over, program want to execute this part of code from break point, because of the registers' mistaken saved or someting wrong

   else when PIT interrupt's coming.

       However,I modify my code,let PPAGE and stack point be saved again before switch context , problems seems go away,although I still

   do not know why and how it happend.

      if its posible could u give me you massage box I send my project to you,

     my English is improving, thanks for your help.

0 Kudos

1,567 Views
RadekS
NXP Employee
NXP Employee

Hi 崇锐 卢,

The problem is probably that when you clear I bit (asm cli;), your PIT interrupt routine may be interrupted by any other interrupt. Since your OS implementation is full of assembler code (not handled by compiler), it is possible that OS function simply do not suppose such case (nested interrupts – ISR interrupted by ISR).

In general - some critical system functions needs to be executed in once, interruption in middle of these functions may cause dangerous situations. For these parts of code, interrupts must be disabled.

Please check whether functions like OSTimeTick(); or OSIntExit(); may be interrupted.


I hope it helps you.

Have a great day,
RadekS

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,567 Views
xianyu
Contributor II

pastedImage_0.pngpastedImage_1.png

pastedImage_2.png

but I am afraid it isn't the reason, after I do this, still Illegal_bp

anyway,I think there is something wrong with PPAGE and stack point , beacause if code like follow

this program run correctly

pastedImage_3.pngpastedImage_4.png

pastedImage_5.pngand the difference between OSIntCtxSw and OSCtxSw is that OSCtxSw saves regesiters and OSCtxSw not,although I still didnt not which register is wrong.

At last , [asm cli]  which is used in that place is truely inappropriate,ISR interrupt truely could be interrupted by another interrupt,thanks for your prompt.

I didnt know how many time zones we have , but I guess that now your time zone is at night.

have a great night.

谢谢, 晚安。

0 Kudos

1,567 Views
xianyu
Contributor II

thanks for your reply.

But the question is still here. I have not enable watchdog.

This is a part of my code.

void INIT_PIT(void)    /* enable a 100hz timer interrupt*/

{

  PITCFLMT=0X00;   //禁用PIT模块

  PITCE_PCE0=1;    //使能PIT定时器0通道

  PITMUX=0X00;     //使用基准1计数

  PITMTLD0=199;   //八位微定时器的模数递减计数器的装载初值 1

  PITLD0=1999;   // 2 4dd  (4DD+1)(FF+1)/64M=1ms

  PITINTE=0X01;    //允许PIT通道0中断请求。

  PITCFLMT=0X80;   //使能PIT模块 

}

#pragma CODE_SEG NON_BANKED

/*

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

*                    PIT定时中断

*                    PIT初始化函数被屏蔽,不调用

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

*/

#pragma TRAP_PROC

void PIT_ISR(void){   

   

    OSIntEnter();

    asm cli;

     

    PITTF_PTF0=1;

    OSTimeTick();      /*  Call uC/OS-II's OSTimeTick()*/

    //g_SysTick++;

    OSIntExit();  

}

/*

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

*                    swi软中断处理函数

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

*/

#pragma TRAP_PROC

void OSCtxSw(void)    //软中断服务子程序 实现用户级上下文切换,用汇编语言实现

{

__asm{

    ldaa  $15                         ;restored ppage;

    psha

    ldx    OSTCBCur                   ;  3~, OSTCBCur->OSTCBStkPtr = Stack Pointer                     

    sts    0,x                        ;  3~      

    }

   

#if OS_CPU_HOOKS_EN > 0

    OSTaskSwHook();/* 4~, Invoke user defined context switch hook */                                        

#endif

                      

__asm{   

    ldx    OSTCBHighRdy               ;  3~, OSTCBCur  = OSTCBHighRdy

    stx    OSTCBCur                   ;  3~                        

    ldab   OSPrioHighRdy              ;  3~, OSPrioCur = OSPrioHighRdy                       

    stab   OSPrioCur                  ;  3~

    ldx    OSTCBCur

    lds    0,x                        ;3~, Load SP into 68HC12

    pula                              ;use ppage

    staa  $15                          

    nop                                 

}

#pragma CODE_SEG DEFAULT

0 Kudos