Skip to content

Add support for optional SD Card programming#131

Open
Arksine wants to merge 17 commits into
masterfrom
dev-sdcard-20220519
Open

Add support for optional SD Card programming#131
Arksine wants to merge 17 commits into
masterfrom
dev-sdcard-20220519

Conversation

@Arksine

@Arksine Arksine commented Oct 4, 2024

Copy link
Copy Markdown
Owner

This PR adds support for SD Card firmware programming in addition to the primary programming interface (ie: CANBus, USB, UART). Currently Katapult can be configured to use Hardware SPI and Software SPI for all supported MCUs. SDIO is supported exclusively for STM32F4 series MCUs. I recognize that there are printer boards that ship with STM32F1 and SMT32H7 series MCUs connected via SDIO, and will consider adding future support for those variants.

The primary motivation behind adding support is two fold. First, it provides a way to program the MCU when the primary interface is not available or not working. Second, many users have expressed a desire to switch to Katapult, however they do not want to lose SD Card programming offered by stock bootloaders.

The readme details how SD Card programming works, but I do want to note the major difference between Katapult and "stock" bootloaders. Katapult does not initialize the SD Card and check for a new firmware file on every reset. It only checks after bootloader entry, either via user request (double reset, button) or when the application area is empty. There are multple reasons why Katapult does this:

  1. Initializing the SD Card can take time, in some cases several hundred milliseconds. Katapult seeks to minimize the reset delay. In addition, this delay can interfere with Katapult's double reset functionality.

  2. During normal operation applications that use the SD Card will receive it in a pristine power on state. Even though Katapult makes every effort to return the SD Card to its original state before exiting, one of Katapult's goals is to launch the application as if the bootloader is not present....that is, all registers and peripherals are in their default power on state.

I have done quite a bit of local testing, however more testing would be welcomed.

@Arksine Arksine force-pushed the dev-sdcard-20220519 branch 2 times, most recently from 23563e5 to ac9edd6 Compare October 23, 2024 09:48
@Arksine Arksine force-pushed the dev-sdcard-20220519 branch from ac9edd6 to 4ef867a Compare November 13, 2024 10:23
@VinnyCordeiro

Copy link
Copy Markdown

What is the state of this PR? This feature would be very useful.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
- Allow 16-bit SPI length requests.
- Add spi_set_rate method.

These additions accommodate the requirements for SD Card
operations.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This contains a port of Klipper's spi_software implementation
for use with CanBoot's sdcard.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This allows local flashing to update transfer state.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Add support for firmware uploads from an SD Card via SPI.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
When an error is detected during the programming
procedure enter command mode.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Syncrhonize SD Card flag values between SPI and SDIO modes.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
@Arksine Arksine force-pushed the dev-sdcard-20220519 branch from 4ef867a to 3dfe4d0 Compare February 25, 2025 00:14
@Arksine

Arksine commented Feb 25, 2025

Copy link
Copy Markdown
Owner Author

@VinnyCordeiro Good question. I recently rebased against the rp2xxx changes and at least the rp2040 still seems to work. I don't have a rp2350 to test.

I pushed this branch to gauge interest in this feature, with the hope that several individuals would volunteer for testing. This addition may require significant maintenance, and I don't want to merge it if:

  1. The overall interest is low
  2. I don't have positive feedback from multiple testers across the platforms supported by Katapult. SD Card updates must be reliable. There must be no regression with updates over CAN, USB, or UART.

I didn't announce this PR, so perhaps no one (but you) has noticed it. I'll see about doing so, in the meantime I'll leave it here for further feedback.

Edit: FWIW, I did cherry pick most of the changes to flashtool.py. They are now available in master.

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