Print card CID in storage info (#2227)

This commit is contained in:
Michal Suchánek 2023-01-30 10:14:30 +01:00 committed by GitHub
parent 7f3ebcd110
commit d9be815889
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 62 additions and 35 deletions

View File

@ -1,5 +1,6 @@
#include <furi.h>
#include <furi_hal.h>
#include <stm32_adafruit_sd.h>
#include <cli/cli.h>
#include <lib/toolbox/args.h>
@ -60,17 +61,28 @@ static void storage_cli_info(Cli* cli, FuriString* path) {
}
} else if(furi_string_cmp_str(path, STORAGE_EXT_PATH_PREFIX) == 0) {
SDInfo sd_info;
SD_CID sd_cid;
FS_Error error = storage_sd_info(api, &sd_info);
BSP_SD_GetCIDRegister(&sd_cid);
if(error != FSE_OK) {
storage_cli_print_error(error);
} else {
printf(
"Label: %s\r\nType: %s\r\n%luKiB total\r\n%luKiB free\r\n",
"Label: %s\r\nType: %s\r\n%luKiB total\r\n%luKiB free\r\n"
"%02x%2.2s %5.5s %i.%i\r\nSN:%04lx %02i/%i\r\n",
sd_info.label,
sd_api_get_fs_type_text(sd_info.fs_type),
sd_info.kb_total,
sd_info.kb_free);
sd_info.kb_free,
sd_cid.ManufacturerID,
sd_cid.OEM_AppliID,
sd_cid.ProdName,
sd_cid.ProdRev >> 4,
sd_cid.ProdRev & 0xf,
sd_cid.ProdSN,
sd_cid.ManufactMonth,
sd_cid.ManufactYear + 2000);
}
} else {
storage_cli_print_usage();

View File

@ -1,4 +1,5 @@
#include "../storage_settings.h"
#include <stm32_adafruit_sd.h>
static void storage_settings_scene_sd_info_dialog_callback(DialogExResult result, void* context) {
StorageSettings* app = context;
@ -11,7 +12,10 @@ void storage_settings_scene_sd_info_on_enter(void* context) {
DialogEx* dialog_ex = app->dialog_ex;
SDInfo sd_info;
SD_CID sd_cid;
FS_Error sd_status = storage_sd_info(app->fs_api, &sd_info);
BSP_SD_GetCIDRegister(&sd_cid);
scene_manager_set_scene_state(app->scene_manager, StorageSettingsSDInfo, sd_status);
dialog_ex_set_context(dialog_ex, app);
@ -26,13 +30,22 @@ void storage_settings_scene_sd_info_on_enter(void* context) {
} else {
furi_string_printf(
app->text_string,
"Label: %s\nType: %s\n%lu KiB total\n%lu KiB free",
"Label: %s\nType: %s\n%lu KiB total\n%lu KiB free\n"
"%02X%2.2s %5.5s %i.%i\nSN:%04lX %02i/%i",
sd_info.label,
sd_api_get_fs_type_text(sd_info.fs_type),
sd_info.kb_total,
sd_info.kb_free);
sd_info.kb_free,
sd_cid.ManufacturerID,
sd_cid.OEM_AppliID,
sd_cid.ProdName,
sd_cid.ProdRev >> 4,
sd_cid.ProdRev & 0xf,
sd_cid.ProdSN,
sd_cid.ManufactMonth,
sd_cid.ManufactYear + 2000);
dialog_ex_set_text(
dialog_ex, furi_string_get_cstr(app->text_string), 4, 4, AlignLeft, AlignTop);
dialog_ex, furi_string_get_cstr(app->text_string), 4, 1, AlignLeft, AlignTop);
}
view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);

View File

