Getting a Hard Fault when accessing PIT (FRDM-KE04Z)

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

Getting a Hard Fault when accessing PIT (FRDM-KE04Z)

535 Views
mikesilva
Contributor II

I'm guessing I've just missed something in the data sheet, but I keep getting a hard fault when accessing PIT_MCR.  I've reduced the code to a bare minimum:

void main(void)
 {
    PTA->PDDR |= (PORT_PUEL_PTBPE3_MASK | PORT_PUEL_PTCPE4_MASK | PORT_PUEL_PTCPE5_MASK); // enable RGB outputs
    PIT->MCR = 0;         // enable PIT
    do
    {
    } while (1);
 }

This compiles fine (I left out the necessary includes here), and the accesses to PTA work (I've gotten the RGB LED changing colors), but the hard fault happens on the access to PIT->MCR, or any other PIT register.  Here is the generated machine code:

PIT->MCR = 0; // enable PIT
     2200        movs r2, #0
     4B03        ldr r3, =0x40037000
     601A        str r2, [r3] ---- hard fault happens here

As seen, the address for PIT->MCR is correct, 0x40037000.  The toolset is Segger Embedded Studio.  If I do a RMW to change the PIT_MCR bit, the hard fault happens on the read access:

PIT->MCR &= ~2; // enable PIT
     4A04        ldr r2, =0x40037000
     6813        ldr r3, [r2] ---- hard fault happens here
     438B        bics r3, r1
     6013        str r3, [r2]  

Any ideas?

0 Kudos
2 Replies

437 Views
davidsherman
Senior Contributor I

Most likely you need to enable the bus clock to the module, it will hard fault if you read or write any of the registers without the bus clock enabled.  Set bit 1 of SIM_SCGC to enable the PIT module.

0 Kudos

437 Views
mikesilva
Contributor II

Thanks for the quick (and correct!) reply.  I figured there was some enable I was missing.  Now I just have to go back into the doc and figure out how I missed that.  Thanks again.

0 Kudos