AnsweredAssumed Answered

LPCXpresso802 board stuck in flash error

Question asked by James Smith on Mar 14, 2019
Latest reply on Mar 15, 2019 by James Smith

I'm working on the Wakeup Timer for the LPC802 but have crashed my board.  The built-in debugger will no longer connect, giving the following error:

 

ProgramPage (0x0, 0x100003D8, 0x80) status 0x1 - driver reported driver error - ONCHIP driver rc 10 - Source and destination data not equal

Closing flash driver LPC80x_16.cfx
Target error from Commit Flash write: Ef(49): Flash driver operation gave error.
GDB stub (crt_emu_cm_redlink) terminating - GDB protocol problem: Pipe has been closed by GDB.

 

I was modifying the CTimer example from the NXP code examples for the LPC802 (LPC802-EX-CODE-MCUXPRESSO) in order to just get the WKT working.  The goal is to use the WKT to drive a LED via the WKT interrupt.  I removed all of the CTimer code in the example, only leaving the WKT code.  I'm also converting the register calls to the values set in LPC802.h, the header file that comes with the SDK for the board (e.g. SYSCON->… instead of LPC_SYSCON->…)

 

I'm looking for suggestions for 

 

1. How to reset the board so it stops hanging.  (I'm assuming that I should use an external debugger via the SWD port)

 

2. What to change about the WKT initialization or the ISR so that it prevents this issue again in the future.

 

thanks!

 

James

 

 

void WKT_Config() {
 // Step 1: In the SYSAHBCLCKCTRL register, set bit 9 to enable the clock to the reg. interface
 // also enable GPIO for the LED.
 SYSCON->SYSAHBCLKCTRL0 |= (SYSCON_SYSAHBCLKCTRL0_WKT_MASK|SYSCON_SYSAHBCLKCTRL0_GPIO0_MASK); //(WKT|GPIO0);// Enable some clocks
 // Power-up the LPOSC
 // PD: Power config register.  Active Low: Bit 6 set to 0 (zero) makes the Low Power Osc. turn ON.
 SYSCON->PDRUNCFG &= ~(SYSCON_PDRUNCFG_LPOSC_PD_MASK);      // Power-up the LPOSC
 // Enable the LPOSC clock to the WKT
 // Enable clock for the Wakeup Timer.
 // Bit 1 of LPOSCCLKEN set to 1 to enable. (Section 6.6.8 of the User Manual)
 SYSCON->LPOSCCLKEN |= (1<<SYSCON_LPOSCCLKEN_WKT_SHIFT);  // Enable the LPOSC clock to the WKT
 // Step 2. Clear the WKT reset using the PRESETCTRL register
 // (Peripheral Reset Control 0 Register)
 // WKT: bit 9.  0 is "assert" the reset. 1 is "clear" the reset.
 SYSCON->PRESETCTRL0 &= (SYSCON_PRESETCTRL0_WKT_RST_N_MASK);   // "0": Assert the reset
 SYSCON->PRESETCTRL0 |= ~(SYSCON_PRESETCTRL0_WKT_RST_N_MASK);  // "1": Clear the reset
 // Step 3. Connect WKT interrupt to #15 in NVIC
 NVIC_EnableIRQ(WKT_IRQn);                 // Enable the WKT interrupt in the NVIC
 // Step 4. Enable the Clock source
 //          a) Enable the low power oscillator in PDRUNCFG register if you're using that clock source
 //   b) Enable the FRO and FRO output in PDRUNCFG register if used as the clock source
 //          c) (otherwise ext. clock source via PIO0_11 and switch matrix PINENABLE0 and CTRL registers)
 //LPC_WKT->CTRL = DIVIDED_IRC<<WKT_CLKSEL;// Select fro_clk/16 as WKT clock source
 WKT->CTRL |= (1<<WKT_CTRL_CLKSEL_MASK); // Set bit 0 to 1 for Low power clock. //LOW_POWER_OSC<<WKT_CLKSEL;// Select LPOSC as WKT clock source (approx. 1 MHz)
 WKT->COUNT = WKT_RELOAD;              // Start the WKT, counts down WKT_RELOAD clocks then interrupts

  // Set data direction on
  // GPIO to Output.
  GPIO->DIRSET[0] = (1UL<<8);
  // Turn on the LED.
  GPIO->CLR[0] = (1UL<<8);
}

 

 

// Function name: WKT_IRQHandler (interrupt service routine)
// Description:   WKT interrupt service routine.
//                Toggles a pin, restarts the WKT.
// Parameters:    None
// Returns:       Void
void WKT_IRQHandler(void) {
  WKT->CTRL |= 1<<WKT_CTRL_ALARMFLAG_SHIFT;         // Clear the interrupt flag
  WKT->COUNT = WKT_RELOAD;               // Restart the WKT
  // Toggle the LED
  GPIO->NOT[0] = (1UL<<8);

  return;
}

 

//
// main routine
//
int main(void) {

  // WKT: Wake Timer
  // Configure and start the WKT, also configures an output pin, which toggles every WKT interrupt
  WKT_Config();
  while(1) { // Have a tequila
   asm("NOP");
  } // end of while 1
} // end of main

Attachments

Outcomes