Wykres commitów

70 Commity (master)

Autor SHA1 Wiadomość Data
Phil Howard dda9b9c6da all: Prune trailing whitespace.
Prune trailing whitespace across the whole project (almost), done
automatically with:

    grep -IUrl --color "[[:blank:]]$" --exclude-dir=.git --exclude=*.exp |\
        xargs sed -i 's/[[:space:]]*$//'

Exceptions:
- Skip third-party code in lib/ and drivers/cc3100/
- Skip generated code in bluetooth_init_cc2564C_1.5.c
- Preserve command output whitespace in docs, eg:
  docs/esp8266/tutorial/repl.rst

Signed-off-by: Phil Howard <phil@gadgetoid.com>
2024-03-07 16:25:17 +11:00
Angus Gratton decf8e6a8b all: Remove the "STATIC" macro and just use "static" instead.
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>
2024-03-07 14:20:42 +11:00
Angus Gratton 00ba6aaae4 ports: On cold boot, enable USB after boot.py completes.
For mimxrt, nrf, renesas-ra, rp2 and samd ports, this commit implements
similar behaviour to the stm32 port, where USB is only brought up after
boot.py completes execution.

Currently this doesn't add any useful functionality (and may break
workflows that depend on USB-CDC being live in boot.py), however it's a
precondition for more usable workflows with USB devices defined in
Python (allows setting up USB interfaces in boot.py before the device
enumerates for the first time).

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-02-15 12:31:26 +11:00
iabdalkader e111793d8d nrf: Fix _start() build issue with CMSIS 5.9.0.
The `_start` function prototype is now declared as no-return, so `main()`
can't return.

To fix this, `main()` is replaced with `_start`.

Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-01-22 12:40:16 +11:00
Maarten van der Schrieck 3bca93b2d0 ports: Fix sys.stdout.buffer.write() return value.
MicroPython code may rely on the return value of sys.stdout.buffer.write()
to reflect the number of bytes actually written. While in most scenarios a
write() operation is successful, there are cases where it fails, leading to
data loss. This problem arises because, currently, write() merely returns
the number of bytes it was supposed to write, without indication of
failure.

One scenario where write() might fail, is where USB is used and the
receiving end doesn't read quickly enough to empty the receive buffer. In
that case, write() on the MicroPython side can timeout, resulting in the
loss of data without any indication, a behavior observed notably in
communication between a Pi Pico as a client and a Linux host using the ACM
driver.

A complex issue arises with mp_hal_stdout_tx_strn() when it involves
multiple outputs, such as USB, dupterm and hardware UART. The challenge is
in handling cases where writing to one output is successful, but another
fails, either fully or partially. This patch implements the following
solution:

mp_hal_stdout_tx_strn() attempts to write len bytes to all of the possible
destinations for that data, and returns the minimum successful write
length.

The implementation of this is complicated by several factors:
- multiple outputs may be enabled or disabled at compiled time
- multiple outputs may be enabled or disabled at runtime
- mp_os_dupterm_tx_strn() is one such output, optionally containing
  multiple additional outputs
- each of these outputs may or may not be able to report success
- each of these outputs may or may not be able to report partial writes

As a result, there's no single strategy that fits all ports, necessitating
unique logic for each instance of mp_hal_stdout_tx_strn().

Note that addressing sys.stdout.write() is more complex due to its data
modification process ("cooked" output), and it remains unchanged in this
patch. Developers who are concerned about accurate return values from
write operations should use sys.stdout.buffer.write().

This patch might disrupt some existing code, but it's also expected to
resolve issues, considering that the peculiar return value behavior of
sys.stdout.buffer.write() is not well-documented and likely not widely
known. Therefore, it's improbable that much existing code relies on the
previous behavior.

Signed-off-by: Maarten van der Schrieck <maarten@thingsconnected.nl>
2023-12-22 10:32:46 +11:00
Damien George cf490a7091 all: Fix various spelling mistakes found by codespell 2.2.6.
Signed-off-by: Damien George <damien@micropython.org>
2023-10-03 11:24:50 +11:00
Damien George b1229efbd1 all: Fix spelling mistakes based on codespell check.
Signed-off-by: Damien George <damien@micropython.org>
2023-04-27 18:03:06 +10:00
Damien George 38e7b842c6 ports: Implement simple write polling for stdout.
This is a best-effort implementation of write polling.  It's difficult to
do correctly because if there are multiple output streams (eg UART and USB
CDC) then some may not be writeable while others are.  A full solution
should also have a return value from mp_hal_stdout_tx_strn(), returning the
number of bytes written to the stream(s).  That's also hard to define.

The renesas-ra and stm32 ports already implement a similar best-effort
mechanism for write polling.

