Go Down

Topic: mkrzero not programmable (Read 4158 times) previous topic - next topic

kobyfr

Hello.
I've followed some online advice in order to make the MKRZERO enter sleep, and wake on interrupt.
That code worked for me, and indeed the MKRZERO responded to a change (rise/fall) in the selected GPIO.
Now, I'm hardly able to re-program it.
I'm afraid I caused some kind of mini-brick, due to the MKRZERO being busy with the different delay() and _WFI commands

I'm getting failure messages of this kind
Code: [Select]
java.net.SocketException: error setting options
at java.net.TwoStacksPlainDatagramSocketImpl.join(Native Method)
at java.net.AbstractPlainDatagramSocketImpl.join(AbstractPlainDatagramSocketImpl.java:178)
at java.net.MulticastSocket.joinGroup(MulticastSocket.java:323)
at javax.jmdns.impl.JmDNSImpl.openMulticastSocket(JmDNSImpl.java:463)
at javax.jmdns.impl.JmDNSImpl.<init>(JmDNSImpl.java:420)
at javax.jmdns.JmDNS.create(JmDNS.java:81)
at cc.arduino.packages.discoverers.NetworkDiscovery.inetAddressAdded(NetworkDiscovery.java:211)
at cc.arduino.packages.discoverers.network.NetworkChecker.run(NetworkChecker.java:67)
at java.util.TimerThread.mainLoop(Timer.java:555)
at java.util.TimerThread.run(Timer.java:505)

Code: [Select]
Sketch uses 9544 bytes (3%) of program storage space. Maximum is 262144 bytes.
Forcing reset using 1200bps open/close on port COM10
processing.app.debug.RunnerException
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:160)
at cc.arduino.UploaderUtils.upload(UploaderUtils.java:78)
at processing.app.SketchController.upload(SketchController.java:709)
at processing.app.SketchController.exportApplet(SketchController.java:682)
at processing.app.Editor$DefaultExportHandler.run(Editor.java:2190)
at java.lang.Thread.run(Thread.java:745)
Caused by: processing.app.SerialException: Error touching serial port 'COM10'.
at processing.app.Serial.touchForCDCReset(Serial.java:87)
at cc.arduino.packages.uploaders.SerialUploader.uploadUsingPreferences(SerialUploader.java:144)
... 5 more
Caused by: jssc.SerialPortException: Port name - COM10; Method name - openPort(); Exception type - Port busy.
at jssc.SerialPort.openPort(SerialPort.java:164)
at processing.app.Serial.touchForCDCReset(Serial.java:81)
... 6 more
An error occurred while uploading the sketch



In what way is the code I entered the cause of this failure?
I'm able sometimes to free it from this programming failure, by pressing the reset while it tries to upload the hex, but I can't any more (I did another code change, which is probably even less agreeable with the upload process).

This is my code

Code: [Select]
// This sketch shows how to activate an interrupt handler in response to a falling edge on GPIO 0.
// After each interrupt (falling-edge), the on-board LED lights for 1 second, and then turns off.

#define CPU_ARM
#ifdef CPU_ARM
#else
# include <avr/sleep.h>
#endif

int wakePin = 1;                 // pin used for waking up
int led=LED_BUILTIN;

int event_counter = 0;

void wakeUpNow() {
  // execute code here after wake-up before returning to the loop() function
  // timers and code using timers (serial.print and more...) will not work here.
  // we don't really need to execute any special functions here, since we
  // just want the thing to wake up
}

void setup() {
  Serial.begin(9600);
  pinMode(wakePin, INPUT_PULLUP);
  pinMode(led, OUTPUT);
}


#ifdef CPU_ARM
  void sleepNow_start_armM0()
  {
      SCB->SCR |= 1<<2; // Enable deep-sleep mode
      __WFI();          // ARM processor wait for interrupt
  }
 
  void afterWakeup_armM0()
  {
      // Do nothing?
  }
#else
  void sleepNow_start_AVR()
  {
      set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here
      sleep_enable();          // enables the sleep bit in the mcucr register
      sleep_mode();            // here the device is actually put to sleep!!
  }
 
  void afterWakeup_AVR()
  {
      sleep_disable();         // first thing after waking from sleep: disable sleep...
  }
#endif

void sleepNow() {
    attachInterrupt(digitalPinToInterrupt(wakePin),wakeUpNow, RISING); // use interrupt X (pin Y) and run function
#   ifdef CPU_ARM   
        sleepNow_start_armM0();
        // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
        afterWakeup_armM0();
#   else
        sleepNow_start_AVR();
        // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
        afterWakeup_AVR();
#   endif       
    detachInterrupt(digitalPinToInterrupt(wakePin));      // disables interrupt X on pin Y so the wakeUpNow code will not be executed during normal running time.
}

void loop() {
  //Serial.println("loop start");
  int i = 5;
  while (i--)
  {
    digitalWrite(led, HIGH);
    //Serial.println("led HIGH");
    delay(100);
    digitalWrite(led, LOW);
    //Serial.println("led LOW");
    delay(100);
  }
  sleepNow();     // sleep function called here
}

kobyfr

I was able to reprogram it, but attaching the RESET pin to GND while the uploading was starting, and detaching it from GND when the IDE started connected to the serial port.
Modifying the code by setting a limit on the number of interrupts, preventing any further delay()or _WFI(), allows me to easily reprogram it.
I guess I should avoid leaving the processor in _WFI() coupled with deep_sleep.

kobyfr

Real answer : had to press reset twice, while the IDE was trying to connect and program the device.

monikah123

Thanks for posting. I've got an MKRZero too. Lots to learn.

robbideloose

Real answer : had to press reset twice, while the IDE was trying to connect and program the device.
Old post, I know, but you saved my day! Got my RocketScream Mini Ultra Pro and screwed it up within 30 minutes after unpacking. Set up alarm timer and sleep without including the delay in the setup.

Double tab did the trick!

Go Up