The STM32 built-in bootloader has a sequence that allows exiting the bootloader and jumping to the application firmware. It consists of a write command with 0 bytes, followed by a read of the status, as explained in AN3156. This crate currently performs this sequence, seemingly by accident, as it does send an empty write here:
|
eof: bytes.is_empty(), |
|
}, |
|
); |
|
let res = self.dfu.io.write_control( |
|
REQUEST_TYPE, |
|
DFU_DNLOAD, |
|
self.block_num, |
|
&bytes[..len as usize], |
|
)?; |
I think the way to avoid this empty write would be to assign eof to copied_pos + len == end_pos, then it would stop at the previous block before the empty one. I assume this is accidental because I couldn't find any mention of it in the docs or the source, and the download function treats it as an error, as the DFU device gets disconnected. The download example from the dfu-libusb crate reports it like this (source):
USB error after upload; Device reset itself?
I was wondering if this could be made into an actual feature that the caller can opt into or out of when calling the download function, or as a separate function altogether if it makes more sense.
The STM32 built-in bootloader has a sequence that allows exiting the bootloader and jumping to the application firmware. It consists of a write command with 0 bytes, followed by a read of the status, as explained in AN3156. This crate currently performs this sequence, seemingly by accident, as it does send an empty write here:
dfu-core/src/download.rs
Lines 313 to 321 in fc9dee3
I think the way to avoid this empty write would be to assign
eoftocopied_pos + len == end_pos, then it would stop at the previous block before the empty one. I assume this is accidental because I couldn't find any mention of it in the docs or the source, and the download function treats it as an error, as the DFU device gets disconnected. The download example from the dfu-libusb crate reports it like this (source):I was wondering if this could be made into an actual feature that the caller can opt into or out of when calling the download function, or as a separate function altogether if it makes more sense.