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

fix(SDHC)!: Fix SDHC Formats Card Size Incorrectly, Update FatFS to R0.15, Add SDXC and exFAT Support #720

Merged
merged 45 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
289e45d
Import FatFS R0.15
Jake-Carter Aug 1, 2023
af8850c
Add diskio implementation from ff13
Jake-Carter Aug 1, 2023
d4ee436
Adjust FatFS R0.15 config to match previous config
Jake-Carter Aug 1, 2023
710474a
Update SDHC_FTHR to use ff15
Jake-Carter Aug 1, 2023
46ded7e
Enable exFAT and LFS
Jake-Carter Aug 2, 2023
131da3e
Remove reference to deprecated FF_RTC_EPOCH_DELTA option
Jake-Carter Aug 15, 2023
05aa8fc
Update MAX32665 SDHC_FAT for ff15
Jake-Carter Aug 15, 2023
9771dcc
Fix integer overflow for native diskio_ctl GET_SECTOR_COUNT implement…
Jake-Carter Aug 23, 2023
e8fa5c3
Cache CSD register to work around DISK_ERR in f_mkfs
Jake-Carter Aug 23, 2023
c14e146
Auto-calculate SDHC clk div as part of initialization, define SDHC_CL…
Jake-Carter Aug 23, 2023
9adedee
SDHC_FAT: Remove clk div setup in main, add 2s delay
Jake-Carter Aug 23, 2023
ebbc091
SDHC_FAT: Remove manual clock div, it's handled by InitCard now
Jake-Carter Aug 25, 2023
57fd2c8
Bump up default SDHC target clock to 40Mhz
Jake-Carter Aug 25, 2023
bb2ffc4
Update libinfo for ff15
Jake-Carter Aug 25, 2023
2c74606
Add MAX32570 to SDHC libinfo.json
Jake-Carter Aug 25, 2023
88ae74b
Fix case sensitivity failure for ff15
Jake-Carter Aug 25, 2023
d3baa72
Add FATFS_VERSION build config variable
Jake-Carter Aug 25, 2023
6b9f659
Update all f_mkfs calls to use new FatFS API, default to FM_ANY
Jake-Carter Aug 27, 2023
acc9d81
Add driver function for getting SDHC input clock freq
Jake-Carter Aug 27, 2023
ddb2fc8
clang-format
Jake-Carter Aug 27, 2023
1b6bd48
clang-format
Jake-Carter Sep 6, 2023
4dfad7e
Import FatFS R0.15
Jake-Carter Aug 1, 2023
31076c2
Add diskio implementation from ff13
Jake-Carter Aug 1, 2023
b81f486
Adjust FatFS R0.15 config to match previous config
Jake-Carter Aug 1, 2023
0b873f9
Update SDHC_FTHR to use ff15
Jake-Carter Aug 1, 2023
9853938
Enable exFAT and LFS
Jake-Carter Aug 2, 2023
d40f513
Remove reference to deprecated FF_RTC_EPOCH_DELTA option
Jake-Carter Aug 15, 2023
0672f5a
Update MAX32665 SDHC_FAT for ff15
Jake-Carter Aug 15, 2023
c0febe4
Fix integer overflow for native diskio_ctl GET_SECTOR_COUNT implement…
Jake-Carter Aug 23, 2023
6f10fc8
Cache CSD register to work around DISK_ERR in f_mkfs
Jake-Carter Aug 23, 2023
02e5654
Auto-calculate SDHC clk div as part of initialization, define SDHC_CL…
Jake-Carter Aug 23, 2023
0216249
SDHC_FAT: Remove clk div setup in main, add 2s delay
Jake-Carter Aug 23, 2023
ebbf328
Set ff13 as default
Jake-Carter Sep 19, 2023
72ca88c
Explicitly use ff15 in examples
Jake-Carter Sep 19, 2023
308052f
Update SDHC library documentation
Jake-Carter Sep 19, 2023
568cc88
clang-format
Jake-Carter Sep 19, 2023
0830f54
Merge branch 'dev/ff15-cache' into HEAD
Jake-Carter Sep 20, 2023
6272896
Delete stray file
Jake-Carter Sep 20, 2023
16aac64
Update projects to ff15
Jake-Carter Sep 20, 2023
fd765aa
Add warnings about future version bump
Jake-Carter Sep 20, 2023
c3d9664
Update main.c to fix getSize()
brianhindman Sep 21, 2023
e8aa123
clang-format bot reformatting.
Jake-Carter Sep 21, 2023
a5a12da
Merge pull request #3 from brianhindman/main
Jake-Carter Sep 21, 2023
0babf62
Resolve merge conflicts
Jake-Carter Sep 21, 2023
cf4c411
clang-format
Jake-Carter Sep 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions Examples/MAX32572/SDHC_FAT/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down Expand Up @@ -565,15 +567,6 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}

