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

Conversation

Jake-Carter
Copy link
Contributor

@Jake-Carter Jake-Carter commented Aug 25, 2023

Description

Bug fix

The SDHC_FAT example would format cards incorrectly. For a 32GB card, the library would format it with a card size of 1.8GB. This was caused by an integer overflow error in the native SDHC library implementation (fixed in 9771dcc)

FatFS Version Upgrade

I aded support for R0.15 of the FatFS library. This has some potentially relevant bug fixes (see change notes).

The default version is still R0.13, but will be updated to R0.15 next release. Users can upgrade now by setting the FATFS_VERSION build configuration variable to ff15.

FatFS R0.15 changed the input parameters for f_mkfs to acccept a format struct.
Users upgrading from R0.13/R0.14 -> R0.15 can make the following change to the f_mkfs function.

-    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) {
         printf("Error formatting SD card: %s\n", FF_ERRORS[err]);
     }

Alternatively, users can set the new FATFS_VERSION build configuration variable to ff13 or ff14 to keep using the old versions for their project.

# Enable SDHC library
LIB_SDHC = 1
# Use FatFS R0.13
FATFS_VERSION = ff13

SDXC and exFAT Support

The ff15 configuration now enables SDXC support out of the box. This enables larger card sizes.

exFAT support requires LFN (Long File-Name Support), which requires unicode support. This increases the library size significantly. I'm open to suggestions on how to deal with it. Should we provide a mechanism for easily toggling SDXC support? Or just rely on the user to edit ffconf.h as needed?

arm-none-eabi-size FAT32.a
   text    data     bss     dec     hex filename
    562       0       5     567     237 diskio.o (ex FAT32.a)
  19307       0    1127   20434    4fd2 ff.o (ex FAT32.a)
      0       0       0       0       0 ffsystem.o (ex FAT32.a)
  60150       0       0   60150    eaf6 ffunicode.o (ex FAT32.a)
    542       4       0     546     222 board.o (ex FAT32.a)
    178       0       0     178      b2 stdio.o (ex FAT32.a)
    327       0       0     327     147 led.o (ex FAT32.a)
   1381       0      17    1398     576 mx25.o (ex FAT32.a)
    777       0       0     777     309 pb.o (ex FAT32.a)
    666       0       0     666     29a sharp_mip.o (ex FAT32.a)

Testing

I tested the SDHC_FAT example on the MAX32666FTHR, MAX32666EVKIT, and MAX78002EVKIT to validate the native SDHC implementation.

  • : ATP 8GB SDHC (Speed Class 10)
  • : SanDisk Ultra 16GB SDHC (Speed Class 10)
  • : SanDisk Ultra 32GB SDHC (Speed Class 10)
  • : Amazon Basics 128GB SDXC (Speed Class 10)

Checklist Before Requesting Review

  • PR Title follows correct guidelines.
  • Description of changes and all other relevant information.
  • (Optional) Link any related GitHub issues using a keyword
  • (Optional) Provide info on any relevant functional testing/validation. For API changes or significant features, this is not optional.

@github-actions github-actions bot added MAX32650 Related to the MAX32650 (ME10) MAX32665 Related to the MAX32665 (ME14) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87) labels Aug 25, 2023
@github-actions github-actions bot added the MAX32570 Related to the MAX32570 (ME13) label Aug 27, 2023
Libraries/libs.mk Outdated Show resolved Hide resolved
@github-actions github-actions bot removed MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX78002 Related to the MAX78002 (AI87) labels Sep 19, 2023
@github-actions github-actions bot added MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX78002 Related to the MAX78002 (AI87) labels Sep 20, 2023
Jake-Carter and others added 8 commits September 20, 2023 14:32
Fix getSize() and change Maxim to Analog on printf statements.
fix(SDHC): The patch repairs getSize() in main.c of SDHC_FAT to properly calculate SD Card disk capacity
- Merge remote-tracking branch 'remotes/upstream/main' into dev/ff15
@Jake-Carter Jake-Carter merged commit 089b461 into analogdevicesinc:main Sep 21, 2023
7 of 8 checks passed
@Jake-Carter Jake-Carter deleted the dev/ff15 branch September 21, 2023 22:27
EricB-ADI pushed a commit that referenced this pull request Nov 21, 2023
…0.15, Add SDXC and exFAT Support (#720)

Co-authored-by: Brian Hindman <[email protected]>
Co-authored-by: Jake-Carter <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
MAX32570 Related to the MAX32570 (ME13) MAX32650 Related to the MAX32650 (ME10) MAX32665 Related to the MAX32665 (ME14) MAX78000 Related to the MAX78000 (AI85) MAX78002 Related to the MAX78002 (AI87)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants