Pin Muxing: Using the NMI Pin as GPIO Pin

Many modern microcontroller have a cool feature: Pin Muxing. What it means is that I can ‘mux’ the pins for different purposes: such as I can use a SPI or I2C pin as GPIO (General Purpose Pin) or vice versa. In an ideal world, I would be able to ‘route’ or ‘mux’ pins freely around. In practice these ‘way switches’ are more or less limited.

In “Using the Reset Button on the Freedom Board as User Button” I muxed the FRDM-KL25Z reset pin as GPIO pin. The same approach can be used for muxing the NMI (Non-Maskable Interrupt) pin for the Freescale Kinetis devices. I’m showing it here how to do this with Processor Expert as this allows me to do this with a few mouse clicks.

NMI Pin Used as GPIO Pin

NMI Pin Used as GPIO Pin

I’m using in my example the FRDM-K64F board. If I want to configure a (BitIO) component to use the NMI pin, I get an error (screenshot with the new Processor Expert view in DriverSuite V10.4).

Selected value is in conflict with other configurations

Selected value is in conflict with other configurations

Hovering over the error gives me already the hint how to ‘fix’ it: I need to go to the CPU component which is already marked with an error flag:

CPU component flagged with Error

CPU component flagged with Error

💡 This cross checking and consistency checks are one of the big benefits to me using Processor Expert. If I would use ‘normal’ coding, these things easily get missed.

In the Cpu component properties, I see that the enabled NMI pin is causing the conflict:

NMI Pin Error in CPU Component Settings

NMI Pin Error in CPU Component Settings

So I have the NMI pin disabled:

Disabled NMI Pin

Disabled NMI Pin

As I do not need the NMI interrupt, I disable this in the CPU interrupts/reset section:

Disabled NMI Interrupt

Disabled NMI Interrupt

💡 The settings of interrupts and pin enable are connected and interlocked. In the earlier version of Processor Expert I had sometimes the issue that one setting was ‘grayed’ out. I had not a clear reproducible case, but it helped if I re-enabled the other setting to ‘unblock’ it.

That’s it. With this I have the NMI pin ‘muxed’ as normal GPIO pin.

💡 The same thing can be done for the reset pin. But here be careful: muxing the reset pin means that there is no way to reset the microcontroller with the reset pin. If I mux the pin early in the startup process, then this means the microcontroller boots and after a micro-seconds later the reset line is disabled. That might mean that the debug probe is not able to get control over the CPU, especially if low power mode is involved, or if this happens that fast. Your microcontroller still runs, but you need to be lucky (or fast enough) to get control over the CPU. I recommend to disable/mux the reset pin only a few second after power up to give the debugger a chance to get access to the CPU.

Happy Muxing 🙂

