This allegedly resolves the reboot crashes seen on ESP32-S3 Zero.
It also removes the peculiar need to explicitly call
esp_vfs_console_register(), the absence of which previously would
trigger an assertion failure in xQueueGenericSend on input.
- If the initial filesystem mounting fails, then a subsequent file.format()
does not mount it afterwards, necessitating a node.restart(). In the normal
case, after file.format() the filesystem is mounted and ready for use.
We now explicitly remount after a format to gain consistent behaviour.
- If using USB CDC, the auto-format on first boot interferes with USB
enumeration, resulting in a failed startup. We now avoid doing an
auto-format if the USB CDC console is enabled. The behaviour is
configurable/overrideable via Kconfig.
With the switch to use the IDF's stdin for feeding the Lua VM, we
unintentionally lost the ability to use uart.on('data') on the console uart.
This is since we no longer install the nodemcu uart driver on said uart.
In order to resolve this shortcoming, this commit refactors the uart.on('data')
delimiter handling and moves it away from platform.c into uart.c where it
really belongs. A new function, uart_feed_data(), is introduced, which is used
both by the nodemcu uart driver task as well as the nodemcu console driver
task (assuming the console is in fact a uart).
The linebuffer allocation/freeing is still in response to
uart.start()/uart.stop(), but it is now in uart.c rather than
platform.c.
The whole uart integration is still too tightly coupled between the platform
component and the module component's uart.c, but this makes it slightly
better at least.
* Proof-of-concept multi-type console support via stdio
* Address crashes on linput's use of printf.
On an empty line input, a C3 with UART console would panic while attempting
to output the new Lua prompt. The backtrace shows a xQueueSemaphoreTake
with uxItemSize==0 as the panic cause, deep inside the uart driver, invoked
via vfs_uart and vfs_console layers, from printf.
Similarly, the printf for outputting a backspace/erase sequence would also
trigger a panic.
This workaround (of not mixing fflush() with printf) is likely merely hiding
a deeper issue, but it appears to be consistent. Plus, printf with no args
and a user-supplied format string is a no-no and should be fixed anyway.
* Work around IDF inconsistency with stdout buffering.
* Increase console task stack size.
Seems on Xtensa it ended up not being enough.
* Switch to single-byte console reads.
* Stop cheating and feed Lua from the right context.
* Work around IDF buffering stdout even when told not to, on ACM consoles.
* Initial build support for esp32c6.
Plus fixup of module selection for a variety of targets.
* Update github actions to node 20 versions.
* Update github build to deal with Lua 5.3 being default.
* Address fatal compiler warning.
Newer IDF toolchain is stricter, and we'd apparently failed to build test
the Lua-5.1 path for some time.
* Initial build support for esp32h2.
* Upgrade IDF to v5.1.3
* Fix left-over incorrect type in uzlib.
* Avoid null pointer crashes when debugging startup.
* Workaround for using wifi module on S2 with USB-CDC console.
---------
Co-authored-by: Jade Mattsson <github@frozenlogic.org>
Plenty of dependency adjustments, printf format specificier updates,
FreeRTOS type and macro name modernisation, not to mention API changes.
Still plenty of legacy/deprecated drivers in use which will need updating.
The following features have been removed due to no longer being available
from the IDF:
- ADC hall effect sensor reading
- Configuration of SD SPI host via sdmmc module (now must be done first
via the spimaster module)
- FAT partition selection on external SD cards; only the first FAT
partition is supported by the IDF now
On the other hand, the eth module now supports the following new chipsets:
- KSZ8001
- KSZ8021
- KSZ8031
- KSZ8051
- KSZ8061
- KSZ8091
- Possibly additional models in the LAN87xx series (the IDF docs aren't
clear on precisely which models are handled)
Further, the sdmmc module is now available on the ESP32-S3 as well.
The IDF-provided VFS resolves several issues:
- The IDF components having a different view of the (virtual) file system
compared to the Lua environment.
- RTOS task/thread safety. Our legacy VFS was only ever safe to use
from the LVM thread, which limited its usability. Upgrading it
would have effectively required a reimplementation of the IDF VFS,
which would have been a bigger task with larger on-going maintenance
issues.
- We're no longer needing to maintain our own SPIFFS component.
- We're no longer needing to maintain our own FATFS component.
- The legacy of the 8266's lack of standard C interface to the file system
is no longer holding us back, meaning that we can use the standard
Lua `io` module rather than the cobbled-together swiss army knife
also known as the file module.
Of course, the downside is that we'll either have to declare a backwards
breakage in regard to the file module, or provide a Lua shim for the old
functions, where applicable.
Also included is some necessary integer type fixups in unrelated code,
which apparently had depended on some non-standard types in either the
SPIFFS or FATFS headers.
A memory leak issue in the sdmmc module was also found and fixed while
said module got switched over to the Espressif VFS.
Module documentation has been updated to match the new reality (and I
discovered in some places it wasn't even matching the old reality).
The IDF provides all we need these days, and the old driver was just
needlessly conflicting with the IDF settings and setup.
This also simplifies our uart input path as we no longer need to
duplicate the raw byte handling for when "run_input" is false.
Changes have been kept to a minimum, but a serious chunk of work was
needed to move from 8266isms to IDFisms.
Some things got refactored into components/lua/common, in particular
the LFS location awareness.
As part of this work I also evicted our partition table manipulation
code, as with the current IDF it kept breaking checksums and rendering
things unbootable, which is the opposite of helpful (which was the
original intent behind it).
The uart module got relocated from base_nodemcu to the modules component
properly, after I worked out how to force its inclusion using Kconfig alone.
The uzlib and parts of Lua had to be switched over to use the
C standard int types, as their custom typedefs conflicted with
RISC-V toolchain provided typedefs.
UART console driver updated to do less direct register meddling
and use the IDF uart driver interface for setup. Still using our
own ISR rather than the default driver ISR. Down the line we
might want to investigate whether the IDF ISR would be a better
fit.
Lua C modules have been split into common and ESP32/ESP32-S
specific ones. In the future there might also be ESP32-C3
specific modules, which would go into components/modules-esp32c3
at that point.
Our old automatic fixup of flash size has been discarded as it
interferes with the checksumming done by the ROM loader and
results in unbootable systems. The IDF has already taken on
this work via the ESPTOOL_FLASHSIZE_DETECT option, which handles
this situation properly.
Some parts dry-coded in the disabled modules; to be fixed when sorting out
the deprecated/removed APIs used in said modules.
Still untested beyond compile/linking.
Using the NODEMCU_ namespace prefix makes it obvious that these are not
part of Lua proper (contrast, e.g., LUA_BUILTIN_STRING). Using
"CMODULE" gives us room to differentiate between modules whose
implementation is in C and whose implemenation is in Lua ("LMODULE").
The ESP8266 branch can adopt the same convention when it moves to
Kconfig; see https://github.com/nodemcu/nodemcu-firmware/issues/3130
Manifests as multiple definition of esp_event_send during compilation, as bthci triggers inclusion of `event_loop.c`. Also improved lbth_init() to support BTDM or BLE_ONLY controller modes.
To avoid races between the lwIP callbacks (lwIP RTOS task) and the Lua
handlers (LVM RTOS task), the data flow and ownership has been simplified
and cleaned up.
lwIP callbacks now have no visibility of the userdata struct. They are
limited to creating small event objects and task_post()ing them over
to the LVM "thread", passing ownership in doing so. The shared identifier
then becomes the struct netconn*.
On the LVM side, we keep a linked list of active userdata objects. This
allows us to retrieve the correct userdata when we get an event with
a netconn pointer. Because this list is only ever used within the LVM
task, no locking is necessary.
The old approach of stashing a userdata pointer into the 'socket' field
on the netconn has been removed entirely, as this was both not
thread/RTOS-task safe, and also interfered with the IDFs internal use
of the socket field (even when using only the netconn layer). As an
added benefit, this removed the need for all the SYS_ARCH_PROTECT()
locking stuff.
The need to track receive events before the corresponding userdata object
has been established has been removed by virtue of not reordering the
"accept" and the "recv" events any more (previously accepts were posted
with medium priority, while the receives where high priority, leading
to the observed reordering and associated headaches).
The workaround for IDF issue 784 has been removed as it is now not needed
and is in fact directly harmful as it results in a double-free. Yay for
getting rid of old workarounds!
DNS resolution code paths were merged for the two instances of "socket"
initiated resolves (connect/dns functions).
Also fixed an instance of using a stack variable for receiving the resolved
IP address, with said variable going out of scope before the DNS resolution
necessarily completed (hello, memory corruption!).
Where possible, moved to use the Lua allocator rather than plain malloc.
Finally, the NodeMCU task posting mechanism got a polish and an adjustment.
Given all the Bad(tm) that tends to happen if something fails task posting,
I went through a couple of iterations on how to avoid that. Alas, the
preferred solution of blocking non-LVM RTOS tasks until a slot is free
turned out to not be viable, as this easily resulted in deadlocks with the
lwIP stack. After much deliberation I settled on increasing the number of
available queue slots for the task_post() mechanism, but in the interest
of user control also now made it user configurable via Kconfig.
With the IDF asserting full control over the linker scripts and insisting on
the application description being the first entry in the .flash.rodata
section, or previous method of doing link-time arrays stopped working.
Why? Because the build patched in a SHA256 digest straight into our arrays.
With the limited language of the gcc linker scripts I could find no other
way of getting it in cleanly.
The IDF "linker fragments" support can not be made to work for our needs:
- no support for setting alignment before including objects
- no support for declaring symbols
- no support for adding our terminating zeros
- insists on grouping objects by lib rather than by declared grouping,
which means we could at most have a single link-time-array using
the IDF mechanism
- also does not like underscores in section names, but that's just an
annoyance
So, the least bad option that I could come up with was to use a project-wide
makefile snippet to add a target in-between the IDF's generation of the
esp32.project.ld file, and the linking of our NodeMCU.elf. In this target
we read in the esp32.project.ld linker script, check whether we have our
arrays in there, and if not rewrites the linker script.
Oh, and the esp32.project.ld file only came into existence on the IDF 3.3
branch, so I had to change up the IDF to the latest release/3.3 as well.
I would've preferred a stable tag, but the v3.3-beta3 had a really nasty
regression for us (can't add partition entry), so that was a no-go.
* ESP32: add support for RS485
This commit adds support for switching UART mode to RS485/IRDA.
Also included are patches for memory leaks then handling UART events other than data.
* ESP32: Documentation for uart.setmode()
* Set stdout to unbuffered
This fixes issue #2507 esp32 serial console doesn't show output until
enter pressed.
* Moved setvbuf call to app_main immediately after console_init
* uart 1/2
* call -> pcall in uart_on_* functions
* fix docs
* fixed console driver when using custom console uart
* fixed line_inverse and error callback
* fixed a crash when uart.start() called more than one time
- Switched hardcoded interrupts to new IDF interrupt allocation
framework.
- gpio module switched to the IDF's per-pin interrupt callback service.
- Improved NodeMCU linker script since it broke with the IDF upgrade.
- Various compatibility updates.
node.dsleep() no longer takes options.
node.output() not yet supported (needs syscall registration/chaining support)
Dynamic CPU frequency changing not currently supported in the IDF.
Various chip IDs not currently available/obtainable.
Boot reason completely revamped in ESP32, will need new code.