Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4666

SDK • How to recover from tud_disconnect() during RAM execution

$
0
0
A program is written for a USB mass storage class device that runs in RAM(pico_set_binary_type(${TARGET} no_flash)). After calling tud_disconnect() on the TinyUSB to reset the connection to the host, the USB device cannot be re-enabled.
When running from Flash, it can be enabled with tud_connect(), but when running from RAM, it is not possible to re-enable the device, probably because processing related to timers, etc. is disabled.

Is there a reasonable way to re-enable USB devices when executing from RAM?

Code:

#include <stdio.h>#include <pico/stdlib.h>#include <tusb.h>int main(void) {    tud_init(0);    stdio_init_all();    tud_disconnect();    sleep_ms(250);    // Are you blocked?    tud_connect();    sleep_ms(250);        while (1) {        tud_task();    }}// ...Some callbacks for tiny usb
My issue is to get the USB MSC device program to run in RAM and reference the littlefs file on the onboard flash memory.
https://github.com/oyama/pico-drive-sync
For example, macos starts USB MSC when booted from RAM. However, Windows 11 does not seem to recognise "USB device changes" without a reboot.
https://github.com/oyama/pico-drive-sync/issues/3

Currently, the procedure used is to load two firmwares (a single-function firmware that does usb_disconnect() and the original firmware that does USB MSC) into RAM in sequence using openocd and then boot.

Code:

add_custom_target(run COMMAND    openocd -f interface/cmsis-dap.cfg -f target/rp2040.cfg               -c "adapter speed 5000" -c "init"               -c "reset halt" -c "load_image deinit.elf" -c "resume 0x20000000"               -c "sleep 250"               -c "reset halt" -c "load_image main.elf" -c "resume 0x20000000"               -c "exit")
This "sequential deinit" is the most reasonable I have found, but I would like Windows 11 to recognise the changing role of USB devices in a single firmware if possible.
Please let me know if you have any information on this.

Best regards.

Statistics: Posted by 0yama — Mon Jun 03, 2024 5:30 am — Replies 0 — Views 12



Viewing all articles
Browse latest Browse all 4666

Trending Articles