Fixes issue #11026.

Signed-off-by: Damien George <damien@micropython.org>
2023-03-23 13:51:17 +11:00
robert-hh 564945a2a0 nrf/boards/seeed_xiao_nrf52: Add defn for Seeed XIAO NRF52840 Sense.
It keeps compatibility with the XIAO bootloader by:
- using Soft Device 7.3.0
- reserving 48k memory for the bootloader.

So on double reset a drive pops for uploading an uf2 image or a nrfutil zip
pkg file.  Instructions to create it from a hex file are included.  The
bootloader can as well be activated with the touch 1200 option of nrfutil.

The script download_ble_stack.sh has been adapted to get the version 7.3.0
soft device files.  It may have to be executed once before building.

The file system is set to 256k and the pin definitions are adapted.
Besides that, it has the common functionality and omissions.  The on-board
sensors and additional flash can be supported by Python scripts.
2022-12-15 14:27:08 +11:00
David Lechner 8a69c54211 nrf: Use MP_REGISTER_ROOT_POINTER().
This uses MP_REGISTER_ROOT_POINTER() to register all port-specific root
pointers for the nrf port.

Signed-off-by: David Lechner <david@pybricks.com>
2022-07-18 13:50:34 +10:00
robert-hh cca2305211 nrf/drivers/usb: Fix reading of a single USB CDC character. 2022-07-17 00:13:15 +10:00
robert-hh c985a0b514 nrf/drivers/usb: Add a tud_cdc_rx_cb() callback to check interrupt char. 2022-07-17 00:12:03 +10:00
robert-hh 60539ea162 nrf/drivers/usb: Probe for interrupt char in USB CDC task.
And ensure that the input queue is empty when scheduling the interrupt.
2022-07-17 00:11:14 +10:00
Stuart Langridge 30c7f1790b nrf/drivers/bluetooth: Handle PHY_UPDATE messages, used in Bluetooth 5.
Some devices, such as the LightBlue BTLE app on iOS, try to use Bluetooth 5
when connecting to a device.  This means that they will send a
BLE_GAP_EVT_PHY_UPDATE_REQUEST message to shift to a new physical layer.
If this event isn't handled, LightBlue (and likely other Bluetooth 5.0
central devices) will try to connect and then fail, staying in
"Connecting..." state forever.  This message should be replied to with
sd_ble_gap_phy_update, as documented in
drivers/bluetooth/s140_nrf52_6.1.1/s140_nrf52_6.1.1_API/include/ble_gap.h.

This commit handles the event.  LightBlue can now successfully connect to a
BTLE device on a P10059 nRF52840 dongle running MicroPython.  Two other
related events have logging added in case they are needed in the future.
2022-07-16 23:46:30 +10:00
Andrew Leech f92da1adc4 nrf/drivers/usb: Fix MP_STREAM_POLL_RD support on USB CDC.
This gets ipoll working on USB CDC stdin.
2022-03-30 15:34:25 +11:00
Andrew Leech dc8b43adc7 nrf/drivers/usb: Fix background events/scheduling while at USB REPL. 2022-03-30 15:33:29 +11:00
Glenn Ruben Bakke 5a873e27eb nrf/drivers: Add support for using flash block device with SoftDevice.
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.
2021-08-08 23:09:26 +10:00
Damien George 96c6b8cae3 ports: Rename USBD_VID/PID config macros to MICROPY_HW_USB_VID/PID.
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>
2021-08-07 23:13:55 +10:00
Damien George 136369d72f all: Update to point to files in new shared/ directory.
Signed-off-by: Damien George <damien@micropython.org>
2021-07-12 17:08:10 +10:00
Damien George e9e9c76ddf all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.
To match mp_sched_exception() and mp_sched_schedule().

Signed-off-by: Damien George <damien@micropython.org>
2021-04-30 15:13:43 +10:00
Damien George 701fdcacaf nrf/drivers/usb: Add USBD_IRQHandler which calls tud_int_handler.
This is needed for TinyUSB to process USB device IRQs.

Related to #6325.

Signed-off-by: Damien George <damien@micropython.org>
2021-02-13 13:52:53 +11:00
Damien George 035d16126a ports: Update to build with new tinyusb.
Signed-off-by: Damien George <damien@micropython.org>
2021-02-12 12:50:36 +11:00
Damien George 18518e26a7 ports: Use correct in/out endpoint size in TUD_CDC_DESCRIPTOR.
The last argument of TUD_CDC_DESCRIPTOR() is the endpoint size (or
wMaxPacketSize), not the CDC RX buffer size (which can be larger than the
endpoint size).

