Go Down

Topic: [SOLVED] Genuino MKR1000 stuck on "Uploading..." (Read 2512 times) previous topic - next topic

noamav

Aug 30, 2016, 09:41 pm Last Edit: Aug 30, 2016, 10:29 pm by noamav
I just got my new Genuino MKR1000 yesterday, fiddled with it for a bit and it seemed to work sell.

I tried to use one of the Core M0's timers, searched online and found the following solution:
https://forum.arduino.cc/index.php?topic=397851.0

I made some minor changes, manly added prints and changed the value of REG_TC4_COUNT8_CC0 from 0x55 to 0xFF, hoping to increase the time between two interrupts.

Code: [Select]


const int LedPin = 6;


void setup()
{
  Serial.begin(9600);
  
  pinMode(LedPin, OUTPUT);
  
  digitalWrite(LedPin, LOW);

    // Set up the generic clock (GCLK4) used to clock timers
  REG_GCLK_GENDIV = GCLK_GENDIV_DIV(3) |          // Divide the 48MHz clock source by divisor 3: 48MHz/3=16MHz
                    GCLK_GENDIV_ID(4);            // Select Generic Clock (GCLK) 4
  while (GCLK->STATUS.bit.SYNCBUSY);              // Wait for synchronization

  REG_GCLK_GENCTRL = GCLK_GENCTRL_IDC |           // Set the duty cycle to 50/50 HIGH/LOW
                     GCLK_GENCTRL_GENEN |         // Enable GCLK4
                     GCLK_GENCTRL_SRC_DFLL48M |   // Set the 48MHz clock source
                     GCLK_GENCTRL_ID(4);          // Select GCLK4
  while (GCLK->STATUS.bit.SYNCBUSY);              // Wait for synchronization

  // Feed GCLK4 to TC4 and TC5
  REG_GCLK_CLKCTRL = GCLK_CLKCTRL_CLKEN |         // Enable GCLK4 to TC4 and TC5
                     GCLK_CLKCTRL_GEN_GCLK4 |     // Select GCLK4
                     GCLK_CLKCTRL_ID_TC4_TC5;     // Feed the GCLK4 to TC4 and TC5
  while (GCLK->STATUS.bit.SYNCBUSY);              // Wait for synchronization

  REG_TC4_CTRLA |= TC_CTRLA_MODE_COUNT8;           // Set the counter to 8-bit mode
  while (TC4->COUNT8.STATUS.bit.SYNCBUSY);        // Wait for synchronization

  REG_TC4_COUNT8_CC0 = 0xFF;                      // Set the TC4 CC0 register to some arbitary value
  while (TC4->COUNT8.STATUS.bit.SYNCBUSY);        // Wait for synchronization
  REG_TC4_COUNT8_CC1 = 0xAA;                      // Set the TC4 CC1 register to some arbitary value
  while (TC4->COUNT8.STATUS.bit.SYNCBUSY);        // Wait for synchronization
  REG_TC4_COUNT8_PER = 0xFF;                      // Set the PER (period) register to its maximum value
  while (TC4->COUNT8.STATUS.bit.SYNCBUSY);        // Wait for synchronization

  //NVIC_DisableIRQ(TC4_IRQn);
  //NVIC_ClearPendingIRQ(TC4_IRQn);
  NVIC_SetPriority(TC4_IRQn, 0);    // Set the Nested Vector Interrupt Controller (NVIC) priority for TC4 to 0 (highest)
  NVIC_EnableIRQ(TC4_IRQn);         // Connect TC4 to Nested Vector Interrupt Controller (NVIC)

  REG_TC4_INTFLAG |= TC_INTFLAG_MC1 | TC_INTFLAG_MC0 | TC_INTFLAG_OVF;        // Clear the interrupt flags
  REG_TC4_INTENSET = TC_INTENSET_MC1 | TC_INTENSET_MC0 | TC_INTENSET_OVF;     // Enable TC4 interrupts
  // REG_TC4_INTENCLR = TC_INTENCLR_MC1 | TC_INTENCLR_MC0 | TC_INTENCLR_OVF;     // Disable TC4 interrupts
 
  REG_TC4_CTRLA |= TC_CTRLA_PRESCALER_DIV64 |     // Set prescaler to 64, 16MHz/64 = 256kHz
                   TC_CTRLA_ENABLE;               // Enable TC4
  while (TC4->COUNT8.STATUS.bit.SYNCBUSY);        // Wait for synchronization
}

