2012-08-06 08:44 AM
Hi,
I am using SD card in SPI mode with STM32F107VC,i am using External Hi speed clock(25MHz) and i am dividing with SPI_BaudRatePrescaler_64 to initialize the SD card,here i am using SPI2 and SPI3 with both the SPIs i have problem,when i am testing i am getting problem like data which i am writing into data register is not getting updated, when i send CMD0 response will continuously 0xFF i am getting from SD card,when i observed on hardware bus using logic analyzer clock is appearing properly and data which i am sending is not showing properly and clock also some times not getting properly,if any suggestions regarding the same will be highly appreciated and if any one have SD card in SPI mode(STM32F107VC) code for reference it will be very help full... Thanks in advance... Regards, Mujeeb Shaik. #sd-card #sd-card #sd-card #metoo #sd-card #sd-card2012-08-06 09:14 AM
Suggest you review code in STM32L152 firmwares, demonstration of SPI SD that might be applicable to your CPU/board.
STM32L152-EVAL_FW_V1.2.0\Utilities\STM32_EVAL\STM32L152_EVAL\stm32l152_eval_spi_sd.c Several of the other firmware libraries have similar examples. Including the USB library which has an example for the STM3210C-EVAL, a board with an STM32F107VCT chip. Anyway lots of example code to review, go dig. See also[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/Driver to use MicroSD card with SPI&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx¤tviews=990]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fSTM32Discovery%2fDriver%20to%20use%20MicroSD%20card%20with%20SPI&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https%3A%2F%2Fmy.st.com%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FAllItems.aspx¤tviews=9902012-08-07 02:54 AM
Hi clive1,
Thanks fro your reply... i got some reference code i am looking into that in that the clock is 2MHz i am getting,but to initialize the SD card ,clock should be 400khz, in STM32F107VC i am using HSI (high speed internal clock) 8Mhz, i am dividing that with SPI_BaudRatePrescaler_16(8Mhz/16=500KHz) i am getting 500Khz, i want 400Khz how to make that one can u please help me regarding this..... Thanks in advance... Regards, Mujeeb2012-08-07 08:11 AM
Less than 400 KHz would work.
If you want to hit specific numbers you'll need to pick your oscillator and PLL settings to get them. The STM32 only has simple integer dividers. A bus running at 24 MHz could get you 375 KHz2012-08-09 04:02 AM
Hi clive1,
Thanks for reply.....I got the solution everything working fine....2013-03-14 05:58 AM
Hi! mujeem,
I to experiencing the same issue with the SD card interface please suggest me the same idea what you did to your code.thanks,manjunatha2013-03-14 06:36 AM
I to experiencing the same issue with the SD card interface please suggest me the same idea what you did to your code.
Please explicitly state YOUR issue, and conditions, the cards need to be initialized at slower speeds, and then depending on the card switched to higher speeds. The speeds the STM32 can use are a function of the speed your chip is running at, and the integer dividers available. The SPI code examples for the 107 and STM3210C do not support SDHC cards, and there will be issues with >2GB cards.2013-03-14 07:36 AM
Hello! clive,
i am testing SD card(2GB) interface using stm320518-Eval board which contains the STM32F051R8T6 Microcontroller. the problem which i have came to know that is i am driving the SPI at higher clock and for SD card it has to be less than 400kHz. For this i tried to configure PLL as a clock source for 24MHz but clock is doesn't changing my functions calls to configure PLL clock are as follows: please let me know if any bugs, because i am new to this concept.//HSI=8MHzRCC_PLLConfig(RCC_PLLSource_HSI_Div2, 6);//6 is multiplier RCC_PLLCmd(ENABLE); RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); SystemCoreClockUpdate();please let me know if the above information supplied is insufficient.thanking you,Manjunatha.2013-03-14 10:10 AM
Ok, well I'm glad I pushed for more information because this seems to be a different problem.
The PLL and bus dividers are typically set up in the SystemInit() routine called before main() under the CMSIS model. The SPI rate is a function of the bus speed to which it is attached, and the prescaler programmed into the peripheral. SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2; See SD_LowLevel_Init() in STM32F0xx_StdPeriph_Lib_V1.0.0\Utilities\STM32_EVAL\STM320518_EVAL\stm320518_eval.c Are you using, or have you evaluated, the SD Card demo (SPI_MSD) for the STM320518-EVAL board? Does that work? What are the issues? STM32F0xx_StdPeriph_Lib_V1.0.0\Project\STM32F0xx_StdPeriph_Examples\SPI\SPI_MSD2013-03-15 07:02 AM
Hello! Clive,
Sorry for the late reply. yes I am usingSTM320518_EVA board, I get it from STMicroelectronics on rent basis. i found the SetSysClock() function which is as follows.
static void SetSysClock(void){ __IO uint32_t StartUpCounter = 0, HSEStatus = 0;/******************************************************************************//* PLL (clocked by HSE) used as System clock source *//******************************************************************************/ /* SYSCLK, HCLK, PCLK configuration ----------------------------------------*/ /* Enable HSE */ RCC->CR |= ((uint32_t)RCC_CR_HSEON); /* Wait till HSE is ready and if Time out is reached exit */ do { HSEStatus = RCC->CR & RCC_CR_HSERDY; StartUpCounter++; } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT)); if ((RCC->CR & RCC_CR_HSERDY) != RESET) { HSEStatus = (uint32_t)0x01; } else { HSEStatus = (uint32_t)0x00; } if (HSEStatus == (uint32_t)0x01) { /* Enable Prefetch Buffer and set Flash Latency */ FLASH->ACR = FLASH_ACR_PRFTBE | FLASH_ACR_LATENCY; /* HCLK = SYSCLK */ RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1; /* PCLK = HCLK */ RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE_DIV1; /* PLL configuration */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL)); RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL6); /* Enable PLL */ RCC->CR |= RCC_CR_PLLON; /* Wait till PLL is ready */ while((RCC->CR & RCC_CR_PLLRDY) == 0) { } /* Select PLL as system clock source */ RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW)); RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL; /* Wait till PLL is used as system clock source */ while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL) { } } else { /* If HSE fails to start-up, the application will have wrong clock configuration. User can add here some code to deal with this error */ } }
here the PLL uses HSE as a clock source. but in eval board ST people has removed the crystal. so i need to change the clock source from HSE to HSI in this function. please help me in this regard. due to some problem in my IAR IDE i couldn't run this code. So i am dealing with IAR support in order to clear that issue. before that i need to get ready with the code.
thanking you,Manjunatha S