ARM Cortex-M4 K60N512 - Hard Fault

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

ARM Cortex-M4 K60N512 - Hard Fault

1,073 Views
DarkInsanePyro
Contributor I

I am comming from the smaller 8/16 bit microcontrollers from Microchip and Atmel, and I got to say things have gone smoother. None the less I am trying. Anyway, I decided to write in pure C rather than a mix of assembly and C thinking it'd smooth the process. Anyway, I seem to keep running into a problem and I am not exactly sure of the issue. I am just trying to get used to the peripherals that the microcontroller comes with. The problem is that it keeps jumping me to isr_default and I am trying to track down the problem. In assembly, I noticed this would occure when a 32-bit encoded instruction gets executed in a word misaligned address (not data relavent). I figure this is probable, only word aligned instructions for 32-bit encoded ones. What I was suprised by is that the compiler generates what I thought was misaligned code too. Not sure what to make of it. The following is just a bit of code I have been dabbling with. I just think I am starting to get lost in the documentation... I have 7 PDFs open currently, and I think I am mixing them up. Thank you for your time.

 

#include "derivative.h"void main(){ //================================================== // setup hardware //================================================== // Configure Clock //MCG_C2 |= MCG_C2_IRCS_MASK; //MCG_C1 = (MCG_C1 & MCG_C1_CLKS_MASK) + (0x1 << MCG_C1_CLKS_SHIFT);   // Configure GPIO SIM_SCGC5 |= SIM_SCGC5_PORTC_MASK; PORTC_PCR18 = PORT_PCR_MUX(0x1); GPIOC_PDDR = (1 << 18);  // Configure PIT PIT_MCR = 0x0; PIT_LDVAL0 = 0xF4240; PIT_TCTRL0 = (0 << PIT_TCTRL_TIE_SHIFT) | (1 << PIT_TCTRL_TEN_SHIFT);  //================================================== // loop //================================================== while(1) {  if(PIT_TFLG0 & PIT_TFLG_TIF_MASK)  {   PIT_TFLG0 |= PIT_TFLG_TIF_MASK;   GPIOC_PTOR |= (1 << 18);  } }}// these seem to not get called... oh well.void HardFault(){ __asm("nop");}void MemFault(){ __asm("nop");}void BusFault(){ __asm("nop");}void UsageFault(){ __asm("nop");}

 Edit:

Let me make note I am using CodeWarrior 10.1.

0 Kudos
2 Replies

502 Views
mjbcswitzerland
Specialist V

HI

 

Have you powered up the PIT (like you have the GPIO)? If not it will give a hard fault each time it tries to access the powered-down peripheral module.

 

The Cortex M4 uses Thumb-2 mode and all call addresses are misaligned (odd addresses) to force the processor to this mode. Therefore this is normal.

 

Regards

 

Mark

 

 

0 Kudos

502 Views
DarkInsanePyro
Contributor I

I am sorry, you are absolutely correct. I have failed to enable the clocking to the PIT module and thus recieved the hard-fault. I am just used to a disabled module being it's "off" state rather than actually shutting it completely down from an external switch (clock gate). Thank you.

 

From what I understand about what you say, I would believe your talking about PC[0] (bit 0 of PC) where it would be set to 1, or such that to indicate the type of instruction as far as I have read. What I am weary about is how does it execute a 32-bit instruction when it is not mod-4 aligned? I assume it would have to be in order to fetch the whole instruction in a single read. Just trying to understand how these devices work on the inside. Thank you for your patience. Also, I noted that while writing in assembler, even without any modules but just basic i/o to the ram, etc., there would be problems if I didn't force wide instructions rather than narrow (by appending w or .w). Example, executing a breakpoint instruction (16-bit), I would append afterwods nop.n so the following instructions were word-aligned, else the system would break to the isr_default.

 

Like I said, thank you for being patient. I am just trying to grasp how the core of this device works. I'd rather know than just have it work and hope for the best. I know the PIC devices basically inside out.

0 Kudos