Open Control Panel
Press Windows + R, type control, and hit Enter.
Go to Power Options
Navigate to:
Hardware and Sound → Power Options.
Edit your active power plan
Click “Change plan settings” next to your selected plan.
Open advanced settings
Click “Change advanced power settings.”
Find USB settings
Expand USB settings → USB selective suspend setting.
Disable it
Set both On battery and Plugged in to Disabled.
Apply
Click Apply → OK.