2018-06-11 04:11 AM
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 #sdcard2018-06-11 04:37 AM
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.
2018-06-12 06:06 AM
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 .
2018-06-12 08:33 AM
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.