This new machine-module driver provides a "USBDevice" singleton object and
a shim TinyUSB "runtime" driver that delegates the descriptors and all of
the TinyUSB callbacks to Python functions. This allows writing arbitrary
USB devices in pure Python. It's also possible to have a base built-in
USB device implemented in C (eg CDC, or CDC+MSC) and a Python USB device
added on top of that.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Previously USB was always enabled, but this created some conflicts when
adding guards to other files on other ports.
Note the configuration with USB disabled hasn't been tested and probably
won't build or run without further work.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
`BLE().config(addr_mode=...)` is not safe to call if the NimBLE stack is
not yet active (because it tries to acquire mutexes which should be
initialized first).
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Disabled by default, but enabled on all boards that previously had
`MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled.
Signed-off-by: Damien George <damien@micropython.org>
If no security mode is provided, use WPA for station and WEP for AP. Note
only WEP is supported in AP mode.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Activate the NIC on calls to connect() or config() if it's not already
active. This change makes the NINA NIC more in line with CYW43 and other
NICs, which allow configuring the NIC before or after it is activated.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
Added a 4MiB flash partitioning variant for ESP32S3: adds support for 4MiB
discrete flash boards or ESP32-S3FH4R2 with embedded 4MiB flash based ones.
Tested on the waveshare ESP32-S3 Mini w/ESP32-S3FH4R2.
Signed-off-by: Stanislav Ponomarev <me@stasponomarev.com>
If the `timeout_char` parameter is not given, we should still configure the
UART to ensure the UART is always initialized consistently. So the default
of 0 gets applied correctly, or if, for example, the baudrate was changed
the char timeout isn't still based on the old baudrate causing weird
behaviour, etc.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
Prior to this commit, the pin defined for power would be used by the
esp_idf driver to reset the PHY. That worked, but sometimes the MDIO
configuration started before the power was fully settled, leading to an
error.
With the change in this commit, the power for the PHY is independently
enabled in network_lan.c with a 100ms delay to allow the power to settle.
A separate define for a reset pin is provided, even if the PHY reset
pin is rarely connected.
Fixes issue #14013.
Signed-off-by: robert-hh <robert@hammelrath.com>
On these targets it's possible to enter the bootloader by setting a bit in
an RTC register before resetting.
Structure it in a way that a board can still provide a custom bootloader
handler. The handler here will be the default if none is provided, for any
board based on the supported targets.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
Currently only the Arduino Nano ESP32 defines a machine.bootloader handler
for ESP32. All other boards will intentionally hang.
There is no error message, nor is a NotImplementedError raised. There's no
indication if Micropython has crashed, or if the bootloader was entered but
USB is not working, which is a real problem the ESP32 bootloader has. It's
not possible escape from this hang with ^C or any other means besides
physical access to the reset pin or the ability to cycle power.
Change this to only define an implementation of machine.bootloader() when
there is a handler for it.
Signed-off-by: Trent Piepho <tpiepho@gmail.com>
The new IDF v5.2 deprecated the task cleanup callback we use, so support
for the new option has been implemented in the previous commit. This also
requires a change in the sdkconfig, via a new variable
${SDKCONFIG_IDF_VERSION_SPECIFIC} which is used in all mpconfigboard.cmake
files to include an extra sdkconfig file based on the IDF version in use.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
The legacy I2S "shim" is removed and replaced by the new I2S driver. The
new driver fixes a bug where mono audio plays only in one channel.
Application code size is reduced by 2672 bytes with this change. Tested on
ESP32, ESP32+spiram, ESP32-S3 using example code from
https://github.com/miketeachman/micropython-i2s-examples
Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
Adds Dx and Ax named pins for Arduino Gigi, Arduino Nicla Vision and
Arduino Portenta H7. The analog pins include the dual-pad _C pins.
Signed-off-by: Sebastian Romero <s.romero@arduino.cc>
This commit adds support for the dual-analog-pads on STM32H7 parts. These
pads/pins are called PA0_C/PA1_C/PC2_C/PC3_C in the datasheet. They each
have an analog switch that can optionally connect them to their normal pin
(eg PA0). When the switch is open, the normal and _C pin are independent
pins/pads.
The approach taken in this commit to make these _C pins available to Python
is:
- put them in their own, independent row in the stm32h7_af.csv definition
file, with only the ADC column defined (they are separate machine.Pin
entities, and doing it this way keeps make-pins.py pretty clean)
- allow a board to reference these pins in the board's pins.csv file by the
name PA0_C etc (so a board can alias them, for example)
- these pins (when enabled in pins.csv) now become available like any other
machine.Pin through both machine.Pin.board and machine.Pin.cpu
- BUT these _C pins have a separate pin type which doesn't have any
methods, because they don't have any functionality
- these _C pins can be used with machine.ADC to construct the appropriate
ADC object, either by passing the string as machine.ADC("PA0_C") or by
passing the object as machine.ADC(machine.Pin.cpu.PA0_C)
- if a board defines both the normal and _C pin (eg both PA0 and PA0_C) in
pins.csv then it must not define the analog switch to be closed (this is
a sanity check for the build, because it doesn't make sense to close the
switch and have two separate pins)
Signed-off-by: Damien George <damien@micropython.org>
This new DMA API corrects possible cache coherency issues on chips with
D-Cache, when working with buffers at arbitrary memory locations (i.e.
supplied by Python code).
The API is used by SPI to fix an issue with corrupt data when reading from
SPI using DMA in certain cases. A regression test is included (it depends
on external hardware connection).
Explanation:
1) It's necessary to invalidate D-Cache after a DMA RX operation completes
in case the CPU reads (or speculatively reads) from the DMA RX region
during the operation. This seems to have been the root cause of issue
#13471 (only when src==dest for this case).
2) More generally, it is also necessary to temporarily mark the first and
last cache lines of a DMA RX operation as "uncached", in case the DMA
buffer shares this cache line with unrelated data. The CPU could
otherwise write the other data at any time during the DMA operation (for
example from an interrupt handler), creating a dirty cache line that's
inconsistent with the DMA result.
Fixes issue #13471.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
The existing MPU_CONFIG_DISABLE macro enables the MPU region but disables
all access to it.
The rename is necessary to support an MPU_CONFIG_DISABLE macro that
actually disables the MPU region entirely.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
With LAN8742, LAN8720, LAN83825 and DP83848 as possible options, and the
symbols PHY_LAN8720, PHY_LAN8742, PHY_DP83825 and PHY_DP8348. The default
is PHY_LAN8742 which is the existing behaviour.
The eth_init() parameters for the Portenta H7 board are set to phy_addr=0
and phy_type=LAN8742, which matches the previous defaults and the
schematics.
Tested with LAN8720 and DP83848 breakout boards at 10M Duplex and 100M
Duplex modes.
Signed-off-by: robert-hh <robert@hammelrath.com>
The default value is 0, which is compatible with the existing behaviour.
Implementing that required changes to eth.c as well. The value of phy_addr
is added to the eth_t data type.
Tested with a STM32F767 and a STM32H750 device.
Signed-off-by: robert-hh <robert@hammelrath.com>
The STATIC macro was introduced a very long time ago in commit
d5df6cd44a. The original reason for this was
to have the option to define it to nothing so that all static functions
become global functions and therefore visible to certain debug tools, so
one could do function size comparison and other things.
This STATIC feature is rarely (if ever) used. And with the use of LTO and
heavy inline optimisation, analysing the size of individual functions when
they are not static is not a good representation of the size of code when
fully optimised.
So the macro does not have much use and it's simpler to just remove it.
Then you know exactly what it's doing. For example, newcomers don't have
to learn what the STATIC macro is and why it exists. Reading the code is
also less "loud" with a lowercase static.
One other minor point in favour of removing it, is that it stops bugs with
`STATIC inline`, which should always be `static inline`.
Methodology for this commit was:
1) git ls-files | egrep '\.[ch]$' | \
xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/"
2) Do some manual cleanup in the diff by searching for the word STATIC in
comments and changing those back.
3) "git-grep STATIC docs/", manually fixed those cases.
4) "rg -t python STATIC", manually fixed codegen lines that used STATIC.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
It's no longer supported by Emscripten (at least at 3.1.55). And it's not
needed when the output is WASM, which it is by default.
Signed-off-by: Damien George <damien@micropython.org>
This sets the BLE key distribution parameters at runtime. This isn't
needed in most ports since we already set the default values in
`extmod/nimble/syscfg/syscfg.h`; however in the ESP32 port that
headerfile is not used, and the default values in the ESP-IDF don't
enable key distribution nor can we change those defaults via
`sdkconfig`. Thus we're setting these values explicitly at runtime.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This moves the runtime initialisation of `ble_hs_cfg` to happen after
`nimble_port_init()`. That is consistent with the order used in NimBLE
examples. On the ESP32 port this is needed because the ESP-IDF sets up
the default RAM secret store callbacks in its implementation of
`nimble_port_init()` (specifically, it calls `esp_nimble_init()` which
in turn calls `ble_store_ram_init()`). We want to override those with
our own callbacks to implement the `IRQ_[GS]ET_SECRET` events in Python.
Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
This test cannot run on boards that have a native USB REPL, so rename it to
indicate that its "special". This makes it easier to run a subset of
tests, for example:
./run-multitests.py multi_bluetooth/ble*.py
./run-multitests.py multi_bluetooth/perf*.py
./run-multitests.py multi_bluetooth/stress*.py
Signed-off-by: Damien George <damien@micropython.org>
Because `mpthreadport.h` is included by `mpthread.h`.
Also remove unnecessary include of `mpthreadport.h` in esp32's `main.c`.
Signed-off-by: Damien George <damien@micropython.org>
This call used to be needed when there was an `emit_bc_pre()` function that
needed to be called at the start of each emitted bytecode. But in
8e7745eb31 that function was removed and now
the call to `mp_emit_bc_adjust_stack_size()` does nothing when adjusting by
0 entries, so it can be removed.
Signed-off-by: Damien George <damien@micropython.org>
For boards with MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES and up.
This gets samd21 boards working (which need the vfs module in _boot.py),
B_L072Z_LRWAN1, and nrf boards with smaller MCUs that use CORE or BASIC
feature levels.
Signed-off-by: robert-hh <robert@hammelrath.com>