小学生
最后登录1970-1-1
在线时间 小时
注册时间2021-4-9
|
rtthread系统在stm32f1上运行正常,sd卡设备注册成功,尝试读写正常,但是挂载文件系统失败,dfs_mount 结果显示FORMAT ERROR
尝试mkfs -t elm sd0 结果显示error -12 FR_NOT_ENABLED
目前想到的是官方例程里SD卡是以HOST设备注册创建的,但是官方对于HOST设备好像没有什么文档说明
不知道这个HOST设备步骤是否必须,因为如果不用操作系统的话,驱动完成后直接f_mount就可以了
有没有大佬有过相关经验,能帮忙看看可能是什么原因的
- struct rt_device my_sdcard;
- rt_err_t rt_sdcard_init(rt_device_t dev)
- {
- /* DMA controller clock enable */
- __HAL_RCC_DMA2_CLK_ENABLE();
- /* DMA interrupt init */
- /* DMA2_Channel4_5_IRQn interrupt configuration */
- HAL_NVIC_SetPriority(DMA2_Channel4_5_IRQn, 1, 0);
- HAL_NVIC_EnableIRQ(DMA2_Channel4_5_IRQn);
-
- 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_ENABLE;
- hsd.Init.ClockDiv = SDIO_TRANSFER_CLK_DIV;
-
- if (HAL_SD_Init(&hsd) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_SD_ConfigWideBusOperation(&hsd, SDIO_BUS_WIDE_4B) != HAL_OK)
- {
- Error_Handler();
- }
-
- return RT_EOK;
- }
- rt_err_t rt_sdcard_open(rt_device_t dev, rt_uint16_t oflag)
- {
- return rt_sdcard_init(dev);
- }
- rt_size_t rt_sdcard_read(rt_device_t dev, rt_off_t sector, void *buffer, rt_size_t size)
- {
- rt_base_t level = 0, status = 0, timeout = 0xff;
- level = rt_hw_interrupt_disable();
-
- status = HAL_SD_ReadBlocks_DMA(&hsd, buffer, sector, size);
- while(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER)
- {
- if(timeout-- == 0)
- {
- status = RT_ERROR;
-
- rt_hw_interrupt_enable(level);
- return status;
- }
- }
-
- rt_hw_interrupt_enable(level);
-
- return RT_EOK;
- }
- rt_size_t rt_sdcard_write(rt_device_t dev, rt_off_t sector, const void *buffer, rt_size_t size)
- {
- rt_base_t level = 0, status = 0, timeout = 0xff;
- level = rt_hw_interrupt_disable();
- status = HAL_SD_WriteBlocks_IT(&hsd, (uint8_t *)buffer, sector, size);
- while(HAL_SD_GetCardState(&hsd) != HAL_SD_CARD_TRANSFER)
- {
- if(timeout-- == 0)
- {
- status = RT_ERROR;
-
- rt_hw_interrupt_enable(level);
- return status;
- }
- }
-
- rt_hw_interrupt_enable(level);
- return RT_EOK;
- }
- void rt_hw_sdcard_init(void)
- {
- my_sdcard.type = RT_Device_Class_Block;
-
- my_sdcard.init = rt_sdcard_init;
- my_sdcard.open = rt_sdcard_open;
- my_sdcard.read = rt_sdcard_read;
- my_sdcard.write = rt_sdcard_write;
-
- rt_device_register(&my_sdcard, "sd0",
- RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_REMOVABLE | RT_DEVICE_FLAG_STANDALONE | RT_DEVICE_FLAG_DMA_RX);
-
- rt_device_open(&my_sdcard, RT_DEVICE_FLAG_RDWR);
- }
- INIT_APP_EXPORT(rt_hw_sdcard_init);
复制代码 |
-
-
|