完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在最新的 cube hal 库里面没有发现dma的地址赋值 ??
/* Includes ------------------------------------------------------------------*/ #include "sdio.h" #include "gpio.h" static SD_HandleTypeDef hsd; static HAL_SD_CardInfoTypedef SDCardInfo; uint8_t HAL_SD_DetectedInit(void) { GPIO_InitTypeDef GPIO_InitStruct; GPIO_InitStruct.Pin = GPIO_PIN_11; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; // GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); return 0; } void MX_SDIO_SD_Init(void) { hsd.Instance = SDIO; hsd.Init.ClockEdge = SDIO_CLOCK_EDGE_RISING; hsd.Init.ClockBypass = SDIO_CLOCK_BYPASS_DISABLE; hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE; hsd.Init.BusWide = SDIO_BUS_WIDE_1B; hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE; hsd.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV; } void HAL_SD_MspInit(SD_HandleTypeDef* hsd) { static DMA_HandleTypeDef dmaRxHandle; static DMA_HandleTypeDef dmaTxHandle; GPIO_InitTypeDef GPIO_InitStruct; if(hsd->Instance==SDIO) { __SDIO_CLK_ENABLE(); __DMAx_TxRx_CLK_ENABLE(); __GPIOC_CLK_ENABLE(); __GPIOD_CLK_ENABLE(); /**SDIO GPIO Configuration PC8 ------> SDIO_D0 PC9 ------> SDIO_D1 PC10 ------> SDIO_D2 PC11 ------> SDIO_D3 PC12 ------> SDIO_CK PD2 ------> SDIO_CMD */ GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF12_SDIO; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_2; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); /* Peripheral interrupt init*/ HAL_NVIC_SetPriority(SDIO_IRQn, 5, 0); HAL_NVIC_EnableIRQ(SDIO_IRQn); /* Configure DMA Rx parameters */ dmaRxHandle.Init.Channel = SD_DMAx_Rx_CHANNEL; dmaRxHandle.Init.Direction = DMA_PERIPH_TO_MEMORY; dmaRxHandle.Init.PeriphInc = DMA_PINC_DISABLE; dmaRxHandle.Init.MemInc = DMA_MINC_ENABLE; dmaRxHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dmaRxHandle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; // DMA_MDATAALIGN_WORD dmaRxHandle.Init.Mode = DMA_PFCTRL; //DMA_NORMAL; dmaRxHandle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dmaRxHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dmaRxHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dmaRxHandle.Init.MemBurst = DMA_MBURST_INC4; dmaRxHandle.Init.PeriphBurst = DMA_PBURST_INC4; dmaRxHandle.Instance = SD_DMAx_Rx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmarx, dmaRxHandle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dmaRxHandle); /* Configure the DMA stream */ HAL_DMA_Init(&dmaRxHandle); /* Configure DMA Tx parameters */ dmaTxHandle.Init.Channel = SD_DMAx_Tx_CHANNEL; dmaTxHandle.Init.Direction = DMA_MEMORY_TO_PERIPH; dmaTxHandle.Init.PeriphInc = DMA_PINC_DISABLE; dmaTxHandle.Init.MemInc = DMA_MINC_ENABLE; dmaTxHandle.Init.PeriphDataAlignment = DMA_PDATAALIGN_WORD; dmaTxHandle.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; dmaTxHandle.Init.Mode = DMA_PFCTRL; //DMA_NORMAL; dmaTxHandle.Init.Priority = DMA_PRIORITY_VERY_HIGH; dmaTxHandle.Init.FIFOMode = DMA_FIFOMODE_ENABLE; dmaTxHandle.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; dmaTxHandle.Init.MemBurst = DMA_MBURST_INC4; dmaTxHandle.Init.PeriphBurst = DMA_PBURST_INC4; dmaTxHandle.Instance = SD_DMAx_Tx_STREAM; /* Associate the DMA handle */ __HAL_LINKDMA(hsd, hdmatx, dmaTxHandle); /* Deinitialize the stream for new transfer */ HAL_DMA_DeInit(&dmaTxHandle); /* Configure the DMA stream */ HAL_DMA_Init(&dmaTxHandle); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD_DMAx_Rx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD_DMAx_Rx_IRQn); /* NVIC configuration for DMA transfer complete interrupt */ HAL_NVIC_SetPriority(SD_DMAx_Tx_IRQn, 6, 0); HAL_NVIC_EnableIRQ(SD_DMAx_Tx_IRQn); } } void HAL_SD_MspDeInit(SD_HandleTypeDef* hsd) { if(hsd->Instance==SDIO) { /* USER CODE BEGIN SDIO_MspDeInit 0 */ /* USER CODE END SDIO_MspDeInit 0 */ /* Peripheral clock disable */ __SDIO_CLK_DISABLE(); /**SDIO GPIO Configuration PC8 ------> SDIO_D0 PC9 ------> SDIO_D1 PC10 ------> SDIO_D2 PC11 ------> SDIO_D3 PC12 ------> SDIO_CK PD2 ------> SDIO_CMD */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11 |GPIO_PIN_12); HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); /* Peripheral interrupt Deinit*/ HAL_NVIC_DisableIRQ(SDIO_IRQn); } } /** * @brief This function handles SDIO global interrupt. */ void SDIO_IRQHandler(void) { HAL_SD_IRQHandler(&hsd); } /** * @brief This function handles DMA2 Stream 3 interrupt request. * @param None * @retval None */ void SD_DMAx_Rx_IRQHandler(void) { HAL_DMA_IRQHandler(hsd.hdmarx); } /** * @brief This function handles DMA2 Stream 6 interrupt request. * @param None * @retval None */ void SD_DMAx_Tx_IRQHandler(void) { HAL_DMA_IRQHandler(hsd.hdmatx); } #define USER_SD_DMA 1u // >0u,使用sd的dma功能,否则=0u不使用 DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) { DRESULT res = RES_OK; #if USER_SD_DMA == 0u if(BSP_SD_ReadBlocks((uint32_t*)buff, (uint64_t) (sector * BLOCK_SIZE), BLOCK_SIZE, count) != MSD_OK) { res = RES_ERROR; } #else if(BSP_SD_ReadBlocks_DMA((uint32_t*)buff, (uint64_t) (sector * BLOCK_SIZE), BLOCK_SIZE, count) != MSD_OK) { res = RES_ERROR; } #endif return res; } DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) { DRESULT res = RES_OK; #if USER_SD_DMA == 0u if(BSP_SD_WriteBlocks((uint32_t*)buff, (uint64_t)(sector * BLOCK_SIZE), BLOCK_SIZE, count) != MSD_OK) { res = RES_ERROR; } #else if(BSP_SD_WriteBlocks_DMA((uint32_t*)buff, (uint64_t)(sector * BLOCK_SIZE), BLOCK_SIZE, count) != MSD_OK) { res = RES_ERROR; } #endif return res; } HAL_DMA_Start_IT 这个函数在 HAL_SD_ReadBlocks_DMA、 HAL_SD_WriteBlocks_DMA 这个两个函数里面都有设置,但实际使用就是不行,不知道是什么情况 ?? |
|
相关推荐
10个回答
|
|
这只是一个接口,是不能单独用的需要配合SDIO 使用
|
|
|
|
|
|
|
|
在开启DMA的时候设置
|
|
|
|
你好,你说的这个HAL_DMA_Start_IT 函数在 HAL_SD_ReadBlocks_DMA、 HAL_SD_WriteBlocks_DMA 函数里面都有调用设置的,但实际使用就是不行,不知道是什么情况 ?? |
|
|
|
7vyydyfwef 发表于 2018-11-20 10:15 怎么不行? |
|
|
|
是我的sd的dma配置有问题,有个mode 配置我配置成了正常模式,结果不行,最后改成 控制模式,完全ok了 |
|
|
|
我用的轮询的模式,读和写的时候都是不返回OK的,不晓得是什么情况!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
2255 浏览 1 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
2071 浏览 3 评论
4687 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
2215 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
2757 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-27 06:31 , Processed in 0.726389 second(s), Total 62, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号