Skip to content

dap_vendor: Buffer MSD_Write packets into 512-byte blocks. #1093

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

microbit-carlos
Copy link
Contributor

@microbit-carlos microbit-carlos commented Feb 3, 2025

Currently flashing a Universal Hex in "segments" or "blocks" format via WebUSB does not work.

This PR sends to the file streamer blocks of the same size as the VFS sector size, which is what vfs_manager does and some stream formats expect, like Universal Hex and in the future UF2.

This could have been implemented inside file_stream instead, but this way it mirrors what the MSC side is doing, buffering the 64 byte packets into 512-byte sectors before passing it to vfs_manager, which then sends it to file_stream.

One constrain is that DAPLink doesn't know when the last DAP.js ID_DAP_MSD_Write packet is sent, so we need to flush whatever is left in the buffer on ID_DAP_MSD_Close. So the "close" response could contain an error writing the last buffer.

There is also a memory hit, as the buffer takes 512 bytes of RAM. We could reuse the usb_buffer from vfs_manager.c (which is passed to usbd_msc.c, so that's where the 64-byte MSC packets are buffer into VFS sectors), not if you prefer to keep them separated. To be fair, using WebUSB flashing + MSD drag&drop at the same time will fail anyway, so probably wouldn't need to worry much about having two different components accessing the same buffer.

@microbit-carlos microbit-carlos marked this pull request as draft February 3, 2025 11:44
To send to the file streamer blocks of size matching the VFS sector
size, which is expected for some stream formats like Universal Hex
Blocks.
@microbit-carlos
Copy link
Contributor Author

microbit-carlos commented Feb 14, 2025

When combining this PR + out of order PR + UF2, it fails building some ports due to insufficient .bss so I had to reuse the usb_buffer from vfs_manager.c in the end to save 512 bytes.

Force pushed, diff can be seen in:

@microbit-carlos microbit-carlos marked this pull request as ready for review February 14, 2025 00:34
@mathias-arm mathias-arm merged commit 8bdba05 into ARMmbed:main Feb 25, 2025
1 check passed
@microbit-carlos microbit-carlos deleted the feature/dap-msd-buffer branch February 25, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants