Hints about the MMC/SD card library by Roland Riegel

Working libraries, libraries being ported and related hardware
stevestrong
Posts: 1450
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Hints about the MMC/SD card library by Roland Riegel

Post by stevestrong » Fri Mar 31, 2017 8:02 pm

Let me put it this way:
the job could be done by any of those who commented within an hour (adapt the spi routines and setup)
But then you did not learn anything.
And you are a hardware guy...if you want to learn sw, and really learn to work with "blue pill", then you should do it yourself, or at least try.
So, if you browse the already ported libraries, then you could see how to deal with #ifdefs, there are even examples how to replace avr ddr registers.
Just show us what did you try, and then we will tell you how to do it right.

User avatar
zoomx
Posts: 457
Joined: Mon Apr 27, 2015 2:28 pm
Location: Mt.Etna, Italy

Re: Hints about the MMC/SD card library by Roland Riegel

Post by zoomx » Fri Mar 31, 2017 8:19 pm

What are the difference in the Arduino library between reading a SD and reading a MMC?

User avatar
martinayotte
Posts: 1194
Joined: Mon Apr 27, 2015 1:45 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by martinayotte » Fri Mar 31, 2017 8:24 pm

STM32 wrote: I agree but natively SdFat doesn't support MMC so I can't use it.
What is the reason you do absolutely want MMC support ? (especially that MMC are slower than SD)
http://www.differencebetween.net/techno ... interface/

What kind of data you wish to place on the SDCard ?

SdFat from Greiman is one of the best library you can found.

STM32
Posts: 17
Joined: Sun Mar 26, 2017 12:18 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by STM32 » Fri Mar 31, 2017 9:31 pm

Hi Stevestrong,
I fully agree with you.
But wait a minute, actually I didn't ask to anybody to do anything.
I only asked about the syntax that I wrote because it is weird at my eyes and by thinking it could be related with the possibility to reach my purpose.
You and other guys have pointed at me your and their opininions so I learn that it is better for me go one other way.
Indeed now I'm trying to change SD and SdFat in order to allows MMC, exactly like I have already did on Arduino long before I discovered the Roland Riegel's library.
I talked about that sketch I have linked and the Roland Riegel's library only hoping the thing was easier to run on STM32.
As I wrote I'm an hardware guy, so please excuse me for being so naive on the software side.
Thanks.

STM32

STM32
Posts: 17
Joined: Sun Mar 26, 2017 12:18 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by STM32 » Fri Mar 31, 2017 9:32 pm

Hi Zoomx,
for the little that I know it should be something related with the initialization of the cards.
Indeed the changes I'm making in the libraries are about the initialization.
I know that it's a crude way but it works, or at least it worked on Arduino.
Thanks.

STM32

STM32
Posts: 17
Joined: Sun Mar 26, 2017 12:18 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by STM32 » Fri Mar 31, 2017 9:33 pm

Hi Martinayotte,
I agree about the SdFat library.
The fact is that the device on which I need to do servicing doesn't allow for SD but only for MMC and MMC+.
Actually it's enough for me to retrieve CSD, CID and few other register's content in order to understand if all it is fine, not do some complicated things.
Due to the fact that for my goal I would have still had to adapt or the standard SD library or the SdFat, I wanted to inquire about the Roland Riegel's library as it natively manages MMC and MMC+ and seemed to me more fit for the purpose.
Thanks.

STM32

victor_pv
Posts: 1485
Joined: Mon Apr 27, 2015 12:12 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by victor_pv » Sat Apr 01, 2017 12:07 am

On your question about the #ifdef, the one for our core is

Code: Select all

#if defined(__STM32F1__)
The SdFat library has all the MCU specific code in a single file per MCU all in the same folder, you can see in the different files how each start with #if defined... for the corresponding MCU:
https://github.com/greiman/SdFat/blob/m ... SdSpiCard/

Since you had previously modified the SdFat library, unless it was a very old version in which the SPI library was not used or was structured in a different way (I dont know the history of that library), chances are you can add the SdSpiSTM32F1.cpp file in that folder in your modified copy of the library and may work right away.

If it doesn't, you can post what modifications you did to the library and someone may be able to tell what part may not work with the stm32f1.
Except for adding one file in that folder, the rest of the SdFat library did not need any modification to work with the stm32f1.

