Convert the samd port from the old `MICROPY_EVENT_POLL_HOOK` macro to use
the new `mp_event_wait_xxx()` functions in conjunction with
`MICROPY_INTERNAL_WFE`.
This change should be functionally equivalent to the existing behaivour
because `mp_event_wait_ms()` is equal to
`mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); __WFE()`,
which is what `MICROPY_EVENT_POLL_HOOK` was.
Signed-off-by: Damien George <damien@micropython.org>
Convert the mimxrt port from the old `MICROPY_EVENT_POLL_HOOK` macro to use
the new `mp_event_wait_xxx()` functions in conjunction with
`MICROPY_INTERNAL_WFE`.
This change should be functionally equivalent to the existing behaivour
because `mp_event_wait_ms()` and `mp_event_wait_indefinite()` are equal to
`mp_handle_pending(MP_HANDLE_PENDING_CALLBACKS_AND_EXCEPTIONS); __WFE()`,
which is what `MICROPY_EVENT_POLL_HOOK` was.
Signed-off-by: Damien George <damien@micropython.org>
usbd_conf.c unconditionally includes shared/tinyusb/mp_usbd.h which
pulls in tusb.h when MICROPY_HW_ENABLE_USBDEV is set. The
BUILDING_MBOOT guard that disables TinyUSB comes after the include,
so mboot builds fail with missing tusb.h. Guard the include with
!BUILDING_MBOOT.
Also add forward declaration of mp_usbd_ll_init() next to the
MICROPY_HW_TINYUSB_LL_INIT macro in mpconfigboard_common.h, since
the function is used in an inline function in mp_usbd.h but only
declared in the port-specific usbd_conf.h.
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
The esp32 port has the machine Counter and Encoder classes implemented in
Python, requiring a `machine.py` that extends the built-in machine module.
That previously used `__getattr__()` to delegate lookups to the built-in,
but that means any failed lookup raises an `AttributeError` instead of an
`ImportError`. This means (among other things) that certain tests like
CAN and I2CTarget would fail because they couldn't skip the test correctly.
This commit improves the situation by using `from machine import *` instead
of `__getattr__()`, which puts all the built-in functions/classes/constants
directly in the `machine.py` global namespace. That means an `ImportError`
is now correctly raised for attributes that don't exist.
Although this takes up a bit more RAM, it's now a lot faster to import from
the machine module: what used to take around 100us to lookup a name now
takes only 5us.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds a new test to make sure ROMFS files are mounted and
read correctly, to be run as part of the CI process.
The changes also include the source binary files that have been used to
create the pre-baked ROMFS partition image used in the test, along with
a Makefile to allow recreating said file.
The CI test ROMFS image is mounted only if no other ROMFS partition is
mounted in slot 0. The specific test is executed only if there actually
is a ROMFS partition mounted and if the partition is identified as the
one used to run tests on. This allows for user images to be mounted and
for a successful test run if that is the case.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit renames the "tests/frozen" directory into "tests/assets" to
make it more explicit that it does contain files that are needed for
other tests to function.
Right now there's only a single pre-compiled module being used for
miscellaneous tests, but it will soon hold ROMFS test data as well.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit lets the SABRELITE machine definition load a ROMFS
partition at the very end of the RAM space.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit lets the MPS2_AN385 machine definition load a ROMFS
partition right at the beginning of the 16MiB PSRAM area.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit reserves a memory area to mount ROMFS partitions into, and
lets the port Makefile know the memory area details.
A 4 MiB segment is allocated at 0x8062_0000, which is inside the
emulated machine's DRAM segment. The virt board requires the image
loaded in its DRAM segment to be contiguous, so the ROMFS segment is
placed right after the stack area.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit reserves a memory area to mount ROMFS partitions into, and
lets the port Makefile know the memory area details.
A 4 MiB segment is allocated at 0x8061_0000, which is inside the
emulated machine's DRAM segment. The virt board requires the image
loaded in its DRAM segment to be contiguous, so the ROMFS segment is
placed right after the stack area.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit refactors shared ROMFS definitions appearing in some Arm
boards configuration, moving them into the QEMU port's Makefile.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
This commit shortens the amount of space taken by the DMA control fields
table, and explicitly marks it as `const`.
The DMA fields info table used a full-size QSTR index value, and 9 bits
of numeric information. Given that the QSTR index could be converted
into a `qstr_short_t`, there is no fields spill outside a machine word
boundary - albeit with having 7 unused bits but there isn't much that
can be done for that. The effective structure size for each entry is
halved, from 8 bytes down to 4.
Also, the structure is only read from, yet it was not marked as `const`.
Marking the structure as constant did not help reduce the final size but
at least correctly signals the compiler that no write accesses are
possible.
This shrinks the RPI_PICO/RPI_PICO_W build by 56 bytes, with a similar
size reduction for RPI_PICO2/RPI_PICO2_W.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Prior to this commit a port would need to manually configure the
`MICROPY_EMIT_THUMB_ARMV7M` and `MICROPY_EMIT_INLINE_THUMB_FLOAT` options,
based on whether the CPU is Thumb2 and whether it has hardware floating
point support (eg Cortex-M0+ vs Cortex-M3 vs Cortex-M4).
This is error prone, for example on stm32:
- `NUCLEO_G0B1RE` (a Cortex-M0+ MCU) had both enabled even though neither
options work on that target.
- `NUCLEO_L152RE` (a Cortex-M3 MCU) had both enabled but this target does
not support hardware floating point.
The change here automatically enables the two options based on built-in
compiler macros.
This change is tested on the following boards:
- alif ALIF_ENSEMBLE: both enabled
- rp2 RPI_PICO: both disabled
- rp2 RPI_PICO2: both enabled
- samd SAMD21_XPLAINED_PRO: both disabled
- samd SAMD_GENERIC_D51X20: both enabled
- stm32 NUCLEO_G0B1RE: both disabled
- stm32 NUCLEO_L152RE: only MICROPY_EMIT_THUMB_ARMV7M enabled
- stm32 PYBD_SF6: both enabled
- stm32 PYBV10: both enabled
Signed-off-by: Damien George <damien@micropython.org>
This isn't a necessary change, but allows make MICROPY_C_HEAP_SIZE=nnn as
an alternative to setting it in a board's .cmake file.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The compiler flags -ansi -std=c11 were both being passed to g++, causing
weirdness. Removed the -ansi flag entirely, it's superseded by explicitly
setting the standard.
Also adds build coverage for user C modules (including C++) in CI.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Move the common CXXFLAGS and LDFLAGS into py/mkrules.mk
Changes ports minimal, esp8266, mimxrt, renesas-ra, samd,
stm32, unix, windows (mingw32).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Also add missing SRC_CXX support to the mimxrt build, same as
on other ports.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
All GPIO pins on the ESP32-P4 are output capable, so there is no need to
define GPIO_FIRST_NON_OUTPUT.
Fixes#18982.
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
This commit extends the output of `WLAN.status('stations')` to also
include the IP address of WiFi stations connected to the device if in AP
mode.
IP address lookup is currently not available on targets that use hosted
WiFi (eg. ESP32P4), as the hosted API does not yet support performing
the MAC->IP lookup on the WiFi MCU end.
The ESP32 port is brought up to parity with most ports in this regard
(primarily with the ESP8266). This functionality depends on the DHCP
server provided by ESP-IDF, which is automatically run on the WiFi
interface if the device is put in AP mode. Currently the ESP32 port
cannot run with said DHCP server disabled, so if a device does not
request a static IP it may either have the wrong IP address returned
(since the DHCP server assigned an address which is then discarded by
the client), or it won't have any (ie. "0.0.0.0"). In the latter case
`None` will be returned as the station's address instead.
This implements #9203.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Resolves part of #18984. On ESP32-P4, SDMMC slot 0 supports SDIO 3.0, and
is liekly the default for most boards. MICROPY_HW_SDMMC_DEFAULT_SLOT can
be set in `mpconfigboard.h` to change default slot.
Signed-off-by: Dryw Wade <dryw.wade@sparkfun.com>
ESP32-S3FH4R2 with SX1262 LoRa (HPD17A), SSD1306 OLED, SD card.
Freezes lora-sx126x and ssd1306 from micropython-lib.
Signed-off-by: Pierre Gaufillet <pierre.gaufillet@bergamote.eu>
This commit adds an implementation for "socket.sendall" to the Unix
port.
Right now the implementation is a wrapper over a single "socket.send"
call, since it wasn't possible to let "socket.send" perform a partial
transfer. With no partial transfers it is not possible to have a
testable implementation following the expected behaviour, so a single
send operation is done and OSErr(EINTR) is raised if a partial transfer
occurs.
The discussion for the issue linked to this PR contains more information
about the efforts made to let partial transfers happen.
This fixes#16803.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
TRB buffers, which are the target of cache clean/invalidate actions, were
not cache-aligned between buffers. Reported the problem to Alif, and
adding padding to them is the proper fix. Appears to work without any
other changes in device behavior.
Signed-off-by: Kwabena W. Agyeman <kwagyeman@live.com>
This commit adds basic ROMFS support. This helps with running tests since
mpremote mount is too slow with big files.
To be configured per-board, and then run with:
$ make QEMU_ROMFS_IMG0=image.romfs ...
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
For uart_irq_update() the allowed return values
are a negative errno or 1. 0 is not allowd.
Therefore ignore the return value.
Also the return type might soon be changed to void.
Signed-off-by: Fin Maaß <f.maass@vogl-electronic.com>
On the esp32 port when adding a user C module, the source code for the user
C module was being compiled without certain C flags. Notably the
optimisation flag was missing.
This commit fixes that by explicitly adding the missing C flags to the
compilation of user C modules.
The missing flags were the following, which are now included when building
user C modules (found by inspecting the generated CMake files when building
with ulab):
-ffunction-sections
-fdata-sections
-Wall
-Werror=all
-Wno-error=unused-function
-Wno-error=unused-variable
-Wno-error=unused-but-set-variable
-Wno-error=deprecated-declarations
-Wextra
-Wno-error=extra
-Wno-unused-parameter
-Wno-sign-compare
-Wno-enum-conversion
-gdwarf-4
-ggdb
-mdisable-hardware-atomics
-O2
-fmacro-prefix-map=micropython/ports/esp32=.
-fmacro-prefix-map=espressif/esp-idf=/IDF
-fstrict-volatile-bitfields
-fno-jump-tables
-fno-tree-switch-conversion
See related issue #18880.
Work done in collaboration with @andrewleech.
Signed-off-by: Damien George <damien@micropython.org>
The webassembly port needs some additional weakref tests due to the fact
that garbage collection only happens when Python execution finishes and
JavaScript resumes.
The `tests/ports/webassembly/heap_expand.py` expected output also needs to
be updated because the amount of GC heap got smaller (weakref WTB takes
some of the available RAM).
Signed-off-by: Damien George <damien@micropython.org>
With the recent addition of `machine.PWM` and `machine.CAN`, the internal
flash of PYBD_SF3 overflows by about 300 bytes.
This commit moves the inline assembler compiler functions from internal to
external QSPI flash. That frees up about 3k internal flash, and shouldn't
affect performance.
Signed-off-by: Damien George <damien@micropython.org>
2.25k Seems necessary so it doesn't crash `thread/thread_stacksize1.py`.
But 2.5k gives a little extra headroom to make that test actually pass.
Signed-off-by: Damien George <damien@micropython.org>
This commit fixes an issue related to the NimBLE initialisation
procedure in low memory environments on ESP32 boards.
MicroPython uses at least two different NimBLE stacks across the
supported ports, mynewt (imported as an external library), and the one
provided by Espressif in their own SDKs. The problem is that these two
ports differ in the signature for `nimble_port_init(void)`, with mynewt
returning `void`, and Espressif's returning a status code on failure.
On ESP32 boards, allocating almost all the available heap and then
turning on the Bluetooth stack would trigger a failure in the NimBLE
initialisation function that is not handled by the NimBLE integration
code, as there's no expectation of a recoverable condition. Since the
stack initialisation would progress, then uninitialised memory accesses
crash the board.
Since we cannot really modify neither mynewt nor Espressif SDKs, the
next best thing is to provide two conditional initialisation paths
depending on a configuration setting. This would make Espressif ports
recover from a failed initialisation whilst retaining the existing
behaviour on other ports.
This fixes#14293.
Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
Intended to catch problems where new features don't build
in old ESP-IDF.
Includes major refactor to the GitHub Actions Workflow for
esp32 port, including making a reusable workflow for both
Code Size and ESP32 build jobs.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
This allows the newly-added `machine.PWM` class to fit on these boards,
which is arguably more useful than the features disabled in this commit.
Signed-off-by: Damien George <damien@micropython.org>
When assigning a TIMx_CHy to a pin, the second available alternate function
is chosen (or the first if there is only one). This gives better overall
static allocation of TIM's to pins.
On most MCUs (eg F4, F7, H5, H7) picking the second gives TIM5_CH[1-4] for
PA0-PA3, and TIM5 is a 32-bit timer. That leaves TIM2 (also usually on
PA0-PA3) for other pins that only have TIM2.
For STM32G0, STM32L432 and STM32L452 the heuristic is to simply use the
first available alternate function because that gives TIM2 (a 32-bit timer)
on PA0-PA3.
The above heuristic guarantees that PA0-PA3 always get a 32-bit timer on
all supported MCUs.
Signed-off-by: Damien George <damien@micropython.org>
This commit implements the standard `machine.PWM` class on stm32, using the
common bindings in `extmod/machine_pwm.c`. Features implemented are:
- construct a PWM object from a pin, with automatic selection of TIM
instance and channel;
- get and set freq, duty_u16 and duty_ns;
- optionally invert the output.
The PWM objects are static objects (partly in ROM, partly in RAM) so
creating a PWM instance on the same pin will return exactly the same
object. That's consistent with other peripherals in the stm32 port, and
consistent with other PWM implementations (eg rp2).
When creating a PWM object on a pin, if that pin has multiple TIM instances
then only the first will be selected. A future extension could allow
selecting the TIM/channel (eg similar to how ADCBlock allows selecting an
ADC).
Signed-off-by: Damien George <damien@micropython.org>
This functionality already exists in the TIM code, and can be reused by the
upcoming PWM implementation.
Signed-off-by: Damien George <damien@micropython.org>
Some MCUs (eg N6) have more timers which are 32-bit, and it's best to use
this macro to work that out.
Signed-off-by: Damien George <damien@micropython.org>