Could not go to debug mode

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

Could not go to debug mode

3,304 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jerry.nguyen on Wed Mar 16 22:02:23 MST 2011
Hi all,

I write a simple code as below...after i download this code to LPCXpresso (LPC1769) board ...the next time i could not go to debug mode any more (have to switch to ISP mode to go to debug)...Does any one have any ideas? is it a problem of the LPC1769 or LPC-Link problem?

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#define UART_DEV LPC_UART3

void init_uart(void)
{
    LPC_SC->PCONP |= (1 << 25);

    LPC_PINCON->PINSEL0    &= (~(0x03 << 0));
    LPC_PINCON->PINSEL0    |= (0x02 << 0);
    LPC_PINCON->PINSEL0    &= (~(0x03 << 2));
    LPC_PINCON->PINSEL0    |= (0x02 << 2);

    LPC_PINCON->PINMODE0 &= (~(3 << 0));
    LPC_PINCON->PINMODE0 &= (~(3 << 2));

    LPC_SC->PCLKSEL1 &= (~(3 << 18)) ;
    //LPC_SC->PCLKSEL1 |= (3 << 18) ;

    LPC_UART3->LCR |= (3 << 0);
    LPC_UART3->LCR &= (~(1 << 2));
    LPC_UART3->LCR |= (1 << 7);
    LPC_UART3->DLM = 0;
    LPC_UART3->DLL = 0x05;
    LPC_UART3->FDR = 0x7c;
    LPC_UART3->FCR |= (1 << 0);
    LPC_UART3->LCR &= (~(1 << 7));
    LPC_UART3->IER |= (3 << 0);
}



int main (void)
{
      init_uart();
    while(1)
    {
        LPC_UART3->THR = 'A';
      }
    return 0;

    while(1);
}

If i change the code as below then it is ok

int main (void)
{
    int i = 0;
    init_uart();
    while(1)
    {
        LPC_UART3->THR = 'A';
        i++;

    }
    return 0;

    while(1);
}
0 Kudos
Reply
13 Replies

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Mon Mar 21 10:48:21 MST 2011

Quote: jerry.nguyen

After this step...i could not connect to debug the board ( have to switch to ISP mode, to be able to get access again)



OK. We can replicate the problem, but as you have found it only seems to occur in a specific situation (ie spinning in a [U][B][I]very tight[/I][/B][/U] loop writing to THR). We will add it to the list of things to investigate for fixing in a future release.

Regards,
CodeRedSupport
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sun Mar 20 17:48:45 MST 2011

Quote: jerry.nguyen
I know the code is wrong...it is from my customer, I can easily to make it work...

But this code show that either debug core or LPC-Link have problem...and my simple code is a easiest way to see that problem. It is good if CodeRed or NXP engineer looks into it



I understood that you think there is a problem with the debugger or LPC-LINK and that is something CodeRed or NXP can determine.

Zero and I were just pointing out issues with the code that could be corrected to avoid the problem.

I know you could make it work, that is easy.

This will send the character 'A' forever at 115200 baud.

#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif
#include <cr_section_macros.h>
#include <NXP/crp.h>
__CRP const unsigned int CRP_WORD = CRP_NO_CRP;
#define UART_DEV LPC_UART3
#define LSR_THRE 0x20
void init_uart(void) {
 LPC_SC->PCONP |= 1<<4 | 1 << 25;
 LPC_PINCON->PINSEL0 &= (~(0x03 << 0));
 LPC_PINCON->PINSEL0 |= (0x02 << 0);
 LPC_PINCON->PINSEL0 &= (~(0x03 << 2));
 LPC_PINCON->PINSEL0 |= (0x02 << 2);
 LPC_PINCON->PINMODE0 &= (~(3 << 0));
 LPC_PINCON->PINMODE0 &= (~(3 << 2));
 LPC_SC->PCLKSEL1 &= (~(3 << 18));
 LPC_UART3->LCR = 0x83;
 LPC_UART3->DLM = 0;
 LPC_UART3->DLL = 0x10;
 LPC_UART3->LCR = 0x03;
 LPC_UART3->FCR = 07;
 LPC_UART3->IER |= (3 << 0);
}
int main(void) {
 int i;
 init_uart();
 while (1) {
  while ((LPC_UART3->LSR & LSR_THRE) == 0)
   ; // Block until tx empty
  LPC_UART3->THR = 'A';
  i++;
 }
 return 0;
}


