Advanced instruction trace

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

Advanced instruction trace

1,344 Views
biafra
Senior Contributor I

Hi everyone,

I have a problem using lwip as I described in the post LWIP_ASSERT on pbuf_free function‌.

To catch the problem, I need a little complex breakpoint: I think the correct tool is using instruction trace; I've read the tutorial, but with that configuration I'm not able to trap the issue.

I need to set a trigger that is true when a (global) variable is written with any value, but only when another (global) variable has a specific value (0).

Is it possible to configure such a trigger? If yes, how? If no, how can I trap this condition?

Many thanks

Biafra

6 Replies

942 Views
lpcxpresso_supp
NXP Employee
NXP Employee

One important thing to note is that the use of the DebugMonitor exception is basically not compatible with using a debug probe (as these will enable "Halting debug" mode).  And changing this is generally not possible from user application code.

To  be honest though, I don't recall ever seeing anyone using the DebugMonitor exception before on Cortex-M devices before (although I'm sure someone somewhere does!). Generally when a debug probe is not connected you will see debug events (like a BKPT instruction) triggering a hard fault. There is more information on this in ARM's Cortex-M documentation.

Regards,

MCUXpresso IDE Support

942 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Biafra,

Yes, you can. This function is called watchpoint. Please read MCUXpresso_IDE_User_Guide.pdf section 11.5. You can set it when the IDE in debug mode.

Regards,

Jing

942 Views
biafra
Senior Contributor I

Hi jingpan‌,

Many thanks for your answer.

I know the watchpoint function, but it isn't the right tool for me, because the variable I'm interested in is written continuously and with such function enabled the CPU runs very slowly and can't work.

I've read about instruction trace (MCUXpresso IDE Instruction Trace) and I think it can be the right tool for me, but the example is related to set a trigger that is true when a variable is written with a specific value (not when it is written with any value, but only when another variable has a specific value: this is the situation I'm trying to catch!).

Many thanks

Biafra

942 Views
biafra
Senior Contributor I

Hi,

I've made some tests and I think that the concept to operate according to my needs can be:

  • When the second variable is written with 0, trace starts
  • When the second variable is written with a value other than 0, trace stops
  • When the first variable is written with any value, a trigger event occurs

How must I configure the instruction trace to work such a way?

Many thanks

Biafra

942 Views
jingpan
NXP TechSupport
NXP TechSupport

Hi Biafra,

These three point can't be done at same time. There are only 4 watchpoint comparator. The first point need 2 comparator, the second one need 1 comparator. And a trigger event A also need 2 comparator. Further more, these comparator should combine together to fulfill your requirement. But as we can see, only 2 comparator can link together.

I made a demo to deal with requirement 1 and 2

instruction_trace_config_start_stop.png

Hope this can give you some help.

Regards,

Jing

942 Views
biafra
Senior Contributor I

Hi jingpan‌,

Unfortunately your solution isn't right for me.

Now I'm trying to use DebugMon interrupt to do the job.

I've configured the DWT peripheral to set the debug monitor interrupt, but I have two problems:

  • Every time I write the variable, the program stops if there is the debug probe connected (P&E multilink universal), whether if it's running a debug session or a release session
  • The interrupt is never executed (whether the debug probe is connected or not)

This is the code I use:

unsigned long DebugVar = 0;
unsigned long DebugHandler = 0;

 

void main( void )
{
   unsigned long DebugCnt = 0;

 

   ...

 

   //init debugmon
   CoreDebug->DEMCR = CoreDebug_DEMCR_TRCENA_Msk | CoreDebug_DEMCR_MON_EN_Msk;
   DWT->COMP0 = ( uint32_t )&DebugVar;
   DWT->MASK0 = 0;
   DWT->FUNCTION0 = ( 1 << 11 ) | ( 1 << 2 ) | ( 1 << 0 );

   NVIC_SetPriority( DebugMonitor_IRQn, 7 );
   EnableIRQ( DebugMonitor_IRQn );

 

   while( 1 )
   {
      if( DebugCnt++ >= 100 ) //every 10 s
      {
         DebugCnt = 0;
         DebugVar++; //write var
      }

 

      ...

 

      if( DebugHandler )
      {
         //debug
         PRINTF( "Debug monitor handler executed\n" );
         DebugHandler = 0;
      }

      vTaskDelay( 10 ); //systick = 10 ms: delay 100 ms

   }
}

 

void DebugMon_Handler( void )
{
   if( DWT->FUNCTION0 & DWT_FUNCTION_MATCHED_Msk )
      DebugHandler = 1;
}

Is there any error? Why is the interrupt never executed? Is it possible to avoid stopping the execution during the debug session?

Many thanks

Biafra