nodemcu / nodemcu-firmware

Lua based interactive firmware for ESP8266, ESP8285 and ESP32

Home Page:https://nodemcu.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple UART stress leads to crash

ptsneves opened this issue · comments

do                                                                                                            
    uart.setup(0, 115200, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
    uart.on("data", 1, function(data)                 
      print(data)
    end, 0)
end

I expected it to keep working indefinitely. Unfortunately it works for some time and then crashes after some time. Changing the characters to read from 1 to 0 did not lead to any improvement.

NodeMCU startup banner

opening port /dev/ttyUSB0 with 115200 baud
Node info
Node info hw
for key,value in pairs(node.info('hw')) do k=tostring(key) print(k .. string.rep(' ', 20 - #k), tostring(value)) end
flash_size          	4096
chip_id             	6920530
flash_mode          	3
flash_speed         	40000000
flash_id            	1458208
> 
Node info sw_version
for key,value in pairs(node.info('sw_version')) do k=tostring(key) print(k .. string.rep(' ', 20 - #k), tostring(value)) end
git_branch          	release
git_release         	
git_commit_id       	f25dc56d3c6213b8ac7ce46d1293466137746eae
node_version_minor  	0
git_commit_dts      	202112300746
node_version_revision	0
node_version_major  	3
> 
Node info build_config
for key,value in pairs(node.info('build_config')) do k=tostring(key) print(k .. string.rep(' ', 20 - #k), tostring(value)) end
ssl                 	false
number_type         	integer
modules             	file,gpio,net,node,tmr,uart,wifi
lfs_size            	0

Hardware

Regular Lolin ESP8266

Let me know if you need further help. I suspect there is some kind of interrupt inside the callback. Is there a way to busy poll the uart without interrupts?

Hi,

This cannot work and has to end in an crash.

Please have a look at the documentation: https://nodemcu.readthedocs.io/en/dev/lua-developer-faq/

It is especially this part:

The main impacts of the ESP8266 SDK and together with its hardware resource limitations are not in the Lua language implementation itself, but in how application programmers must approach developing and structuring their applications. As discussed in detail below, the SDK is non-preemptive and event driven. Tasks can be associated with given events by using the SDK API to registering callback functions to the corresponding events. Events are queued internally within the SDK, and it then calls the associated tasks one at a time, with each task returning control to the SDK on completion. The SDK states that if any tasks run for more than 15 mSec, then services such as WiFi can fail.

So you can start a timer that does your loop while giving enough resources to the SDK so ESP8266 feels fine.

Let's close the issue.

Thanks Lukáš