-
Notifications
You must be signed in to change notification settings - Fork 991
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
dap_vendor: Buffer MSD_Write packets into 512-byte blocks. #1093
base: main
Are you sure you want to change the base?
dap_vendor: Buffer MSD_Write packets into 512-byte blocks. #1093
Conversation
e2482f4
to
15d3016
Compare
// TODO: It might be more memory efficient to re-use the usb_buffer from vfs_manager.c | ||
static uint8_t __ALIGNED(4) file_stream_buffer[VFS_SECTOR_SIZE]; | ||
static uint16_t file_stream_buffer_pos = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As described in the PR, this is the buffer that could be removed and usb_buffer
from vfs_manager.c
used instead.
static uint32_t usb_buffer[VFS_SECTOR_SIZE / sizeof(uint32_t)]; |
Line 35 in 82dc31d
extern U8 *USBD_MSC_BlockBuf; |
DAPLink/source/daplink/drag-n-drop/vfs_manager.c
Lines 379 to 391 in 82dc31d
static void build_filesystem() | |
{ | |
// Update anything that could have changed file system state | |
file_transfer_state = default_transfer_state; | |
vfs_user_build_filesystem(); | |
vfs_set_file_change_callback(file_change_handler); | |
// Set mass storage parameters | |
USBD_MSC_MemorySize = vfs_get_total_size(); | |
USBD_MSC_BlockSize = VFS_SECTOR_SIZE; | |
USBD_MSC_BlockGroup = 1; | |
USBD_MSC_BlockCount = USBD_MSC_MemorySize / USBD_MSC_BlockSize; | |
USBD_MSC_BlockBuf = (uint8_t *)usb_buffer; | |
} |
Left it as a TODO comment to come to an agreement before merging the PR.
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.
15d3016
to
eba229a
Compare
When combining this PR + out of order PR + UF2, it fails building some ports due to insufficient Force pushed, diff can be seen in: |
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 tovfs_manager
, which then sends it tofile_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 onID_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
fromvfs_manager.c
(which is passed tousbd_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.