STM32 with SD card hangs :(

I cant get my STM32F4 to get past initializing the SD card, ive got it hooked up to SPI1 and PA4 on a 3V breakout board. It just hangs on SD.begin(). Ive tried SD and SDFat on a 16gb sd card
#include <SPI.h>
#include <SdFat.h>
const int chipSelect = PA4;
SdFat SD;
void setup() {
Serial.begin(115200);
while (!Serial);
delay(1000);
pinMode(PA4, OUTPUT);
digitalWrite(PA4, HIGH);

Serial.println("3");delay(1000);
Serial.println("2");delay(1000);
Serial.println("1");delay(1000);
Serial.println("G");delay(100);

if (!SD.begin(chipSelect)) {
delay(100);
Serial.println("SD init failed");
while(1);
}
delay(100);

}

void loop() {
// Nothing here
Serial.println("meow");
}
#include <SPI.h>
#include <SdFat.h>
const int chipSelect = PA4;
SdFat SD;
void setup() {
Serial.begin(115200);
while (!Serial);
delay(1000);
pinMode(PA4, OUTPUT);
digitalWrite(PA4, HIGH);

Serial.println("3");delay(1000);
Serial.println("2");delay(1000);
Serial.println("1");delay(1000);
Serial.println("G");delay(100);

if (!SD.begin(chipSelect)) {
delay(100);
Serial.println("SD init failed");
while(1);
}
delay(100);

}

void loop() {
// Nothing here
Serial.println("meow");
}
No description
60 Replies
Demon Lord of the Round Table
try initializing sd.Begin outside the if statement and comparing it later
squirrel
squirrelOP2d ago
still hangs there :(
Demon Lord of the Round Table
check wiring?
squirrel
squirrelOP2d ago
douyble checked
Demon Lord of the Round Table
have you soldered the header pins to the sd module? also which board
squirrel
squirrelOP2d ago
stm32f4 blackpill its wired w dupont i shouldve designed the header to match the layout of the module, but this was before i got this module for other projects
Demon Lord of the Round Table
have you checked to see if the sd card has a fat32/fatfs file system? also what ide are you using to program it?
squirrel
squirrelOP2d ago
im using ardunio for stm32 yeah, i just formatted it to fat32 weird it was in GPT mode formatted the partition table to MBR nope :P
Demon Lord of the Round Table
oh well doesnt the miso,mosi and sclk pins need to be set aswell?
squirrel
squirrelOP2d ago
i dont think so? ive never had to do that before theres not much documentation of using SPI either, usually ppl just use SDIO but thats not really possible for me unless i maybe add a second STM32 but like..
squirrel
squirrelOP2d ago
letse see ive just been playing with modified examples
Demon Lord of the Round Table
btw i havent gotten into stm32,what pcb is the blackpill sitting on?
squirrel
squirrelOP2d ago
custom designed board to support IO and stuff for my weather balloon ive got the entire i2c part working
squirrel
squirrelOP2d ago
itsj ust the sd card is killing me i dont like SPI anyway its so finicky no matter what youre doing unholy
Demon Lord of the Round Table
in so used to absolute beginners asking questions here without reading docs an stuff can like a regular person just launch an air balloon?don't you need permits for that and stuff
squirrel
squirrelOP2d ago
if youre doing like really big ones yeah you need permits im under the weight limit best to notify the FAA n stuff tho
Demon Lord of the Round Table
i dont see why setting the pa4 to high would do anything,but maybe mosi and rest of the pins are initialized in the header files?ill dowload them and look
squirrel
squirrelOP2d ago
especially when near airports grasping for straws really
Demon Lord of the Round Table
logically those pins need to be set for recieving and outputting somewhere
squirrel
squirrelOP2d ago
the one you sent me doesnt explode when you enable the SDcard fortunately just fails to init lol i might check w multimeter
Demon Lord of the Round Table
ye,might just have a faulty module :/
squirrel
squirrelOP2d ago
low chance tho i mean its just some resistors capacitors and a sd socket
Demon Lord of the Round Table
im assuming youve checked for corrosion
squirrel
squirrelOP2d ago
wired properly i dont think thered be corrosion huh it worked
squirrel
squirrelOP2d ago
im not sure? thats scary though what if it fails again i didnt change anything see why i say SPI is unholy
Demon Lord of the Round Table
turn it off/unplug it and back in to see if it works again?
squirrel
squirrelOP2d ago
maybe?
squirrel
squirrelOP2d ago
waow
No description
squirrel
squirrelOP2d ago
it wrote to the file
Demon Lord of the Round Table
maybe the old binary was in a cache and didnt load the new one i sent(???)
squirrel
squirrelOP2d ago
no it was definitely in there at least the new one doesnt hang if it fails like the old one
Demon Lord of the Round Table
the hanging was cause of the infinite while loop i remember spitting inside an sd card module like this and it working
squirrel
squirrelOP2d ago
yes it got stuck inside SD begin
Demon Lord of the Round Table
whats the write speed of the card? from this forum it seems when you try to write multiple times quickly the sd card has to finish writing the first instruction and then the next
squirrel
squirrelOP2d ago
honestly i have no idea i was just trying to open it
Demon Lord of the Round Table
so if you were spamming the program it mightve caused something similar?? https://community.st.com/t5/stm32-mcus-embedded-software/sdio-multi-block-write-fails-sometimes/td-p/571749
SDIO multi block write fails sometimes
Hi. I have few questions regarding SDIO and SD card write performance. I am using STM32F446 MCU and a simple application using polling SDIO that writes (appends) 32 blocks (16KB) of data to the SD card every 20ms. I do not use filesystem, just writing RAW bytes. Application increases block address o...
squirrel
squirrelOP2d ago
whatever happens in the open() function killed it
Demon Lord of the Round Table
the cards dead now?
squirrel
squirrelOP2d ago
sorry my stupid dialect it caught the STM32 in a loop it couldnt get out of it i guess i mean i have no way to debug it my UART programmers not that fancy
Demon Lord of the Round Table
i see.....reformat the card and see if the current thing works?
squirrel
squirrelOP2d ago
no its working now
Demon Lord of the Round Table
just to be redundant
squirrel
squirrelOP2d ago
im integrating it into the flight code
squirrel
squirrelOP2d ago
:3
squirrel
squirrelOP2d ago
:3
Demon Lord of the Round Table
its fun to google my disc name and my posts from here show up
squirrel
squirrelOP2d ago
wait what :omori_basil_scared:
Demon Lord of the Round Table
I think it scrapes after youve marked the thread as solved and only the help threads(for the most part....)
squirrel
squirrelOP2d ago
damn
No description
squirrel
squirrelOP2d ago
Oscilloscope Online: An online Graph Plotter, A cool alternative to...
Questions related to Oscilloscope Online: An online Graph Plotter, A cool alternative to Arduino IDE's Serial Plotter in Arduino
squirrel
squirrelOP2d ago
oscilloscope online?? i love oscilloscopes also ace combat !!! waow this is perfectly relatvent because uh im.. my flight software is called ace combat oscilloscope is the name of the file log .CSV file
Demon Lord of the Round Table
FUCKKKKK MY OPSEC IS SHIT!
squirrel
squirrelOP2d ago
MY HYPERFIXATION oscilloscopes i have four

Did you find this page helpful?