Mercurial > ~darius > hgwebdir.cgi > stm32temp
diff hw.c @ 49:ace431a0d0f5
Add SDIO code poached from STM. Use FatFS to read from SD card.
LFN doesn't work reliably so it's disabled for now.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Wed, 03 Apr 2013 23:34:20 +1030 |
parents | 2db4bb90cfca |
children | bb52e6dad784 |
line wrap: on
line diff
--- a/hw.c Wed Apr 03 23:33:47 2013 +1030 +++ b/hw.c Wed Apr 03 23:34:20 2013 +1030 @@ -297,4 +297,33 @@ *SCB_DEMCR = *SCB_DEMCR | 0x01000000; *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter + + /* Setup SDIO + * See SD_LowLevelInit from libs/STM32F10x_StdPeriph_Lib_V3.5.0/Utilities/STM32_EVAL/STM3210E_EVAL/stm3210e_eval.c + */ + + /* GPIOC and GPIOD Periph clock enable */ + RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD, ENABLE); + + /* Configure SDIO pins for AF + PC8 -> SD0 + PC9 -> SD1 + PC10 -> SD2 + PC11 -> SD3 + PC12 -> SCK + */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12; + GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; + GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; + GPIO_Init(GPIOC, &GPIO_InitStructure); + + /* Configure PD2 -> CMD SDIO pin for AF */ + GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; + GPIO_Init(GPIOD, &GPIO_InitStructure); + + /* Enable the SDIO AHB Clock */ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_SDIO, ENABLE); + + /* Enable the DMA2 Clock */ + RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE); }