Roland's library has a problem, it access the AVR registers directly. To make a conversion someone needs to know the SPI peripheral for both the AVR and for the STM32 well enough.
For example I know the stm32f1 spi, but have no knowledge whatsoever of the AVR ones, so I can't even say how difficult or easy would be to port it.
If you want to go thru the effort of learning both for the pleasure or learning, then your first step is to read the datasheets for the STM32F1 and the AVR to learn how the SPI peripheral works in both. Then you will be able to figure out how to achieve the same result.

stevestrong
Posts: 1450
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Hints about the MMC/SD card library by Roland Riegel

Post by stevestrong » Sat Apr 01, 2017 2:22 pm

If I would need to port something, I would start with commenting out parts of the header files which are AVR related.
Then go through the CPP code and replace functionality.

For example:
- comment out line 6 of the cpp file
- add #include "SPI.h"
- replace lines 219-227 by: SPI.beginTransaction(SPISettings(250000, DATA_MODE0, MSB_FIRST));
- and so on.

STM32
Posts: 17
Joined: Sun Mar 26, 2017 12:18 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by STM32 » Sun Apr 02, 2017 3:53 pm

Hi Victor_pv,
thank you very much for your hint.
I'm not gone, I only need time in order to find the solution.
I tried your suggestion, I have put the Sd Spi STM32F1.cpp inside the same folder of the modified version of the SdFat that I made but the thing doesn't work:

File included from C:\Arduino\libraries\SdFat/SdFat.h:38:0,

from C:\Arduino\libraries\SdFat\examples\MMC\MMC.ino:4:

C:\Arduino\libraries\SdFat/SdFile.h:44:7: error: conflicting return type specified for 'virtual int SdFile::write(const char*)'

int write(const char* str);

^

In file included from C:\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple/HardwareSerial.h:38:0,

from C:\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple/wirish.h:69,

from C:\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple/Arduino.h:30,

from sketch\MMC.ino.cpp:1:

C:\Arduino\hardware\Arduino_STM32\STM32F1\cores\maple/Print.h:41:20: error: overriding 'virtual size_t Print::write(const char*)'

virtual size_t write(const char *str);

^

exit status



My modified version of the SdFat is based on the main version 20131225.
In order to unlock MMC support for the SdFat the changes I made are into the SD2Card.cpp and SdInfo.h.
Basically into SD2Card.cpp I changed the original line 176 from

return 0;

to

return 1;

This disables the error checking while initialization allowing the code to continue despite everything.

Then immediately after the line 259

bool Sd2Card::begin(uint8_t chipSelectPin, uint8_t sckDivisor) {

I added the line 260 as:

bool useCmd1 = false;

This in order to define the command CMD1 that is used to initialize MMC cards.

Then I replaced the original lines from 309 to 315 with these:

while (cardAcmd(ACMD41, arg) != R1_READY_STATE) {
// check for timeout
if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {
error(SD_CARD_ERROR_ACMD41);
goto fail;
}
}

This in order to perform a valid initialization both for SD and MMC cards.

Finally into SdInfo.h I added the definition for CMD1 as line 37 and 38:

/** SEND_OP_COND */
uint8_t const CMD1 = 0x01;

This in order to be able to use the new command.
I made all those changes on the base of something I read somewhere on the net but that I forgot exactly where.
So I don't remember who is the real author, anyway with Arduino it works although I needed to change the original sketches into the SdFat due to the fact that they were no longer functioning like they are just out of the box.
In attachment are the modified files and a sample sketch for those who might find it useful or other.
Pay attention that it is a very crude code and it only works on Arduino.
Meanwhile I'll continue the test and I'll post the solution if I'll find it.
Thanks.

STM32
Attachments
SdFatMMC.zip
(10.1 KiB) Downloaded 19 times

STM32
Posts: 17
Joined: Sun Mar 26, 2017 12:18 pm

Re: Hints about the MMC/SD card library by Roland Riegel

Post by STM32 » Sun Apr 02, 2017 3:55 pm

Hi Stevestrong,
thanks a lot for the useful hints.
As you and others have made me realize I'm still too newbie to work on the porting so I'll try in the future.
Actually porting wasn't in my intention, I had just needed something capable to handle the MMC cards.
Following your indications I'm now working on the SdFat that it could be much easier for me due the fact that in the past I have succeeded with it into Arduino side.
Thanks.

STM32

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest