-
-
Subscribe to Newsletter
Enter your e-mail address to receive the top headlines.
-
Videos
This text will be replaced -
Authors
-
Categories
-
Cores:
ARM7,
ARM9,
Cortex-M0,
Cortex-M3,
Cortex-M4
Design: Board design, Dev Tools, Evaluation boards, Firmware, Low Power
Technologies: Connectivity, LCD Display, Security, Signal processing, USB
General: Design Examples, Industry News, LPC product news, Use Cases
-
-
LPC800 Switch Matrix: Making life easier one pin at a time
LPCnow (Dec 16 2012) Cortex-M0 , Firmware , LPC product news
-
As a follow-up to my earlier blog post on NXP's new ARM Cortex M0+ LPC800 family of MCUs -- First Thoughts on NXP's New M0+ LPC800 MCUs -- I wanted to dig into what's probably the most innovative feature of these new chips: the switch matrix.
The switch matrix basically decouples specific functionality from a fixed pin location, giving you an extraordinary amount of flexibility on even the smallest packages, and liberating end users from package design decisions that were previously made by chip manufacturers.
Before we can really explain why this is such a great feature, though, it helps to step back a bit and see how we've been doing things up until now ...
Small Packages, Big Feature Sets (AKA: "The Challenges of Multiplexing")
Multiplexing has been present on microcontrollers – ARM or otherwise – for ages. In a day and age where general purpose MCUs need to include more and more peripherals, there simply aren't enough pins or surface-area to expose everything.
Pin multiplexing solved this problem by connecting several functions to a single physical pin. Chip designers can place more functionality in smaller packages, and end users have the flexibility to choose the functionality they need. Everybody wins!
Unfortunately, there are some tradeoffs inherent in this approach:
- Some pins require specific electrical characteristics for certain roles, limiting where they can be placed.
- Sometimes you require two functions that are located on the same pin, and you may end up having to bit-bang a digital interface to make room for an analog function on the same pin.
- On very pin-limited packages there just aren't enough pins to expose all the peripherals you might need, even if they exist on the die inside the package.
The last point is particularly important on small packages like the LPC800 or many 8-bit chips. These chips get optimized for the 'most common' scenarios, but they can rarely accommodate special situations like needing two UARTs plus HW I2C on an 8 pin package. Chip designers try to minimize these problems with smart pin multiplexing, but conflicts are unavoidable, and you just have to accept certain trade-offs or choices made by the designers.
What Makes the LPC800 and the Switch Matrix Special?
The LPC800 is no different than many other modern MCUs in that it includes a rich set of peripherals, and each pin potentially exposes multiple functions. End users have the flexibility to select the peripherals they need and drop the ones that aren't required.
What makes the LPC800 special, though, is that it includes a new feature called the switch matrix that adds a level of flexibility that goes well beyond classic multiplexing.
Essentially, the switch matrix picks up where multiplexing leaves off by completely decoupling physical pins from specific functionality or peripherals, allowing end users to map any movable function to any available GPIO pin, within the limits of the electrical characteristics of the pin.
It's easy to see some of the advantages of this approach compared to simple multiplexing ...
Small Packages for Edge Case Scenarios
One of the biggest drawbacks with multiplexing on very small packages (8-16 pins) is that you can only expose so many features on the chip, and manufacturers need to optimize the peripheral array for the most common scenarios. This is a necessary evil in the general purpose MCU market, where you need to appeal to the largest number of people with the most flexibility possible.
This might work for 90% of customers, where you need the basics like one UART/USART, one SPI bus, etc., but if you find yourself in the unfortunate 10% of users with more unusual requirements you'll probably have to move to a physically larger and more expensive package to accommodate your needs.
The switch matrix solves this problem admirably by giving end users the ability to expose almost any peripheral on the die on any package size to almost any GPIO pin, allowing you to pick the right package size and chip and nothing more.
Lets say you want to use a low pin count and easy to assemble 8-pin package, but you require two UARTs plus a HW I2C interface. You might have a hard time to find a low-cost chip that accommodates that, since most manufacturers would probably opt to include a single UART/USART interface on a package that size, multiplexed with I2C and SPI, etc.
Thankfully, the switch matrix on the LPC800 can easily solve this problem by remapping any 6 pins on an 8-pin package to include TXD0, RXD0, TXD1, RXD1, SCL and SDA plus VCC and GND for power. Problem solved!
Another benefit of this approach is that when your next project requires HW SPI and HW I2C, you don't have to move to a new chip and code base every time since you can simply remap the existing chip with a couple lines of code, rather than having to dig around for another MCU that meets your HW requirements.
The switch matrix allows the smallest packages to accommodate edge cases that designers wouldn't have been able to justify … or even imagine!
Simplified Routing
Another significant advantage of the switch matrix is on board layout.
Multiplexing is useful to give end users access to the peripherals they need, but one of the weaknesses of this approach is that those peripherals are tied to specific physical pins and locations and external components or sensors need to bend to this pin layout.
For very compact boards, or boards with specific routing requirements (matching trace lengths, single-sided layouts, etc.), pairing external components with your MCU can pose significant challenges and make some boards awkward to route.
With a traditional MCU, you have to add extra vias and route signals on a bottom layer, or snake the traces around the board, potentially introducing signal integrity issues or increasing the total board size with the extra signals.
The switch matrix enables you to carefully match the pinout of your MCU to the pinout of the sensors or components in question, making clean single-sided routing possible using a smaller surface area than would be possible with a traditional pinout.
The switch matrix can help solve routing requirements in an elegant way, minimizing the number of vias, layers and board space required for your design.
So How does it Work?
NXP has made a number of resources available explaining the switch matrix, and there have been a number of good third-party explanations of it … for example:
-
First Steps with the LPC800 - Duane Benson does a good job of explaining the Switch Matrix in practice here
In a nutshell, though, the switch matrix functions as an additional physical layer between the GPIO pins and the peripherals on the LPC800. This basic architectural diagram gives a good illustration of how this works:

Simply assign the desired functionality to any available GPIO pin, and they will be connected via the switch matrix! (Keep in mind, of course, that some pins do have certain electrical requirements. For example, there are only two genuine open-drain pins on the LPC81x die so you probably want to stick to those locations when possible for I2C – although the very flexible LPC800 pins do also include a psuedo open-drain mode should you need to map the I2C functions elsewhere on the LPC800!)
Setting the Switch Matrix Up
It's extremely simple to use the switch matrix. You only require two lines of code to remap any movable function to any available pin, and it can be changed at any point in your code.
To make it even easier, though, NXP has produced a simple stand-alone utility called the Switch Matrix Tool that allows you to remap the pins and peripherals in a graphic interface, and you can export C code generated by the tool into your project using your favorite toolchain.
Configuring Pins with the Switch Matrix Tool
The Switch Matrix Tool – available on NXP's developer website LPCWare.com – allows you to visualise the chip layout and graphically map functions to pins, and then export or copy and paste the initialisation code to configure the matrix in your project.
Have a look at NXP's video overview of the tool – LPC800 Switch Matrix Configuration – but the tool itself is reasonably intuitive, and well explained, so we won't dig into it too much here.

Manually Configuring Pins on the Switch Matrix
While the Switch Matrix Tool above makes it extremely easy to visualize the switch matrix and connect function to pins, it's also extremely easy to do this in code as well!
It essentially takes two lines of code to map any movable function to any pin.
Each movable function on the LPC800 is associated with one of eight PINASSIGN registers, as can be seen in the table below listing all movable functions on the LPC800.
These PINASSIGN registers are used to map the movable function to a specific GPIO pin location, using the GPIO pin number as a reference (ex: '4' for GPIO pad 0.4):
MOVEABLE FUNCTIONS
Function
Description
SWM Pin Assign Register
U0_TXD
Transmitter output for USART0
PINASSIGN0
U0_RXD
Receiver input for USART0.
PINASSIGN0
U0_RTS
Request To Send output for USART0.
PINASSIGN0
U0_CTS
Clear To Send input for USART0.
PINASSIGN0
U0_SCLK
Serial clock input/output for USART0 in synchronous mode.
PINASSIGN1
U1_TXD
Transmitter output for UART1.
PINASSIGN1
U1_RXD
Receiver input for UART1.
PINASSIGN1
U2_TXD
Transmitter output for UART2.
PINASSIGN2
U2_RXD
Receiver input for UART2.
PINASSIGN2
SPI0_SCK
Serial clock for SPI0.
PINASSIGN3
SPI0_MOSI
Master Out Slave In for SPI0.
PINASSIGN4
SPI0_MISO
Master In Slave Out for SPI0.
PINASSIGN4
SPI0_SSEL
Slave select for SPI0.
PINASSIGN4
SPI1_SCK
Serial clock for SPI1.
PINASSIGN4
SPI1_MOSI
Master Out Slave In for SPI1.
PINASSIGN5
SPI1_MISO
Master In Slave Out for SPI1.
PINASSIGN5
SPI1_SSEL
Slave select for SPI1.
PINASSIGN5
CTIN_0
SCT input 0.
PINASSIGN5
CTIN_1
SCT input 1.
PINASSIGN6
CTIN_2
SCT input 2.
PINASSIGN6
CTIN_3
SCT input 3.
PINASSIGN6
CTOUT_0
SCT output 0.
PINASSIGN6
CTOUT_1
SCT output 1.
PINASSIGN7
CTOUT_2
SCT output 2.
PINASSIGN7
CTOUT_3
SCT output 3.
PINASSIGN7
I2C0_SDA
I2C-bus data input/output (open-drain if assigned to pin PIO0_11). High-current sink only if assigned to pin PIO0_11 and if I2C Fast-mode Plus is selected in the I/O configuration register.
PINASSIGN7
I2C0_SCL
I2C-bus clock input/output (open-drain if assigned to pin PIO0_10). High-current sink only if assigned to PIO0_10 and if I2C Fast-mode Plus is selected in the I/O configuration register.
PINASSIGN8
ACMP_O
Analog comparator output.
PINASSIGN8
CLKOUT
Clock output.
PINASSIGN8
GPIO_INT_BMAT
Output of the pattern match engine.
PINASSIGN8
For example, lets say we want to map the CLKOUT functionality to pin 0.4 (since this pin is present on all the packages in the LPC800 family).
Looking up PINASSIGN8 in the user manual, we can see the individual bits that we need to manipulate for CLKOUT at located at position 23:16.
PINASSIGN8 Register
Bits
Moveable Function
7:0
I2C clock input/output
15:8
Analog comparator output
23:16
Clock output
31:24
Output of the pattern match engine
To assign CLKOUT to GPIO 0.4, we simply need to configure PINASSIGN8 as follows, then enable CLKOUT:
/* Read the PINASSIGN8 register to avoid changing the other functions */
uint32_t regVal = LPC_SWM->PINASSIGN8 & ~( 0xFF << 16 );
/* Update bits 23..16 of PINASSIGN8 to route CLKOUT to pin 0.4 */
LPC_SWM->PINASSIGN8 = regVal | ( 4 << 16 );
/* Enable CLKOUT */
CLKOUT_Setup( CLKOUTCLK_SRC_MAIN_CLK );If we were to run this code and hook an oscilloscope up to pin 0.4 we should see something like this :

(NOTE: There's a fair amount of overshoot on the signal above, but its caused by the large GND loop between the GND lead and probe tip on the oscilloscope probe not the CLKOUT signal itself.)
If we wanted to change CLKOUT to be assigned instead to pin 0.1, we only need to change one line of code:
/* Update bits 23..16 of PINASSIGN8 to route CLKOUT to pin 0.1 */
LPC_SWM->PINASSIGN8 = regVal | ( 1 << 16 );It's that simple! You're free to connect almost any function to any pin with two lines of code, you can configure your MCU pinout to precisely match any external components or sensors without traces snaking all across your boards, and clean, efficient routing is more accessible than it's every been in the past!
This feature alone has me sold on the LPC800 ... but up next I'll be talking about one of the other big ticket items on the ARM Cortex M0+ and the LPC800 in particular, the low power modes!
Kevin Townsend specializes in ARM Cortex M0/3/4 design and development, with a particular interest in low power design and wireless sensors, and is active in the open source HW world as Lead Engineer at Adafruit Industries. Involved with NXP's LPC chip family since the ARM7 LPC2000, he's been an active contributor on several projects online, and continues to produce new open source HW designs and software libraries around the LPC family of Cortex M chips at www.microbuilder.eu.
Related Articles
- ARM claims Cortex-M0+ as world's most efficient CPU
- also categorized in Cortex-M0
- First Dual Supply Voltage Cortex-M0 MCUs released
- also categorized in Cortex-M0
- LPC800 Low Power Features
- also written by Kevin Townsend
- Atollic TrueSTUDIO adds support for NXP microcontrollers
- also categorized in Cortex-M0
- NXP Revolutionizes Simplicity with LPC800
- also mentions LPC800
- NXP releases first dual supply voltage ARM Cortex-M0 MCUs
- also categorized in Cortex-M0
- LPC800: Switch Matrix Configuration
- also mentions Switch Matrix
- MCU touts 1.6µA deep sleep current, 5µs wake-up time
- also categorized in Cortex-M0
- NXP Licenses ARM Cortex-M0+ Processor
- also categorized in Cortex-M0
- Re: New LPC1100LV: Cortex-M0 Dual Supply, 1.6 uA Deep Sleep Current,
- also categorized in Cortex-M0
-


Recent Comments