When MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 is enabled the port's hardware
I2C transfer functions should support the MP_MACHINE_I2C_FLAG_WRITE1
option, but software I2C will not. So add a flag to the I2C protocol
struct so each individual protocol can indicate whether it supports this
option or not.
Fixes issue #8765.
Signed-off-by: Damien George <damien@micropython.org>
Both led_init and led_state are configurable via MBOOT_BOARD_LED_INIT and
MBOOT_BOARD_LED_STATE respectively, so don't need to be MP_WEAK.
Furthermore, led_state and led0_state are private to ui.c so can be made
static.
Signed-off-by: Damien George <damien@micropython.org>
This IO was enabled in IDF commit 68f8b999bb69563f2f3d1d897bc073968f41f3bf,
which is available in IDF release v4.3.2 and above.
Signed-off-by: Damien George <damien@micropython.org>
Otherwise include directories are added unconditionally to the build
variables if the component (submodule) is checked out. This can lead to,
eg, the esp32 build using lib/lwip header files, instead of lwip header
files from the IDF.
Fixes issue #8727.
Signed-off-by: Damien George <damien@micropython.org>
System config block contains hardware unrelated to USB. So calling
`__SYSCFG_CLK_DISABLE()` during `HAL_PCD_MspDeInit()` has an adverse effect
on other system functionality.
Removing call to `__SYSCFG_CLK_DISABLE()` to rectify this issue.
This call was there since the beginning of the USB CDC code, added in
b30c02afa0.
According to ST Errata ES0206 Rev 18, Section 2.2.1, on STM32F427x,
STM32F437x, STM32F429x and STM32F439x.
If the system tick interrupt is enabled during stop mode while certain
bits are set in the DBGMCU_CR, then the system will immediately wake
from stop mode.
Suggested workaround is to disable system tick timer interrupt when
entering stop mode.
According to ST Errate ES0394 Rev 11, Section 2.2.17, on STM32WB55Cx and
STM32WB35Cx.
If the system tick interrupt is enabled during stop 0, stop 1 or stop 2
while certain bits are set in DBGMCU_CR, then system will immediately
wake from stop mode but the system remains in low power state. The CPU
therefore fetches incorrect data from inactive Flash, which can cause a
hard fault.
Suggested workaround is to disable system tick timer interrupt when
entering stop mode.
This was added by mistake in 8f68e26f79 when
adding support for G4 MCUs, which does not using this get_bank() function.
FLASH_OPTR_DBANK is only defined on G4 and L4 MCUs, so on H7 this
FLASH_BANK_2 code was being wrongly excluded.
Signed-off-by: Damien George <damien@micropython.org>
Also remove redundant modusocket.c and modnetwork.c sources, they are
already added by extmod/extmod.cmake.
Signed-off-by: Damien George <damien@micropython.org>
The callback passed to add_alarm_in_ms must return microseconds, even
though the initial delay is in milliseconds. Fix this use, and to avoid
further confusion use the add_alarm_in_us function instead.
Signed-off-by: Damien George <damien@micropython.org>
The nxp_driver v2.10 allows for/requires some changes to the code:
- Remove some part of pwm_backlog.*, which is provided by the lib now.
- Change eth.c: the newer versions have additional parameters of the
library versions.
- Change sdcard.c: use TransferBlocking instead of TransferNonblocking.
- Add some support for the MIMXRT1176 device.
- Set the clocks for UART, I2C, Timer.
- Integrate the I2S module and fix a rebase error.
- Use blocking transfer only for SPI. It's faster and interferes less with
other modules.
- Use the clock_config.c files of library v2.8.5. The mimxrt files keeps
the clock_config.c files from Verson 2.8.5. With clock_config.c from
v2.10, the boards do not work. Refactoring of the clock set-up is on the
to-do list.
- Enable expiry timers for UART, I2C and SPI, avoiding a stall in library
code.
- The clock_config.* files are moved from the board-specific directories to
the boards directory and given a MCU related name.
It's no longer needed because this macro is now processed after
preprocessing the source code via cpp (in the qstr extraction stage), which
means unused MP_REGISTER_MODULE's are filtered out by the preprocessor.
Signed-off-by: Damien George <damien@micropython.org>
This cleans up the parsing of MP_REGISTER_MODULE() and generation of
genhdr/moduledefs.h so that it uses the same process as compressed error
string messages, using the output of qstr extraction.
This makes sure all MP_REGISTER_MODULE()'s that are part of the build are
correctly picked up. Previously the extraction would miss some (eg if you
had a mod.c file in the board directory for an stm32 board).
Build speed is more or less unchanged.
Thanks to @stinos for the ports/windows/msvc/genhdr.targets changes.
Signed-off-by: Damien George <damien@micropython.org>
The following changes are made:
- Use software SPI for external SPI flash access when building mboot.
- Enable the mboot filesystem-loading feature, with FAT FS support.
- Increase the frequency of the CPU when in mboot to 96MHz, to increase the
speed of SPI flash accesses and programming.
Signed-off-by: Damien George <damien@micropython.org>
This allows a board to modify initial_r0 if needed.
Also make default board behaviour functions always available, named as
mboot_get_reset_mode_default and mboot_state_change_default.
Signed-off-by: Damien George <damien@micropython.org>
I2C transfers are much more efficient if they are combined, instead of
doing separate writes and reads.
Fixes issue #7134.
Signed-off-by: Damien George <damien@micropython.org>
This follows on from a5324a1074 and allows
mpy-cross to dynamically select whether ARMv7-M instructions are supported
in @micropython.asm_thumb functions.
The config option MICROPY_EMIT_INLINE_THUMB_ARMV7M is no longer needed, it
is now controlled by MICROPY_EMIT_THUMB_ARMV7M.
Signed-off-by: Damien George <damien@micropython.org>
For ports with MICROPY_VFS and MICROPY_PY_IO enabled their configuration
can now be simplified to use the defaults for mp_import_stat and
mp_builtin_open.
This commit makes no functional change, except for the following minor
points:
- the built-in "open" is removed from the minimal port (it previously did
nothing)
- the duplicate built-in "input" is removed from the esp32 port
- qemu-arm now delegates to VFS import/open
Signed-off-by: Damien George <damien@micropython.org>
The following changes are made:
- If MICROPY_VFS is enabled then mp_vfs_import_stat and mp_vfs_open are
automatically used for mp_import_stat and mp_builtin_open respectively.
- If MICROPY_PY_IO is enabled then "open" is automatically included in the
set of builtins, and points to mp_builtin_open_obj.
This helps to clean up and simplify the most common port configuration.
Signed-off-by: Damien George <damien@micropython.org>
This reverts commit 2668337f36.
The issue with potential breaking of the BLE RX path in the radio is fixed
since WS v1.12.0.
Signed-off-by: Damien George <damien@micropython.org>
This adds a new command line option to the unix port `-X realtime` to
enable realtime priority on threads. This enables high precision timers
for applications that need more accurate timers.
Related docs:
https://developer.apple.com/library/archive/technotes/tn2169/_index.html
Fixes issue #8621.
Signed-off-by: David Lechner <david@pybricks.com>
This adds the `mp_` prefix to the `thread_t` type. The name `thread_t`
conflicts with the same in `mach/mach_types.h` on macOS.
Signed-off-by: David Lechner <david@lechnology.com>
Reasons for removal:
- It did not work properly because it stopped the hardware watchdog
timer while keeping the software watchdog running (issue #8597).
- There isn't a deinit method for the WDT in any other port.
- "The watchdog is not intended to be stopped. That is a feature."
(See #8600.)
Replace the timer-based sleep with the standard win32 call since the former
has no benefits: even though it allows specifying the time in 100uSec
chunks, the actual resolution is still limited by the OS and is never
better than 1mSec.
For clarity move all of this next to the mp_hal_delay_ms definition so all
related functions are in one place.
This replaces occurences of
foo_t *foo = m_new_obj(foo_t);
foo->base.type = &foo_type;
with
foo_t *foo = mp_obj_malloc(foo_t, &foo_type);
Excludes any places where base is a sub-field or when new0/memset is used.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* Change device name table to list style to show properly.
* Change the link of cable connection information to the latest.
Signed-off-by: Takeo Takahashi <takeo.takahashi.xv@renesas.com>
This contains a string useful for identifying the underlying machine. This
string is kept consistent with the second part of the REPL banner via the
new config option MICROPY_BANNER_MACHINE.
This makes os.uname() more or less redundant, as all the information in
os.uname() is now available in the sys module.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds the git hash and build date to sys.version. This is
allowed according to CPython docs, and is what PyPy does. The docs state:
A string containing the version number of the Python interpreter plus
additional information on the build number and compiler used.
Eg on CPython:
Python 3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.version
'3.10.4 (main, Mar 23 2022, 23:05:40) [GCC 11.2.0]'
and PyPy:
Python 2.7.12 (5.6.0+dfsg-4, Nov 20 2016, 10:43:30)
[PyPy 5.6.0 with GCC 6.2.0 20161109] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> import sys
>>>> sys.version
'2.7.12 (5.6.0+dfsg-4, Nov 20 2016, 10:43:30)\n[PyPy 5.6.0 with GCC ...
With this commit on MicroPython we now have:
MicroPython v1.18-371-g9d08eb024 on 2022-04-28; linux [GCC 11.2.0] v...
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> import sys
>>> sys.version
'3.4.0; MicroPython v1.18-371-g9d08eb024 on 2022-04-28'
Note that the start of the banner is the same as the end of sys.version.
This helps to keep code size under control because the string can be reused
by the compiler.
Signed-off-by: Damien George <damien@micropython.org>
This commit adds a board definition for NUCLEO_G0B1RE. This board has the
REPL on UART2 which is connected to the on-board ST-link USB-UART.
Signed-off-by: Asensio Lorenzo Sempere <asensio.aerospace@gmail.com>
This implements self-triggering of the Flash NVIC interrupt on Cortex-M0
devices, which allows enabling internal storage on those MCUs.
Signed-off-by: Asensio Lorenzo Sempere <asensio.aerospace@gmail.com>
These files that are reformatted only now fall under the list of files to
apply uncrustify/black formatting to.
Signed-off-by: Damien George <damien@micropython.org>
To avoid any I/O glitches in mp_hal_pin_config, make sure a valid alternate
function is set in AFR first before switching the pin mode. When switching
from AF to INPUT or OUTPUT, the AF in AFR will remain valid up until the
pin mode is switched.
On ESP32 S2/S3 variants, GPIO0 through GPIO21 are valid RTC pins. This
commit defines the valid RTC_VALID_EXT_PINS for the S2/S3 variants,
otherwise, it keeps functionality the same.
For ESP32-S3 configurations, CONFIG_SPIRAM_MODE_OCT requires pins 33-37 for
PSRAM. So exclude them from the machine_pin_type and machine_pin_irq_type
object tables.
These boards do not build with IDF v4.4 because the section .iram0.text
does not fit in region iram0_0_seg. Enabling SPIRAM increases the code
size so use -Os instead of -O2 to build these boards.
Fixes issue #8260.
Some S2/S3 modules don't use the native USB interface but instead have an
external USB-UART. To make the GENERIC_S3/S3 firmware work on these boards
the UART REPL is enabled in addition to the native USB CDC REPL.
Fixes issues #8418 and #8524.
Signed-off-by: Damien George <damien@micropython.org>
Duplication of characters is caused by re-entrant calls from separate cores
of uart_fill_tx_fifo(). This patch uses a mutex to ensure that a
re-entrant execution of the function returns without affecting the UART
FIFO.
Fixes issues #8344 and #8360.
- Add board-level configuration option to set the SMPS supply mode.
- Wait for valid voltage levels after configuring the SMPS mode.
- Wait for external supply ready flag if SMPS supplies external circuitry.
All user interface (LED, button) code has been moved to ui.c, and the
interface to this code with the rest of the system now goes through calls
to mboot_state_change(). This state-change function can be overridden by a
board to fully customise the user interface behaviour.
Signed-off-by: Damien George <damien@micropython.org>
This follows the CPython change: https://bugs.python.org/issue21455
Socket listen backlog defaults to 2 if not given, based on most bare metal
targets not having many resources for a large backlog. On UNIX it defaults
to SOMAXCONN or 128, whichever is less.
Changes in this commit:
- Fix USB CDC RX handling to not block when unprocessed. The fix follows
5873390226.
- Fix dupterm rx.
- Remove some obsolete lines.
This commit changes the method of waiting for SPI being not busy. Instead
of the FIFO size, the TransferBusyFlag is probed.
Also, raise an error if the transfer failed.
Changes in this commit:
- Start the RTC Timer at system boot. Otherwise time.time() will advance
only if an RTC() object was created.
- Set the time to a more recent date than Jan 1, 1970, if not set. That is
2013/10/14, 19:53:11, MicroPython's first commit.
- Compensate an underflow in in timeutils_seconds_since_2000(), called by
time.time(), if the time is set to a pre-2000 date.
This is enabled at MICROPY_CONFIG_ROM_LEVEL_EXTRA_FEATURES, which is the
default for stm32. Not setting the value in mpconfigboard.h allows boards
to optionally configure it.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit, the USB CDC OUT endpoint got NACK'd if a character
was received but not consumed by the application, e.g. via
sys.stdin.read(). This meant that USB CDC was blocked and no additional
characters could be sent from the host. In particular a ctrl-C could not
interrupt the application if another character was pending.
To fix the issue, the approach in this commit uses a callback tud_cdc_rx_cb
which is called by the TinyUSB stack on reception of new CDC data. By
consuming the data immediately, the endpoint does not stall anymore. The
previous handler tud_cdc_rx_wanted_cb was made obsolete and removed.
In addition some cleanup was done along the way: by adding interrupt_char.c
and removing the existing code mp_hal_set_interrupt_char(). Also, there is
now only one (stdin) ringbuffer.
Fixes issue #7996.
The CAN.initfilterbanks() class method is removed, and its functionality is
replaced with the "num_filter_banks" keyword argument to the CAN
constructor and CAN.init(). This configures the filter bank split.
This new approach provides more flexibility configuring the resources used
by a given CAN instance, allowing other MCUs like H7 to fit the API. It
also brings CAN closer to how other machine peripherals are configured,
where everything is done in the constructor/init method.
This is a breaking change to the CAN API.
CAN.recv() now returns a 5-tuple, with the new element in the second
position being a boolean, True if the ID is extended.
This is a breaking change of the API for CAN.recv().
A CAN bus can have mixed classic/FD nodes. Prior to this patch the CAN API
could be configured for either standard or extended ID, but not both/mixed
operation.
This patch allows extended IDs to be filtered and enabled on a per-message
basis, in send(), setfilter() and clearfilter().
This is a breaking change to the API: init() no longer accepts the extframe
keyword argument.
- Enable CAN FD frame support and BRS.
- Optimize the message RAM usage per FDCAN instance.
- Document the usage and different sections of the Message RAM.
This commit adds support for machine.I2S on the mimxrt port. The I2S API
is consistent with the existing stm32, esp32, and rp2 implementations.
I2S features:
- controller transmit and controller receive
- 16-bit and 32-bit sample sizes
- mono and stereo formats
- sampling frequencies from 8kHz to 48kHz
- 3 modes of operation:
- blocking
- non-blocking with callback
- uasyncio
- configurable internal buffer
- optional MCK
Tested with the following development boards:
- MIMXRT1010_EVK, MIMXRT1015_EVK, MIMXRT1020_EVK, MIMXRT1050_EVK
- Teensy 4.0, Teensy 4.1
- Olimex RT1010
- Seeed ARCH MIX
Tested with the following I2S hardware peripherals:
- UDA1334
- GY-SPH0645LM4H
- WM8960 codec on board the MIMXRT boards and separate breakout board
- INMP441
- PCM5102
- SGTL5000 on the Teensy audio shield
Signed-off-by: Mike Teachman <mike.teachman@gmail.com>
In particular, it is called by the constructor if the instance already
exists. So if the previous instance was deinit'd then it will be deinit'd
a second time.
Signed-off-by: Damien George <damien@micropython.org>
Tested on PYBV10 and PYBD_SF6, with MBOOT_FSLOAD enabled and programming
new firmware from a .dfu.gz file stored on the SD card.
Signed-off-by: Damien George <damien@micropython.org>
If enabled via MBOOT_ADDRESS_SPACE_64BIT (it's disabled by default) then
read addresses will be 64-bit.
Signed-off-by: Damien George <damien@micropython.org>
Even if MBOOT_FSLOAD is disabled, mboot should still check for 0x70ad0080
so it can immediately return to the application if this feature is not
enabled. Otherwise mboot will get stuck in DFU mode.
Signed-off-by: Damien George <damien@micropython.org>
The main functionality of this info function is available via the existing
micropython.mem_info() and micropython.qstr_info() functions. The printing
of the address space layout doesn't add much and removing esp.info() saves
about 600 bytes.
Signed-off-by: Damien George <damien@micropython.org>
Add a new function to control whether held pins will retain their function
through deep-sleep.
Also document this function and explain how to use this in quickref to
retain pin configuration during deep-sleep.
The current pull=Pin.PULL_HOLD argument doesn't make a lot of sense in the
context of what it actually does vs what the ESP32 quickref document says
it does.
This commit removes PULL_HOLD and adds a new hold=True|False keyword
argument to Pin()/Pin.init(). Setting this to True will cause the ESP32 to
lock the configuration of the pin – including direction, output value,
drive strength, pull-up/-down – such that it can't be accidentally changed
and will be retained through a watchdog or internal reset.
Fixes issue #8283, and see also #8284.
According to the C standard the free(void *ptr) function: if ptr is a null
pointer, no action occurs.
Signed-off-by: Peter Züger <zueger.peter@icloud.com>