SparkFun Forums 

Where electronics enthusiasts find answers.

Everything ARM and LPC
By az83
#131836
Hi,

Please correct me if my understanding of programming the LPC1768 is wrong - there are 2 ways to do it, one via JTAG (OpenOCD), or another way is via through serial communication.

I have chose the latter for my project using USB-to-serial comm - I have soldered an FT2232 together with all the required components and I have both Channel A and Channel B connected to TXD0/RXD0 and TXD2/RXD2 of my LPC1768 processor. Previously, whenever I connected it to the PC, 2 different COM ports will appear, and I had no problems sending data from the PC to FT2232. (I tried to type something from the Hyperterminal and the TXLED for the appropriate channels would light up).

I was more ambitious then and badly wanted to do a simple echo program, where anything I typed would be displayed on the Hyperterminal. As such, I googled for a UART program for LPC17xx, and I found this:
http://code.google.com/p/32bitmicro/sou ... ART/?r=116

However, the Makefile, when compiled in my Eclipse, gave me an error about the "include ../Makefile.rules" part. As such, I have used the Makefile by Sagar G V - this is the link: http://code.google.com/p/cortex-m3-tuto ... r&can=2&q=
All this while, neither my RTC nor my Main Oscillator (12MHz crystal) was soldered onto the PCB yet.

Unfortunately, although it did work once on Hyperterminal, I was unable to get the COM port for Channel B to appear again. Worst, FlashMagic kept giving me the error "Failed to autobaud" even when I tried to flash via Channel A.

Now, upon reading the LPC17xx manual, it did mention that the LPC17xx would only switch to the main crystal only via software. However, if we try to flash it via FlashMagic, doesn't FlashMagic require us to define the crystal used - hence, how can they make use of this crystal when it has to be programmed by software? In any case, when I tried probing it using an oscilloscope, the 32.768kHz RTC appeared correctly, but I couldn't get the 12MHz main oscillator to work. As for the FT2232D, the 6MHz crystal used also appears correctly upon probing using an oscilloscope.

============================================================================
User avatar
By viskr
#131886
The family of LPC17xx parts all start up using the 4 MHz internal oscillator. When you hold P2.10 low during reset they enter the bootloader. The bootloader looks for the ? character, and times the transitions to set the baud rate for download. It responds with "Synchronized"

The bootloader no longer uses the crystal setting.
By az83
#131994
Hi viskr,

Thank you for your response.

I managed to somehow get both channels detected by my PC after removing the EEPROM. It could be that the EEPROM was faulty.

