Skip to content

Don't reallocate USB buffers if already allocated #295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2018

Conversation

facchinm
Copy link
Member

USB Configuration was meant to run only once, but if the board comes back from standby the host can reconfigure the device again.
Probably a cleaner patch could be free()-ing the buffers on standby() to release the memory but at least we don't leak anymore.

Fixes #293

USB Configuration was meant to run only once, but if the board comes back from standby the host can reconfigure the device again.
Probably a cleaner patch could be free()-ing the buffers on standby() to release the memory but at least we don't leak anymore.

Fixes arduino#293
@ArduinoBot
Copy link

✅ Build completed.

⬇️ Build URL: http://downloads.arduino.cc/PR/samd/package_samd-b185_index.json

ℹ️ To test this build:

  1. Open the Preferences of the Arduino IDE.
  2. Add the Build URL above in the Additional Boards Manager URLs field, and click OK.
  3. Open the Boards Manager (menu Tools->Board->Board Manager...)
  4. Install Arduino SAMD core - Pull Request Don't reallocate USB buffers if already allocated #295
  5. Select one of the boards under SAMD Pull Request Don't reallocate USB buffers if already allocated #295 in Tools->Board menu
  6. Compile/Upload as usual

@Terryp44
Copy link

Hi, Thanks a lot for making this change. The SerialUSB port will only work after the first sleep cycle. The next sleep cycle, the SerialUSB port does not communicate. Reconnecting the USB cable does not fix it either. A board soft reset allows port to work again. however Putty does not lose connection ....just does not communicate. Then if the USB cable is unplugged and then plugged back in, putty displays a writing error.but device manager shows Arduino zero is connected.

@facchinm
Copy link
Member Author

I'm using this sketch to test the fix

#include "ArduinoLowPower.h"

extern "C" char *sbrk(int i);
int FreeRam (void)
{
char stack_dummy = 0;
return &stack_dummy - sbrk(0);
}

void setup() {
  // put your setup code here, to run once:
  SerialUSB.begin(115200);
  while (!SerialUSB){}
}

void loop() {
  // put your main code here, to run repeatedly:
  SerialUSB.println(FreeRam());
  LowPower.sleep(1000);
}

and I can get the prints before and after sleep(). My host PC is Linux so the different behaviour can be easily explained with the different USB stack.
Are you using version 1.2.0 of LowPower library?

@Terryp44
Copy link

Thanks Again, Well same behavior as before, using your sketch. I am using custom hardware, so there could be something there. Our LowPower Lib is the same. Or my PC just does not like re-connecting after CPU sleep.
Thanks for your help. the memory leak is fixed!!!

@facchinm facchinm requested a review from cmaglie January 18, 2018 17:43
@sandeepmistry sandeepmistry merged commit 2bb5406 into arduino:master Jan 25, 2018
@sandeepmistry sandeepmistry added this to the Release 1.6.18 milestone Jan 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants