cancel
Showing results for 
Search instead for 
Did you mean: 

How can I interface STM32Cube_FW_F1_V1.0.0 FatFs_uSD with SPI2 on STM32F107?

antonius
Senior
Posted on January 28, 2016 at 21:47

Guys,

I see:

STM32Cube_FW_F1_V1.0.0\Projects\STM3210C_EVAL\Applications\FatFs\FatFs_uSD

Could you tell me which file should I modify so I can use SPI2 on STM32F107 with this application ?

Thanks
9 REPLIES 9
Amel NASRI
ST Employee
Posted on January 29, 2016 at 11:31

Hi h.rick,

In the example STM32Cube_FW_F1_V1.0.0\Projects\STM3210C_EVAL\Applications\FatFs\FatFs_uSD, the SPI configuration is done in the files stm3210c_eval and stm3210c_eval_sd available under STM32Cube_FW_F1_V1.3.0\Drivers\BSP\STM3210C_EVAL.

The SPI3 is used in this example as you can see it in the file stm3210c_eval.h.

Hope this will help you to go ahead with your application.

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on January 29, 2016 at 19:09

Does this support SD-HC cards? Seems not to use the right commands, and arbitrarily truncates a 64-bit byte offset into a 32-bit one. So I don't expect anything above 2GB to be viable.

In 2015-2016 it doesn't really seem fit for purpose.. The HC specs date from a decade ago. There seems to be a disconnect here between what needs to be supplied for a competitive solution and framework, and what is being delivered.

As frustrated as I am with h.rick, he wouldn't be mired in these issues if the stuff just worked properly out of the box.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
Posted on January 29, 2016 at 23:00

Which file is for user_diskinitialize() ?

I can't find it.... It's only abstraction not a complete user_diskinitialize().... Low level one with :

Stat = STA_NOINIT;
DSTATUS stat = RES_OK;
BYTE n, cmd, ty, ocr[4];
//; 
if (pdrv) return STA_NOINIT; /* Supports only single drive */
power_off(); /* Turn off the socket power to reset the card */
if (stat & STA_NODISK) return stat; /* No card in the socket */;
power_on(); /* Turn on the socket power */
FCLK_SLOW();
for (n = 10; n; n--) xchg_spi(0xFF); /* 80 dummy clocks */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
Timer1 = 100; /* Initialization timeout of 1000 msec */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2? */
for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF); /* Get trailing return value of R7 resp */
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
while (Timer1 && send_cmd(ACMD41, 1UL << 30)); /* Wait for leaving idle state (ACMD41 with HCS bit) */
if (Timer1 && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
for (n = 0; n < 4; n++) ocr[n] = xchg_spi(0xFF);
ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 */
}
}
} else { /* SDv1 or MMCv3 */
if (send_cmd(ACMD41, 0) <= 1) {
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
} else {
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
}
while (Timer1 && send_cmd(cmd, 0)); /* Wait for leaving idle state */
if (!Timer1 || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
ty = 0;
}
}
CardType = ty;
deselect();
if (ty) { /* Initialization succeded */
stat &= ~STA_NOINIT; /* Clear STA_NOINIT */
FCLK_FAST();
HAL_UART_Transmit(&huart1, ''USER INITIALIZE SUCCEDED! 

'', 100, 1000);
} else { /* Initialization failed */
power_off();
}
HAL_UART_Transmit(&huart1, ''USER INITIALIZE FINISHED! 
 
'', 100, 1000);

Thanks
antonius
Senior
Posted on January 29, 2016 at 23:25

Can you tell me how it connects to :

if(FATFS_LinkDriver(&SD_Driver, SDPath) == 0)

There are too many abstraction and jumping around between many disk_initialize function....

Could you please tell me the relation ?

I created one with atmega128 and it's straight forward....,

There are only 3 files on atmega128, sdmmc.c, diskio.h and ff.c....

and all the low level are in sdmmc.c

thanks

antonius
Senior
Posted on January 29, 2016 at 23:40

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6W8&d=%2Fa%2F0X0000000bpj%2FMXzAaFTnWR0WMHewmzNEaafExo2CO2Sh3UpkgaSn.ts&asPdf=false
antonius
Senior
Posted on January 29, 2016 at 23:47

USER_initialize (0);

          if (USER_initialize (0)==RES_OK)

            {

                HAL_UART_Transmit(&huart1, ''DISK INITIALIZE SUCCEEDED! main.c\r\n'', 100, 1000);

            }   

0690X00000602bDQAQ.jpg
antonius
Senior
Posted on January 31, 2016 at 10:20

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6WD&d=%2Fa%2F0X0000000bpl%2F3bqHhyJbV76tswov5mamQ1BNbedr6A4JPKIuNkxY7Y8&asPdf=false
antonius
Senior
Posted on February 01, 2016 at 10:29

Can I bypass user_diskio.c and fatfs.c and put my init code in diskio.c ?

I don't what are those functions inside those files for, making the job more complicated...

Thanks

antonius
Senior
Posted on February 02, 2016 at 14:25

Please find the complete project attached, it's compiled with keil, thanks

________________

Attachments :

STM32F107_SDCard_SPI2.7z : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Htgx&d=%2Fa%2F0X0000000aVo%2FdybQJF19seF4i0gRH4BYe2scz7hae.2B7j8hNB7Oac8&asPdf=false