Hints about the MMC/SD card library by Roland Riegel

Working libraries, libraries being ported and related hardware
victor_pv
Posts: 1650
Joined: Mon Apr 27, 2015 12:12 pm

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

Post by victor_pv » Sun Apr 02, 2017 5:37 pm

Can you post a link to the version of the sdfat library that you are using?

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 » Wed Apr 05, 2017 8:37 pm

Hi

@Victor_pv,
as I wrote the SdFat library that I'm using is the version 20131225.
Nowadays I'm not able to retrieve it from the repository, and it is to big to be attached here.
I know it's very old so I have downloaded the more recent SdFat version 20160719 that I'll try to modify in order to allow for MMC although this release is pretty different as structure.
I have to take a look at it before I can do the needed changes to allow for the MMC cards, but first I wanted to try the libray with normal SD cards.
As soon as there is something new I'll post.
Tanks

STM32

Little OT.
Here is started something weird.
I have compiled the example SdInfo sketch without problem, then I have put it on the Blue Pill, but the code doesn't start as it should.
In fact every time I start the terminal it is empty, there isn't the text:

SdFat version: 20160719

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 53
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start

not even starting the whole thing with the SD shield not connected.
Into the sketch I have set
SD_CHIP_SELECT = PA4;
and when the SD shield is linked I use

PA5 SD_SCK
PA6 SD_DO (=MISO)
PA7 SD_DI (=MOSI)

I have tried to move data on SPI2 but nothing change, terminal is always empty.
Seems to me that the "Blue Pill" is working because by using other examples, for instance Test_RTClock, then the terminal shows data correctly.
I'm using the Arduino IDE 1.8.1 terminal.

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

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

Post by victor_pv » Thu Apr 06, 2017 2:40 am

STM32 wrote:Hi

@Victor_pv,
as I wrote the SdFat library that I'm using is the version 20131225.
Nowadays I'm not able to retrieve it from the repository, and it is to big to be attached here.
I know it's very old so I have downloaded the more recent SdFat version 20160719 that I'll try to modify in order to allow for MMC although this release is pretty different as structure.
I have to take a look at it before I can do the needed changes to allow for the MMC cards, but first I wanted to try the libray with normal SD cards.
As soon as there is something new I'll post.
Tanks

STM32

Little OT.
Here is started something weird.
I have compiled the example SdInfo sketch without problem, then I have put it on the Blue Pill, but the code doesn't start as it should.
In fact every time I start the terminal it is empty, there isn't the text:

SdFat version: 20160719

Assuming the SD is the only SPI device.
Edit DISABLE_CHIP_SELECT to disable another device.

Assuming the SD chip select pin is: 53
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start

not even starting the whole thing with the SD shield not connected.
Into the sketch I have set
SD_CHIP_SELECT = PA4;
and when the SD shield is linked I use

PA5 SD_SCK
PA6 SD_DO (=MISO)
PA7 SD_DI (=MOSI)

I have tried to move data on SPI2 but nothing change, terminal is always empty.
Seems to me that the "Blue Pill" is working because by using other examples, for instance Test_RTClock, then the terminal shows data correctly.
I'm using the Arduino IDE 1.8.1 terminal.
Remember the stm32 is 3v and the sdcard is 3v, so there should be no level converter between the two.
If the sdcard module was working for Arduino, then since arduino is 5v, there was a level converter. Unless you added it, it may in the sd card module. There are several threads about issues with that. Some sdcard modules have resistors as level converters, and they may need to be shorted.
Check that out first of all.
Also the power voltage can be a problem. Many sdcard modules have a voltage regulator to produce 3V from 5V VCC. If you feed them with 3V from the bluepill, the voltage at the output of the regulator will be even lower.
Some of my sdcard modules did not have voltage converters for the IO pins, but had the regulator, and I have to feed them power past the regulator. Normally they will have some pads that you can short with some solder and will skip the regulator.

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 » Thu Apr 06, 2017 8:00 pm

Hi Victor_pv,
the SD shield that I'm using with "Blue Pill" consists only by the connector, there isn't any other hardware, it is 3,3V only.
For Arduino I use a different one which has level converter because my Arduino is one of the 5V series.
The weird thing isn't that I can access the cards but rather that "Blue Pill" fails to perform the SdInfo sketch, Arduino IDE's terminal doesn't show any text.
I have to check data bus with an oscilloscope.
Also by starting the whole thing without any SD shield connected, namely by using the "Blue Pill" alone, nothing appears on the terminal inside the Arduino IDE.
This is the fact.
Anyway I had a look into the library and I saw what I guess I need to change in order to unlock MMC's support.
During the weekend I'll try to make some changes and I'll post the results.
Due the problem I wrote, my current goal is to achieve the right compilation of the sketches with the SdFat modified by me in order to allow also for MMCs.
After that I'll succeeded I'll dig the matter about code that doesn't appears into the Arduino IDE terminal, which is weird since other sample sketches are working fine with "Blue Pill".
Thanks.

STM32

ag123
Posts: 740
Joined: Thu Jul 21, 2016 4:24 pm

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

Post by ag123 » Thu Apr 06, 2017 9:26 pm

hi stm32
1st i know hardly anything about the internals of sd cards vs mmc cards
hence i did some google and ran into this site, i'd think it may be a pretty helpful as a starting point for info
http://wiki.seabright.co.nz/wiki/SdCardProtocol.html

it seemed that mmc vs sd are pretty different in terms of the *protocol* (i.e. commands to access the cards internals) even if both use an spi bus.
i'm not sure about this really, the specs are verbose and it'd take 1 to review that perhaps for those 'low level' ports
i.e. it may not be that 'easy' to sort of patch sdfat into and mmc-fat perhaps, one may end up rewriting large fractions of it (hope not)
perhaps someone more familar with sd vs mmc is in a better position to comment about it

