STM32CubeMX, FatFS and SDIO?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-02-20 1:57 PM
Everyone,
How can I use cubeMX for SDcard ? I have generated for MDK but :
this function doesn't work , from UM1721
User manualDeveloping Applications on STM32Cube with FatFs page 21.:
uint32_t wbytes; /* File write counts */
uint8_t wtext[] = 'text to write logical disk'; /* File write buffer */if(FATFS_LinkDriver(&mynewdisk_Driver, mynewdiskPath) == 0){if(f_mount(&mynewdiskFatFs, (TCHAR const*)mynewdiskPath, 0) == FR_OK){if(f_open(&MyFile, 'STM32.TXT', FA_CREATE_ALWAYS | FA_WRITE) == FR_OK){if(f_write(&MyFile, wtext, sizeof(wtext), (void *)&wbytes) == FR_OK);{f_close(&MyFile);}}}}FATFS_UnLinkDriver(mynewdiskPath);This variable :
&mynewdisk_Driver doesn't exist, which file is related ?
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 7:32 PM
You should be able to enable pull-ups on the pins internally.
The FatFs code will not work if the underlying SDIO code isn't functional.
What pin is being used on the socket's card detect?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 7:33 PM
Lower the SDIO init speed, there's one file for doing that. I have
posted in here I reckon.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 7:34 PM
That's right, connect SD Detect as well, it's inside the code PB14 if
I'm not wrong..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 8:06 PM
Yeah, in STM32CubeMX under 'Configuration' -> 'GPIO' a 'Pin Configuration' window comes up. Under the 'SDIO' tab it shows the SDIO pins, which are defaulted as 'Alternate Function Push Pull' for 'GPIO mode', but under 'GPIO Pull-up/Pull-down' it's defaulted as 'No pull-up and no pull down' - I can change this to 'Pull-up' for just the 4 data lines and the CMD line only (so no open-drain external pull-up resistors needed - just internal). By default STM32Cube SDIO settings don't include the SD detect pin; I'll have to do that manually. I'll change the clock speed setting to what you put manually in code; but I'll have to see what this changes in the clock tree as well.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 9:52 PM
Yes it depends on the main clock from HSE or HSI or internal and divider,
I'm not in windows now so I can not run STM32CubeMX but I'll have a look
on my code, there're some hints on it..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 10:05 PM
Have a dig on the code at stm32f1xx_II_sdmmc.h ==> STM32F103, for
STM32F4xx, I reckon you need to change the name.
/* SDIO Intialization Frequency (400KHz max) */ ==> check your main
clock and divider on STM32CubeMX
&sharpdefine SDIO_INIT_CLK_DIV ((uint8_t)0xC3)
/* SDIO Data Transfer Frequency */
/* SDIO_CK = SDIOCLK / (SDIO_TRANSFER_CLK_DIV + 2) */
&sharpdefine SDIO_TRANSFER_CLK_DIV ((uint8_t)0x0F) // ==72/(15+2) = 4.23MHz
, work best for my MP3 chip syncronization speed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 10:22 PM
Some debug to UART for seeing the response
/=====/
/**
@brief Initializes the SD card device.
@retval SD status
*/
uint8_t BSP_SD_Init(void)
{
uint8_t sd_state = MSD_OK;
printf('BSP_SD_Init Function!\n');
/* Check if the SD card is plugged in the slot */
if (BSP_SD_IsDetected() != SD_PRESENT)
{
return MSD_ERROR;
}
/* HAL SD initialization */
sd_state = HAL_SD_Init(&hsd, &SDCardInfo);
&sharpifdef BUS_4BITS
/* Configure SD Bus width */
if (sd_state == MSD_OK)
{
/* Enable wide operation */
if (HAL_SD_WideBusOperation_Config(&hsd, SDIO_BUS_WIDE_4B) != SD_OK)
{
sd_state = MSD_ERROR;
printf('MSD_ERROR\n');
}
else
{
sd_state = MSD_OK;
printf('MSD_OK \n');
}
}
&sharpendif
return sd_state;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-26 10:23 PM
&sharpdefine __SD_DETECT_GPIO_CLK_ENABLE() __HAL_RCC_GPIOB_CLK_ENABLE()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-27 1:19 PM
I have
__HAL_RCC_GPIOB_CLK_ENABLE() defined and enabling the clock on that port. Are you redefining this function
__SD_DETECT_GPIO_CLK_ENABLE() ? I don't have __SD_DETECT_GPIO_CLK_ENABLE() in my code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-04-27 1:29 PM
This is the list of alternate functions for PB14 in CubeMX. Which one would be the Card Detect for SDIO mode? How would you write this in the code?