I have also tried reading the user manual for lpc17xx (http://www.nxp.com/documents/user_manual/UM10360.pdf), but being a newbie to this, I have no idea how to "communicate with the bootloader"? Do I use Hyperterminal to send the "?" and if I do so, how do I send a program which activates the main crystal, since flashing it would require another tool (eg. Flash Magic)?
User avatar
By viskr
#131995
You need to write a program that enables the oscillator, and to switch the clock source.

Once you have the program written you can download it with Flash Magic or other utilities.

As for choices in how to write that program, our tools would work for the LPC1768, or Code Red's Eclipse based version, or Keil's and others.
By az83
#132255
Hi again,

I am currently equipped with Eclipse Galileo and Codesourcery G++ Lite - hence, I believe the software environment to build a program is somewhat sufficient.

However, I am still unsure how one can activate the main oscillator via software. In NXP's UM10360, Chapter 3 Section 7, it is mentioned that

"... the main oscillator may not be used at all in some applications, it will only be started by software request. ...accomplished by setting the OSCEN bit in the SCS register... The main oscillator provides a status flag (the OSCSTAT bit in the SCS register) so that software can determine when the oscillator is running and stable. At that point, software can control switching to the main oscillator as a clock source."
Code: Select all
SystemInit()
function in system_LPC17xx.c does a check if Main Oscillator is enabled, but nowhere in the code do I see how this main oscillator is enabled.

(Sideline a li'l...) Furthermore, everytime I power on my PCB, I am unable to detect any oscillations from my 12MHz crystal. It has a 16pF load capacitance, and I have used 2x 33pF capacitors as X1 and X2 to be connected to my crystal. As for my 32.768KHz crystal, only one leg (pin) shows the correct waveform, while the other does not output the correct waveform. I am using 15pF (x 2) for my 32.768KHz crystal which has a load capacitance of 12.5pF.

Thanks in advance! :)
User avatar
By viskr
#132256
As for the main oscillator the code is probably just checking to see if it has already been enabled, in which case it doesn't need to do it again, especially as it normally has to wait for the PLL to sync up.

The 32 KHz oscillator is extremely low current so the load of the scope probe is washing out the input side.
By az83
#132270
Hi viskr,

My apologies, but I couldn't quite catch your first sentence. I'm using a "raw" LPC1768 chip, unlike most others who are using the mbed LPC1768 which comes equipped with all other applications. Hence, based on the user manual, my "clock" will always come from the internal RC oscillator, unless if s/w switches it to the main oscillator.

Are you implying that system_LPC17xx.c is not the right code to start the main oscillator? If so, is there a sample software which does exactly this?

Once again, thank you for the verification.
User avatar
By viskr
#132271
There is nothing magic in the code or the startup.

From a hard reset the IRC (internal osc) is the clock source.

When the main oscillator is used, most of the time it is enabling the crystal oscillator and then using that to drive the PLL. This lets you run up to 120 MHz, something you can't do any other way.

My assumption is the author of the code to do that wrote it with the idea that it is possible for the code to be called more than once, and to save time to check to see if the oscillator is running and the PLL already locked, and if so just return.
By az83
#132995
Hi again,

When I did my overall design, I have decided to use P1.27 (CLKOUT / USB_OVRCR) as the USB_OVRCR function (active low, pulled high). Hence each time I probe into this pin, I get a constant high voltage, i.e. I had to override the CLKOUT function in order to use the USB overcurrent function. Are there any other methods for me to check that my internal oscillator of my LPC1768 is really working?

I am still unable to get any oscillations on the oscilloscope for my 12MHz crystal, but based on past explanations, it is because I have yet to activate it by software. I hope this is the right explanation on why the main oscillator doesn't show any oscillations yet?

Thank you.
By az83
#133361
Hi,

I'm now able to communicate with my board, but when I downloaded the startup code to use my 12MHz crystal, I'm unable to get any oscillations from the oscilloscope.

The code I'm using is starter_code_21Oct2010 available from http://code.google.com/p/cortex-m3-tuto ... 0&start=50. I downloaded it via FlashMagic and I didn't get any errors. I ensured that my INT0 was still pressed before I released my RESET button (and subsequently released) to enter the bootloader before downloading the program.

I'm currently using a pair of 33pF capacitors for my 12Mhz crystal (from Abracon, through hole type, with a load cap of 16pF). Would using 22pF (as shown by the NGX website) help to solve this issue? Or could it simply be something gone wrong with the soldering?
By az83
#133398
Sigh, I have tried using a pair of 18pF capacitors, but all I get from the oscilloscope is still noise - similar to that when I used a pair of 33pF capacitors. I have also changed my 12MHz crystal before. The startup code, from my basic understanding of C programming, should start the main oscillator.

What can possibly go wrong?
User avatar
By viskr
#133405
Most likely software. You are debugging the hardest thing to do without JTAG tools or even with them. Basically if the software fails during the boot up stage you have very few tools for debugging.

What I use is wiggling an IO to see how far the software got.

In my case P2.10 is connected to an LED. So I put a routine called wiggle in and start binary searching to see where the problem is, by inserting calls to wiggle. If the LED does not flash the code never got there.

#define ABOUT_1_SECOND 400000

volatile int bit_bucket;

void wiggle(void) {
GPIO2_DIR = 1<<10;
while (1) {
GPIO2_CLR = 1 << 10;
for (bit_bucket=0; bit_bucket<ABOUT_1_SECOND; bit_bucket++);
GPIO2_SET = 1 << 10;
for (bit_bucket=0; bit_bucket<ABOUT_1_SECOND; bit_bucket++);
}
}

This is a good reason to buy a pre-tested PCB with a known good software tool to get started. Without that you are debugging your code, your setup (software and hardware), and your PCB.
By az83
#134355
Hi,

Thanks for the suggestion. I was away for quite some time and was unable to try out your suggestion then.

Anyway, I tried out the wiggle() method in a few areas, but all didn't seem to work out. My last resort was to put it at the start of the Reset_Handler() method in startup_LPC17xx.c, but again, the LED didn't blink. Here's a snippet of the part that I added. (I used P2.0 as my LED)
Code: Select all
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
#define ABOUT_1_SEC			  0x61A80		//equivalent to 400000 decimal
////////////////////////////////////////////////////////////////////////////////
volatile uint32_t bit_bucket;


void wiggle (void)
{
	LPC_GPIO2->FIODIR |= 1<<0;
	while (1) {
		LPC_GPIO2->FIOSET = (1<<0);
		for (bit_bucket=0; bit_bucket<ABOUT_1_SEC; bit_bucket++);
		LPC_GPIO2->FIOCLR = (1<<0);
		for (bit_bucket=0; bit_bucket<ABOUT_1_SEC; bit_bucket++);
	}

}
////////////////////////////////////////////////////////////////////////////////

void Reset_Handler(void)
{
	////////////////////////////////////////////////////////////////////////////////
	  wiggle();
	////////////////////////////////////////////////////////////////////////////////
I doubt there's a problem when downloading the code via FlashMagic, coz when I probed into P0.2 and P0.3 (near the CPU side to ensure no broken link between the FT2232 chip and LPC1768 (CPU) chip), I see moving waveforms whenever a program is downloaded. Furthermore, FlashMagic did not present me with any errors. I thank you for your suggestion on getting a pre-tested PCB, but that option is unfortunately not possible for me as there is a limited budget for my project.

I am really at a loss as to what can go wrong since it seems that my hardware seems fine. On the s/w side, FlashMagic didn't present any errors.

Thanks once again for all the useful info!
User avatar
By viskr
#134382
As Flash Magic seems to be happy the part is probably working.

You can verify that with most any terminal program, hold P2.10 low and reset the part

Send a ? from the PC (any baudrate - I usually use 19.2Kb)

The part should respond with Synchronized

If so, then the part is OK, and its your software setup that's wrong (wrong memory map, no CRC value inserted at 0x14, though I thought Flash Magic inserted this). Flash Magic allows you to read the memory you just programmed, you might check that vs. what your software tool generated.