Blue pill and SD card

Generic boards that are not Maple or Maple mini clones, and don't contain the additional USB reset hardware
stevestrong
Posts: 1521
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Blue pill and SD card

Post by stevestrong » Thu May 25, 2017 6:36 am

Have you checked the 3.3V supply? On the blue pill the 5V->3.3V voltage regulator is not very strong.
It seems that the read data is mostly 0x00, so there still must be something wrong there.

skematic
Posts: 6
Joined: Tue May 23, 2017 11:36 am

Re: Blue pill and SD card

Post by skematic » Thu May 25, 2017 9:23 am

stevestrong wrote:Have you checked the 3.3V supply? On the blue pill the 5V->3.3V voltage regulator is not very strong.
It seems that the read data is mostly 0x00, so there still must be something wrong there.
The blue pill and SD card are powered by a USB serial adapter. Measurements with my multimeter show the power pins is roughly 3.3V. I've put decoupling ceramic capacitors of 220 nF at both VCC-GND connection on the SD card just in case, but did not help.

The following serial outputs come from the Arduino Pro Mini 3.3V with the exact same connection. This is the kind of output I hope to get on the STM32f103.

Code: Select all

Initializing SD card...Wiring is correct and a card is present.

Card type: SDHC

Volume type is FAT32

Volume size (bytes): 3749183488
Volume size (Kbytes): 3661312
Volume size (Mbytes): 3575

Files found on the card (name, date and size in bytes): 
SYSTEM~1/     2016-11-07 14:21:02
  INDEXE~1      2016-11-07 14:21:02 76
DOOR4.BMP     2016-10-28 23:04:02 14646
DOOR5.BMP     2016-10-28 23:04:30 14646
FYWK.BMP      2016-10-28 22:58:20 5494
HAITONG.BMP   2016-10-28 16:12:56 2782
KAIDONG.BMP   2016-10-28 16:13:18 4086
KDSM.BMP      2016-10-29 01:09:48 7542
KEY1.BMP      2016-10-28 16:36:16 4346
KEY2.BMP      2016-10-28 16:37:14 4346
KEY3.BMP      2016-10-28 16:38:08 4346
KEY4.BMP      2016-10-28 16:38:40 4346
LOCK.BMP      2016-10-28 17:36:08 6086
LOGO1.BMP     2016-10-28 16:06:34 13110
ME.BMP        2016-10-29 01:50:02 29238
MMMK.BMP      2016-10-28 17:38:12 3998
MNW.BMP       2016-10-28 17:39:00 3998
NDNSMZ.BMP    2016-10-29 00:26:06 9454
PASSBAR.BMP   2016-10-28 17:36:42 12702
PPL.BMP       2016-10-28 23:53:06 4054
SNOW1.BMP     2016-10-28 23:52:52 18422
SNOW2.BMP     2016-10-28 23:53:42 18422
SNOW3.BMP     2016-10-28 23:54:12 18422
SNOW4.BMP     2016-10-28 23:54:38 18422
SNOW6.BMP     2016-10-29 00:01:46 18422
TTN.BMP       2016-10-29 01:09:16 5814
VERSION3.BMP  2016-10-29 01:50:18 2030
ZMHZDMA.BMP   2016-10-29 01:11:40 9094
BIGKEY.BMP    2016-10-29 01:09:34 6990
DOOR1.BMP     2016-10-28 23:01:28 14646
DOOR2.BMP     2016-10-28 23:02:52 14646
DOOR3.BMP     2016-10-28 23:03:22 14646

Code: Select all

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: 10
Edit SD_CHIP_SELECT to change the SD chip select pin.

type any character to start

init time: 6 ms

Card type: SDHC

Manufacturer ID: 0X12
OEM ID: 4V
Product: SD
Version: 0.0
Serial number: 0X1B000000
Manufacturing date: 6/2010

cardSize: 8053.06 MB (MB = 1,000,000 bytes)
flashEraseSize: 128 blocks
eraseSingleBlock: true
OCR: 0XC0FF8000

