Skip to content
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

DFU support (Phase 1) #78

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

DFU support (Phase 1) #78

wants to merge 5 commits into from

Conversation

kpfleming
Copy link
Contributor

@kpfleming kpfleming commented Mar 27, 2024

Implementation of #77.

  • Adds "DFU Runtime" support while the application is in "HID" (normal) mode; this is controllable in user_config.h and defaults to 'off'. This allows a DFU tool to trigger a reboot into "DFU" mode.

  • Adds "DFU" mode for the application, which avoids most normal setup steps and prepares the device for firmware/config upload or download. The board still stay in this mode for a maximum of 30 seconds, and will reboot if no successful DFU operation occurs within that time.

  • Adds serial number reporting using the Pico SDK "unique_id" function which obtains the hardware serial number from the flash chip.

  • Refactors usb_descriptors.c into dfu.c and hid.c for clarity.

  • Adds DFU 'upload' mode, allowing the user to obtain the current firmware or runtime configuration from the device.

  • Adds DFU 'download' mode, allowing the user to flash new firmware or configuration to the device. The device will automatically reboot after the flash operation.

Since this is 'phase 1', it only supports DFU operations against the board it is attached to (A or B), it does not support operations against the 'other' board over a single connection. This means that upgrading firmware must be done twice, connecting to each board.

@hrvach
Copy link
Owner

hrvach commented Mar 27, 2024

I'll test it a bit and play around with it, on first look it seems very well done. Thank you for contributing!

@kpfleming
Copy link
Contributor Author

kpfleming commented Mar 28, 2024

Thanks! I'm going to keep this in draft mode until it actually has some functionality that is useful :-)

(Edit: thoughts about cross-board communication removed)

@kpfleming
Copy link
Contributor Author

More progress: it is now possible to use DFU to extract the firmware and config from a running board :-)

Example commands (while connected to board A; change 'a' to 'b' if connected to board B):

dfu-util -a board_a_fw -d 2e8a:107c -D firmware.bin
dfu-util -a config -d 2e8a:107c -D config.bin

In each case dfu-util will trigger the board to reboot into DFU mode and perform the transfer. The board will reset itself to normal mode 500ms after the transfer has been completed.

@kpfleming kpfleming changed the title DFU support DFU support (Phase 1) Mar 29, 2024
@kpfleming
Copy link
Contributor Author

I have now successfully used this to upgrade firmware a half-dozen times. I'll write some docs for it tomorrow and then it will be ready for review/testing.

@kpfleming
Copy link
Contributor Author

Also, apologies for the inconsistent code formatting... I've tried to follow the style in various source files but they aren't consistent with each other so it was challenging!

@kpfleming
Copy link
Contributor Author

Documentation has been added and I've re-ordered the commits so that the first three are simpler to review (they don't include the DFU code).

@kpfleming kpfleming marked this pull request as ready for review March 30, 2024 13:19
@kpfleming kpfleming marked this pull request as draft March 30, 2024 15:20
@kpfleming
Copy link
Contributor Author

Going back to draft mode; I need to do some more work on handling configuration data.

Simplify access to config buffer in flash.
* Adds "DFU Runtime" support while the application is in "HID"
  (normal) mode; this is controllable in `user_config.h` and defaults
  to 'off'. This allows a DFU tool to trigger a reboot into "DFU"
  mode.

* Adds "DFU Transfer" mode for the application, which avoids most
  normal setup steps and prepares the device for firmware/config
  upload or download. The board will stay in this mode for a maximum
  of 30 seconds, and will reboot if no successful DFU operation occurs
  within that time (or if a successful operation occurs.)

* Adds serial number reporting using the Pico SDK "unique_id" function
  which obtains the hardware serial number from the flash chip.

* Adds DFU 'upload' mode, allowing the user to obtain the current
  firmware or runtime configuration from the device.

* Adds DFU 'download' mode, allowing the user to flash new firmware or
  configuration to the device. The device will automatically reboot
  after the flash operation.

Since this is 'phase 1', it only supports DFU operations against the
board the host is attached to (A or B), it does not support operations
against the 'other' board over a single connection. This means that
upgrading firmware must be done twice, connecting to each board.
@kpfleming
Copy link
Contributor Author

I spent some time trying to determine whether it made sense to build a simple 'transfer configuration over the UART link' mechanism, but decided that it does not make sense at this time as we'll eventually want to be able to transfer entire firmware binaries over that link too and the design will need to be done with both usages in mind.

Given that, I'm putting this back in 'ready to review' mode after updating DFU.md to demonstrate how to upload configuration data into both boards.

@kpfleming kpfleming marked this pull request as ready for review April 4, 2024 17:12
@kpfleming
Copy link
Contributor Author

Before this can be merged, a second request will need to be made to the RPi team for a PID for the DeskHop to use while in 'DFU transfer' mode. This is primarily needed for Windows, since Windows assigns combinations of drivers to VID/PID combinations, and when the board goes into that mode it should not have any HID drivers attached to it, which would happen if the PID did not change.

@hrvach
Copy link
Owner

hrvach commented Apr 8, 2024

Haven't forgotten about this, don't worry - just been super busy. Thanks again for working on this, I'll take a look as soon as I can scrape some free time.

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.

None yet

2 participants