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

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

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

1,187 次查看
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 项奖励
回复
2 回复数

1,089 次查看
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 项奖励
回复

1,089 次查看
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 项奖励
回复