AnsweredAssumed Answered

Why does BME operation for GPIO causes the hard fault?

Question asked by Yasuhiko Koumoto on Jun 30, 2016
Latest reply on Jul 1, 2016 by Yasuhiko Koumoto

Hello experts,

 

I have a question regarding BME operation for GPIO.
I am using FRDM-KL25Z and KSDK 1.3.
The following code causes the hard fault when BME accessed GPIO areas.
I think some register setting would be lost, but I cannot find what it is.
The codes had worked with the previoys sample code of KL25_SC environment.
Can anyone help me?


Best regards,
Yasuhiko Koumoto.

 

#define BME_BFI_MASK(BIT,WIDTH)  (1<<28) | (BIT<<23) | ((WIDTH-1)<<19)
#define BME_BFI_W(addr, bit, width)  \
          (*(volatile uint32_t*)((uint32_t)addr | BME_BFI_MASK(bit,width)))
void my_wait(void)
{
  volatile int i;
  for(i=0;i<0x50000;i++);
}
int main(void)
{
    SIM_SCGC5 |= SIM_SCGC5_PORTB_MASK | SIM_SCGC5_PORTD_MASK;
    // RED LED Initialization
    PORTB_PCR18 &= ~PORT_PCR_MUX_MASK;
    PORTB_PCR18 |= PORT_PCR_MUX(1);
    GPIOB_PDDR |= (1<<18); 
    // Yellow LED Initialization
    PORTB_PCR19 &= ~PORT_PCR_MUX_MASK;
    PORTB_PCR19 |= PORT_PCR_MUX(1);
    GPIOB_PDDR |= (1 << 19);
    // Blue LED Initialization
    PORTD_PCR1 &= ~PORT_PCR_MUX_MASK;
    PORTD_PCR1 |= PORT_PCR_MUX(1);
    GPIOD_PDDR |= (1 << 1);  

    while(1) {

        BME_BFI_W(&GPIOB_PCOR, 18, 1) = (1<<18); 
        BME_BFI_W(&GPIOB_PSOR, 19, 1) = (1<<19);
        BME_BFI_W(&GPIOD_PSOR,  1, 1) = (1<<1); 
        my_wait();
        BME_BFI_W(&GPIOB_PSOR, 18, 1) = (1<<19); 
        BME_BFI_W(&GPIOB_PCOR, 19, 1) = (1<<18); 
        BME_BFI_W(&GPIOD_PSOR,  1, 1) = (1<<1); 
        my_wait(); 
        BME_BFI_W(&GPIOB_PSOR, 18, 1) = (1<<18);
        BME_BFI_W(&GPIOB_PSOR, 19, 1) = (1<<19);
        BME_BFI_W(&GPIOD_PCOR,  1, 1) = (1<<1);
        my_wait();  
        BME_BFI_W(&GPIOB_PSOR, 18, 1) = (1<<18);
        BME_BFI_W(&GPIOB_PSOR, 19, 1) = (1<<19);
        BME_BFI_W(&GPIOD_PSOR,  1, 1) = (1<<1); 
        my_wait(); 
    } 
}

Outcomes