AnsweredAssumed Answered

Hard Fault trying to access LPUART0->STAT

Question asked by Robert Poor on May 2, 2017
Latest reply on May 3, 2017 by Hui_Ma

I recently broke the serial I/O routines in my KL27Z : I'm now getting hard faults when I first try to access the LPUART0->STAT register in the LPUART_GetStatusFlags(base) method, specifically:

temp = base->STAT;

... where base = LPUART0 = 0x40054000.  

 

Any hints on what I might have failed to initialize?

 

Prior to calling LPUART_GetStatusFlags(base), I've done the following:

  // from BOARD_InitPins()

  CLOCK_EnableClock(kCLOCK_PortA);                           /* Port A Clock Gate Control: Clock enabled */

  PORT_SetPinMux(PORTA, PIN1_IDX, kPORT_MuxAlt2);            /* PORTA1 (pin 23) is configured as LPUART0_RX */

  PORT_SetPinMux(PORTA, PIN2_IDX, kPORT_MuxAlt2);            /* PORTA2 (pin 24) is configured as LPUART0_TX */

  SIM->SOPT5 = ((SIM->SOPT5 &

    (~(SIM_SOPT5_LPUART0TXSRC_MASK | SIM_SOPT5_LPUART0RXSRC_MASK))) /* Mask bits to zero which are setting */

      | SIM_SOPT5_LPUART0TXSRC(SOPT5_LPUART0TXSRC_LPUART_TX) /* LPUART0 Transmit Data Source Select: LPUART0_TX pin */

      | SIM_SOPT5_LPUART0RXSRC(SOPT5_LPUART0RXSRC_LPUART_RX) /* LPUART0 Receive Data Source Select: LPUART_RX pin */

    );


  // Serial initialization

  CLOCK_SetLpuart0Clock(0x03);  // MCGIRCLK (correct?)

  lpuart_config_t config;

  LPUART_GetDefaultConfig(&config);
  config.baudRate_Bps = baud_rate;
  config.enableTx = true;
  config.enableRx = true;

  LPUART_Init(LPUART0, &config, CLOCK_GetFreq(kCLOCK_McgInternalRefClk));

  // ### It gets a hard fault inside the call to LPUART_GetStatusFlags ###

  while (!(kLPUART_TxDataRegEmptyFlag & LPUART_GetStatusFlags(LPUART0))) {

    // busy wait for previous tx data...

  }

  // ... doesn't get here...

  LPUART_WriteByte(LPUART0, ch);

Outcomes