@ -779,25 +779,10 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) {
Cid->ManufacturerID = CID_Tab[0];
/* Byte 1 */
Cid->OEM_AppliID = CID_Tab[1] << 8;
/* Byte 2 */
Cid->OEM_AppliID |= CID_Tab[2];
memcpy(Cid->OEM_AppliID, CID_Tab + 1, 2);
/* Byte 3 */
Cid->ProdName1 = CID_Tab[3] << 24;
/* Byte 4 */
Cid->ProdName1 |= CID_Tab[4] << 16;
/* Byte 5 */
Cid->ProdName1 |= CID_Tab[5] << 8;
/* Byte 6 */
Cid->ProdName1 |= CID_Tab[6];
/* Byte 7 */
Cid->ProdName2 = CID_Tab[7];
memcpy(Cid->ProdName, CID_Tab + 3, 5);
/* Byte 8 */
Cid->ProdRev = CID_Tab[8];
@ -815,11 +800,12 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) {
Cid->ProdSN |= CID_Tab[12];
/* Byte 13 */
Cid->Reserved1 |= (CID_Tab[13] & 0xF0) >> 4;
Cid->ManufactDate = (CID_Tab[13] & 0x0F) << 8;
Cid->Reserved1 = (CID_Tab[13] & 0xF0) >> 4;
Cid->ManufactYear = (CID_Tab[13] & 0x0F) << 4;
/* Byte 14 */
Cid->ManufactDate |= CID_Tab[14];
Cid->ManufactYear |= (CID_Tab[14] & 0xF0) >> 4;
Cid->ManufactMonth = (CID_Tab[14] & 0x0F);
/* Byte 15 */
Cid->CID_CRC = (CID_Tab[15] & 0xFE) >> 1;
@ -837,6 +823,21 @@ uint8_t SD_GetCIDRegister(SD_CID* Cid) {
return retr;
}
uint8_t BSP_SD_GetCIDRegister(SD_CID* Cid) {
uint8_t retr = BSP_SD_ERROR;
/* Slow speed init */
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_sd_slow);
furi_hal_sd_spi_handle = &furi_hal_spi_bus_handle_sd_slow;
memset(Cid, 0, sizeof(SD_CID));
retr = SD_GetCIDRegister(Cid);
furi_hal_sd_spi_handle = NULL;
furi_hal_spi_release(&furi_hal_spi_bus_handle_sd_slow);
return retr;
}
/**
* @brief Sends 5 bytes command to the SD card and get response
* @param Cmd: The user expected command to send to SD card.

View File

@ -133,16 +133,16 @@ typedef struct {
* @brief Card Identification Data: CID Register
*/
typedef struct {
__IO uint8_t ManufacturerID; /* ManufacturerID */
__IO uint16_t OEM_AppliID; /* OEM/Application ID */
__IO uint32_t ProdName1; /* Product Name part1 */
__IO uint8_t ProdName2; /* Product Name part2*/
__IO uint8_t ProdRev; /* Product Revision */
__IO uint32_t ProdSN; /* Product Serial Number */
__IO uint8_t Reserved1; /* Reserved1 */
__IO uint16_t ManufactDate; /* Manufacturing Date */
__IO uint8_t CID_CRC; /* CID CRC */
__IO uint8_t Reserved2; /* always 1 */
uint8_t ManufacturerID; /* ManufacturerID */
char OEM_AppliID[2]; /* OEM/Application ID */
char ProdName[5]; /* Product Name */
uint8_t ProdRev; /* Product Revision */
uint32_t ProdSN; /* Product Serial Number */
uint8_t Reserved1; /* Reserved1 */
uint8_t ManufactYear; /* Manufacturing Year */
uint8_t ManufactMonth; /* Manufacturing Month */
uint8_t CID_CRC; /* CID CRC */
uint8_t Reserved2; /* always 1 */
} SD_CID;
/**
@ -207,6 +207,7 @@ uint8_t
uint8_t BSP_SD_Erase(uint32_t StartAddr, uint32_t EndAddr);
uint8_t BSP_SD_GetCardState(void);
uint8_t BSP_SD_GetCardInfo(SD_CardInfo* pCardInfo);
uint8_t BSP_SD_GetCIDRegister(SD_CID* Cid);
/* Link functions for SD Card peripheral*/
void SD_SPI_Slow_Init(void);