2017-01-15 03:45 PM
I have two boards designed for stm32f405 and stm32f411 to test uSD card.
The problem of using uSD on STM32F405 was fixed as discussed earlier:
https://community.st.com/thread/35991-microsd-card-problem-bug-in-the-filestm32f4xxhalsdc
Reading file/writing file are totally fine withut any problem on the STM32F405.Then I study the another board with a chip stm32f411ret6. These two boards are very similar because these two chips has very close pin configration.
Here is what is going on on the board with the chip stm32f4
I generated the code with cubemx, copy the testing code, and fixed the bug in the file mentioned above.
Low level io writing/reading has been tested. Pass!
Can I say that hardware problem (such as connection)is out of question?
But when I try to use file system to read/write file, there is an error in the line:
fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT boot sector as SFD */
returns FR_DISK_ERR.
Tried two sd card, 1g and 32g. Both works on the board with chip stm32f
What is wrong? Any instructions please.
The code for reading/writing testing is as followings
void SD_Test_LowLevel(void) { uint8_t SD_state = MSD_OK; static uint8_t prev_status = 0; char usbbuffer[200]; SD_state = BSP_SD_Init(); if(SD_state != MSD_OK) { sprintf(usbbuffer,'\n---initialize failed ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back Error_Handler(); } //initialization is done. Now go ahead for SD operation in low level SD_state = BSP_SD_Erase(BLOCK_START_ADDR, (BLOCKSIZE * NUM_OF_BLOCKS)); if(SD_state != MSD_OK) { sprintf(usbbuffer,'\n---erase failed ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back Error_Handler(); } /* Fill the buffer to write */ Fill_Buffer(aTxBuffer, BUFFER_WORDS_SIZE, 0x22FF); SD_state = BSP_SD_WriteBlocks(aTxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS); if(SD_state != MSD_OK) { Error_Handler(); } SD_state = BSP_SD_ReadBlocks(aRxBuffer, BLOCK_START_ADDR, BLOCKSIZE, NUM_OF_BLOCKS); if(SD_state != MSD_OK) { sprintf(usbbuffer,'\n---reading failed ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back } else { sprintf(usbbuffer,'\n---Reading OK ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back if(Buffercmp(aTxBuffer, aRxBuffer, BUFFER_WORDS_SIZE) > 0) { sprintf(usbbuffer,'\n---reading/writing compare failed ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back } else { sprintf(usbbuffer,'\n---Testing is done, OK ---\n');//export it to char buffer first. SendTextMsgToUSB(usbbuffer); //send the txt back } } GREEN_LED_ON;//Good while (1) { } }�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
#stm32f411 #sdio #stm32f405
Note: this post was migrated and contained many threaded conversations, some content may be missing.
2017-01-21 03:32 AM
47K pull up is up to me too weak (i had this value on my problematic proto SD board), it was perfectly fin ewith some sd card but not all.
it was
http://store.digilentinc.com/pmod-sd-full-sized-sd-card-slot/
but likely a rev A i remenber 47K pull up not 10K as in this new revb.some extra input if that can help:
Check SD/DMa irq pri same in both project ?
In you SD msp init code i noticed dma 'low piroity' i would use much higher given the data rate
i would raise apb clk to and cpu to max , lower this down later if to optimize power.
their could be some tight bus and interrupt timing where it can make the difference
Use of usb from 'HSI'
:(
scary that may not work well i always had issue without ext HSE 8Mhz base clock.strange that what work on 405 is not on f411 good luck
:(
2017-01-23 02:36 PM
Hello Clive
Can I combine old the stdperiph_lib with Hal?
The Cubemx is very good but it is really hard for sdio. I can't figure it out what is wrong.
stdperiph_lib is not that friendly but should be reliable.
My question is may I just use stdperiph_lib for sdio and others with hal?
How to do that?
Or can you provide me an example code for STM32F411RET6 with cubemx?
I really can't figure out why it works for F405 but not F411.
thanks
2017-01-23 04:21 PM
I tested with board (STM32F411)
erase and writing
(low level block writing) and read data using the another board(F405).The data were correctly wrote in SD card, veified in debug. In order to make sure I didn\t make mistake, I changed the data written to sd card. The another board only reads data.
So I can tell hardware such as connection should be OK. If there is any problem, it shouldn\t be able correctly write to sd card.
So the problem is why it can't read the data?
Please help
2017-01-23 05:13 PM
Clive,
PC7 is used for detection.
Or maybe you can just leave it always enabled
.I have two LED,
PB1 is for green
, PB2 is for red. Turn on green if everything is OK, otherwise turn on red.I used USB(CDC) for debug info. If you could build simple msg output interface,such as keep sending data to usb to tell the progress, that will be great. Please set PC1 as gpio_output, and set it to 0 to enable usb. Or just light up LED to indicate the status without usb msg.
Button: I use
PA1 as inpu
t. Once button is pushed(io reading turns to LOW), the program starts writing/reading sd card and send msg to usb. If it not convenient, just ignore it.As the pin configration. F405 is different from F411 for 3pins, two grounds and one VCap. I do check the difference.
when I use difference chip, the connection of the board was slightly modified such as jump wire etc.
Please use the schematic below to generate a testing code. If it go through, which means hardware is not the problem.
Appreciate your assistance.
2017-01-23 05:33 PM
I'm not an advocate for HAL/CubeMX
What Pin are you using for the Card Detect pin of the socket?
If you have details of pins, USARTs and LEDs, I could build a demo using the SPL
Are you sure it is not something with the pins of the 411 vs 405? Did any of the power, VCAP, or strapping get changed. Review a F411 DISCO schematic vs the F407 one.
2017-01-25 12:29 PM
Clive,
Do you have anything I can test on the board? Appreciate for your continuous support.
2017-01-25 03:10 PM
Not got to it yet, need to separate things out and deal with the lack of USART output for diagnostic. I guess we could use SWV
On headless stuff I'd write logs to the SD card, but that obviously has to work for that to be viable, so a bit of a catch-22 in this situation.
The LED appears to be on PB10 not PB1
SDIO_D0 PC8
SDIO_D1 PC9
SDIO_D2 PA9
SDIO_D3 PC11
SDIO_CLK PB15
SDIO_CMD PA6
SDIO_DETECT PC7
2017-01-25 03:39 PM
swv is good enough.
It is PB2 and PB10. Sorry PB1 is used in another board.
If I can see the info via SWV, no led is fine
I double checked the pin for sdio, they are correct.
Thanks
2017-01-25 10:34 PM
Here is a test build, should output to SWV a 100 MHz on F411 and 168 MHz on F407
https://drive.google.com/open?id=0B7OY5pub_GfIelExRk5TcjBRZmc
2017-01-26 11:19 AM
Clive,
Do you mind send me the source code?
I tested the hex file you sent to me. I didn\t see msg in the swv window.
I tried 100MHz or 96MHz. Still didn't see anything.
The LED light: at beginning both of them light up. after pretty long time about 1min, the left led(green) is on, and the right is off. Then wait for another 1 min maybe, leds switch. I checked the uSD card, there is no file on it.
By the way I am using internal 16MHz clock as the clock source, then PLL to 96MHz. No extern clock source is available on the board.