[BSP][RT1050] improve sdio stability and speed. | 优化SDIO接口稳定性和速度.
1.格式化代码. 2.优化SDIO接口稳定性和速度: 将SDIO时钟树中分频数增大, 提高内部时钟的稳定性, 同时SDIO速度提高到30M. 并且通过USB拷贝12M MP3文件测试, 多次拷贝数据稳定.
This commit is contained in:
parent
236fd82e5d
commit
51f638ad63
|
@ -76,14 +76,15 @@ static int enable_log = 1;
|
|||
|
||||
ALIGN(USDHC_ADMA2_ADDR_ALIGN) uint32_t g_usdhcAdma2Table[USDHC_ADMA_TABLE_WORDS] SECTION("NonCacheable");
|
||||
|
||||
struct imxrt_mmcsd {
|
||||
struct rt_mmcsd_host *host;
|
||||
struct rt_mmcsd_req *req;
|
||||
struct rt_mmcsd_cmd *cmd;
|
||||
struct imxrt_mmcsd
|
||||
{
|
||||
struct rt_mmcsd_host *host;
|
||||
struct rt_mmcsd_req *req;
|
||||
struct rt_mmcsd_cmd *cmd;
|
||||
|
||||
struct rt_timer timer;
|
||||
struct rt_timer timer;
|
||||
|
||||
rt_uint32_t *buf;
|
||||
rt_uint32_t *buf;
|
||||
|
||||
//USDHC_Type *base;
|
||||
usdhc_host_t usdhc_host;
|
||||
|
@ -93,7 +94,7 @@ struct imxrt_mmcsd {
|
|||
uint32_t *usdhc_adma2_table;
|
||||
};
|
||||
|
||||
static void _mmcsd_gpio_init(struct imxrt_mmcsd * mmcsd)
|
||||
static void _mmcsd_gpio_init(struct imxrt_mmcsd *mmcsd)
|
||||
{
|
||||
gpio_pin_config_t sw_config;
|
||||
|
||||
|
@ -112,54 +113,54 @@ static void _mmcsd_gpio_init(struct imxrt_mmcsd * mmcsd)
|
|||
/* voltage select PIN */
|
||||
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_14_USDHC1_VSELECT, 0);
|
||||
|
||||
/* card detect PIN */
|
||||
/* card detect PIN */
|
||||
IOMUXC_SetPinMux(IOMUXC_GPIO_B1_12_GPIO2_IO28, 0);
|
||||
/* power reset pin */
|
||||
IOMUXC_SetPinMux(IOMUXC_GPIO_AD_B0_05_GPIO1_IO05, 0);
|
||||
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_00_USDHC1_CMD, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK | IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) | IOMUXC_SW_PAD_CTL_PAD_PUS(1) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK | IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) | IOMUXC_SW_PAD_CTL_PAD_PUS(1) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_01_USDHC1_CLK, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(1) | IOMUXC_SW_PAD_CTL_PAD_PUS(1) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(1) | IOMUXC_SW_PAD_CTL_PAD_PUS(1) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_02_USDHC1_DATA0, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_03_USDHC1_DATA1, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_04_USDHC1_DATA2, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_SD_B0_05_USDHC1_DATA3, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
|
||||
/*voltage select pin*/
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_14_USDHC1_VSELECT, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(4));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(4));
|
||||
|
||||
IOMUXC_SetPinConfig(IOMUXC_GPIO_B1_12_GPIO2_IO28, IOMUXC_SW_PAD_CTL_PAD_SRE_MASK | IOMUXC_SW_PAD_CTL_PAD_PKE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUE_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_HYS_MASK |
|
||||
IOMUXC_SW_PAD_CTL_PAD_SPEED(2) |
|
||||
IOMUXC_SW_PAD_CTL_PAD_PUS(1) | IOMUXC_SW_PAD_CTL_PAD_DSE(1));
|
||||
|
||||
sw_config.direction = kGPIO_DigitalOutput;
|
||||
sw_config.outputLogic = 0;
|
||||
|
@ -172,10 +173,10 @@ static void _mmcsd_gpio_init(struct imxrt_mmcsd * mmcsd)
|
|||
#endif
|
||||
|
||||
#ifdef RT_USING_SDIO2
|
||||
if (mmcsd->usdhc_host.base == USDHC2)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
if (mmcsd->usdhc_host.base == USDHC2)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
@ -199,7 +200,7 @@ static void SDMMCHOST_ErrorRecovery(USDHC_Type *base)
|
|||
}
|
||||
}
|
||||
|
||||
static void _mmcsd_host_init(struct imxrt_mmcsd * mmcsd)
|
||||
static void _mmcsd_host_init(struct imxrt_mmcsd *mmcsd)
|
||||
{
|
||||
usdhc_host_t *usdhc_host = &mmcsd->usdhc_host;
|
||||
|
||||
|
@ -214,28 +215,28 @@ static void _mmcsd_host_init(struct imxrt_mmcsd * mmcsd)
|
|||
USDHC_Init(usdhc_host->base, &(usdhc_host->config));
|
||||
}
|
||||
|
||||
static void _mmcsd_clk_init(struct imxrt_mmcsd * mmcsd)
|
||||
static void _mmcsd_clk_init(struct imxrt_mmcsd *mmcsd)
|
||||
{
|
||||
CLOCK_EnableClock(mmcsd->ip_clock);
|
||||
CLOCK_SetDiv(mmcsd->usdhc_div, 0U);
|
||||
CLOCK_SetDiv(mmcsd->usdhc_div, 5U);
|
||||
}
|
||||
|
||||
static void _mmcsd_isr_init(struct imxrt_mmcsd * mmcsd)
|
||||
static void _mmcsd_isr_init(struct imxrt_mmcsd *mmcsd)
|
||||
{
|
||||
//NVIC_SetPriority(USDHC1_IRQn, 5U);
|
||||
}
|
||||
|
||||
static void _mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
|
||||
{
|
||||
struct imxrt_mmcsd * mmcsd;
|
||||
struct rt_mmcsd_cmd * cmd;
|
||||
struct rt_mmcsd_data * data;
|
||||
struct imxrt_mmcsd *mmcsd;
|
||||
struct rt_mmcsd_cmd *cmd;
|
||||
struct rt_mmcsd_data *data;
|
||||
status_t error;
|
||||
usdhc_adma_config_t dmaConfig;
|
||||
usdhc_transfer_t fsl_content = {0};
|
||||
usdhc_command_t fsl_command = {0};
|
||||
usdhc_data_t fsl_data = {0};
|
||||
rt_uint32_t * buf = NULL;
|
||||
rt_uint32_t *buf = NULL;
|
||||
|
||||
RT_ASSERT(host != RT_NULL);
|
||||
RT_ASSERT(req != RT_NULL);
|
||||
|
@ -294,11 +295,11 @@ static void _mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
|
|||
case RESP_R5:
|
||||
fsl_command.responseType = kCARD_ResponseTypeR5;
|
||||
break;
|
||||
/*
|
||||
case RESP_R5B:
|
||||
fsl_command.responseType = kCARD_ResponseTypeR5b;
|
||||
break;
|
||||
*/
|
||||
/*
|
||||
case RESP_R5B:
|
||||
fsl_command.responseType = kCARD_ResponseTypeR5b;
|
||||
break;
|
||||
*/
|
||||
default:
|
||||
RT_ASSERT(NULL);
|
||||
}
|
||||
|
@ -341,7 +342,7 @@ static void _mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
|
|||
MMCSD_DGB(" blksize:%d, blks:%d ", fsl_data.blockSize, fsl_data.blockCount);
|
||||
|
||||
if (((rt_uint32_t)data->buf & (CACHE_LINESIZE - 1)) || // align cache(32byte)
|
||||
((rt_uint32_t)data->buf > 0x00000000 && (rt_uint32_t)data->buf < 0x00080000) /*|| // ITCM
|
||||
((rt_uint32_t)data->buf > 0x00000000 && (rt_uint32_t)data->buf < 0x00080000) /*|| // ITCM
|
||||
((rt_uint32_t)data->buf >= 0x20000000 && (rt_uint32_t)data->buf < 0x20080000)*/) // DTCM
|
||||
{
|
||||
|
||||
|
@ -414,7 +415,7 @@ static void _mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
|
|||
cmd->resp[1] = fsl_command.response[2];
|
||||
cmd->resp[0] = fsl_command.response[3];
|
||||
MMCSD_DGB(" resp 0x%08X 0x%08X 0x%08X 0x%08X\n",
|
||||
cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
|
||||
cmd->resp[0], cmd->resp[1], cmd->resp[2], cmd->resp[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -430,7 +431,7 @@ static void _mmc_request(struct rt_mmcsd_host *host, struct rt_mmcsd_req *req)
|
|||
static void _mmc_set_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *io_cfg)
|
||||
{
|
||||
|
||||
struct imxrt_mmcsd * mmcsd;
|
||||
struct imxrt_mmcsd *mmcsd;
|
||||
unsigned int usdhc_clk;
|
||||
unsigned int bus_width;
|
||||
uint32_t src_clk;
|
||||
|
@ -441,9 +442,9 @@ static void _mmc_set_iocfg(struct rt_mmcsd_host *host, struct rt_mmcsd_io_cfg *i
|
|||
|
||||
mmcsd = (struct imxrt_mmcsd *)host->private_data;
|
||||
usdhc_clk = io_cfg->clock;
|
||||
bus_width = io_cfg->bus_width;
|
||||
bus_width = io_cfg->bus_width;
|
||||
|
||||
if(usdhc_clk > IMXRT_MAX_FREQ)
|
||||
if (usdhc_clk > IMXRT_MAX_FREQ)
|
||||
usdhc_clk = IMXRT_MAX_FREQ;
|
||||
src_clk = (CLOCK_GetSysPfdFreq(kCLOCK_Pfd2) / (CLOCK_GetDiv(mmcsd->usdhc_div) + 1U));
|
||||
|
||||
|
@ -492,64 +493,65 @@ FINSH_FUNCTION_EXPORT(log_toggle, toglle log dumple);
|
|||
//
|
||||
//}
|
||||
|
||||
static const struct rt_mmcsd_host_ops ops = {
|
||||
_mmc_request,
|
||||
_mmc_set_iocfg,
|
||||
static const struct rt_mmcsd_host_ops ops =
|
||||
{
|
||||
_mmc_request,
|
||||
_mmc_set_iocfg,
|
||||
RT_NULL,//_mmc_get_card_status,
|
||||
RT_NULL,//_mmc_enable_sdio_irq,
|
||||
RT_NULL,//_mmc_enable_sdio_irq,
|
||||
};
|
||||
|
||||
rt_int32_t _imxrt_mci_init(void)
|
||||
{
|
||||
struct rt_mmcsd_host *host;
|
||||
struct imxrt_mmcsd *mmcsd;
|
||||
struct rt_mmcsd_host *host;
|
||||
struct imxrt_mmcsd *mmcsd;
|
||||
|
||||
host = mmcsd_alloc_host();
|
||||
if (!host)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
host = mmcsd_alloc_host();
|
||||
if (!host)
|
||||
{
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
mmcsd = rt_malloc(sizeof(struct imxrt_mmcsd));
|
||||
if (!mmcsd)
|
||||
{
|
||||
rt_kprintf("alloc mci failed\n");
|
||||
goto err;
|
||||
}
|
||||
mmcsd = rt_malloc(sizeof(struct imxrt_mmcsd));
|
||||
if (!mmcsd)
|
||||
{
|
||||
rt_kprintf("alloc mci failed\n");
|
||||
goto err;
|
||||
}
|
||||
|
||||
rt_memset(mmcsd, 0, sizeof(struct imxrt_mmcsd));
|
||||
rt_memset(mmcsd, 0, sizeof(struct imxrt_mmcsd));
|
||||
mmcsd->usdhc_host.base = USDHC1;
|
||||
mmcsd->usdhc_div = kCLOCK_Usdhc1Div;
|
||||
mmcsd->usdhc_adma2_table = g_usdhcAdma2Table;
|
||||
|
||||
host->ops = &ops;
|
||||
host->freq_min = 375000;
|
||||
host->freq_max = 25000000;
|
||||
host->valid_ocr = VDD_32_33 | VDD_33_34;
|
||||
host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | \
|
||||
MMCSD_SUP_HIGHSPEED | MMCSD_SUP_SDIO_IRQ;
|
||||
host->max_seg_size = 65535;
|
||||
host->max_dma_segs = 2;
|
||||
host->max_blk_size = 512;
|
||||
host->max_blk_count = 4096;
|
||||
host->ops = &ops;
|
||||
host->freq_min = 375000;
|
||||
host->freq_max = 25000000;
|
||||
host->valid_ocr = VDD_32_33 | VDD_33_34;
|
||||
host->flags = MMCSD_BUSWIDTH_4 | MMCSD_MUTBLKWRITE | \
|
||||
MMCSD_SUP_HIGHSPEED | MMCSD_SUP_SDIO_IRQ;
|
||||
host->max_seg_size = 65535;
|
||||
host->max_dma_segs = 2;
|
||||
host->max_blk_size = 512;
|
||||
host->max_blk_count = 4096;
|
||||
|
||||
mmcsd->host = host;
|
||||
mmcsd->host = host;
|
||||
|
||||
_mmcsd_clk_init(mmcsd);
|
||||
_mmcsd_isr_init(mmcsd);
|
||||
_mmcsd_gpio_init(mmcsd);
|
||||
_mmcsd_gpio_init(mmcsd);
|
||||
_mmcsd_host_init(mmcsd);
|
||||
|
||||
host->private_data = mmcsd;
|
||||
host->private_data = mmcsd;
|
||||
|
||||
mmcsd_change(host);
|
||||
mmcsd_change(host);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
err:
|
||||
mmcsd_free_host(host);
|
||||
mmcsd_free_host(host);
|
||||
|
||||
return -RT_ENOMEM;
|
||||
return -RT_ENOMEM;
|
||||
}
|
||||
|
||||
int imxrt_mci_init(void)
|
||||
|
|
Loading…
Reference in New Issue