/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / SD Card with STM32 Primer1

Username:     
Password:     
             

Forum

# 1   2010-05-31 12:06:22 SD Card with STM32 Primer1

vineetrvce
New member
Registered: 2009-12-08
Posts: 4

SD Card with STM32 Primer1

Hello All,
  I am trying to run the FatFS file system using the RIDE IDE with STM32 Primer1 board.
I have used the external header to connect the following:

SPI_CS : PA4
SPI_MOSI: PA7
SPI_MISO: PA6
SPI_CLK : PA5

I have made the following changes.

1. I added:

#elif defined(USE_STM32_PRIMER)

#define CARD_SUPPLY_SWITCHABLE   0
#define SOCKET_WP_CP_CONNECTED   0
#define SPI_SD                   SPI1
#define GPIO_CS                  GPIOA
#define RCC_APB2Periph_GPIO_CS   RCC_APB2Periph_GPIOA
#define GPIO_Pin_CS              GPIO_Pin_4
#define DMA_Channel_SPI_SD_RX    DMA1_Channel2
#define DMA_Channel_SPI_SD_TX    DMA1_Channel3
#define DMA_FLAG_SPI_SD_TC_RX    DMA1_FLAG_TC2
#define DMA_FLAG_SPI_SD_TC_TX    DMA1_FLAG_TC3
#define GPIO_SPI_SD              GPIOA
#define GPIO_Pin_SPI_SD_SCK      GPIO_Pin_5
#define GPIO_Pin_SPI_SD_MISO     GPIO_Pin_6
#define GPIO_Pin_SPI_SD_MOSI     GPIO_Pin_7
#define RCC_APBPeriphClockCmd_SPI_SD  RCC_APB2PeriphClockCmd
#define RCC_APBPeriph_SPI_SD     RCC_APB2Periph_SPI1
/* - for SPI1 and full-speed APB2: 72MHz/4 */
#define SPI_BaudRatePrescaler_SPI_SD  SPI_BaudRatePrescaler_4

------------------------------------------------------------------------------------------

Under main: I do this:

System_Init();

power_on();          // using the same function as provided by the port of FatFS

while(1)
    {
GPIO_ResetBits(GPIOA, GPIO_Pin_4) ;   /* MMC CS = L */
     delay(ret_val);
    ret_val = stm32_spi_rw(0xff);
    stm32_spi_rw(0x40);
    stm32_spi_rw(0x0);
    stm32_spi_rw(0x0);
    stm32_spi_rw(0x0);
    stm32_spi_rw(0x0);
    ret_val = stm32_spi_rw(0x95);
    ret_val = stm32_spi_rw(0xff);
    ret_val = stm32_spi_rw(0xff);
    ret_val = stm32_spi_rw(0xff);
    ret_val = stm32_spi_rw(0xff);
    ret_val = stm32_spi_rw(0xff);
    GPIO_SetBits(GPIOA, GPIO_Pin_4);    /* MMC CS = L */
        delay(ret_val);
    }


static void System_Init( void )
{
    /* Start with the clocks in their expected state. */
    RCC_DeInit();

    /* Enable HSE (high speed external clock). */
    RCC_HSEConfig( RCC_HSE_ON );

    /* Wait till HSE is ready. */
    while( RCC_GetFlagStatus( RCC_FLAG_HSERDY ) == RESET )
    {
    }

    /* 2 wait states required on the flash. */
    *( ( unsigned portLONG * ) 0x40022000 ) = 0x02;

    /* HCLK = SYSCLK */
    RCC_HCLKConfig( RCC_SYSCLK_Div1 );

    /* PCLK2 = HCLK */
    RCC_PCLK2Config( RCC_HCLK_Div1 );

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config( RCC_HCLK_Div2 );

    /* PLLCLK = 12MHz * 6 = 72 MHz. */
    RCC_PLLConfig( RCC_PLLSource_HSE_Div1, RCC_PLLMul_6 );

    /* Enable PLL. */
    RCC_PLLCmd( ENABLE );

    /* Wait till PLL is ready. */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }

    /* Select PLL as system clock source. */
    RCC_SYSCLKConfig( RCC_SYSCLKSource_PLLCLK );

    /* Wait till PLL is used as system clock source. */
    while( RCC_GetSYSCLKSource() != 0x08 )
    {
    }

    /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
    RCC_APB2PeriphClockCmd(    RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC    | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE );

    /* SPI2 Periph clock enable */
    //RCC_APB1PeriphClockCmd( RCC_APB1Periph_SPI2, ENABLE );


    /* Set the Vector Table base address at 0x08000000 */
    NVIC_SetVectorTable( NVIC_VectTab_FLASH, (uint32_t)&_isr_vectorsflash_offs /*was 0x0 before*/ );

    NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );
   
    /* Configure HCLK clock as SysTick clock source. */
    SysTick_CLKSourceConfig( SysTick_CLKSource_HCLK );
   
    STM32_Primer_LED_Init();
}

When I check the value of ret_val, it is 0x39. It should be 0x01, i.e. IDLE State.
Can anyone tell what could be the issue.

Regards,
Vineet.

Offline

 

# 2   2010-05-31 12:07:47 SD Card with STM32 Primer1

vineetrvce
New member
Registered: 2009-12-08
Posts: 4

Re: SD Card with STM32 Primer1

Also I am using MircoSD Card of 1 GB from Kingston.

Offline

 

Board footer