Signed-off-by: Damien George <damien@micropython.org>
2020-10-17 15:49:16 +11:00
Damien George 27e117307d nrf: Remove unnecessary includes of mpconfigport.h and its header guard.
The mpconfigport.h file is an internal header and should only ever be
included once by mpconfig.h.

Signed-off-by: Damien George <damien@micropython.org>
2020-09-09 00:13:34 +10:00
Glenn Ruben Bakke f22f7b285e nrf/bluetooth/ble_uart: Swap end character on cooked strings.
Changing line ending character of cooked strings makes rshell/pyboard.py
work correctly over Bluetooth socat/pts devices.
2020-07-01 22:51:30 +10:00
Glenn Ruben Bakke 5996bf72f1 nrf/bluetooth/ble_uart: Fix random advertisement name.
The storage space of the advertisement name is not declared static, leading
to a random advertisement name.  This commit fixes the issue by declaring
it static.
2020-07-01 22:50:56 +10:00
Glenn Ruben Bakke ab0c14dba0 nrf/bluetooth/ble_uart: Add mp_hal_stdio_poll function.
This adds support for enabling MICROPY_PY_SYS_STDFILES when running UART
over Bluetooth (NUS).
2020-07-01 22:50:41 +10:00
Glenn Ruben Bakke fc1f22a097 nrf/bluetooth: Handle data length update request.
The Bluetooth link gets disconnected when connecting from a PC after 30-40
seconds.  This commit adds handling of the data length update request.  The
data length parameter pointer is set to NULL in the reply,  letting the
SoftDevice automatically set values and use them in the data length update
procedure.
2020-07-01 22:49:04 +10:00
Glenn Ruben Bakke 9dfb4ae6aa nrf/bluetooth/ble_uart: Fix implicit declaration of function.
mp_keyboard_interrupt() triggers a compiler error because the function is
implicitly declared.  This commit adds "py/runtime.h" to the includes.

Fixes issue #5732.
2020-07-01 22:48:25 +10:00
Glenn Ruben Bakke 8d71cc2e7d nrf/bluetooth: Use MP_ERROR_TEXT for all error messages.
This follows up on commit def76fe4d9.

Fixes issue #6152.
2020-06-17 11:33:22 +10:00
Jim Mussared e7f8c7d9a3 nrf: Update to work with nrfx v2.0.0, to match TinyUSB.
Commit 6cea369b89 updated the TinyUSB
submodule to a version based on nrfx v2.0.0.  This commit updates the nrf
port to work with the latest TinyUSB and nrfx v2.0.0.
2020-05-15 15:06:02 +10:00
Jim Mussared def76fe4d9 all: Use MP_ERROR_TEXT for all error messages. 2020-04-05 15:02:06 +10:00
Damien George ac8383a95d nrf: Use MICROPY_HW_ENABLE_RNG instead of MICROPY_PY_RANDOM_HW_RNG.
The "random" module no longer uses the hardware RNG (the extmod version of
this module has a pseudo-random number generator), so the config option
MICROPY_PY_RANDOM_HW_RNG is no longer meaningful.  This commit replaces it
with MICROPY_HW_ENABLE_RNG, which controls whether the hardware RNG is
included in the build.
2020-02-18 12:43:16 +11:00
Damien George 6ad3bb1e12 nrf: Remove custom "random" module and use extmod version instead.
Hardware RNG code is moved to drivers/rng.[ch].
2020-02-18 12:43:16 +11:00
cccc 4f3e5ea934 nrf/drivers/bluetooth: Fix variable initialisation error with older gcc.
Without this change, arm-none-eabi-gcc version 4.9.3 (at least) would give
a "missing braces around initializer" error.
2020-02-16 23:46:27 +11:00
Damien George ad7213d3c3 py: Add mp_raise_msg_varg helper and use it where appropriate.
This commit adds mp_raise_msg_varg(type, fmt, ...) as a helper for
nlr_raise(mp_obj_new_exception_msg_varg(type, fmt, ...)).  It makes the
C-level API for raising exceptions more consistent, and reduces code size
on most ports:

   bare-arm:   +28 +0.042%
minimal x86:  +100 +0.067%
   unix x64:   -56 -0.011%
unix nanbox:  -300 -0.068%
      stm32:  -204 -0.054% PYBV10
     cc3200:    +0 +0.000%
    esp8266:   -64 -0.010% GENERIC
      esp32:  -104 -0.007% GENERIC
        nrf:  -136 -0.094% pca10040
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2020-02-13 11:52:40 +11:00
Damien George 580fd636c0 nrf/drivers: Use mp_raise_msg where appropriate, and shorten exc msgs.
If the exception doesn't need printf-style formatting then calling
mp_raise_msg is more efficient.  Also shorten exception messages to match
style in core and other ports.
2020-02-11 11:45:14 +11:00
Glenn Ruben Bakke 82fe6b0526 nrf: Add nrf9160 base support.
This patch add basic building blocks for nrf9P60.

