summaryrefslogtreecommitdiffstatshomepage
path: root/shared/tinyusb
Commit message (Collapse)AuthorAge
* shared/tinyusb: Set MSC max endpoint size based on device speed.iabdalkader2024-12-10
| | | | Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* shared/tinyusb: Wake main task if needed at end of USB ISR.Andrew Leech2024-10-07
| | | | Signed-off-by: Andrew Leech <andrew@alelec.net>
* esp32: Add automatic bootloader handling for S2 and S3.Andrew Leech2024-10-07
| | | | | | | | | Enables support for the ESP standard DTR/RTS based reboot to bootloader. Switches from OTG to Serial/Jtag mode to workaround issue discussed in: https://github.com/espressif/arduino-esp32/issues/6762 Signed-off-by: Andrew Leech <andrew@alelec.net>
* shared/tinyusb: Remove MICROPY_HW_USB_EXTERNAL_TINYUSB.Andrew Leech2024-10-07
| | | | | | No longer needed as shared tinyusb is now used by the esp32 port. Signed-off-by: Andrew Leech <andrew@alelec.net>
* shared/tinyusb: Use new persistent-tx-fifo configure interface.Damien George2024-09-26
| | | | | | The old configuration option has been removed from TinyUSB. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Only run TinyUSB on the main thread if GIL is disabled.Angus Gratton2024-09-19
| | | | | | | | | | | | | | | | | | | If GIL is disabled then there's threat of a race condition if some other code specifically requests USB processing (i.e. to unblock stdio), while a scheduled TinyUSB callback is already running on another thread. Relies on the change in the parent commit, where scheduler is restricted to main thread if GIL is disabled. Fixes #15390 - "TinyUSB callback can't recurse" exceptions on rp2 when using _thread module and USB serial I/O. Adds a unit test for stdin functioning correctly in threads (fails on rp2 port without this fix). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Allow ports to define CDC TX/RX buffer sizes.iabdalkader2024-08-26
| | | | Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* shared/tinyusb/mp_usbd_cdc: Skip writing to an uninitialized USB device.robert-hh2024-07-20
| | | | | | | | | | | During execution of `boot.py` the USB device is not yet initialized. Any attempt to write to the CDC (eg calling `print()`) would lock up the device. This commit skips writing when the USB device is not initialized. Any output from `boot.py` is lost, but the device does not lock up. Also removed unnecessary declaration of `tusb_init()`. Signed-off-by: robert-hh <robert@hammelrath.com>
* shared/tinyusb/mp_usbd_cdc: Fix short CDC TX timeouts.Damien George2024-06-26
| | | | | | | | | | | | | | The `mp_event_wait_ms()` function may return earlier than the requested timeout, and if that happens repeatedly (eg due to lots of USB data and IRQs) then the loop waiting for CDC TX FIFO space to become available may exit much earlier than MICROPY_HW_USB_CDC_TX_TIMEOUT, even when there is no space. Fix this by using `mp_hal_ticks_ms()` to compute a more accurate timeout. The `basics/int_big_mul.py` test fails on RPI_PICO without this fix. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb/mp_usbd_runtime: Fix pointer comparison in assert.Peter Harper2024-06-26
| | | | | | | | | Addresses build warning "comparison of distinct pointer types lacks a cast". Fixes issue #15276. Signed-off-by: Peter Harper <peter.harper@raspberrypi.com>
* shared/tinyusb: Buffer startup CDC data to send to host on connection.Andrew Leech2024-06-04
| | | | | | | | | | | | | | | | | | | | At startup, buffer initial stdout / MicroyPthon banner so that it can be sent to the host on initial connection of the USB serial port. This buffering also works for when the CDC becomes disconnected and the device is still printing to stdout, and when CDC is reconnected the most recent part of stdout (depending on how big the internal USB FIFO is) is flushed to the host. This change is most obvious when you've first plugged in a MicroPython device (or hit reset), when it's a board that uses USB (CDC) serial in the chip itself for the REPL interface. This doesn't apply to UART going via a separate USB-serial chip. The stm32 port already has this buffering behaviour (it doesn't use TinyUSB) and this commit extends such behaviour to rp2, mimxrt, samd and renesas-ra ports, which do use TinyUSB. Signed-off-by: Andrew Leech <andrew@alelec.net>
* shared/tinyusb: Allow ports to use 1200bps-touch without other CDC code.Damien George2024-06-02
| | | | | | | | | | | | | | | | | | This fixes the build for some esp32 and nrf boards (for example `ARDUINO_NANO_33_BLE_SENSE` and `ARDUINO_NANO_ESP32`) due to commit c98789a6d8e05acb608afe4b30cf3ca563419b2d. Changes are: - Allow the CDC TX/RX functions in `mp_usbd_cdc.c` to be enabled separately to those needed for `MICROPY_HW_USB_CDC_1200BPS_TOUCH`. - Add `MICROPY_EXCLUDE_SHARED_TINYUSB_USBD_CDC` option as a temporary workaround for the nrf port to use. - Declare `mp_usbd_line_state_cb()` in a header as a public function. - Fix warning with type cast of `.callback_line_state_changed`. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Add common CDC TX/RX functions.Andrew Leech2024-05-31
| | | | | | | | | | | | There are a few TinyUSB CDC functions used for stdio that are currently replicated across a number of ports. Not surprisingly in a couple of cases these have started to diverge slightly, with additional features added to one of them. This commit consolidates a couple of key shared functions used directly by TinyUSB based ports, and makes those functions available to all. Signed-off-by: Andrew Leech <andrew@alelec.net>
* shared/tinyusb: Stall the CDC IN endpoint while disconnecting.Angus Gratton2024-05-09
| | | | | | | | | | | | | | | | | | | Only when dynamic USB devices are enabled. The issue here is that when the USB reset triggers, the dynamic USB device reset callback is called from inside the TinyUSB task. If that callback tries to print something then it'll call through to tud_cdc_write_flush(), but TinyUSB hasn't finished updating state yet to know it's no longer configured. Subsequently it may try to queue a transfer and then the low-level DCD layer panics. By explicitly stalling the endpoint first, usbd_edpt_claim() will fail and tud_cdc_write_flush() returns immediately. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Fix dynamic USB control callbacks for wLength==0.Angus Gratton2024-04-17
| | | | | | | | | | | | | | | | | | | | In the case where an OUT control transfer triggers with wLength==0 (i.e. all data sent in the SETUP phase, and no additional data phase) the callbacks were previously implemented to return b"" (i.e. an empty buffer for the data phase). However this didn't actually work as intended because b"" can't provide a RW buffer (needed for OUT transfers with a data phase to write data into), so actually the endpoint would stall. The symptom was often that the device process the request (if processing it in the SETUP phase when all information was already available), but the host sees the endpoint stall and eventually returns an error. This commit changes the behaviour so returning True from the SETUP phase of a control transfer queues a zero length status response. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Increase default string descr max length to 40 chars.Damien George2024-03-27
| | | | | | | | When defining custom USB devices, longer strings may be needed. Eventually the memory for string descriptors can be allocated on demand, but for now this bigger value should be reasonable. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Update some code comments for runtime USB.Angus Gratton2024-03-27
| | | | | | | | | Updates a few code comments that were out of date or poorly worded. No code changes. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Don't disconnect on soft reset unless USB was active.Angus Gratton2024-03-27
| | | | | | | | | | | | | | | Previously, constructing the singleton USBDevice object was enough to trigger a USB disconnect on soft reset. Now it also has to be active. The only case where this changes the behaviour is if the USBDevice object has been constructed but never set to active (no more disconnect in this case). Otherwise, behaviour is the same. This change was requested by hippy on the raspberrypi forums. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/machine_usb_device: Add support for Python USB devices.Angus Gratton2024-03-15
| | | | | | | | | | | | | 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>
* all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton2024-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. 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>
* ports: On cold boot, enable USB after boot.py completes.Angus Gratton2024-02-15
| | | | | | | | | | | | | | | | 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>
* extmod/modmachine: Provide common Python bindings for bootloader().Damien George2023-11-30
| | | | Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Add a helper for hex string conversion.Angus Gratton2023-11-16
| | | | | | | | | | | Change the rp2 and renesas-ra ports to use the helper function. Saves copy-pasta, at the small cost of one more function call in the firmware (if not using LTO). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Expose mp_usbd_task as a public function.Damien George2023-11-09
| | | | Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Schedule TinyUSB task function from dcd_event_handler.Angus Gratton2023-11-09
| | | | | | | | | | | | | | dcd_event_handler() is called from the IRQ when a new DCD event is queued for processing by the TinyUSB thread mode task. This lets us queue the handler to run immediately when MicroPython resumes. Currently this relies on a linker --wrap hack to work, but a PR has been submitted to TinyUSB to allow the function to be called inline from dcd_event_handler() itself. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* rp2/msc_disk: Allow configuring the USB MSC inquiry response.Jim Mussared2023-09-29
| | | | | | | | | | | | This was previously hard-coded to "Micropy" / "Mass Storage" / "1.0". Now allow it to be overridden by a board. Also change "Micropy" to "MicroPy" and "1.0" to "1.00" to match stm32. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* shared/tinyusb: Support HS endpoint sizes.iabdalkader2023-09-14
| | | | | | | Set buffer and endpoint sizes to 512 if the device is configured as a High Speed device. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* shared/tinyusb: Avoid symbol clash on targets with external TinyUSB.Luca Burelli2023-07-20
| | | | | | | | | | | | On targets that provide a reference TinyUSB implementation, like ESP32, the SDK already defines and implements standard callback functions such as tud_cdc_line_state_cb(). This causes a symbol clash when enabling shared implementations like the MicroPython 1200 touch functionality. To avoid this symbol clash, add an optional macro to allow ports to use a different function name in the shared implementation. Signed-off-by: Luca Burelli <l.burelli@arduino.cc>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Revert setting of CFG_TUD_CDC_EP_BUFSIZE to 256.Damien George2023-04-21
| | | | | | | | | | | | | This reverts commit 0613d3e3561a82fffa36594647ef916b19bc912b. The value of CFG_TUD_CDC_EP_BUFSIZE should match the endpoint size, otherwise data may stay in the lower layers of the USB stack (and not passed up to the higher layers) until a total of CFG_TUD_CDC_EP_BUFSIZE bytes have been received, which may not happen for a long time. Fixes issue #11253. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Allow max USB descriptor string to be configured.Damien George2023-04-04
| | | | Signed-off-by: Damien George <damien@micropython.org>
* rp2: Allow disabling USB via MICROPY_HW_ENABLE_USBDEV config.robert-hh2023-03-20
| | | | | | | | | | | | Previously, setting MICROPY_HW_ENABLE_USBDEV to 0 caused build errors. The change affects the nrf and samd ports as well, so MICROPY_HW_ENABLE_USBDEV had to be explicitly enabled there. The configuration options MICROPY_HW_ENABLE_USBDEV and MICROPY_HW_ENABLE_UART_REPL are independent, and can be enabled or disabled by a board. Signed-off-by: Damien George <damien@micropython.org>
* shared/tinyusb: Fix CDC bNumInterfaces value.Damien George2022-11-14
| | | | | | This fixes a regression from c8913fdbfadd43c879bba4d6d565be8b644f1feb Signed-off-by: Damien George <damien@micropython.org>
* rp2: Allow enabling USB device without enabling USB-CDC.Angus Gratton2022-11-11
| | | | | | Requires changing the USB-CDC stdin/stdout guards from MICROPY_HW_ENABLE_USBDEV to the new (in this port) MICROPY_HW_USB_CDC.
* shared/tinyusb: Further refactor static USB device implementation.Angus Gratton2022-11-11
| | | | | | | | | | | | App the mp_ prefix to usbd_ symbols and files which are defined here and not in TinyUSB. rp2 only for now. This includes some groundwork for dynamic USB devices (defined in Python). This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* shared/tinyusb: Create common TinyUSB code for reuse by ports.Blake Felt2022-11-11
This code originates from the rp2 port, and the rp2 port has been updated to use this common code.