Hard Fault in running custom code in FRDM KL25Z

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

Hard Fault in running custom code in FRDM KL25Z

Jump to solution
732 Views
zoromoth
Contributor II

I am new to MCUXpresso but have had some experience with LPCXpresso. I wanted to write my own code to run with FRDM-KL25Z. I am using a PE-Micro debugger. I wanted to custom program the registers on the chip as per the user guide using MCUXpresso's inbuilt register naming/address layout. Attached below is my program:

#include <stdio.h>
#include "board.h"
#include "peripherals.h"
#include "pin_mux.h"
#include "clock_config.h"
#include "MKL25Z4.h"
#include "fsl_debug_console.h"
/* TODO: insert other include files here. */

/* TODO: insert other definitions and declarations here. */

/*
* @brief Application entry point.
*/
int main(void) {

/* Init board hardware. */
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitBootPeripherals();
/* Init FSL debug console. */
BOARD_InitDebugConsole();

//uint8_t msba0,lsba0;
PORTE->PCR[22] &= ~((1<<10)|(1<<9)|(1<<8));
PORTE->PCR[22] |= (1<<10);
PORTE->PCR[23] &= ~(1<<10)|(1<<9)|(1<<8);
PORTE->PCR[23] |= (1<<10);


UART2->BDL |= 0x1a;
UART2->C2 |=(1<<3)|(1<<2);

//lsba0=0x77;
//msba0=0xad;

while(1)
{
UART2->D=0x77;
while(~((UART2->S1 & (1<<6))>>5));
UART2->D=0xad;
while(~((UART2->S1 & (1<<6))>>5));
}

return 0;
return 0 ;
}

However, upon execution the standard function runs but my code starting from PORTE->PCR[22]... causes the hard fault handler to be invoked. I have attached my entire SDK configuration below. Does anyone have a sample project for running the above code. Any help would be greatly appreciated!!!

1 Solution
645 Views
BlackNight
NXP Employee
NXP Employee

Your pin muxing lacks the

CLOCK_EnableClock(kCLOCK_PortE);

If you don't enable the clock for your port, you will get a hard fault.

See for example the tutorial in NXP Pins Tool: Clock Gates and Controlling the Bits | MCU on Eclipse 

I hope this helps,

Erich

View solution in original post

2 Replies
646 Views
BlackNight
NXP Employee
NXP Employee

Your pin muxing lacks the

CLOCK_EnableClock(kCLOCK_PortE);

If you don't enable the clock for your port, you will get a hard fault.

See for example the tutorial in NXP Pins Tool: Clock Gates and Controlling the Bits | MCU on Eclipse 

I hope this helps,

Erich

645 Views
zoromoth
Contributor II

Thank you so much. I set the SIM module register and it worked. This register was not present in LPC IC's with which I had experience. Something new on Kinetis IC's.

0 Kudos