A previous commit removed the unix-specific select module implementation
and made unix use the common one.
This commit adds an optimisation so that the system poll function is used
when polling objects that have a file descriptor. With this optimisation
enabled, if code registers both file-descriptor-based objects, and non-
file-descriptor-based objects with select.poll() then the following occurs:
- the system poll is called for all file-descriptor-based objects with a
timeout of 1ms
- then the bare-metal polling implementation is used for remaining objects,
which calls into their ioctl method (which can be in C or Python)
In the case where all objects have file descriptors, the system poll is
called with the full timeout requested by the caller. That makes it as
efficient as possible in the case everything has a file descriptor.
Benefits of this approach:
- all ports use the same select module implementation
- the unix port now supports polling of all objects and matches bare metal
implementations
- it's still efficient for existing cases where only files and sockets are
polled (on unix)
- the bare metal implementation does not change
- polling of SSL objects will now work on unix by calling in to the ioctl
method on SSL objects (this is required for asyncio ssl support)
Note that extmod/vfs_posix_file.c has poll disable when the optimisation is
enabled, because the code is not reachable when the optimisation is used.
Signed-off-by: Damien George <damien@micropython.org>
The unix port has a custom select module which only works with objects that
have a file descriptor, eg files and sockets. On the other hand, bare
metal ports use the common extmod/modselect.c implementation of the select
module that supports polling of arbitrary objects, as long as those objects
provide a MP_STREAM_POLL in their ioctl implementation (which can be done
in C or Python).
This commit removes the unix-specific code and makes unix use the common
one provided by extmod/modselect.c instead. All objects with file
descriptors implement MP_STREAM_POLL so they continue to work.
Signed-off-by: Damien George <damien@micropython.org>
Listing the IDF version number in the board description is not as important
as it once was, when the IDF was still undergoing a lot of changes. Now,
all builds use IDF 5.x and it's possible to query the exact version with
platform.platform().
Signed-off-by: Damien George <damien@micropython.org>
Otherwise constructing an invalid SPI instance (eg machine.SPI(3)) will
mess up machine.SPI(2)'s state before it's detected that it's an invalid
SPI id.
Signed-off-by: Damien George <damien@micropython.org>
On ESP32C3 it's not doing anything. On ESP32S3 the original code prevented
prevented machine.SPI(1) from working.
Signed-off-by: Damien George <damien@micropython.org>
SPI3_HOST is not a macro but rather an enum, so use SOC_SPI_PERIPH_NUM to
detect if it's defined.
Fixes issue #11919.
Signed-off-by: Damien George <damien@micropython.org>
Previously this was explicitly enabled on esp32/stm32/renesas/mimxrt/samd,
but didn't get a default feature level because it wasn't in py/mpconfig.h.
With this commit it's now enabled at the "extra features" level, which adds
rp2, unix-standard, windows, esp8266, webassembly, and some nrf boards.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This changes the ESP32 WDT implementation to use a custom handle so that it
becomes possible to reset the WDT from a thread.
By default esp_task_wdt_add subscribes the task_id of the current task.
That means that if we're running in a different task we are unable to reset
the WDT, which prevents feeding the WDT from a thread directly, or even
from a timer (which may randomly run in a different task when there's
multiple threads).
As an added bonus, the name we set makes the error clearly specify that it
was the user-specified WDT that reset the chip.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Since commit beeb74 we already check in modussl_mbedtls whether this
function is provided by the ESP-IDF before calling it, thus we no longer
need to define it here in order to compile.
Removing it so that if CONFIG_MBEDTLS_DEBUG is defined we do not cause any
'multiple definition' compile errors.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This provides similar functionality to the former zlib.DecompIO and
especially CPython's gzip.GzipFile for both compression and decompression.
This class can be used directly, and also can be used from Python to
implement (via io.BytesIO) zlib.decompress and zlib.compress, as well as
gzip.GzipFile.
Enable/disable this on all ports/boards that zlib was previously configured
for.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This library used a mix of "tinf" and "uzlib" to refer to itself. Remove
all use of "tinf" in the public API.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
There are enough places that implement __exit__ by forwarding directly to
mp_stream_close that this saves code size.
For the cases where __exit__ is a no-op, additionally make their
MP_STREAM_CLOSE ioctl handled as a no-op.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This will be replaced with a new deflate module providing the same
functionality, with an optional frozen Python wrapper providing a
replacement zlib module.
binascii.crc32 is temporarily disabled.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Implement a standard machine.bootloader() method for ESP32-series devices.
No default implementation, each board can enable it as required.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Some targets like the ESP32-S3 use the IDF Component Manager to provide
additional dependencies to the build. Make sure to include these extra
components when collecting properties used by MicroPython-specific build
steps, like qstr preprocessing.
Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
Re-enable some features required for the board to still build and the lora
driver to run.
This board only has 192KB of flash total, so default stm32 build is very
close to the limit.
Before:
LINK build-B_L072Z_LRWAN1/firmware.elf
text data bss dec hex filename
184352 68 14112 198532 30784 build-B_L072Z_LRWAN1/firmware.elf
(12256 bytes free)
After:
LINK build-B_L072Z_LRWAN1/firmware.elf
text data bss dec hex filename
155028 68 14052 169148 294bc build-B_L072Z_LRWAN1/firmware.elf
(41580 bytes free)
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This adds named-pins support to the esp32 port, following other ports.
Since the name of esp32 CPU pins is just GPIOx, where x is an integer, the
Pin.cpu dict is not supported and CPU pins are just retrieved via their
existing integer "name" (the cost of adding Pin.cpu is about 800 bytes,
mostly due to the additional qstrs).
What this commit supports is the Pin.board dict and constructing a pin by
names given by a board. These names are defined in a pins.csv file at the
board level. If no such file exists then Pin.board exists but is empty.
As part of this commit, pin and pin IRQ objects are optimised to reduce
their size in flash (by removing their gpio_num_t entry). The net change
in firmware size for this commit is about -132 bytes.
Signed-off-by: Damien George <damien@micropython.org>
Sometimes mp_hal_get_pin_obj() was used. machine_pin_find() is the
internal name, and the external interface is mp_hal_get_pin_obj().
Signed-off-by: robert-hh <robert@hammelrath.com>
Allowing the machine.pwm() and esp.apa102() module to accept Pin(x) integer
parameters. Not so much of a gain, just consistent with other ports.
Signed-off-by: robert-hh <robert@hammelrath.com>
This applies to all machine modules which have pins as arguments. Since
machine_pin_get_id() calls pin_find(), these pin arguments may be at the
moment either integer objects or Pin objects. That allows for instance to
write
uart = UART(1, tx=Pin(4), rx=Pin(5))
instead of
uart = UART(1, tx=4, rx=5)
which is consistent with other ports. Since this handling is done at a
single place in the code, extending that scheme to accept strings for named
pins is easy.
Signed-off-by: robert-hh <robert@hammelrath.com>
The new machine_pin_find() function accepts a Pin object and a integer
object as input and returns a pin object. That can be extended later to
accept a string object, once named pins are supported.
Signed-off-by: robert-hh <robert@hammelrath.com>
And use it in mp_hal_get_pin_obj() and machine_pin_make_new(). That way,
mp_hal_get_pin_obj() accepts both int and str objects as argument, allowing
use of a pin specifier instead of a pin object in the constructor of
devices which need a pin as parameter.
E.g. instead of
uart = UART(0, tx=Pin(0), rx=Pin(1))
one can write:
uart = UART(0, tx=0, rx=1)
Signed-off-by: robert-hh <robert@hammelrath.com>
The legacy driver was deprecated in IDF v5, and crashes when the ISR
handler is called. Instead of fixing the legacy code, this commit reworks
the machine.Timer class to use the low-level HAL driver.
Tested on ESP32, ESP32S2, ESP32S3 and ESP32C3. Behaviour is the same as it
was before this commit, except the way the Timer object is printed, it now
gives more useful information (timer id, mode, period in ms).
Fixes issue #11970.
Signed-off-by: Damien George <damien@micropython.org>
When the "typeof window" check is run within a web worker the window is
undefined, causing an error because "require" is only defined in a Node
environment. Change the logic to reflect the true intentions of when this
code should run, ie in Node only.
Signed-off-by: Damien George <damien@micropython.org>
The existing qspi for stm32 implementation can only send a spi command with
exactly 0 or 2 data bytes. Certain spiflash chips (e.g. AT25SF321B) have
commands that only take a single data byte, and will ignore the command if
more than that is sent. This commit allows sending a command with a single
data byte.
Signed-off-by: Victor Rajewski <victor@allumeenergy.com.au>
For STM32G4, there is a errata on ADC that may get wrong ADC result.
According to the errata sheet, this can be avoid by performing two
consecutive ADC conversions and keep second result.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
For STM32G4 series, the internal sensors are connected to:
- ADC1_IN16: Temperature sensor
- ADC1_IN17: Battery voltage monitoring
- ADC1_IN18: Internal voltage reference
but ADC_CHANNEL_TEMPSENSOR_ADC1, ADC_CHANNEL_VBAT,
ADC_CHANNEL_VREFINT are not defined as 16, 17, 18.
This commit converts channel 16, 17, 18 to ADC_CHANNEL_x in
adc_get_internal_channel().
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
For STM32G4,
* TS_CAL1 raw data acquired at a temperature of 30°C
* TS_CAL2 raw data acquired at a temperature of 130°C
Also, these values are at VDDA=3.0V.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
For STM32G4, ADC clock frequency should be equal or less than 60MHz.
To satisfy this specification, ADC clock prescaler should be equal or
greater than 4 (For example, NUCLEO_G474RE runs 170MHz).
In addition, to obtain accurate internal channel value,
the ADC clock prescaler is set to 16 because vbat needs at least 12us
(16/170*247.5=23.3us).
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
For STMG4 MCUs, the peripheral registers for DAC have to be accessed by
words (32bits) because DAC is connected to AHB directly.
(This requirement is also there for other MCU series. However, if DAC is
connected to APB like F4/L1/L4 MCUs, AHB byte or half-word transfer is
changed into a 32-bit APB transfer. This means that PSIZE does not have to
be DMA_PDATAALIGN_WORD on these MCUs, and in fact must be BYTE/HALFWORD to
function correctly.)
Fixes issue #9563.
Signed-off-by: Yuuki NAGAO <wf.yn386@gmail.com>
This is a fix for commit bccbaa92b1fc6237f0f49a7f07cc194835fbf4e3:
- Should only wait for WIFI_EVENT_STA_START when invoked on the STA_IF
interface.
- The WIFI_EVENT_STA_START event is generated every time the STA_IF
interface is set active(True) and it was previously inactive, ie. not
only after calling esp_wifi_start().
- Also wait for WIFI_EVENT_STA_STOP when deactivating the interface.
- Also wait for relevant AP events.
Fixes issue #11910.
Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Enabling mDNS put this firmware over the limit of the OTA partition size,
so tweak the compiler settings to reduce the firmware size.
Signed-off-by: Damien George <damien@micropython.org>
To match the other functions in the machine module, in particular so that
MICROPY_PY_MACHINE can be disabled without getting a compiler warning about
unused code.
Signed-off-by: Damien George <damien@micropython.org>