SD Partition Table
part,boot,type,start,length
1,0X0,0XB,8192,15719443
2,0X0,0X0,0,0
3,0X0,0X0,0,0
4,0X0,0X0,0,0

Volume is FAT32
blocksPerCluster: 64
clusterCount: 245488
freeClusters: 245455
freeSpace: 8043.07 MB (MB = 1,000,000 bytes)
fatStartBlock: 12548
fatCount: 2
blocksPerFat: 1918
rootDirStart: 2
dataStartBlock: 16384

type any character to start

skematic
Posts: 6
Joined: Tue May 23, 2017 11:36 am

Re: Blue pill and SD card

Post by skematic » Fri May 26, 2017 2:13 pm

Anything else I could try?

User avatar
Pito
Posts: 1502
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Blue pill and SD card

Post by Pito » Fri May 26, 2017 4:50 pm

What is your chipselect pin?? Try to use a different one.
Also try to exchange MOSI/MISO pins..
Pukao Hats Cleaning Services Ltd.

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

Re: Blue pill and SD card

Post by ag123 » Fri May 26, 2017 6:32 pm

as you have an LDO regulator on the SD breakout board
Image
you may like to try to route a 5V pin from your bluepill to the VCC pin on the SD breakout board
*warning*, when doing all these, have voltmeter handy. after connecting 5V VCC my guess is first measure voltages off the msoi, mosi, sck, cs pins on the breakout before even connecting it to bluepill since SPI 1 is not 5V tolerant
you would probably need to measure voltages on blue pill e.g. the 5V pin which seemed to be pin 3 to ascertain that it is the correct pin
the schematics are in the stm32duino forum wiki
http://wiki.stm32duino.com/index.php?title=Blue_Pill

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

Re: Blue pill and SD card

Post by ag123 » Fri May 26, 2017 7:25 pm

are you using 'greiman''s SD fat? currently this seem to be one that works pretty well
http://www.stm32duino.com/viewtopic.php?f=13&t=20
https://github.com/greiman/SdFat

in addition, i actually used the SPI.cpp, SPI.h 'drivers' in libraries/SPI
https://github.com/rogerclarkmelbourne/ ... raries/SPI

you could use the sd fat libraries that you are familiar with, but i'd guess you would need to check where they are hooked into SPI.h.
i like to copy SPI.c, SPI.h from libraries/SPI and put that in the same folder as the sketch and update the codes to include "SPI.h" rather than <SPI.h>. there seem to be some codes in the libmaple core dealing with spi. i copied the files and place it in the same folder to avoid possibly including the incorrect libraries from the libmaple core

these pins looks a little strange to me as well
CS -> PA15
SCK -> PB3
MISO-> PB4
MOSI -> PB5
GND->GND
SPI1 is normally on

Code: Select all

PA4 - SS (you could use this as /CS if you'd like)
PA5 - SCK1
PA6 - MISO1
PA7 - MOSI1
^^^^ these pins are not 5v tolerant
SPI2 on

Code: Select all

PB12 - SS (you could use this as /CS if you'd like)
PB13 - SCK2
PB14 - MISO2
PB15 - MOSI2
^^^^ these pins seemed to be 5v tolerant, but do check datasheets/manuals

do verify the pins against the datasheets / schematics etc
http://www.st.com/en/microcontrollers/stm32f103c8.html
http://wiki.stm32duino.com/index.php?title=Blue_Pill

sweetlilmre
Posts: 1
Joined: Sun Jul 16, 2017 2:31 pm

Re: Blue pill and SD card

Post by sweetlilmre » Sun Jul 16, 2017 4:40 pm

ag123 wrote:
Fri May 26, 2017 7:25 pm
SPI1 is normally on

Code: Select all

PA4 - SS (you could use this as /CS if you'd like)
PA5 - SCK1
PA6 - MISO1
PA7 - MOSI1
^^^^ these pins are not 5v tolerant
Using your suggested pins I managed to get the sketch in the OP to work using a soldered up micro SD card adapter.
Thank you very much! The other part of the solution was to use SPI_CLOCK_DIV2.

-(e)

Post Reply