硬汉嵌入式论坛

 找回密码
 立即注册
查看: 4509|回复: 4
收起左侧

[有问必答] 基于FATFS文件系统在向SD卡写入文件时能被中断吗

[复制链接]

2

主题

5

回帖

34

积分

新手上路

积分
34
发表于 2018-1-6 23:08:03 | 显示全部楼层 |阅读模式
基于FATFS文件系统在向SD卡写入文件时能被中断吗?
比如定时器中断。
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
发表于 2018-1-7 03:37:41 | 显示全部楼层
没问题,现在的SD卡读写操作是基于DMA的,随意中断。
回复

使用道具 举报

0

主题

26

回帖

26

积分

新手上路

积分
26
发表于 2018-1-10 13:48:18 | 显示全部楼层
eric2013 发表于 2018-1-7 03:37
没问题,现在的SD卡读写操作是基于DMA的,随意中断。

你好,看SD卡的f_read,f_write等都是启动DMA并等待结束后再继续操作,那比如SD卡拷贝数据期间(for循环)怎么响应串口数据?
    /* Copy source to destination */
    for (;;)
{
        fr = f_read(&SDFile, buffer, sizeof buffer, &br);  /* Read a chunk of source file */
        if (fr || br == 0) break; /* error or eof */
        fr = f_write(&USBHFile, buffer, br, &bw);            /* Write it to the destination file */
        if (fr || bw < br) break; /* error or disk full */
        _pRunStrt->SDCard.UseFrameNum++;
}

-------------------
DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
  DRESULT res = RES_ERROR;
  WriteStatus = 0;
  uint32_t timeout;
#if (ENABLE_SD_DMA_CACHE_MAINTENANCE == 1)
  uint32_t alignedAddr;
  /*
   the SCB_CleanDCache_by_Addr() requires a 32-Bit aligned address
   adjust the address and the D-Cache size to clean accordingly.
   */
  alignedAddr = (uint32_t)buff & ~3;
  SCB_CleanDCache_by_Addr((uint32_t*)alignedAddr, count*BLOCKSIZE + ((uint32_t)buff - alignedAddr));
#endif

  if(BSP_SD_WriteBlocks_DMA((uint32_t*)buff,
                           (uint32_t) (sector),
                           count) == MSD_OK)
  {
    /* Wait that the writing process is completed or a timeout occurs */

    timeout = HAL_GetTick();
    while((WriteStatus == 0) && ((HAL_GetTick() - timeout) < SD_TIMEOUT))
    {
    }
    /* incase of a timeout return error */
    if (WriteStatus == 0)
    {
      res = RES_ERROR;
    }
    else
    {
      WriteStatus = 0;
      timeout = HAL_GetTick();

      while((HAL_GetTick() - timeout) < SD_TIMEOUT)
      {
        if (BSP_SD_GetCardState() == SD_TRANSFER_OK)
        {
          res = RES_OK;
          break;
        }
      }
    }
  }

  return res;
}
回复

使用道具 举报

1万

主题

7万

回帖

11万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
117586
QQ
发表于 2018-1-11 00:44:08 | 显示全部楼层
ck123 发表于 2018-1-10 13:48
你好,看SD卡的f_read,f_write等都是启动DMA并等待结束后再继续操作,那比如SD卡拷贝数据期间(for循环) ...

串口中断里面接收,或者串口DMA接收,又或者使用了RTOS的话,在另一个高优先级任务里面实现均可。
回复

使用道具 举报

0

主题

26

回帖

26

积分

新手上路

积分
26
发表于 2018-1-11 11:48:54 | 显示全部楼层
eric2013 发表于 2018-1-11 00:44
串口中断里面接收,或者串口DMA接收,又或者使用了RTOS的话,在另一个高优先级任务里面实现均可。

不上RTOS的情况下,串口接收到的的后续数据怎么处理(响应,比如modbus数据响应); SD卡,循环连续读取一个文件16M,大概30S,那这30S内一直for循环吗?   还是中途人为暂时停止读取文件?不然看门狗也接受不了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2025-8-17 02:31 , Processed in 0.036935 second(s), 24 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表