Custom PCB with the LPC1786

This notebook page is here to document my experiences putting a LPC1768 onto a custom PCB. Before I start the document, I would like to thank the other that have put the information up for everyone to use. http://mbed.org/users/ms523/notebook/turning-an-mbed-circuit-into-a-custom-pcb/ http://mbed.org/users/chris/notebook/prototype-to-hardware/ I am going to try to keep the document short and to the point. If you are looking for an *eagle* library that contains the LPC1768, look here

Recommendations for your next board

  • Include the ISP header. Even if your using JTAG.
  • Prepare to solder small pins.
  • Have extra space around your LPC in case your need to fly-wire.

Developing your a schematic

I have created a template that has all of the required parts to have the LPC1768 work properly. It also includes the LED1-4 that the mbed uses. Beware I am using surface mount components for the LED and resistors (size: 1206). There are also decoupling capacitors that I have attached to the micro. When you do end up making a PCB make sure to put these cap's as close as you can to the micro, when I made the board I put them on the bottom side. I have also included a crystal oscillator with the supporting passive components. This is not necessary if you aren't using the USB on chip, you can use the internal oscillator. The code to do that is located later in this document.

There is a FTDI chip that will allow USB communication, but the LPC has that available if you write the code for it. The FTDI, and USB port are available from the Sparkfun Eagle Library. The following image is a low definition image of the file I am talking about. If you want to look at the high definition one go here.

http://www.ethankhall.com/hardware_data/micro_with_isp_and_usb_ftdi_ld.png

If you want to download the schematic, so you can use it on your next project, download it from my github page.

If you look carefully I have two ways you can program the LPC, the serial programmer that uses the NXP bootloader and a program like Flash Magic that other have recommended. Even if you are going to use JTAG to program the device include the ISP port. If you don't you may regret it. I was using a uLink2 programmer with the Keil software and locked up the LPC. The only way I was able to get it to come out of this state was using Flash Magic to erase the device, then all started to work again.

Next you can find that there is a JTAG programmer, this is nice because you can use a device like the uLink2 to step though your code if you use uVision4 or something similar to program.

Programming

JTAG

I used a JTAG programmer with Keil's uVision4. Go to my github to get my blinky project. This project is able to use the normal mbed programming features along with all the library functions. The blinky project is set up to the internal oscillator as its clocking source. It uses the PLL to bumb the frequency to 96MHz, just like a normal mbed runs at. This won't be able to use the USB functionality, USB requires greater persision then the internal oscillator uses. If you want to use a crystal either use the provided compiled version of the statup code, or modify the constants in the startup_LPC17xx.c file to match the features you want to use.

ISP

If you don't want to deal with using uVision4 or other software, and use the mbed compiler then you can use the ISP programmer. Another user created a program where you can use your mbed to program the LPC. I have published code that can be found on Chris's Prototype-To-Hardware notebook page. All credit for this program should go to Chris.

You are going to need a program like Flash Magic to send data from your computer to your custom PCB. I think that you can use the FTDI chip to program it aswell, if you don't want to use the mbed to program it.

Misc

If you find that your using JTAG to program and get an error "Cannot enter debug", or "Cannot read memory" you will need to use the ISP and Flash Magic(or other flash programmer) to clear the flash. You might be asking yourself what happened, O have found two possible answers, I think the second one is correct, but I am putting both here for completeness.

  1. Kiels uVision4 and the uLink has problem sometimes and locks out the JTAG port.
  2. You have accidentally changed clock settings that will disable the JTAG port.

Either way the easiest way to fix this is to use the ISP to clear the flash and you will be good to go.

Clock Selection

If you are going to be using the LPC1768's USB you *must* use a crystal. If you don't need to use USB and want to remove some components (crystal, 2 capacitors) and reduce the cost of building your project you don't have to include the crystal. Like I have said earlier, you can recompile the system_LPC17xx.c to change the clock selection options.

The normal clocking operations will be controlled by PLL0. NXP has released a spreadsheet that you can use to choose your clocking options. You can download the one that I have used here or directly from NXP. If you look at mine you can see that I have the target frequency set to be 96MHz(what the mbed uses).

If you look in system_LPC17xx.c and look at line 299(at the time of writing this) you will see the definition of the PLL settings. I have chosen the value of 'N' to be 6 and 'M' to be 300. Be sure when you do the configuration to turn on the PLL, this is done by line 298(PLL0_SETUP).

#define PLL0_SETUP            1
#define PLL0CFG_Val           0x0005012B

The value 'N' can be found in bits 23-16, you can see the value is 5, then add 1 to the value to get 6. When you set your own value of 'N' you will pick the number, subtract 1, convert it to hex and put it in bits 23-16 with a 0 fill. The value is 'M' is done the exact same way except it is located in bits 0-14.

USB

When using USB you need a very precise clock. To do this, you will need an external crystal between 10 and 25MHz. You will be using PLL1 for USB clocking. For more information look at the LPC1768's datasheet in section '7.29.3 USB PLL (PLL1)'.

In the eagle file I have included the crystal, but if you don't need it then please remove it.

Final Thoughts

If you are going to use the ISP, you might want to add a jumper you can set to enable ISP. If you do that you might not need the mbed to program, you can just use the FTDI chip to program. You might have to hit reset after setting the jumper to program mode. If you do that then you can remove the jumper that sets the FTDI into reset.

They way the FTDI is set up, it will mimic the way that the mbed is set up. When you use USBTX, USBRX in the mbed environment it will equate to using the USB port that this schematic contains.

If anyone has any comments please leave them. Again I have pulled a lot of this data from Chris's notebook and some things that I have run into that might be useful. When building your PCB be sure to send regulated 3.3V power to the LPC1768, if you don't it might blow up.


Please log in to post comments.