1. Product Selection Guide

    parametric search on NXP.com
  2. Videos

    This text will be replaced

  1. LPC800 Switch Matrix: Making life easier one pin at a time

    LPCnow (Dec 16 2012)

    1. LPC800 Switch Matrix: Making life easier one pin at a time

      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:

      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:

      LPC800 Block Diagram


      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.

      Switch Matrix Tool



      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):




      SWM Pin Assign Register


      Transmitter output for USART0



      Receiver input for USART0.



      Request To Send output for USART0.



      Clear To Send input for USART0.



      Serial clock input/output for USART0 in synchronous mode.



      Transmitter output for UART1.



      Receiver input for UART1.



      Transmitter output for UART2.



      Receiver input for UART2.



      Serial clock for SPI0.



      Master Out Slave In for SPI0.



      Master In Slave Out for SPI0.



      Slave select for SPI0.



      Serial clock for SPI1.



      Master Out Slave In for SPI1.



      Master In Slave Out for SPI1.



      Slave select for SPI1.



      SCT input 0.



      SCT input 1.



      SCT input 2.



      SCT input 3.



      SCT output 0.



      SCT output 1.



      SCT output 2.



      SCT output 3.



      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.



      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.



      Analog comparator output.



      Clock output.



      Output of the pattern match engine.


      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


      Moveable Function


      I2C clock input/output


      Analog comparator output


      Clock output


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



      If we were to run this code and hook an oscilloscope up to pin 0.4 we should see something like this :

      CLKOUT Signal - 24MHz


      (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.

      Bookmark or Share this article