19 thoughts on “Pin Muxing: Using the NMI Pin as GPIO Pin

  1. That’s a great feature of modern chips. But I have been burned by that pin mux’ing countless times. I run into problems by not reading the datasheets carefully enough before building hardware. Then find out a certain peripheral isn’t available on a pin I hoped to use. Or limitations due to lower pin count packages (which I always select because I’m soldering by hand).

    Sorta related, on S08JS16 one pin was open-drain only. Of course I didn’t bother to notice that before building a PCB.

    -Bill

    Like

    • Bill,
      yes, I appreciate and hate that feature the same time. Especially if the pin muxing is not clearly documented. I have trashed a few PCB’s because I *thought* that I can mux things in a certain way, until to find out that it is not possible that way I thought it is possible. The semiconductor provided documenation does not make it simpler, and with the plethora of devices things get even more complicated. So I have burnt my fingers too many times on this, especially migrating from one device to a different package or different controller in the same family. My only help in this is Processor Expert: I do not build that PCB until I have at least all pins I need allocated and configured in Processor Expert to make sure I can make the assignment and muxing the way I need it. So I’m using Processor Expert as the muxing verification (at least with dummy components and software) to ensure that my pin assignment and routing will work. To verify muxing, pull-up/pull-down/interrupt settings. Of course Processor Expert could be wrong with it too, but so far it always worked when I made the pin muxing with Processor Expert before doing the PCB layout.
      Erich

      Like

  2. This pin problems are always a nightmare! I had a development board (not made by me) that I can’t use all the resources because pin comflicts Luckly it’s gona change! Alredy exist some micro that you can assing any digital function to any pin 🙂 (execpt Vss and Vcc)

    Like

  3. Hi Erick;

    I’m trying to use NMI_b pin as digital output, my setup is as follows (CW 10.6 + Processor Expert):
    ->CPU MKL25Z128VLK4
    CPU interrupts / resets -> NMI interrupt -> Disable
    Internal peripherals -> NMI pin -> Disable

    ->BitIO_LDD as output -> PTA4/NMI_b pin, the pin never changes state

    Is there anything else to be configured for it to work?

    Charles

    Like

    • Hi Charles,

      Here is what I did for KL25Z:

      a) disable Cpu component > Internal Peripherals > Flash Configuration Fields > Peripheral Settings > NMI function

      b) disable Cpu component > Internal Peripherals > NMI pin

      c) added BitIO component, configured as output and for PTA4, named it NMI (but this does not matter).

      d) then I used NMI_ClrVal(); NMI_SetVal();

      and it was working for me?

      Erich

      Liked by 1 person

      • Hi, Erick;
        It works, unfortunately i was using the wrong pin, because i have changed my project.
        In the same project i’m using the USB CDC Device, every time when i open the CW 10.6, the FLS_USB_Stack show me error in:
        CDC Settings -> Bus reported device (minimal lenght 16 caracters)
        Bus vendor device (minimal length 28 caracters)
        The CW let me not change this descriptions and i can’t compiling the project because that error, I need delete the FS_USB_Stack from my project and insert it again, after insertion I can compiling the project again and the error disappears, you know what might be causing this problem?

        Thanks

        Charles

        Like

        • Hi Charles,

          ahhrg, that’s a problem in Processor Expert of MCU10.6 (just see your problem now too) 😦

          The thing is this: the strings need to have the exact length for the USB descriptor.

          Previously, I had spaces at the end, but now it seems that Processor Expert removes trailing spaces automatically 😦

          The solution is that you use the exact number of characters, e.g.

          FSL HID Keyboard123

          FREESCALE INC.12345678901234

          If you enter that, the errors will be gone.

          I’ll file a ticket on this issue.

          Erich

          Like

  4. Hello Erich,

    I do not understand 100%. Is possible to use NMI pin as GPIO and use NMI Interrputs?
    I saw that you turned NMI interrupts off.
    I mean, I would like to use both of them. I’ve implemented a pwm in the NMI_b pin but I’m already using Systick Timer interrupt. I’m having some problems that are pointing that this is not possible or maybe I’m doing something wrong.

    Thanks.
    Frederico

    Like

  5. Erich, Hi!

    Please; I am using a MKE02Z64VLC4. I’m desactivating the debug pins, for use how to general IO (led indicator), and still; =(, the reset pin disabled to use an input pin! Oh nooo…. no, no, I forgot it!

    My programmer is USBDM, does not have advanced functions for programming. Exists some way to recover the chip??

    Thanks.

    Like

  6. I used PTA4(NMIb) for TPM0_CH1,(MKL27Z64XXX4), It is important to disable the IRQC. The configure line for PTA4 is PORTA->PCR[4] =BIT8+BIT9; not PORTA->PCR[4] |=BIT8+BIT9;
    So it works fine.

    Like

  7. Hi,
    It is easy with processor expert. I am using FRDM-KE06Z with MCUexpresso. How can I disable the NMI Pin on MCU and change it as GPIO with MCUEXpresso?.

    Like

  8. Pingback: Disabling NMI (Non Maskable Interrupt) Pin | MCU on Eclipse

What do you think?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.