int rt_hw_sdio_init(void)
{
struct stm32_sdio_des sdio_des;
SD_HandleTypeDef hsd;
hsd.Instance = SDCARD_INSTANCE;
{
rt_uint32_t tmpreg = 0x00U;
#if defined(SOC_SERIES_STM32F1)
/* enable DMA clock && Delay after an RCC peripheral clock enabling*/
SET_BIT(RCC->AHBENR, sdio_config.dma_rx.dma_rcc);
tmpreg = READ_BIT(RCC->AHBENR, sdio_config.dma_rx.dma_rcc);
#elif defined(SOC_SERIES_STM32F4) || defined(SOC_SERIES_STM32F7) || defined(SOC_SERIES_STM32L4)
SET_BIT(RCC->AHB1ENR, sdio_config.dma_rx.dma_rcc);
/* Delay after an RCC peripheral clock enabling */
tmpreg = READ_BIT(RCC->AHB1ENR, sdio_config.dma_rx.dma_rcc);
#endif
UNUSED(tmpreg); /* To avoid compiler warnings */
}
HAL_NVIC_SetPriority(SDIO_IRQn, 2, 0);
HAL_NVIC_EnableIRQ(SDIO_IRQn);
HAL_SD_MspInit(&hsd);
sdio_des.clk_get = stm32_sdio_clock_get;
sdio_des.hw_sdio = (struct stm32_sdio *)SDCARD_INSTANCE;
sdio_des.rxconfig = DMA_RxConfig;
sdio_des.txconfig = DMA_TxConfig;
host = sdio_host_create(&sdio_des);
if (host == RT_NULL)
{
LOG_E("host create fail");
return -1;
}
return 0;
}
INIT_DEVICE_EXPORT(rt_hw_sdio_init);
static int dfs_file_init(void)
{
if (0 == dfs_mount("sd0", "/", "elm", 0, 0))
{
rt_kprintf(" \n");
rt_kprintf("SD card mount successful.\n");
return 0;
}
else
{
rt_kprintf(" \n");
rt_kprintf("SD card mount failed.\n");
return -1;
}
}
INIT_ENV_EXPORT(dfs_file_init);
这样的情况下,会出现
(dev != RT_NULL) assertion failed at function:rt_device_control, line number:423
如何避免这样的问题发生?
常规的 这里INIT_DEVICE_EXPORT(rt_hw_sdio_init); 都是系统默认的,需要等里面的一个 mmc 探测线程成功识别到 SD 卡后,一般有什么方法不用等待,或有什么标志位,我们检测到就初始化这样 可以加快系统启动?
没有办法,只能在线程里不断地查询是否有 sd0 设备, 有了 sd0 设备才能进行后续挂载文件系统地操作。
rt_device_find("sd0");