/* Configure for fastest possible clock, must not exceed 52 MHz for eMMC */
if (SystemCoreClock > 96000000) {
printf("SD clock ratio (at card) 4:1\n");
MXC_SDHC_Set_Clock_Config(1);
} else {
printf("SD clock ratio (at card) 2:1\n");
MXC_SDHC_Set_Clock_Config(0);
}

while (run) {
f_getcwd(cwd, sizeof(cwd));

Expand Down
13 changes: 3 additions & 10 deletions Examples/MAX32650/SDHC_FAT/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down Expand Up @@ -542,15 +544,6 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}

/* Configure for fastest possible clock, must not exceed 52 MHz for eMMC */
if (SystemCoreClock > 96000000) {
printf("SD clock ratio (at card) 4:1\n");
MXC_SDHC_Set_Clock_Config(1);
} else {
printf("SD clock ratio (at card) 2:1\n");
MXC_SDHC_Set_Clock_Config(0);
}

while (run) {
f_getcwd(cwd, sizeof(cwd));

Expand Down
14 changes: 4 additions & 10 deletions Examples/MAX32665/SDHC_FAT/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down Expand Up @@ -488,6 +490,7 @@ int example()
/******************************************************************************/
int main(void)
{
MXC_Delay(MXC_DELAY_SEC(2));
mxc_sdhc_cfg_t cfg;

FF_ERRORS[0] = "FR_OK";
Expand Down Expand Up @@ -555,15 +558,6 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}

/* Configure for fastest possible clock, must not exceed 52 MHz for eMMC */
if (SystemCoreClock > 96000000) {
printf("SD clock ratio (at card) 4:1\n");
MXC_SDHC_Set_Clock_Config(1);
} else {
printf("SD clock ratio (at card) 2:1\n");
MXC_SDHC_Set_Clock_Config(0);
}

while (run) {
f_getcwd(cwd, sizeof(cwd));

Expand Down
1 change: 1 addition & 0 deletions Examples/MAX78000/CNN/faceid_evkit/db_single/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/facial_recognition/SDHC_weights/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/facial_recognition/src/sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78000/CNN/kws20_demo/sd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down
4 changes: 2 additions & 2 deletions Examples/MAX78000/SDHC_FTHR/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/SDHC/Include",
"${config:MAXIM_PATH}/Libraries/SDHC/ff14/Source"
"${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source"
],
"C_Cpp.default.browse.path": [
"${workspaceFolder}",
Expand All @@ -66,7 +66,7 @@
"${config:MAXIM_PATH}/Libraries/MiscDrivers/PushButton",
"${config:MAXIM_PATH}/Libraries/MiscDrivers/Touchscreen",
"${config:MAXIM_PATH}/Libraries/MiscDrivers",
"${config:MAXIM_PATH}/Libraries/SDHC/ff14/Source"
"${config:MAXIM_PATH}/Libraries/SDHC/ff15/Source"
],
"C_Cpp.default.defines": [

Expand Down
4 changes: 3 additions & 1 deletion Examples/MAX78000/SDHC_FTHR/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down
13 changes: 3 additions & 10 deletions Examples/MAX78002/SDHC_FAT/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ int formatSDHC()

printf("FORMATTING DRIVE\n");

if ((err = f_mkfs("", FM_ANY, 0, work, sizeof(work))) !=
MKFS_PARM format_options = { .fmt = FM_ANY };

if ((err = f_mkfs("", &format_options, work, sizeof(work))) !=
FR_OK) { //Format the default drive to FAT32
printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
} else {
Expand Down Expand Up @@ -545,15 +547,6 @@ int main(void)
printf("Card type: MMC/eMMC\n");
}

/* Configure for fastest possible clock, must not exceed 52 MHz for eMMC */
if (SystemCoreClock > 96000000) {
printf("SD clock ratio (at card) 4:1\n");
MXC_SDHC_Set_Clock_Config(1);
} else {
printf("SD clock ratio (at card) 2:1\n");
MXC_SDHC_Set_Clock_Config(0);
}

while (run) {
f_getcwd(cwd, sizeof(cwd));

Expand Down
7 changes: 7 additions & 0 deletions Libraries/CMSIS/Device/Maxim/GCC/temp.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ifeq "$(_OS)" "windows"

else
ifeq "1" "$(shell expr `$(CC) -dumpversion` \>= 12)"
LDFLAGS += -Xlinker --no-warn-rwx-segments
endif
endif
12 changes: 6 additions & 6 deletions Libraries/PeriphDrivers/Include/MAX32570/sdhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,21 +142,21 @@ int MXC_SDHC_Shutdown(void);
/**
* @brief Set clock divider
* @param clk_div Divider setting
* s
* @returns #E_NO_ERROR upon success, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
void MXC_SDHC_Set_Clock_Config(unsigned int clk_div);

/**
* @brief Get clock divider
* @return Clock divider setting
* s
* @returns #E_NO_ERROR SDHC shutdown successfully, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
unsigned int MXC_SDHC_Get_Clock_Config(void);

/**
* @brief Get the input clock frequency for the SDHC peripheral.
* @return Input clock frequency in Hz
*/
unsigned int MXC_SDHC_Get_Input_Clock_Freq(void);

/**
* @brief Send Command, <em>blocking</em>.
*
Expand Down
9 changes: 6 additions & 3 deletions Libraries/PeriphDrivers/Include/MAX32650/sdhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,15 @@ void MXC_SDHC_Set_Clock_Config(unsigned int clk_div);
/**
* @brief Get clock divider
* @return Clock divider setting
* s
* @returns #E_NO_ERROR SDHC shutdown successfully, @ref MXC_Error_Codes "error" if
* unsuccessful.
*/
unsigned int MXC_SDHC_Get_Clock_Config(void);

/**
* @brief Get the input clock frequency for the SDHC peripheral.
* @return Input clock frequency in Hz
*/
unsigned int MXC_SDHC_Get_Input_Clock_Freq(void);

/**
* @brief Send Command, <em>blocking</em>.
*
Expand Down
6 changes: 6 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX32665/sdhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ void MXC_SDHC_Set_Clock_Config(unsigned int clk_div);
*/
unsigned int MXC_SDHC_Get_Clock_Config(void);

/**
* @brief Get the input clock frequency for the SDHC peripheral.
* @return Input clock frequency in Hz
*/
unsigned int MXC_SDHC_Get_Input_Clock_Freq(void);

/**
* @brief Send Command, <em>blocking</em>.
*
Expand Down
6 changes: 6 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX78002/sdhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ void MXC_SDHC_Set_Clock_Config(unsigned int clk_div);
*/
unsigned int MXC_SDHC_Get_Clock_Config(void);

/**
* @brief Get the input clock frequency for the SDHC peripheral.
* @return Input clock frequency in Hz
*/
unsigned int MXC_SDHC_Get_Input_Clock_Freq(void);

/**
* @brief Send Command, <em>blocking</em>.
*
Expand Down
16 changes: 16 additions & 0 deletions Libraries/PeriphDrivers/Source/SDHC/sdhc_ai87.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,22 @@ int MXC_SDHC_Init(const mxc_sdhc_cfg_t *cfg)
return MXC_SDHC_RevA_Init((mxc_sdhc_reva_regs_t *)MXC_SDHC, cfg);
}

unsigned int MXC_SDHC_Get_Input_Clock_Freq(void)
{
// Figure 4-1 of the preliminary AI85 UG (04/01/2022) shows the SDHC hardware block
// connected directly to the SYS_CLK node. This is most likely inaccurate, but the
// register description for MXC_GCR->pclkdiv marks the usual SDHC divider as reserved.
// We will follow figure 4-1 for now.

// if (MXC_GCR->pclkdiv & MXC_F_GCR_PCLKDIV_SDHC) {
// return SystemCoreClock >> 2; // Div by 4
// } else {
// return SystemCoreClock >> 1; // Div by 2
// }

return SystemCoreClock;
}

/* ************************************************************************** */
void MXC_SDHC_PowerUp(void)
{
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Source/SDHC/sdhc_me10.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ unsigned int MXC_SDHC_Get_Clock_Config(void)
return MXC_SDHC_RevA_Get_Clock_Config((mxc_sdhc_reva_regs_t *)MXC_SDHC);
}

unsigned int MXC_SDHC_Get_Input_Clock_Freq(void)
{
if (MXC_GCR->pclk_div & MXC_F_GCR_PCLK_DIV_SDHCFRQ) {
return SystemCoreClock >> 1; // Div by 2
} else {
return 50000000; // UG specifies a hard-coded 50Mhz value in this case
}
}

/* ************************************************************************** */
int MXC_SDHC_SendCommand(mxc_sdhc_cmd_cfg_t *sd_cmd_cfg)
{
Expand Down
10 changes: 10 additions & 0 deletions Libraries/PeriphDrivers/Source/SDHC/sdhc_me13.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ int MXC_SDHC_Init(const mxc_sdhc_cfg_t *cfg)
return MXC_SDHC_RevA_Init((mxc_sdhc_reva_regs_t *)MXC_SDHC, cfg);
}

unsigned int MXC_SDHC_Get_Input_Clock_Freq(void)
{
// TODO(JC): Confirm this is the scheme used by ME13
if (MXC_GCR->pclkdiv & MXC_F_GCR_PCLKDIV_SDHCFRQ) {
return SystemCoreClock >> 2; // Div by 4
} else {
return SystemCoreClock >> 1; // Div by 2
}
}

/* ************************************************************************** */
void MXC_SDHC_PowerUp(void)
{
Expand Down
9 changes: 9 additions & 0 deletions Libraries/PeriphDrivers/Source/SDHC/sdhc_me14.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ int MXC_SDHC_Init(const mxc_sdhc_cfg_t *cfg)
return MXC_SDHC_RevA_Init((mxc_sdhc_reva_regs_t *)MXC_SDHC, cfg);
}

unsigned int MXC_SDHC_Get_Input_Clock_Freq(void)
{
if (MXC_GCR->pckdiv & MXC_F_GCR_PCKDIV_SDHCFRQ) {
return SystemCoreClock >> 2; // Div by 4
} else {
return SystemCoreClock >> 1; // Div by 2
}
}

/* ************************************************************************** */
void MXC_SDHC_PowerUp(void)
{
Expand Down
9 changes: 9 additions & 0 deletions Libraries/SDHC/Include/sdhc_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@
#include "sdhc.h"
#include "sdhc_resp_regs.h"

/**
* @brief SDHC target clock frequency.
* @details Max freq. is limited by GCR register to be @ref SystemCoreClock / 2 or @ref SystemCoreClock / 4.
* This field is used as a target for the SDHC peripheral's internal clock divider.
* R/W reliability issues can sometimes be eliminated by reducing the clock frequency, which is a good first step for troubleshooting.
*/
#define SDHC_CLK_FREQ 40000000


/**
* @ingroup sdhc
* @{
Expand Down
Loading