Skip to content

sdcard: remove fmt package references - #942

Open
colegarien wants to merge 1 commit into
tinygo-org:devfrom
colegarien:sdcard-remove-fmt
Open

colegarien wants to merge 1 commit into
tinygo-org:devfrom
colegarien:sdcard-remove-fmt

Conversation

@colegarien

@colegarien colegarien commented Nov 8, 2026 •

Copy link
Copy Markdown

sdcard imported fmt only for fmt.Errorf, one fmt.Sprintf in NewCID, and fmt.Printf in CSD.Dump. This pulls fmt, strconv and reflect into any program using the driver, even if it never prints.

  • Replace fmt.Errorf with package level sentinel errors in errors.go. This also stops allocating on every error.
  • Build CID.ProductVersion from bytes. The field is still a string.
  • Keep CSD.Dump with the same hex output, using print and a small helper.
  • ReadData now returns the real waitStartBlock error.

Behavior changes

  • All error messages changed and now start with "sdcard: ".
  • The two CMD8 errors are now separate errors and no longer include the status byte.
  • The init_card_v1 error no longer ends with "\r\n".
  • Dump output goes through print instead of fmt.Printf.

Size

STM32F103 program mounting the card as LittleFS through tinyfs, TinyGo 0.44.0, 512 KB flash linker script.

v0.37.0 fmt free
flash 91.4 KB 47.0 KB
RAM 5.6 KB 4.4 KB

Testing

  • gofmt -l sdcard is clean
  • tinygo build -target=feather-m4 ./examples/sdcard/console/ builds
  • Hardware test on a Blue Pill with the v0.37.0 based copy

@colegarien
colegarien marked this pull request as ready for review November 8, 2026 19:50
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.

1 participant