Author Topic: Did cli() just destroyed everything?  (Read 1189 times)

0 Members and 1 Guest are viewing this topic.

Offline ppTRNTopic starter

  • Regular Contributor
  • *
  • Posts: 127
  • Country: it
Did cli() just destroyed everything?
« on: May 21, 2023, 07:06:25 pm »
Hi, I uploaded a very stupid program into my arduino yun (Atmega16U4)

Code: [Select]
void loop(){
   cli();
}

As soon as i uploaded it windows notified me that "usb device not responding" and told me that it might not be funcional. Tried to upload blink(), reset and immediatly try to upload, tried to reupload bootloader, nothing. Did I screw up?
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 13132
Re: Did cli() just destroyed everything?
« Reply #1 on: May 21, 2023, 08:41:53 pm »
cli() disables interrupts. Disabling interrupts crashes the USB link to the host after approximately 1ms when the Arduino fails to respond to USB link activity, resulting in a 'dirty' disconnect.

Try pressing the Arduino reset button twice in quick succession.  It should then enter USB bootloader mode, and you then have about eight seconds to select the correct COM port and upload a good sketch (e.g. 'Blink') before it drops out of bootloader mode and starts your FUBARed code.
 
The following users thanked this post: SiliconWizard, ppTRN

Offline barshatriplee

  • Regular Contributor
  • *
  • !
  • Posts: 130
  • Country: bd
Re: Did cli() just destroyed everything?
« Reply #2 on: May 22, 2023, 01:35:27 am »
Uploading a program that disables interrupts (cli()) in the loop() function of your Arduino Yun sketch can indeed cause issues with the board's functionality. Disabling interrupts can lead to a situation where the board becomes unresponsive or behaves unexpectedly.
 

Online brucehoult

  • Super Contributor
  • ***
  • Posts: 4538
  • Country: nz
Re: Did cli() just destroyed everything?
« Reply #3 on: May 22, 2023, 04:24:51 am »
It's not even that it's in the loop() function. Even if it was in setup(), disabling interrupts and not re-enabling them will prevent responding to external interrupt-driven communication -- or even timers.

You should always endeavour to put as few instructions as possible between cli() and sei().
 
The following users thanked this post: Someone

Offline ppTRNTopic starter

  • Regular Contributor
  • *
  • Posts: 127
  • Country: it
Re: Did cli() just destroyed everything?
« Reply #4 on: May 22, 2023, 11:15:26 am »
Try pressing the Arduino reset button twice in quick succession.  It should then enter USB bootloader mode, and you then have about eight seconds to select the correct COM port and upload a good sketch

Thanks, I did not know this boot mode. I will try it as soon as possible.
 

Offline ppTRNTopic starter

  • Regular Contributor
  • *
  • Posts: 127
  • Country: it
Re: Did cli() just destroyed everything?
« Reply #5 on: May 22, 2023, 01:55:18 pm »
It worked! Thank you very much
 
The following users thanked this post: Ian.M


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf