Hi RenesasRulz members,
I have modified the SDMMC_HAL_FRWK_FX_MG_AP example to use SDHI1 and the following pin configuration on a PK-S5D9 with QSPI disconnected and a uSD connector added:
Pin Group Selection: Mixed
Operation Mode: SD_MMC 4-Bit
I formatted a 4GB uSD card on my PC as FAT32, and also created a short Readme.txt file using the PC.
I am able to open, read, and close the existing file, but if I try to create a directory or create a new file, fx_directory_create or fx_file_create return 35d, or 0x23, which is FX_WRITE_PROTECT (0x23) Underlying media is write protected according to the FileX manual.
As far as I know, there is no write protect pin on the uSD card. Is there something that I may have configured incorrectly that might be causing an inability to write to the uSD card?
Thanks in advance for any help. I am going to try adding the FileX/ThreadX source to see if I can find out more about why writes are failing. I have also attached a zip file with my exported project, hoping that someone can take a look.
You should wire the WP line to ground, not write protected I believe. You may be able to do it in the configurator with an internal resistor. I did a SD card project a while back and we did use the WP…
The SD/MMC driver incorreclty always reads the state of the WP bit in the SDHI peripheral when the card type is set to SD Card :-
r_sdmmc_write_protect_get() is called in the function R_SDMMC_Open().
Take a look here - lots of things to try and check in your design.
After reviewing the link you provided, I changed the type from Card to Embedded. I was also informed that CD needed to be disabled if the type is Embedded, so I did that, even though CD is connected to a pin in our system. WP is not connected to any pin.
After making these changes and rebuilding, the card can now be written to. What I don't quite understand is _why_. It appears that changing the type to Embedded skips the check for the write protect line (probably assuming that eMMC is being used?).
With a micro SD card, do I still need to have the WP write-protect line set to a certain configuration, either high or low? I don't think it's actually connected to the card, but I'm not certain.
I appreciate your help, and have something that works, but would really like to understand WHY it works to make sure I have a robust solution.
Thanks for any advice you can provide, and best regards!
You should wire the WP line to ground, not write protected I believe. You may be able to do it in the configurator with an internal resistor. I did a SD card project a while back and we did use the WP switch on the card socket.
You may be able to check the state of the WP pin in your design as it is using a HAL call, or stepping through the FileX code if you have the source. It probably thinks it's high due to a pullup or floating.
You are correct on the MMC - no WP is used on those parts.
Couldn't do it via the configurator - no pull-down option to force the WP line low.
Looks like that's the case. You might have to wire it to ground, If you can get the sdMMC driver source (it maybe be encrypted depending on your license), you could take out the check for WP.
Can't think of any other solution and it looks like others have tried.
The function r_sdmmc_write_protect_get() probably should be something like :-
and set Write Protect to "Not Used" in the configurator, then the WP pin of the SDHI peripheral does not have to be used.
The SD/MMC driver is in clear text so can be edited. Exclude the original from the build so it doesn't get overwritten, and copy it to the src/ directory to make the changes :-