LPC1764 Project Randomly Working

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

LPC1764 Project Randomly Working

896 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Sat Jul 13 16:00:13 MST 2013
Hey guys, I'm in a bit of a bind as I cannot figure out a problem I have been having for a while. I have a LPC1764 and I am using LPC Expresso 5.2.6 ( before I used 5.2.4 and had the same issues) with LPC-Link 2.

The problem is that when I program the target microcontroller using the "Program Flash" chip icon it sometimes works and other times it doesn't. The project involves a simple blinking LED based off of the systemtick example. However, if I unplug the target or go to it program again, it appears variable when it will work or not. Here is the code I am using:

Here is the code I am using:

/*
===============================================================================
 Name        : main.c
 Author      : 
 Version     :
 Copyright   : Copyright (C) 
 Description : main definition
===============================================================================
*/

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

#include <cr_section_macros.h>
#include <NXP/crp.h>

// #define PLL0CFG_Val 0x00090063 ensure this is the case in CMISvp00_17xx under system_LPCxx.c
// see user manual section 4.5 for more information

// 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 ;

// TODO: insert other include files here

// TODO: insert other definitions and declarations here
// Function to initialize GPIO to access LED2
void led2_init (void)
{
// Set P0_22 to 00 - GPIO
//LPC_PINCON->PINSEL1= 0x0;//&= (~(3 << 12));
// Set GPIO - P0_22 - to be output
LPC_GPIO0->FIODIR |= (1 << 22);
}


// Function to turn LED2 on
void led2_on (void)
{
LPC_GPIO0->FIOSET = (1 << 22);
}

// Function to turn LED2 off
void led2_off (void)
{
LPC_GPIO0->FIOCLR = (1 << 22);
}

void led2_invert (void)
{
int ledstate;

// Read current state of GPIO P0_0..31, which includes LED2
ledstate = LPC_GPIO0->FIOPIN;
// Turn off LED2 if it is on
// (ANDing to ensure we only affect the LED output)
LPC_GPIO0->FIOCLR = ledstate & (1 << 22);
// Turn on LED2 if it is off
// (ANDing to ensure we only affect the LED output)
LPC_GPIO0->FIOSET = ((~ledstate) & (1 << 22));
}

volatile uint32_t msTicks; // counter for 1ms SysTicks

// ****************
//  SysTick_Handler - just increment SysTick counter
void SysTick_Handler(void) {
  msTicks++;
}

// ****************
// systick_delay - creates a delay of the appropriate number of Systicks (happens every 1 ms)
__INLINE static void systick_delay (uint32_t delayTicks) {
  uint32_t currentTicks;

  currentTicks = msTicks;// read current tick counter
  // Now loop until required number of ticks passes.
  while ((msTicks - currentTicks) < delayTicks);
}

// ****************
int main(void) {

led2_init();// Setup GPIO for LED2
led2_on();// Turn LED2 on

// Setup SysTick Timer to interrupt at 1 msec intervals
if (SysTick_Config(SystemCoreClock / 1000)) {
    while (1);  // Capture error
}


// Enter an infinite loop, just incrementing a counter and toggling leds every second
volatile static int i = 0 ;
while(1) {
i++;
    systick_delay (500); // wait 2 seconds (2000ms)
    led2_invert();// Toggle state of LED2
}
return 0 ;
}


Also, under CMSISv2p00_LPCxx and within system_LPC17xx.c it is still configured for 12MHz crystal.

#define PLL0CFG_Val           0x00050063


I am using the following crystal and capacitors off of digikey:
Crystal selected
Capacitor selected

I looked in the user manual under table 15 of section 4 and I believe it is within spec. I'm not sure if the issue is with the system core clock, hardware, or in fact an issue with the compiler/software drivers.

In sum, the target operates properly only at times. While it is working there is no change and it appears that it can operate indefinitely. However, upon re-programming or disconnecting and reconnecting the USB cable to power the target via the LPC-Link 2, the project stops working (LED does not blink) at times.

