9 years, 10 months ago.

How can I access the FTFA_FOPT register on the KL25Z?

I need to disable the NMI interrupt on startup. As I found in the datasheet it is possible through the FTFA_FOPT register. How can I write to/configure it?

2 Answers

9 years, 10 months ago.

Apparantly that bit is set by loading a certain flash address on startup. In for example http://mbed.org/users/mbed_official/code/mbed-src/file/f9e72c209510/vendor/Freescale/KL25Z/cmsis/ARM/startup_MKL25Z4.s it is defined on line 181. So in theory if your import the mbed-src library and compile it, you should be able to change it. However that is the /ARM/ subfolder, and I don't know if the online compiler uses that one, or one of the others.

But aren't there more straight forward solutions to your issue?

Bela Nagy
9 years, 10 months ago.

That's what I was afraid of... Yes, I guess there are other solutions for it, but I'am just learning ARM now (since 4-5 hours :-) ).

My problem is that I use the NMI pin as output, and there are a resistor pulling it low. When I'am powering on the circuit the firmware doesn't start up until I disconnect NMI from ground. After that I can reconnect it, it'll work normally. I guess the MKL25 goes to an interrupt immediately after power up and don't get to the point where I'am configuring the pin as output. Can I disable interrupts immediately after power up? (but NMI means non-maskable, so it shouldn't be possible to disable it...)

Or simply just add an interrupt handler. I didn't get to that point in my learning.

Is it something like that?

extern "C" void NMI_Handler() { 
//here I should clear the interrupt !? }

How can I clear the interrupt?

I guess I should have used "Post a comment" instead of post answer...

posted by Bela Nagy 21 Jul 2013

So I was thinking a bit about it, reproduced the issue on my KL25Z (really one which can make you spend alot of time looking on wtf is going on).

You are right about the non-maskable part. Your idea of NMI_Handler was good, so I tried to globally disable irqs there: non-maskable. To be sure I enabled the red led, and it did light up, so the NMI_Handler was called, but even disabling all interrupts doesn't stop the NMI. Just clearing interrupt doesn't help either, since it is a low-level interrupt, it will be called as long as the pin is low. So I thought about what else you could do in the NMI_Handler, and suddenly Eureka!:

void NMI_Handler() {
    DigitalIn test(PTA4);

I got the extern void part above my main function. So simply in the NMI_Handler define it as a digital input. (Or digital output with whatever state you want, but for my test method I preferred an input), then it is set as GPIO instead of NMI. Later when user code runs your code overwrites it to whatever you want.

posted by Erik - 21 Jul 2013

Great idea, thank you! Will try it tomorrow. This is mouch better solution than to rewire my PCB :-)

Regards, Bela

posted by Bela Nagy 21 Jul 2013


Based on your help (pointing to the right file) I could manage to disable the NMI pin. I deleted the mbed.bld from my project and imported mbed-src. Then modifyed the file:

FOPT            EQU     0xFB

and compiled it. It is working ok!

thanks once more!

posted by Bela Nagy 22 Jul 2013

actually line no. is 181

posted by Bela Nagy 22 Jul 2013