Skip to content

Commit a155e58

Browse files
committed
On some connections (Serial, >9600 baud) XON/XOFF flow control is too slow to reliably throttle data transfer when writing files,
and data can be lost. By default we add a delay after each write to Storage to help avoid this, but if your connection is stable you can turn this off and greatly increase write speeds.
1 parent f578c36 commit a155e58

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

core/serial.js

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,32 @@ To add a new serial device, you must add an object to
6262
defaultValue : 9600,
6363
});
6464
Espruino.Core.Config.add("SERIAL_IGNORE", {
65-
section : "Communications",
66-
name : "Ignore Serial Ports",
67-
description : "A '|' separated list of serial port paths to ignore, eg `/dev/ttyS*|/dev/*.SOC`",
68-
type : "string",
69-
defaultValue : "/dev/ttyS*|/dev/*.SOC|/dev/*.MALS"
70-
});
65+
section : "Communications",
66+
name : "Ignore Serial Ports",
67+
description : "A '|' separated list of serial port paths to ignore, eg `/dev/ttyS*|/dev/*.SOC`",
68+
type : "string",
69+
defaultValue : "/dev/ttyS*|/dev/*.SOC|/dev/*.MALS"
70+
});
7171
Espruino.Core.Config.add("SERIAL_FLOW_CONTROL", {
72-
section : "Communications",
73-
name : "Software Flow Control",
74-
description : "Respond to XON/XOFF flow control characters to throttle data uploads. By default Espruino sends XON/XOFF for USB and Bluetooth (on 2v05+).",
75-
type : "boolean",
76-
defaultValue : true
77-
});
72+
section : "Communications",
73+
name : "Software Flow Control",
74+
description : "Respond to XON/XOFF flow control characters to throttle data uploads. By default Espruino sends XON/XOFF for USB and Bluetooth (on 2v05+).",
75+
type : "boolean",
76+
defaultValue : true
77+
});
78+
Espruino.Core.Config.add("STORAGE_UPLOAD_METHOD", {
79+
section : "Communications",
80+
name : "Storage Upload Strategy",
81+
description :
82+
"On some connections (Serial, >9600 baud) XON/XOFF flow control is too slow to reliably throttle data transfer when writing files, "+
83+
"and data can be lost. By default we add a delay after each write to Storage to help avoid this, but if your connection is stable "+
84+
"you can turn this off and greatly increase write speeds.",
85+
type : {
86+
0: "Delay Storage writes",
87+
1: "No delays"
88+
},
89+
defaultValue : 0
90+
});
7891

7992
var devices = Espruino.Core.Serial.devices;
8093
for (var i=0;i<devices.length;i++) {
@@ -356,7 +369,8 @@ To add a new serial device, you must add an object to
356369
split = findSplitIdx(split, /reset\(\);?\n/, 250, "reset()"); // Reset
357370
split = findSplitIdx(split, /load\(\);?\n/, 250, "load()"); // Load
358371
split = findSplitIdx(split, /Modules.addCached\("[^\n]*"\);?\n/, 250, "Modules.addCached"); // Adding a module
359-
split = findSplitIdx(split, /require\("Storage"\).write\([^\n]*\);?\n/, 500, "Storage.write"); // Write chunk of data
372+
if ((0|Espruino.Config.STORAGE_UPLOAD_METHOD)==0) // only throttle writes if we haven't disabled it
373+
split = findSplitIdx(split, /require\("Storage"\).write\([^\n]*\);?\n/, 250, "Storage.write"); // Write chunk of data
360374
}
361375
// Otherwise split based on block size
362376
if (!split.match || split.end >= writeData[0].blockSize) {

0 commit comments

Comments
 (0)