I am basing my schematic off of this:
[IMG]http://i188.photobucket.com/albums/z265/fac7orx/LPC1764_c_zpsc4308fe7.gif[/IMG]
(Note: I am using a 12MHz crystal with 39pF capacitors and I am using SWD (SWDIO, SWDCLK, and RESET) for programming and not JTAG)
Labels (1)
0 Kudos
Reply
11 Replies

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Tue Jul 30 07:56:17 MST 2013
I am glad that it works now.
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Mon Jul 29 16:27:13 MST 2013
Here's what I posted earlier:

1. RESETOUT shows ~3.2V and I have an LED connected to the pin that is on.
2. The chip revision is LPC1764FBD100 and underneath it says SW2268.1 and 10 to the right of that.
3. Voltage is ~3.2V

Also, it is interesting to not that every GPIO pin (including p0.22 the pin I am using to blink the LED) reads 2.2V

As for the debug log, I did not see an option that explicitly says "debug log." However from the drop down menu of the console window (the bottom window/console icon to the right) I see "debug messages."



EDIT:
Also, I have ordered a new chip and I am going to test it now, so I'll let you know how it goes.

It works! The previous chip could have a had one pin soldered improperly. Thank you for trying to troubleshooting the issue with me.

If anyone would like to do a custom board you can us my schematic above (however the RESET pin should be coming out of pin 6 not 7, it was correct in my circuit, its just that I placed it incorrectly while making it).
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Mon Jul 29 11:01:07 MST 2013
Yes it does work I made a post a while ago, but it appears to be stuck in moderator approval. I also PMed you further details. Hopefully, you received it OK.
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Mon Jul 29 09:52:33 MST 2013
Hi,
Does your debugger work?
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Fri Jul 26 20:16:21 MST 2013
On VDD and RESETOUT I see ~3.2V. I also have an LED on RESETOUT pin 14 that is on. The chip revision says LPC1764FBD100, underneath that it says SW2268.1 and a number 10 is to the right of it.

Also, I have gotten flash magic using UART0 (RX0 and TX0 pins 99 and 98) to work and the debug issues have stopped. Pin 6 on reset now appears to be working. However, the program still does not run (LED blinking example). I checked each GPIO port and I am getting ~2.2V  out of each pin including the pin 56, p0.22 (which is supposed to be blinking the LED from the example program). Any advice on how to troubleshoot this further? Thanks again.

EDIT:
When I debug, and click on the console icon towards the right in the bottom window, I don't explicitly see "debug log," but I do see "LPCX176x_cmsis2_systick Debug messages." Here is what was outputted under "debug messages" :


Quote:
LPCXpresso Debug Driver v5.2 (Jul  1 2013 14:58:41 - crt_emu_cm_redlink build 34)
Looked for chip XML file in C:/nxp/LPCXpresso_5.2.6_2137/lpcxpresso/bin/LPC1764.xml
Looked for vendor directory XML file in C:/nxp/LPCXpresso_5.2.6_2137/lpcxpresso/bin/NXP_directory.xml
Found generic directory XML file in C:/nxp/LPCXpresso_5.2.6_2137/lpcxpresso/bin/crt_directory.xml
Emu(0): Conn&Reset. DpID: 2BA01477. Info: Redlink: 300567
Debug protocol: SWD. RTCK: Disabled. Vector catch: Disabled.
Loaded LPC175x_6x_128.cfx: LPC175x_6x (128K) Apr 22 2013 12:14:34  On-chip Flash Memory
Connected: was_reset=true. was_stopped=false
v Registered license, download limit of 128K
Writing 1524 bytes to 0000 in Flash (assumed clock: unknown)
Erased/Wrote page  0-0 with 1524 bytes in 407msec
Flash write Done
Stopped (Was Reset)  [Reset from Unknown]

0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mc on Tue Jul 23 11:53:37 MST 2013
Hi micro9000,
Could you please let us know following?
1) Voltage at RESETOUT pin during this problem. It should be high for correct operation
2) Chip revision. You can see marking on the top side of the chip.
3) Voltage should be greater than 3 Volt please check the voltage during this problem. 

-----------
Thanks,
NXP Support
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Tue Jul 23 00:26:04 MST 2013
Info on booting into ISP mode can be found at:

http://support.code-red-tech.com/CodeRedWiki/DebugAccessChip

But in summary, to boot into ISP mode:

1) Pull the ISP pin to ground and hold
2) Pull reset, whilst still pulling ISP
3) Release reset
4) Release ISP

Please confirm that you have actually looked through the FAQ I previously pointed you at:
http://support.code-red-tech.com/CodeRedWiki/HardwareDebugConnections

How are you connecting your LPC-Link2 to your target board? The 10-pin debug header on the board is generally what we would expect you to use.

With regards to vector catch, are you actually clicking on the apply button in the Launch Configuration dialog after changing the value to "true"?

http://support.code-red-tech.com/CodeRedWiki/LaunchConfigMenu


Also, you say that you can now program the flash. How are you doing this? Are you launching a debug session using the Debug button in the Quickstart panel. If so please supply the debug log:

http://support.code-red-tech.com/CodeRedWiki/DebugLog

And if flash programming is succeeding, do you hit the default breakpoint on main()? And if so, can you debug/step through your code?

Regards,
LPCXpresso Support

0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Mon Jul 22 10:10:47 MST 2013
I looked at the schematic for the LPC-LINK:

http://www.nxp-lpc.com/updated_materials/LPC-Link2/LPC-Link-II_schematic_Rev_C.pdf

It shows on page 5 out of 6, J6 is connected to J8. Using this information I was able to make this diagram:

[IMG]http://i51.photobucket.com/albums/f379/XMachine9000/jtagconnections_zps2951f033.jpg[/IMG]

However, just tried moving RESET to pin 5 of the LPC-link 2 and it is now able to program the flash. However, I do not see the LED blinking, so I am not sure what the issue is sine the crystals were working before all of the errors started taking place.
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by lpcxpresso-support on Mon Jul 22 00:49:00 MST 2013
Check your debug/reset circuitry against the details in:

http://support.code-red-tech.com/CodeRedWiki/HardwareDebugConnections

Erratic debug connections often to do with reset/isp pins wired up incorrectly.

Regards,
LPCXpresso Support

0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by micro9000 on Fri Jul 19 17:01:51 MST 2013
I'm not sure if it is the crystal (I have a spare on hand). Either way, I am now getting either one of two errors:


Quote:
05: File load failure: EM(12). System rejected access at location 0x10000000 - verify Population of memory and peripherals



I looked into possible fixes for this and found this:

ISP pin and vector cache fix.

I'm not sure if I did the ISP fix right. I grounded reset and grounded the ISP pin (pin 53) and then held reset high. It didn't work and I'm not sure if I did that right. Also, I tried changing vector cache to true by right clicking on the project going to Launch configurations->Edit current and under "C/C++ (code Red)MCU Application" I selected my project and clicked on the debugger tab and under "Configuration Option" I selected True under vector cache.

However, upon trying to program to flash I get either the previous error before or:


Quote:
02: Failed on connect: Ep:(01). Target marked as not debuggable.



And, the popup window still says vector cache is false when I set it to true using the methods above. So, I may have done it wrong...

EDIT:
_______________

I plan to fix the issue by programming via flash magic. However, I am having difficulty with flash magic. It keeps giving me an "autobaud rate" error. I looked into it a bit and it could be the connections. The way I have it connected it as follows:

LPC1768 Pin #   <------> FTDI RS232 3v3 Pin #
__________________________________
All VSS      <------>  1 (GND)
All VDD     <------>   3  (Power)
(TXD1) 73 <------>  4 (TXO)
(TXD1) 74 <------>  5 (RXT)

*Note: Pin 53 ISP pin is grounded.

I have made to select the right part (LPC1764) and I have imported the hex file that was taken from the build of interest using LPC Expresso.

EDIT 2:

The problem still persists. But, I made this schematic, maybe this will be more clearer and will be easier to point out any issues:

[IMG]http://i51.photobucket.com/albums/f379/XMachine9000/LPC1764schematic1_zps259834bf.png[/IMG]
0 Kudos
Reply

867 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by serge on Tue Jul 16 03:32:00 MST 2013
Time to check the hardware I am afraid.

Configure your clkout pin (read UM 10360 chapter 4.10 External clock output pin) and scope it.
check the crystal with the scope when your mcu is not operating.
0 Kudos
Reply