打印
[STM32F2]

STM32F207+SDIO+DMA 调试不通,请教

[复制链接]
1625|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
luojm|  楼主 | 2017-2-24 21:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
STM32F207+SDIO+DMA 做项目

调用 f_opendir 时一直在此处循环
uint32_t SD_DMAEndOfTransferStatus(void)
{
    return (uint32_t)DMA_GetFlagStatus(DMA2_Stream6, DMA_FLAG_TCIF6);  
}

配置如下:
void NVIC_ConfigurationSDIO(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Configure the NVIC Preemption Priority Bits */
  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = SDIO_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

static void SDIO_GPIO_Configuration(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;

  /*!< GPIOC and GPIOD Periph clock enable */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOD , ENABLE);

        GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_SDIO);
        GPIO_PinAFConfig(GPIOC, GPIO_PinSource9, GPIO_AF_SDIO);
        GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SDIO);
        GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_SDIO);
        GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SDIO);
        GPIO_PinAFConfig(GPIOD, GPIO_PinSource2, GPIO_AF_SDIO);
       
  /* Configure PC.08, PC.09, PC.10, PC.11 pins: D0, D1, D2, D3 pins */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  //GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);
       
  /*!< Configure PD.02 CMD line */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
       
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOC, &GPIO_InitStructure);       
       
        /*!< Enable the SDIO AHB Clock */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SDIO, ENABLE);

  /*!< Enable the DMA2 Clock */
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2, ENABLE);
}

void SD_DMA_RxConfig(uint32_t *BufferDST, uint32_t BufferSize)
{
    DMA_InitTypeDef DMA_InitStructure;

    DMA_ClearFlag(DMA2_Stream6, DMA_FLAG_FEIF6 | DMA_FLAG_TCIF6 | DMA_FLAG_TEIF6 | DMA_FLAG_HTIF6 | DMA_FLAG_DMEIF6);//清除DMA标志位
    DMA_Cmd(DMA2_Stream6, DISABLE);       
    //DMA_DeInit(DMA2_Stream6);
       
    DMA_InitStructure.DMA_Channel = DMA_Channel_4;//通道4  
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferDST; //内存地址 *********
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;//外设到内存     *********
    DMA_InitStructure.DMA_BufferSize = BufferSize / 4; //缓冲大小
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址不增
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//内存地址增
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//no循环模式
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;//优先级高
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;// 开fifo
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
                               
    DMA_Init(DMA2_Stream6, &DMA_InitStructure);
          //DMA_FlowControllerConfig(DMA2_Stream6, DMA_FlowCtrl_Peripheral);
    DMA_Cmd(DMA2_Stream6, ENABLE);
}

void SD_DMA_TxConfig(uint32_t *BufferSRC, uint32_t BufferSize)
{
    DMA_InitTypeDef DMA_InitStructure;

    DMA_ClearFlag(DMA2_Stream6, DMA_FLAG_FEIF6 | DMA_FLAG_TCIF6 | DMA_FLAG_TEIF6 | DMA_FLAG_HTIF6 | DMA_FLAG_DMEIF6);//清除DMA标志位
          DMA_Cmd(DMA2_Stream6, DISABLE);       
    //DMA_DeInit(DMA2_Stream6);
       
    DMA_InitStructure.DMA_Channel = DMA_Channel_4;//通道4  
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)SDIO_FIFO_ADDRESS;
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)BufferSRC; //内存地址 *********
    DMA_InitStructure.DMA_DIR = DMA_DIR_MemoryToPeripheral;//    *********
    DMA_InitStructure.DMA_BufferSize = BufferSize / 4; //缓冲大小
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;//外设地址不增
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;//内存地址增
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
    DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;//no循环模式
    DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;//优先级高
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Enable;// 开fifo
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_Full; //
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_INC4;
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_INC4;
                               
    DMA_Init(DMA2_Stream6, &DMA_InitStructure);
          //DMA_FlowControllerConfig(DMA2_Stream6, DMA_FlowCtrl_Peripheral);
    DMA_Cmd(DMA2_Stream6, ENABLE);
}
#define SDIO_TRANSFER_CLK_DIV            ((uint8_t)0x00)
#define SDIO_INIT_CLK_DIV                ((uint8_t)0x76)

SDIO的CLK脚用示波器打过有24M的信号。
百度过,发现很多出现这种,但按提供的方法,还是解决不了。
想请教问问题下哪里??


沙发
luojm|  楼主 | 2017-2-27 09:21 | 只看该作者
#define SDIO_FIFO_ADDRESS                ((uint32_t)0x40012C80)

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

12

帖子

0

粉丝