在最新的 cube hal 库里面没有发现dma的地址赋值 ??
/* Includes ------------------------------------------------------------------*/
#include "sdio.h"
#include "gpio.h"
sta
tic 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 这个两个函数里面都有设置,但实际使用就是不行,不知道是什么情况 ??
怎么不行?
一周热门 更多>