void loop()
{

    delay(200);

  Serial.println("N");
}

void TC4_Handler()                              // Interrupt Service Routine (ISR) for timer TC4
{    
  // Check for overflow (OVF) interrupt
  if (TC4->COUNT8.INTFLAG.bit.OVF && TC4->COUNT8.INTENSET.bit.OVF)            
  {
    // Put your timer overflow (OVF) code here:    
    // ...
  
    REG_TC4_INTFLAG = TC_INTFLAG_OVF;         // Clear the OVF interrupt flag
  }

  // Check for match counter 0 (MC0) interrupt
  if (TC4->COUNT8.INTFLAG.bit.MC0 && TC4->COUNT8.INTENSET.bit.MC0)            
  {

    static int status = HIGH;
    status = !status;
    digitalWrite(LedPin, LOW);
  Serial.println("INT");
  
    REG_TC4_INTFLAG = TC_INTFLAG_MC0;         // Clear the MC0 interrupt flag
  }

  // Check for match counter 1 (MC1) interrupt
  if (TC4->COUNT8.INTFLAG.bit.MC1 && TC4->COUNT8.INTENSET.bit.MC1)          
  {
    // Put your counter compare 1 (CC1) code here:
    // ...
  
    REG_TC4_INTFLAG = TC_INTFLAG_MC1;        // Clear the MC1 interrupt flag
  }
}



After uploading the sketch, the Mkr1000 seems to be stuck with the current code, unable to be re-flashed.
The computer sets the COM ports correcrtly, and when opening the serial monitor to the device's port, it's flooded with "INT" prints (printed in the interupt service routine).

The status bar is stuck on "Uploading...".
After about a minute the upload process stops.
The upload verbose output is:



Code: [Select]


Forcing reset using 1200bps open/close on port COM5
****** The log stops here for about 20 seconds *****
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
PORTS {COM1, COM5, } / {COM1, COM5, } => {}
Uploading using selected port: COM5
C:\Users\*\AppData\Local\Arduino15\packages\arduino\tools\bossac\1.6.1-arduino/bossac.exe -i -d --port=COM5 -U true -i -e -w -v C:\Users\*~1\AppData\Local\Temp\builda5bd59b160197c1338ec9fdd7c2830fa.tmp/Blink.ino.bin -R




Pressing the reset button during the upload, in various timings, didn't help.

One time I received the following error when trying to upload the sketch:

Code: [Select]

processing.app.debug.RunnerException
 at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:159)
 at cc.arduino.UploaderUtils.upload(UploaderUtils.java:78)
 at processing.app.Sketch.upload(Sketch.java:1187)
 at processing.app.Sketch.exportApplet(Sketch.java:1160)
 at processing.app.Sketch.exportApplet(Sketch.java:1132)
 at processing.app.Editor$DefaultExportHandler.run(Editor.java:2409)
 at java.lang.Thread.run(Thread.java:745)
Caused by: processing.app.SerialException: Error touching serial port 'COM5'.
 at processing.app.Serial.touchForCDCReset(Serial.java:87)
 at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:143)
 ... 6 more
Caused by: jssc.SerialPortException: Port name - COM5; Method name - openPort(); Exception type - Port busy.
 at jssc.SerialPort.openPort(SerialPort.java:164)
 at processing.app.Serial.touchForCDCReset(Serial.java:81)
 ... 7 more




What shall I do?
Thanks!

ballscrewbob

Did you try the "double tap" on the reset button ?

That places it in bootloader mode and often allows you to upload a sketch again.
It may show a different port when you do that so use the new one for an upload and you have to double tap quite quickly too.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

noamav

Did you try the "double tap" on the reset button ?

That places it in bootloader mode and often allows you to upload a sketch again.
It may show a different port when you do that so use the new one for an upload and you have to double tap quite quickly too.
It worked!
I never thought it'd be so simple
Thanks amigo, you're the best!

ballscrewbob

WOW you must have been sat waiting for that answer LOL
I Asked for this thread to be moved to the MKR section too.
It may not be the answer you were looking for but its the one I am giving based on either experience, educated guess, google (who would have thunk it ! ) or the fact that you gave nothing to go with in the first place so I used my wonky crystal ball.

shanefromfargo

Thank you! I was stuck on this for hours! I had the exact same thing happen to me. I have ran many different programs on my MKR1000 and on one sketch it just stopped working. I tried restarting the computer uninstalling arduino studio, everything. Simply double tapping on the reset button did the trick!

Go Up