Using the NMI_b pin as GPIO on KL15 device

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Using the NMI_b pin as GPIO on KL15 device

Jump to solution
2,430 Views
Safwat
Contributor III

Hi everyone. I am working with a 32pin KL15 MCU. I need to disable the NMI_b function on PTA4 and use it as a normal GPIO.

I understand from the reference manual that I need to write to FTFA_FOPT--> NMI_DIS to disable the NMI function.

This is what I have done so far:

> Write 0xFB to address 0x0040D in flash configuration field. 0x0040D is the address for FOPT. Writing 0xFB should set 0 in the NMI_DIS bit.

> Verified the written value by reading back the memory.

> Configured PTA4 as a GPIO. Set direction to Output. Disable Passive filter. Disable internal pull up.

> Toggle the pin at 1Hz in a loop.

But I am not able to see any change in the state of PTA4. Can someone help me find what I am missing?

Thanks!

Labels (1)
Tags (1)
0 Kudos
1 Solution
987 Views
chris_brown
NXP Employee
NXP Employee

Hi Safwat,

You aren't configuring PTA4 for a GPIO.  PTA4 defaults to the NMI_b functionality which is a MUX value of 0x7 (or b111).  So when you execute PORTA_PCR4 |= PORT_PCR_MUX(1); you end up ORing 0b111 with 0b001, which leaves your MUX value in the default state.  Try PORTA_PCR4 = PORT_PCR_MUX(1).  This way, you also won't have to explicitly disable the pull-up and passive filter.

Hope this helps,

Chris

View solution in original post

0 Kudos
6 Replies
987 Views
chris_brown
NXP Employee
NXP Employee

Hi Safwat,

Doesn't sound like you're missing anything right now.  Maybe you just have a typo somewhere?  Could you post your register values for PORTA_PCR4 and all of the GPIOA_xxx registers just before you start to toggle your pins?

Thanks,

Chris

0 Kudos
987 Views
Safwat
Contributor III

May be I post the section of my code which is doing the entire thing..

// Save the 1k sector that is to be erased

memcpy(Buffer,(unsigned long*)(0x400),1024);

// Change the byte for FOPT

Buffer[13]=0xFB;

//Erase the sector to be written back

FLASH_EraseSector((unsigned long)(0x400));

// Write the modified buffer back to the original address

// *Note: The size here is in long words. 32 bits. 4 bytes. So 256 words = 1024 bytes

FLASH_ProgramSectionByLongs((unsigned long)(0x400),(unsigned long*)Buffer,256);

// Select ALT1(GPIO) function for PTA4

PORTA_PCR4 |= PORT_PCR_MUX(1);

// Setting PTA4 pin as Output

GPIOA_PDDR |= (0x01<<4);

// Disable PU and PFE

PORTA_PCR4 &= (~((0x1<<1)|(0x1<<4)));

// Start The toggle loop

for( ;; )

  {

  COMSendStringLine("Toggle");

  // toggle the PTA4 pin

  GPIOA_PCOR |= (0x01<<4); // Clear the pin.

  vTaskDelay(1000/portTICK_RATE_MS);

  GPIOA_PSOR |= (0x01<<4); // Set the pin

  vTaskDelay(1000/portTICK_RATE_MS);

  }

For the very first time this block of code is executed, it will not have any effect because the value of the FOPT is loaded from the flash config field during reset. So If I cycle the power to my board one time, it should start working and toggling the pin.

Unless there is some mistake in my code Smiley Happy

0 Kudos
987 Views
dieterteuchert
Contributor IV

You need to enable the clock gate for port A.

0 Kudos
987 Views
Safwat
Contributor III

It is already enabled in the startup code.

/* Enable all of the port clocks. */

  SIM_SCGC5 |= (SIM_SCGC5_PORTA_MASK

               | SIM_SCGC5_PORTB_MASK

               | SIM_SCGC5_PORTC_MASK

               | SIM_SCGC5_PORTD_MASK

               | SIM_SCGC5_PORTE_MASK );

I am able to use other pins of PORT A without any issue.

0 Kudos
988 Views
chris_brown
NXP Employee
NXP Employee

Hi Safwat,

You aren't configuring PTA4 for a GPIO.  PTA4 defaults to the NMI_b functionality which is a MUX value of 0x7 (or b111).  So when you execute PORTA_PCR4 |= PORT_PCR_MUX(1); you end up ORing 0b111 with 0b001, which leaves your MUX value in the default state.  Try PORTA_PCR4 = PORT_PCR_MUX(1).  This way, you also won't have to explicitly disable the pull-up and passive filter.

Hope this helps,

Chris

0 Kudos
987 Views
Safwat
Contributor III

Hi Chris,

Thanks for finding the bug. I think you've nailed it :smileyhappy:. I will test and share the update here as soon as I get near my hardware.

Update: If worked after changing it to PORTA_PCR4 = PORT_PCR_MUX(1);

Safwat

0 Kudos