This is very difficult to debug and maintain as it is without documentation and you have to calculate the parameters for the UART by hand.

There are much easier ways to to set up the UART.  See the UART example for the LPC17xx that is included with LPCXpresso.

Good Luck,
Larry
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jerry.nguyen on Sun Mar 20 06:24:25 MST 2011
I know the code is wrong...it is from my customer, I can easily to make it work...

But this code show that either debug core or LPC-Link have problem...and my simple code is a easiest way to see that problem. It is good if CodeRed or NXP engineer looks into it
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Mar 19 11:53:30 MST 2011
Now I know where to look for those error messages.


Quote:
However, it's not my job to search for problems of wrong code after it's clear why this code is wrong :)



Agreed and noted.  I was just curios to know if you had some insight on this.:)
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Mar 19 11:35:14 MST 2011
Error messages like:

Quote:

02: Failed on connect: Em(12). System rejected access at location 0xE000EDF0 - verify Population of memory and peripherals


shows the problem. CMSIS core_cm3.h defines:

#define CoreDebug_BASE (0xE000EDF0) /*!< Core Debug Base Address */

So I would guess that pumping data to UART without waiting for empty transmit buffer is disturbing either debug connection or something else vital.

However, it's not my job to search for problems of wrong code after it's clear why this code is wrong :)
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Sat Mar 19 01:03:30 MST 2011
I also tested the code in the previous post in a non-semihosting project just to confirm the results and they were the same.

Zero what do you think was getting corrupted?:confused:

By the way this is my 100th post.  Happy Anniversary!:D
0 Kudos
Reply

3,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Fri Mar 18 23:57:19 MST 2011
I was able to duplicate and confirm this behavior.

I created a new semihosting project and dropped Jerry's code into main.c.  Built and debugged several times then closed the debugger and exited LPCXpresso.

Cycled power on the board and restarted LPCXpresso and tried to run the debugger. It failed with the message below.

I had to use FlashMagic to erase memory before I could debug again.

After applying Zero's patch  I was able to debug after cycling power on the board without using FlashMagic.

I don't know if there are any other issues as I have not tested the rest of the code.

The code below is what I used to test with.  Jerry try this:

/*****************************************************************************
 
 
 *   Reading data from UART1 and writing to UART2 (and vice versa)
 
 
 *
 
 
 *   Copyright(C) 2010, Embedded Artists AB
 
 
 *   All rights reserved.
 
 
 *
 
 
 ******************************************************************************/
 
 
 
#ifdef  __USE_CMSIS
 
 
 
#include "LPC17xx.h"
 
 
#endif
 
 
 
 
 
 
#include  <cr_section_macros.h>
 
 
 
#include  <NXP/crp.h>
 
 
 
 
 
// Variable to store CRP value in. Will be placed automatically
 
 
// by the linker when "Enable Code Read Protect" selected.
 
 
// See crp.h header for more information
 
 
 
__CRP const unsigned int CRP_WORD = CRP_NO_CRP;
 
 
 
 
 
 
#include  <stdio.h>
 
 
 
 
 
 
#define UART_DEV LPC_UART3
 
 
 
