There is a race between when we run background tasks and when we
sleep. If an interrupt happens between the two, then we may delay
executing the background task. On some ports we checked this for
TinyUSB already. On iMX RT, we didn't which caused USB issues.
This PR makes it more generic for all background tasks including
USB.
Fixes#5086 and maybe others.
This function can be used to enable and disable the DC/DC converter with or
without the Bluetooth stack enabled. It can also be used to query the
current state of the DC/DC.
This commit also adds a definition of ARRAY_SIZE needed by nrfx HAL-layer.
extmod/vfs_lfs.c needs to resolve `mp_hal_time_ns()` in order to calculate
a timestamp from 1970 epoch. A wall clock is not available in the nrf
port, hence the function is implemented to resolve compilation linkage
error. The function always return 0.
Set the default manifest to "modules/manifest.py". This includes files
from the folder "modules/scripts". The manifest default value is overriden
by all nrf51 boards that have SoftDevice present (SD=s110) to save flash.
Also add "modules/manifest.py" which is set to freeze
"modules/scripts/_mkfs.py".
Add a helper script _mkfs.py which automatically formats the file system if
nrf.Flash() is located and a VFS file system has been included in the
compilation.
The precedence is: first LFS1, LFS2 then FAT.
Update the Makefile to handle FROZEN_MANIFEST, and the README with some
small samples on how to use freeze manifests. And add BOARD_DIR to the
Makefile which can be referenced in boards/<board>/mpconfigboard.mk to
include a board specific manifest.
Enable the following features for all boards except
nrf51 boards with SoftDevice present:
- MICROPY_VFS
- MICROPY_PY_NRF
- MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE
Add posibility to override linker script "_fs_size" from make by adding the
FS_SIZE parameter. The syntax of value is linker script syntax. For
example, the value of 131072 bytes can be written as 128K like this:
FS_SIZE=128K.
If not set, default value for "_fs_size" from linker script will be used.
Disable MICROPY_FATFS_MULTI_PARTITION configuration because there is no
partition table in the flash for FATFS to read.
Also, set MICROPY_FATFS_MAX_SS to the size of a flash page. For nrf51 the
value 1024 is set. For nrf52/nrf91 the value 4096 is set.
This documents parameters that can be passed to make to enable a specific
file system to included in the build. Also, document the Makefile override
parameter "FS_SIZE" that can be used to tune the size of the flash region
to use as internal flash file system.
Update flash.c to also be compiled in when
MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE is enabled and SoftDevice is
present.
Update bluetooth/ble_drv.c to forward flash events to flash.c when
MICROPY_HW_ENABLE_INTERNAL_FLASH_STORAGE is enabled.
This commit adds the "nrf" module for port specific modules and objects.
Included in it is the "Flash" object which exposes a block device
implementation to access internal SoC flash.
Thanks to @aykevl aka Ayke van Laethem for the initial implementation.
Calculate the unused flash area on the target device. The values will be
exposed by _unused_flash_start and _unused_flash_length. The start address
and the length are not aligned to either word or pages.
For consistency with other board-level config macros that begin with
MICROPY_HW_USB.
Also allow boards in the mimxrt, nrf and samd ports to configure these
values.
Signed-off-by: Damien George <damien@micropython.org>
Call `supervisor.disable_ble_workflow()` and the BLE workflow will
be disabled until the chip is reset.
This also includes a couple fixes:
1. Terminals can now be deinit by setting the tilegrid to NULL. This
prevents using the tilegrid before display is init.
2. Fix BLE serial send amount when sending more than a single packet.
Fixes#5049
On ESP ctrl-c during fake sleep will now stop the sleep. A crash
on real deep sleep is now fixed as well. (Exception string saving
was crashing on reading the deep sleep exception.) Fixes#4010
This also fixes nRF fake sleep after the first time. The internal
variable wasn't being reset early enough. Fixes#4869
Passing in a PWMOut still works but is deprecated. It will be
removed in CircuitPython 8.0.0
This also switches STM32 timer indices and channel indices to
0-based in our pin data rather than `- 1` everywhere. The latter is
more bug prone.
Most of the way for #3264
Tested on Metro M0, Metro M4, Feather S2, Feather nRF52840, Feather
STM32F4 and Arduino RP2040.
nRF CircuitPython boards will now provide the file transfer
service defined here: https://github.com/adafruit/Adafruit_CircuitPython_BLE_File_Transfer
USB capable boards will only advertise if previously bonded to a
device or if the reset button is pressed during the fast blue
flashes on start up. When pressed, the board will restart again but
the blue period will not flash.
Boards without USB will always advertise.
When previously bonded, the advertisement is private so that no
other peers can connect. If advertising publicly, the tx power is
lowered to reduce the likelihood of bonding from a distance.
This PR also fixes issues with loading identities of bonded peers
so that our address can now be resolved and we can resolve others'
addresses when scanning.
This moves mp_pending_exception from mp_state_vm_t to mp_state_thread_t.
This allows exceptions to be scheduled on a specific thread.
Signed-off-by: David Lechner <david@pybricks.com>
This commit adds a few math functions to the source list in the Makefile,
and implements the log2f function, so that ulab can be compiled on the nrf
boards. It also addresses part of #5162.
This configuration is used by @ladyada and more often than it should
we've discovered late that a change introduced problems building
there.
By adding this to regular CI, hopefully we learn about and fix these
issues sooner rather than later.
This also removes the need to pin share because we don't use the
status LED while user code is running.
The status flashes fallback to the HW_STATUS LED if no RGB LED is
present. Each status has a unique blink pattern as well.
One caveat is the REPL state. In order to not pin share, we set the
RGB color once. PWM and single color will be shutoff immediately but
DotStars and NeoPixels will hold the color until the user overrides
it.
Fixes#4133
After discussing with danh, I noticed that `a/**/b` would not match `a/b`.
After correcting this and re-running "pre-commit run --all", additional
files were reindented, including the codeformat script itself.
In #4683, tannewt noticed that uncrustify was not running on some
file in common-hal.
I investigated and found that it was not being run on a bunch of paths.
Rather than make incremental changes, I rewrote list_files to work
bsaed on regular expressions; these regular expressions are created from
the same git-style glob patterns.
I spot-checked some specific filenames after this change, and all looks good:
```
$ python3 tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c
tools/codeformat.py -v --dry-run tests/basics/int_small.py ports/raspberrypi/common-hal/pulseio/PulseIn.c extmod/virtpin.c tests/thread/thread_exit1.py ports/raspberrypi/background.h extmod/re1.5/recursiveloop.c
uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup extmod/virtpin.c ports/raspberrypi/background.h ports/raspberrypi/common-hal/pulseio/PulseIn.c
black --fast --line-length=99 -v tests/thread/thread_exit1.py
```
recursiveloop and int_small are excluded, while PulseIn, virtpin,
and background are included.
Testing running from a subdirectory (not _specifically_ supported though):
```
(cd ports && python3 ../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c)
../tools/codeformat.py -v --dry-run raspberrypi/common-hal/pulseio/PulseIn.c ../extmod/virtpin.c
uncrustify -c /home/jepler/src/circuitpython/tools/uncrustify.cfg -lC --no-backup ../extmod/virtpin.c raspberrypi/common-hal/pulseio/PulseIn.
```
As a side-effect, a bunch more files are re-formatted now. :-P
H7 compatibility problems in port.c and peripherals/exti
NRF build failures due to new use of const for PinAlarm pin objects
Isolated board flash overage on blackpill_with_flash, remove audio modules
Unify USB-related makefile var and C def as CIRCUITPY_USB.
Always define it as 0 or 1, same as all other settings.
USB_AVAILABLE was conditionally defined in supervisor.mk,
but never actually used to #ifdef USB-related code.
Loosely related to #4546
This is handy for remote characteristics because it allows for
the PacketBuffer binding code to have the correct max size. This
PR also adds checks so we don't write outside the outgoing buffer.
Also found a race condition between timer_disable and redraw, which
would happen if I debugger-paused inside common_hal_rgbmatrix_timer_disable
or put a delay or print inside it. That's what pausing inside reconstruct
fixes.
So that the "right timer" can be chosen, `timer_allocate` now gets the `self`
pointer. It's guaranteed at this point that the pin information is accurate,
so you can e.g., find a PWM unit related to the pins themselves.
This required touching each port to add the parameter even though it's
unused everywhere but raspberrypi.
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t
which is not always the same as the size of a pointer on the target
architecture. So rename this config value to better reflect what it
measures, and also prefix it with MP_.
For uses of BYTES_PER_WORD in setting the stack limit this has been
changed to sizeof(void *), because the stack usually grows with
machine-word sized values (eg an nlr_buf_t has many machine words in it).
Signed-off-by: Damien George <damien@micropython.org>
To simplify config, there's no need to specify MP_PLAT_PRINT_STRN if it's
the same as the default definition in py/mpconfig.h.
Signed-off-by: Damien George <damien@micropython.org>
Add "make submodules" to commands when building for the first time.
Otherwise, on a first time build, the submodules have not been checked out
and a lot of `fatal error: nrfx.h: No such file or directory` errors are
printed.
This changes lots of files to unify `board.h` across ports. It adds
`board_deinit` when CIRCUITPY_ALARM is set. `main.c` uses it to
deinit the board before deep sleeping (even when pretending.)
Deep sleep is now a two step process for the port. First, the
port should prepare to deep sleep based on the given alarms. It
should set alarms for both deep and pretend sleep. In particular,
the pretend versions should be set immediately so that we don't
miss an alarm as we shutdown. These alarms should also wake from
`port_idle_until_interrupt` which is used when pretending to deep
sleep.
Second, when real deep sleeping, `alarm_enter_deep_sleep` is called.
The port should set any alarms it didn't during prepare based on
data it saved internally during prepare.
ESP32-S2 sleep is a bit reorganized to locate more logic with
TimeAlarm. This will help it scale to more alarm types.
Fixes#3786