It also includes a secure bootloader which forwards all
possible peripherals that are user selectable to become
non-secure. After configuring Flash, RAM and peripherals
the secure bootloader will jump to the non-secure domain
where MicroPython is placed.

The minimum size of a secure boot has to be a flash
block of 32Kb, hence why the linker scripts are
offsetting the main application this much.

The RAM offset is set to 128K, to allow for later
integration of Nordic Semiconductor's BSD socket
library which reserves the range 0x20010000 - 0x2001FFFF.
2019-10-10 21:35:27 +02:00
Glenn Ruben Bakke 60b0b69f20 nrf: Add tinyusb support for nrf52840.
Add nrf-port finyusb driver files. USB CDC can be activated
by board configuration files using the MICROPY_HW_USB_CDC.

Updating BLE driver, Makefile, nrfx-glue and main.c to plug
in the tinyusb stack.
2019-10-10 20:21:07 +02:00
Glenn Ruben Bakke cf383412ef nrf/flash: Update flash driver to use nrfx_nvmc driver.
The the nrfx driver is aware of chip specific registers, while
the raw HAL abstraction is not. This driver enables use of NVMC
in non-secure domain for nrf9160.
2019-10-02 21:28:34 +02:00
Damien George 1fe1ff935b nrf: Clean up source by removing tabs, trailing spaces, non-ASCII chars. 2019-08-28 13:34:45 +10:00
Glenn Ruben Bakke 696549d2e5 nrf/bluetooth: Deprecate use of SoftDevice s140 v6.0.0.
Removing linker script for nrf52840 s140 v6.0.0 as pca10056
target board now points to the new v6.1.1. Also, removing the
entry from the download_ble_stack.sh script.
2019-03-15 20:50:15 +01:00
Glenn Ruben Bakke d3c1436e75 nrf/bluetooth: Add support for SoftDevice s140 version 6.1.1.
Updating download script to fetch the new SoftDevice, and
adding corresponding linker script for the BLE stack.
2019-03-15 20:50:15 +01:00
Glenn Ruben Bakke 1e5e3e3d48 nrf/bluetooth: Deprecate use of SoftDevice s132 v6.0.0.
Removing linker script for nrf52832 s132 v6.0.0 as all target
boards now points to the new v6.1.1. Also, removing the entry
from the download_ble_stack.sh script.
2019-03-15 20:50:15 +01:00
Nguyen Hoan Hoang e8ed2dea71 nrf/bluetooth: Add support for SoftDevice s132 version 6.1.1.
Updating download script to fetch the new SoftDevice, and
adding corresponding linker script for the BLE stack.
2019-03-15 20:50:15 +01:00
Glenn Ruben Bakke ca2bb66127 nrf/bluetooth: Resolve compilation warning in ble_drv.c.
This patch makes sure that the char_data.props is first
assigned a value before other flags are OR'd in.
Resolves compilation warning on possible unitialized variable.
2019-02-20 07:25:51 +01:00
Glenn Ruben Bakke 0c6f5bc529 nrf/bluetooth: Improve advertisment behavior for nrf52 targets.
This patch makes sure that advertisment data is located in
persistent static RAM memory throughout the advertisment.

Also, setting m_adv_handle to predifined
BLE_GAP_ADV_SET_HANDLE_NOT_SET value to indicate first time
usage of the handle. Upon first advertisment configuration
this will be populated with a handle value returned by the
stack (s132/s140).
2019-02-20 07:25:51 +01:00
Stig Bjørlykke 63eae33b7b nrf/ticker: Remove duplicate NRFX_IRQ_PRIORITY_SET. 2019-01-31 17:50:10 +11:00
Glenn Ruben Bakke 9e5768a6db nrf/bluetooth: Update BLE stack download script.
Due to new webpages at nordicsemi.com, the download links
for Bluetooth LE stacks were broken.

This patch updates the links to new locations for the current
targets.
2018-12-10 20:42:06 +01:00
Glenn Ruben Bakke 11bc38d55f nrf/bluetooth: Set GAP_ADV_MAX_SIZE to 31 (s132/s140).
For s132 and s140, GAP_ADV_MAX_SIZE was currently set to
BLE_GATT_ATT_MTU_DEFAULT, which is 23. The correct value
should have been 31, but there are no define for this in
the s132/s140 header files as for s110.

Updating define in ble_drv.c to the correct value of 31.
2018-10-11 23:38:11 +02:00