Can NMI_b be disabled on KL02Z at startup? I have pull down and am using it for ADC capture. The pulldown causes the NMI_b.

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

Can NMI_b be disabled on KL02Z at startup? I have pull down and am using it for ADC capture. The pulldown causes the NMI_b.

858 Views
clivepalmer
Contributor III

I want to use PTB5 as one of the ADC channels. In the HW design there is a pulldown fitted. Out of reset this pin defaults to NMI_b and hence causes the device to be stuck.

Can NMI_b be disabled on KL02Z at startup? I have tried setting the following in my kinetis_sysinit.c.

NV_FOPT &= ~NV_FOPT_NMI_DIS_MASK;

SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK;

PORTB_PCR5 = PORT_PCR_MUX(1);

Maybe this is not possible and I just cant use this pin. Can it be done and if so what am I doing wrong.

Thanks

Clive

0 Kudos
4 Replies

533 Views
mjbcswitzerland
Specialist V

Clive

NV_FOPT &= ~NV_FOPT_NMI_DIS_MASK;

This will not work since the value is read in from the flash configuration area on reset.

If you set the pattern correctly in the flash configuration area (0x400..0x40f) it will disable the NMI function out of reset.

Regards

Mark

533 Views
clivepalmer
Contributor III

Hi Mark,

Thanks for taking time to reply. How do I set the pattern in the flash configuration area? I'm not that experienced with this chip and if this is in the linker file, which I suspect it is, then that's not a place I have really delved or feel that comfortable doing. I don't want to get myself locked out of flash or something horrible.

Sometimes a little knowledge is dangerous in the wrong hands. :smileyhappy:

0 Kudos

533 Views
mjbcswitzerland
Specialist V

Clive

Each time you generate a binary file simply view the area in a binary viewer to ensure that you haven't put an unwanted pattern there. If you are not happy with the content don't load it and you can't cause any damage.

Here's how it is done in the uTasker project (assuming GCC compiler).

typedef struct stKINETIS_FLASH_CONFIGURATION                        // loaded from FLASH 0x00000400 at reset

{

unsigned char  ucBackdoorComparisonKey[8];
unsigned char  ucProgramFlashProtection[4];
unsigned char  ucFlashSecurity;
unsigned char  ucNonvolatileOption;
unsigned char  ucEEPROM_protection;
unsigned char  ucDataFlashProtection;

} KINETIS_FLASH_CONFIGURATION;

const KINETIS_FLASH_CONFIGURATION __attribute__((section(".f_config"))) __flash_config

= {

    KINETIS_FLASH_CONFIGURATION_BACKDOOR_KEY,

    KINETIS_FLASH_CONFIGURATION_PROGRAM_PROTECTION,

    KINETIS_FLASH_CONFIGURATION_SECURITY,

    KINETIS_FLASH_CONFIGURATION_NONVOL_OPTION,

    KINETIS_FLASH_CONFIGURATION_EEPROM_PROT,

    KINETIS_FLASH_CONFIGURATION_DATAFLASH_PROT

};

For a KL device a header file configures the project settings as required:

// FLASH configuration settings

//

#define BACKDOOR_KEY_0    0

#define BACKDOOR_KEY_1    0

#define BACKDOOR_KEY_2    0

#define BACKDOOR_KEY_3    0

#define BACKDOOR_KEY_4    0

#define BACKDOOR_KEY_5    0

#define BACKDOOR_KEY_6    0

#define BACKDOOR_KEY_7    0

#define PROTECTION_0      0xff                                          // not protected

#define PROTECTION_1      0xff

#define PROTECTION_2      0xff

#define PROTECTION_3      0xff

#define KINETIS_FLASH_CONFIGURATION_BACKDOOR_KEY      {BACKDOOR_KEY_0, BACKDOOR_KEY_1, BACKDOOR_KEY_2, BACKDOOR_KEY_3, BACKDOOR_KEY_4, BACKDOOR_KEY_5, BACKDOOR_KEY_6, BACKDOOR_KEY_7}

#define KINETIS_FLASH_CONFIGURATION_PROGRAM_PROTECTION {PROTECTION_0, PROTECTION_1, PROTECTION_2, PROTECTION_3}

#define KINETIS_FLASH_CONFIGURATION_SECURITY          (FTFL_FSEC_SEC_UNSECURE | FTFL_FSEC_FSLACC_GRANTED | FTFL_FSEC_MEEN_ENABLED | FTFL_FSEC_KEYEN_ENABLED)

#define KINETIS_FLASH_CONFIGURATION_NONVOL_OPTION  (FTFL_FOPT_LPBOOT_CLK_DIV_8 | FTFL_FOPT_RESET_PIN_ENABLED)

#define KINETIS_FLASH_CONFIGURATION_EEPROM_PROT        0xff

#define KINETIS_FLASH_CONFIGURATION_DATAFLASH_PROT    0xff

Note that the reset pin is configured for the reset function but the NMI is not enabled.

The linker script needs to define the area, which can be done be defining a section

  __Fconfig_segment_start__ = 0x00000400;

  __Fconfig_segment_end__  = 0x00000410;

  .f_config ALIGN(__Fconfig_segment_start__ , 4) :

  {

    __flash_config = .;

    KEEP(*(.f_config .f_config.*))

  }

I have attached a linker script file for the KL02 which does this.

You can get complete code from http://www.utasker.com/forum/index.php?topic=1721.0

Regards

Mark

P.S. There are some configurations bits there that are not used in the KL02 (eg. data flash protection) but the complete solution adapts itself to the chip type so they are included for compatibility (but just set to 0xff). The complete solution is also compatible with various IDEs/compilers but I just picked out the GCC type here for clarity since most people will be using that (CW, KDS etc.)

533 Views
clivepalmer
Contributor III

Thanks. I will take some time to go through this. Hopefully I wont have any more questions.

The help is much appreciated.

Clive

0 Kudos