#define LSR_THRE 0x20
 
 
 
 
 
 
void init_uart(void) {
 
 
 
    LPC_SC->PCONP |= (1 << 25);
 
 
 
 
 
 
    LPC_PINCON->PINSEL0 &= (~(0x03 << 0));
 
 
 
    LPC_PINCON->PINSEL0 |= (0x02 << 0);
 
 
 
    LPC_PINCON->PINSEL0 &= (~(0x03 << 2));
 
 
 
    LPC_PINCON->PINSEL0 |= (0x02 << 2);
 
 
 
 
 
 
    LPC_PINCON->PINMODE0 &= (~(3 << 0));
 
 
 
    LPC_PINCON->PINMODE0 &= (~(3 << 2));
 
 
 
 
 
 
    LPC_SC->PCLKSEL1 &= (~(3 << 18));
 
 
 
    //LPC_SC->PCLKSEL1 |= (3 << 18) ;
 
 
 
 
 
 
    LPC_UART3->LCR |= (3 << 0);
 
 
 
    LPC_UART3->LCR &= (~(1 << 2));
 
 
 
    LPC_UART3->LCR |= (1 << 7);
 
 
 
    LPC_UART3->DLM = 0;
 
 
 
    LPC_UART3->DLL = 0x05;
 
 
 
    LPC_UART3->FDR = 0x7c;
 
 
 
    LPC_UART3->FCR |= (1 << 0);
 
 
 
    LPC_UART3->LCR &= (~(1 << 7));
 
 
 
    LPC_UART3->IER |= (3 << 0);
 
 
}
 
 
 
 
 
 
int main(void) {
 
//   int i = 0;
 
 
    init_uart();
 
 
 
 
 
 
    while (1) {
 
 
 
        while ((LPC_UART3->LSR & LSR_THRE) == 0)
 
 
 
            ; // Block until tx empty
 
 
//        i++;
 
 
 
        LPC_UART3->THR = 'A';
 
 
    }
 
 
 
 
 
 
    return 0;
 
 
 
 
 
}
0 Kudos
Reply

3,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jerry.nguyen on Fri Mar 18 19:21:51 MST 2011
Hi Zero,

I know what you mean...we already done that to be able to send UART correctly...just my curiously is that why this can cause the board could not go to debug mode? it seems there is a bug either from LPC1769 or from the LPCXpresso.

Hi Larryvc,

when I power off and on again...i restart another debug session...for other example is ok but just for this special project...the board just can not enter the debug mode again.

Thanks in advance
Jerry
0 Kudos
Reply

3,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Mar 18 13:43:27 MST 2011
Before transmitting, check 'Transmitter Holding Register Empty' (THRE):

THRE is set immediately upon detection of an empty UARTn THR and is cleared on a UnTHR write. (See: UM10360)

Try:
#define LSR_THRE 0x20
...
 
  while( (LPC_UART3->LSR & LSR_THRE) == 0 ); // Block until tx empty
  LPC_UART3->THR = 'A';


With i++ you generate a little delay, so your wrong code causes less problems with debugger
0 Kudos
Reply

3,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by larryvc on Fri Mar 18 09:17:24 MST 2011
Are you getting any popups or error messages when you try to debug again?

If you power down the board while in a debug session and then power up and try to continue using the current debug session it will not work.
0 Kudos
Reply

3,258 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jerry.nguyen on Fri Mar 18 03:43:43 MST 2011
Just to add on

To reproduce problem...

1. Run debug to download the code in
2. Power off and on the board

After this step...i could not connect to debug the board ( have to switch to ISP mode, to be able to get access again)
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jerry.nguyen on Fri Mar 18 03:40:19 MST 2011
Hi,

I attached the project file...it is quite strange for me...since in theory there only 2 reasons which can cause this problem:

1. The application disable some debug pin
2. Setting wrong PLL

But in my project, just changing in the while loop can cause the problem (my board is LPCXpresso LPC1769)

Thanks in advance
Jerry
0 Kudos
Reply

3,259 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Mar 17 02:34:12 MST 2011
Sorry, can't reproduce that.

I've tried:
int main (void)
{
 init_uart();
 while(1)
 {
 LPC_UART3->THR = 'A';
 }
 return 0;
}

in Debug configuration with optimization none and most. Both versions are working and I can see valid code in Disassembly view:

OPT: NONE
 LPC_UART3->THR = 'A';
0x00000370 <main+72>: movw  r3, #49152 ; 0xc000
0x00000374 <main+76>: movt  r3, #16393 ; 0x4009
0x00000378 <main+80>: mov.w r2, #65 ; 0x41
0x0000037c <main+84>: strb  r2, [r3, #0]
0x0000037e <main+86>: b.n   0x370 <main+72>

OPT: MOST
 LPC_UART3->THR = 'A';
0x00000242 <main+190>: mov.w  r3, #65 ; 0x41
0x00000246 <main+194>: strb   r3, [r1, #0]
0x00000248 <main+196>: strb   r3, [r1, #0]
0x0000024a <main+198>: b.n    0x246 <main+194>

So I assume there's another problem somewhere (SystemInit ?).

Perhaps you want to post your zipped project
0 Kudos
Reply