Skip to content

feat(sdspi): add public API to read SD card CID/CSD registers #49

@cptkoolbeenz

Description

@cptkoolbeenz

Summary

The SDSPI driver already reads and stores the SD card CID (Card Identification) and CSD (Card-Specific Data) registers during initialization (CMD9/CMD10), but provides no public API for application code to access this data.

The CID contains useful information: manufacturer ID, OEM ID, product name, revision, serial number, and manufacturing date. The CSD contains capacity, speed class, and block size information.

Current State

  • DRV_SDSPI_CID and DRV_SDSPI_CSD union types are defined in drv_sdspi_local.h (private)
  • Raw CID/CSD data is stored in static buffers gDrvSDSPICidData / gDrvSDSPICsdData in drv_sdspi.c
  • DRV_SDSPI_OBJ has pCidData and pCsdData pointers
  • No public function exists to retrieve this data

Proposed API

// In drv_sdspi.h
bool DRV_SDSPI_GetCID(const DRV_HANDLE handle, uint8_t* cidBuffer, size_t bufLen);
bool DRV_SDSPI_GetCSD(const DRV_HANDLE handle, uint8_t* csdBuffer, size_t bufLen);

Returns the raw 16-byte CID/CSD register contents. Application code can then parse the fields as needed. Returns false if no card is attached or buffer is too small.

Use Case

We build data acquisition devices that log to SD cards. Being able to query the inserted card's manufacturer, model, and serial number helps users verify they're using a compatible/recommended card and assists with debugging field issues.

Workaround

We've added a custom DRV_SDSPI_GetCID() function directly to the generated drv_sdspi.c, with a __attribute__((weak)) fallback stub in our application code so that if the driver is regenerated, the command degrades gracefully rather than failing to compile.

Environment

  • Harmony core: v3.15.5
  • Checked latest: v3.16.1 (no CID/CSD API added)
  • MCU: PIC32MZ2048EFM144
  • Driver: SDSPI (SPI mode)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions