cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f103 sdio problem

vahid javadi
Associate
Posted on June 11, 2018 at 13:11

Hi 

i use stm32f103rct6 for w/r sd card but it not work exactly , it just work once and dont work again . i look to logic analyzer and i think it not  work true . what can i do ?

 my code :

if (f_mount(&myFat,SDPath, 1) == FR_OK) {

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_3,GPIO_PIN_SET);

res=1;

f_open(&fil,'javvah2.txt',FA_WRITE|FA_CREATE_ALWAYS);

f_write(&fil,'xxxx hellow world',20,&byteCount);

f_close(&fil);

}else{

HAL_GPIO_WritePin(GPIOB,GPIO_PIN_4,GPIO_PIN_SET);

f_open(&fil,'javvah2.txt',FA_WRITE|FA_CREATE_ALWAYS);

f_write(&fil,'xxxxhellow worldzzzz',20,&byteCount);

f_close(&fil);

}

#sdio #cubemx-4.26 #stm32f103rct6 #sdcard
3 REPLIES 3
Posted on June 11, 2018 at 13:37

For the SPI connectivity the stm32_adafruit_sd.c  code in the HAL BSP is a good starting point.

Your code doesn't seem to check for error status returned by the FatFs library, although to be honest when debugging this stuff you're going to need to get into the DISKIO and SPI layers, and instrument those rather than tinker and observe from the high level code shown.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 12, 2018 at 13:06

I get  FR_DISK_ERR from f_mount function . I test  it on 405 and 767 microcontrollers and get same results . I read somewhere the hal library have some bugs like this but i didnt find any solution for it . i test my connection on arduino and it work very well .

Posted on June 12, 2018 at 15:33

I've discussed the multi-sector read/write error in the adafruit_sd code before, but this shouldn't cause a failure of f_mount()

If the SPI initialization doesn't work the first time around, you can try it a second time. The pins at boot are some what indeterminate.

There really isn't any detail from your query describing the connectivity of the hardware, or configuration of the pins. The Adafruit shield describes some specific pins and connectivity expectations.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..