Commit Graph

20 Commits

Author SHA1 Message Date
Johny Mattsson fbef7feae1 Discard old console driver.
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.
2021-08-23 23:00:54 +10:00
Johny Mattsson 17df207a5f Port Terry's Lua 5.1 + 5.3 work from the esp8266 branch.
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.
2021-08-22 02:03:05 +10:00
Johny Mattsson f123d46209 Add ESP32C3 support/coexistence.
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.
2021-08-11 17:32:47 +10:00
Johny Mattsson 62b3d06020 idf4: part 2.1 - uplift to new esp_event system events
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.
2021-07-19 17:23:38 +10:00
Johny Mattsson 16ef39e255 idf4: overhaul to new build system, part 1 of 3
Yet to come:
  - part 2: dealing with deprecated and removed APIs
  - part 3: making it actually work again
2021-07-15 16:27:03 +10:00
David Thornley 7774b5fa30
Fix bthci compilation issue (#3201)
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.
2020-08-03 13:39:42 +02:00
Johny Mattsson f44e6e9639 Fix net module data loss & RTOS task unsafety (#2829)
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.
2019-07-14 23:20:20 +02:00
tomsci 35c0f15805 Set stdout to unbuffered (#2508)
* 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
2018-10-07 21:40:49 +02:00
devsaurus 90f5b7696b handle undefined CONFIG_CONSOLE_BIT_RATE_AUTO 2017-04-06 21:09:22 +02:00
Johny Mattsson d48265348a Fixed various warnings. 2016-11-27 13:28:48 +11:00
Johny Mattsson 389980fc0c Removed call to deprecated system_init(). 2016-11-12 13:23:09 +11:00
Johny Mattsson 5df981010a Prevent UART/startup race ala 1517.
We're already in the right context, there is no point posting back the
Lua start, we can do it right then and there instead.
2016-10-03 13:05:17 +11:00
Johny Mattsson e355057de6 Fix our esp_event_send() implementation. 2016-09-29 18:21:18 +10:00
Johny Mattsson febc8f7f36 Updated to latest IDF. 2016-09-28 17:57:00 +10:00
Johny Mattsson 33eb1bc790 Updated to new startup & esp event handling.
Modules can now subscribe to ESP system events via the new
NODEMCU_ESP_EVENT() macro. See nodemcu_esp_event.h for details.
2016-09-27 18:42:08 +10:00
Johny Mattsson baf8249a79 Improved flash-size auto-detection.
No longer limited to the default 2MB.
2016-09-23 17:39:06 +10:00
Johny Mattsson 60339b812b SPIFFS partition support, file module from dev.
Now uses the designated partition (type 0xC2, 0x00) unconditionally.
2016-09-22 17:18:22 +10:00
Johny Mattsson 0fe0096c04 Platform flash layer updated for ESP32.
It would appear my ESP3212 only has a 2MB flash chip despite the
bootloader saying 4MB.
2016-09-22 14:56:40 +10:00
Johny Mattsson 4f1b33d522 Grabbed latest spiffs + vfs layer from dev branch.
Also included the recent LVM fix.

Platform flash layer not yet functional.
2016-09-21 18:14:15 +10:00
Johny Mattsson 9bbf8f43fb Successfully boot barebones NodeMCU on ESP32 (only).
RTOS driver evicted as it did not play nice with stdio etc.

Implemented a minimal driver to fully support Lua console on UART0. Output
on UART0 done via stdout (provided by the IDF). Input and setup handled
via driver_console/console.c. In addition to the direct input function
console_getc(), the driver also registers in the syscall tables to enable
regular stdio input functions to work (yay!). The Lua VM is still using the
direct interface since it's less overhead, but does also work when going
through stdin/fd 0.

Auto-bauding on the console is not yet functional; revisit when the UART docs
are available.

Module registration/linking/enabling moved over to be Kconfig based. See
updates to base_nodemcu/include/module.h and base_nodemcu/Kconfig for
details.

The sdk-overrides directory/approach is no longer used. The IDF is simply
too different to the old RTOS SDK - we need to adapt our code directly instead.

Everything in app/ is now unused, and will need to be gradually migrated
into components/ though it is probably better to migrate straight from the
latest dev branch.
2016-09-20 13:35:56 +10:00