LPC812 with MBED
.
Intro
I was having trouble finding resources on using the LPC812 especially on a custom board, so I decided I wanted to gather and share the resources I did find and my progress on using it in my own designs. I would be more than happy to get input from the many people that are either smarter and/or have more experience than me.
My intent is to use the LPC812 without the MBED interface but want to be able to use the online compiler and/or offline LPCxpresso IDE to build projects. Eventually I want to have the ISP programming setup as well but still want SWD interface for offline debugging.
Resources
Wim Huiskamp http://mbed.org/users/wim/notebook/lpc812-lpcxpresso-board/
LPC812-MAX (LPC800-MAX) Getting started page https://mbed.org/handbook/mbed-NXP-LPC800-MAX-Getting-Started
LPC812-MAX (LPC800-MAX) Handbook page https://mbed.org/handbook/mbed-NXP-LPC800-MAX
Main areas of focus
External XTAL
Goals
- Have good generic example of using external XTAL
- Library for using external XTAL as well as other setting for the LPC8xx
Code thanks to Paul Staron (I believe he was helped by Wim Huiskamp) found on the following page https://mbed.org/handbook/mbed-NXP-LPC800-MAX
LPC812 Enable external Xtal
#include "mbed.h" #include "TextLCD.h" int i; extern int stdio_retargeting_module; extern "C" void $Sub$$SystemInit (void) { LPC_SYSCON->SYSAHBCLKCTRL |= ( (0x1 << 7) | (0x1 << 18) ); LPC_IOCON->PIO0_8 &= ~(0x3 << 3); LPC_IOCON->PIO0_9 &= ~(0x3 << 3); LPC_SWM->PINENABLE0 &= ~(0x3 << 4); LPC_SYSCON->PDRUNCFG &= ~(0x1 << 5); /* Power-up System Osc */ LPC_SYSCON->SYSOSCCTRL = 0x00; for (i = 0; i < 200; i++) __NOP(); LPC_SYSCON->SYSPLLCLKSEL = 0x01; /* Select PLL Input */ LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */ while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */ LPC_SYSCON->SYSPLLCTRL = 0x00000040; /* Set PLL, not sure if this is correct */ LPC_SYSCON->PDRUNCFG &= ~(0x1 << 7); /* Power-up SYSPLL */ while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); /* Wait Until PLL Locked */ LPC_SYSCON->MAINCLKSEL = 0x03; /* Select PLL Clock Output */ LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */ while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */ LPC_SYSCON->SYSAHBCLKDIV = 0x01; }
Switch Matrix
Thanks to takahiro maeda, which created a good example showing the switch matrix in use. All that is really needed is call to a function that runs the CMSIS commands to update the registers based on your needs. If you are not sure how to figure those out you can use the tool NXP provides (see below).
https://mbed.org/users/maro/code/lpc810_helloworld_SwMat_uart/file/e5f3c8836d1c/main.cpp
Switch Matrix
void SwitchMatrix_Init() //generated by NXP Switch Matrix Tool { /* Enable SWM clock */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); /* Pin Assign 8 bit Configuration */ /* U0_TXD */ /* U0_RXD */ LPC_SWM->PINASSIGN0 = 0xffff0100UL; /* Pin Assign 1 bit Configuration */ /* SWCLK */ /* SWDIO */ /* RESET */ LPC_SWM->PINENABLE0 = 0xffffffb3UL; }
There is also this good project with an example on how to use the switch matrix with the MBED The work is thanks to Suga koubou http://mbed.org/users/okini3939/notebook/vetinaris-clock/
NXP Switch matrix online tool http://www.lpcware.com/content/tools/lpc-initializer
Serial code size
The serial library is heavy for the LPC812 and below. MBED has released of version of their library with the "RawSerial" library. You will basically need to deal with serial communication on the character by character level but it is much smaller than the standard library.
I found this thanks to takahiro maeda.
Please log in to post comments.