Skip to content

Commit 3579f52

Browse files
committedOct 29, 2024
Updated console module doc with CDC-ACM info.
1 parent f9875d0 commit 3579f52

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed
 

‎docs/modules/console.md

+21-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ There is a helper script (`scripts/upload-file.py`) which can be used to
1616
easily upload files to NodeMCU via this module. The script may also be used
1717
as inspiration for integrating such functionality into IDEs.
1818

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+
1928
## console.on()
2029

2130
Used to register or deregister a callback function to handle console events.
@@ -97,10 +106,14 @@ it reach the Lua interpreter.
97106
-- The chunk_cb gets called incrementally with partial stream data which is
98107
-- effectively unescaped. When the end of frame is encountered, the done_cb
99108
-- 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)
101113
local inframe = false
102114
local escaped = false
103115
local done = false
116+
local len = 0
104117
local STX = 2
105118
local ETX = 3
106119
local DLE = 16
@@ -110,6 +123,11 @@ function transmission_receiver(chunk_cb, done_cb)
110123
end
111124
return function(data)
112125
if done then return end
126+
len = len + #data
127+
while len >= blocksize do
128+
len = len - blocksize
129+
console.write("> ")
130+
end
113131
local from
114132
local to
115133
for i = 1, #data
@@ -160,8 +178,8 @@ function resume_interactive()
160178
end
161179

162180
-- 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))
165183
console.mode(console.NONINTERACTIVE)
166184
```
167185

0 commit comments

Comments
 (0)
Failed to load comments.