in addition, i do not know anything about the atmega platform (e.g. arduino uno ) as well, there could be subtle differences even with things like spi etc
do check pins etc to see that they after all hooked up correctly to spi etc
http://wiki.stm32duino.com/index.php?title=Blue_Pill

and with these 'low level' stuff, it could really help to patch up gdb / openocd etc for debugs, etc, i'm not too sure how too

2 more links
http://elm-chan.org/docs/mmc/mmc_e.html
^^^ this is a good site, there are apparently something common in both mmc and sd, reading this web
http://ralimtek.com/Stm32_SPI_SD/

oh yes, i think there are also various stm32 'platform specifics'
e.g. clocking the peripheral bus
http://electronics.stackexchange.com/qu ... igital-pot
^^^i think these are catered in the libraries that's hooked up via stm32_arduino, but i think the notation may be different in the sense of 'enabling' it
and things like there are 2 SPI buses on stm32f103cbt6, make sure you have clocked/enabled the right bus and is 'talking' to the correct bus
http://www.st.com/en/microcontrollers/stm32f103c8.html

stevestrong
Posts: 1608
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 Apr 07, 2017 11:38 am

ag123 wrote:it seemed that mmc vs sd are pretty different in terms of the *protocol* (i.e. commands to access the cards internals) even if both use an spi bus.
i'm not sure about this really, the specs are verbose and it'd take 1 to review that perhaps for those 'low level' ports
i.e. it may not be that 'easy' to sort of patch sdfat into and mmc-fat perhaps, one may end up rewriting large fractions of it (hope not)
perhaps someone more familar with sd vs mmc is in a better position to comment about it
I'm not an expert on MMC but I am also of opinion that it would be much more secure to adapt the existing library to work with STM32 rather than to patch the SD fat lib to support MMC cards.

ag123
Posts: 740
Joined: Thu Jul 21, 2016 4:24 pm

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

Post by ag123 » Fri Apr 07, 2017 7:27 pm

@stevestrong

i've 'mixed feelings' about this. i'm not totally against the idea of using a 'common' sd / mmc library, i.e. a single library caters to both
as the web from elm-chan pointed out, it'd seem sd and mmc do share common commands
http://elm-chan.org/docs/mmc/mmc_e.html
my guess is that sd-fat is possibly a derivative from elm-chan's original library hence, it could possibly already have codes that is compatible with both sd and mmc cards

however, i'd think sd vs mmc do diverge when the features that have made their way into the new hardware (e.g. the recent uhs type of sd cards / sdio (non-spi) interface etc is considered)

as to why it may be necessary to separate libraries, an easiest way to think is that after all we only have 20k of ram in stm32f103cb or stm32f103c8 which makes up the maple mini and blue pill and many other stm32f103xx boards (i.e. c-r medium density dev, less those v and z series)
trying to exploit the features specific to sd or mmc would mean running out of ram before anything much can be done

hence i'd think having a *separate* 'lowest common denominator' imho may not be a bad thing, just that 'lowest common denominator' means throwing out codes (i.e. reducing features to a minimum set, but that could mean breaking compatibility be it sd or mmc) that possible needs to be different between sd vs mmc.

and in addition sd being a lot more common today vs mmc, i'd agree that having them separate is probably a better thing

just 2c

stevestrong
Posts: 1608
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 Apr 07, 2017 10:15 pm

My idea was just to port a code which is already proven to run for that application on other target boards.
So am not talking about a general lib which should support both sd and mmc and who knows what else, or some exotic functionality.
I am still convinced that porting the lib to blue pill would be the qickest way to get the sw running, to do what is actually designed for.
But, of corse, when someone has a better overview what is actually running in the background, other approaches would be also feasible.

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 » Thu Apr 20, 2017 8:03 pm

Hi guys,
I'm still looking for a solution in order to change SdFat library to allow for MMC cards.
Until now I was unable to do the job because recent release is pretty different from the old so the trick I used in the past doesn't work anymore, honestly not even the same trick with the oldest release 20131225 is working with my "Blue Pill".
Anyway by surfing the web I found something very similar to the hint I used in the past in order to changes from myself the standard Arduino's SD library and the SdFat library release 20131225.
As your reference, here it's:

https://tinyurl.com/kwnnbe4

In the bottom, among some thoughts into >32 thoughts on “Arduino SD Library support for MMC Cards”< is explained how do the trick on SdFat library for Arduino.
I'll don't give up but now my problem is on a different side that I already wrote here, my "Blue Pill" doesn't work as is expected due the fact the terminal it's empty, there isn't the output of the sketch.
With a MSO I checked pins output and all it's 100% fine but no text as output on the Arduino IDE 1.8.1 terminal.
I have tried also with a second "Blue Pill" with the same result.
Seems to me that the two "Blue Pill" I have used are working because by using other examples on them, for instance Test_RTClock, then the terminal shows data correctly.
Both of the "Blue Pill" they have a 1.5kohm pullup resistor on D+ (R10 on the board).
Can someone who has experimented with "Blue Pill" and SD cards confirm that output is working via USB to the terminal?
Eventually can someone provide an example code which can be use for testing or put a link to something like that?
Thanks.

STM32

stevestrong
Posts: 1608
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 » Thu Apr 20, 2017 8:13 pm

Try a simple blinky sketch with simple serial output in loop, without including SD card header.
Check the 3.3V voltage level, the on-board regulator is week.
It must be your software, and we cannot help if you don´t post it.

Post Reply