@@ -16,6 +16,15 @@ There is a helper script (`scripts/upload-file.py`) which can be used to
16
16
easily upload files to NodeMCU via this module. The script may also be used
17
17
as inspiration for integrating such functionality into IDEs.
18
18
19
+ If using a SoC with USB CDC-ACM as the console, consider increasing the receive
20
+ buffer from the default. This type of console is quite prone to overflows, and
21
+ increasing the receive buffer helps mitigate (but not completely resolve) that.
22
+ Look for ` Component config -> ESP system settings -> Size of USB CDC RX buffer `
23
+ in the menuconfig (` ESP_CONSOLE_USB_CDC_RX_BUF_SIZE ` in sdkconfig). Increasing
24
+ this value from the default 64 to 512 makes it match what is typically used
25
+ for a UART console. Some utilities and IDEs may have their own minimum
26
+ requirements for the receive buffer.
27
+
19
28
## console.on()
20
29
21
30
Used to register or deregister a callback function to handle console events.
@@ -97,10 +106,14 @@ it reach the Lua interpreter.
97
106
-- The chunk_cb gets called incrementally with partial stream data which is
98
107
-- effectively unescaped. When the end of frame is encountered, the done_cb
99
108
-- gets invoked.
100
- function transmission_receiver (chunk_cb , done_cb )
109
+ -- To avoid overruns on slower consoles (e.g. CDC-ACM) each block gets
110
+ -- acknowledged by printing another prompt. This allows the sender to easily
111
+ -- throttle the upload to a maintainable pace.
112
+ function transmission_receiver (chunk_cb , done_cb , blocksize )
101
113
local inframe = false
102
114
local escaped = false
103
115
local done = false
116
+ local len = 0
104
117
local STX = 2
105
118
local ETX = 3
106
119
local DLE = 16
@@ -110,6 +123,11 @@ function transmission_receiver(chunk_cb, done_cb)
110
123
end
111
124
return function (data )
112
125
if done then return end
126
+ len = len + # data
127
+ while len >= blocksize do
128
+ len = len - blocksize
129
+ console .write (" > " )
130
+ end
113
131
local from
114
132
local to
115
133
for i = 1 , # data
@@ -160,8 +178,8 @@ function resume_interactive()
160
178
end
161
179
162
180
-- The 0 may be adjusted upwards for improved efficiency, but be mindful to
163
- -- always send enough data to reach the ETX marker.
164
- console .on (" data" , 0 , transmission_receiver (print_hex , resume_interactive ))
181
+ -- always send enough data to reach the ETX marker if so .
182
+ console .on (" data" , 0 , transmission_receiver (print_hex , resume_interactive , 64 ))
165
183
console .mode (console .NONINTERACTIVE )
166
184
```
167
185
0 commit comments