你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

STM32F107 + FatFS + SPI FLASH(Spansion- S25FL064K-8MB) does not work)

[复制链接]
saiRam 提问时间:2011-5-22 13:39 /
Hi Friends,

I am using STM32F107 to which an external FLASH is connected through SPI interface.
I am facing an issue with the configuration in subject line. My Flash size is 8MB and what I am doing is I have put a Mass Storage library from ST and FatFS( from Chan's site). I use Mass Storage library so that my flash device will be recognized by windows like a storage device.  As expected, windows recognizes it like a storage device, but pops up a message saying " you need to format the disk before you can use it". Obviously, it indicates that there is no file system existing on the device. Now, I ported the file system from chan(FatFS) into my system and it still shows the same issue. I am not sure what I am doing wrong. I tried my level best to debug before posting here.. any help will be greatly appreciated.

My flash(as you can see from datasheet, it is organized into 128 blocks each of size 65536(64KB). Each block contains 16 sectors. Each sector size is 4KB. Thus I have, 2048 sectors each of size 4KB.  
The changes I made to diskio.c  relavant to this problem:

#if _READONLY == 0
DRESULT disk_write (
                    BYTE drv,                        /* Physical drive nmuber (0..) */
                    const BYTE *buff,        /* Data to be written */
                    DWORD sector,                /* Sector address (LBA) */
                    BYTE count                        /* Number of sectors to write (1..255) */
                      )
{

  switch (drv)
  {
    case FLASH_DRIVE:
    {      
        for (int secNum = 0; secNum < count ; secNum++)
        {
          SPI_FLASH_SectorErase((sector*4096)+(secNum*4096));
          SPI_FLASH_BufferWrite((BYTE *)(buff+(4096*secNum)),((sector*4096)+(secNum*4096)),4096);         
        }
      }
      break;
   }
  
  return RES_OK;
}


DRESULT disk_ioctl (
                    BYTE drv,                /* Physical drive nmuber (0..) */
                    BYTE ctrl,                /* Control code */
                    void *buff                /* Buffer to send/receive control data */
                      )
{
  switch (drv)
  {
    case FLASH_DRIVE:
    {      
      switch (ctrl)
      {
        case CTRL_SYNC:
          // no synchronization to do since not buffering in this module
          return RES_OK;
        case GET_SECTOR_SIZE:
          *(WORD*)buff = 4096;
          return RES_OK;
        case GET_SECTOR_COUNT:
          *(DWORD*)buff = 2048;
          return RES_OK;
        case GET_BLOCK_SIZE:
          *(DWORD*)buff = 65536;
          return RES_OK;
      }
    }
  }
  return RES_PARERR;
}
收藏 评论3 发布时间:2011-5-22 13:39

举报

3个回答
LxiaoseI 回答时间:2012-3-14 22:34:49

回复:STM32F107 + FatFS + SPI FLASH(Spansion- S25FL064K-8MB) does not work)

I am facing the same issue .
roger-391567 回答时间:2012-9-24 22:55:23

RE:STM32F107 + FatFS + SPI FLASH(Spansion- S25FL064K-8MB) does not work)

太谢谢了AAAAAAAAAAAAAAAAAAAAAA
QQ897956996 回答时间:2012-10-19 11:15:57

回复:STM32F107 + FatFS + SPI FLASH(Spansion- S25FL064K-8MB) does not work)

   大师,我移植了FATFS到flash(sst39vf1601),发现格式化未成功(未移植文件系统时多扇区(n*512B)读写没问题,已经测试过),如何配置格式化函数呀:
 
#define _MAX_SS 512 /* 512, 1024, 2048 or 4096 */
/* Maximum sector size to be handled.
/  Always set 512 for memory card and hard disk but a larger value may be
/  required for floppy disk (512/1024) and optical disk (512/2048).
/  When _MAX_SS is larger than 512, GET_SECTOR_SIZE command must be implememted
/  to the disk_ioctl function. */
 
 
/*-----------------------------------------------------------------------*/
/* Miscellaneous Functions                                               */
 
DRESULT disk_ioctl( 
                      BYTE drv,             /* Physical drive nmuber (0..) */
                      BYTE ctrl,            /* Control code */
                      void *buff            /* Buffer to send/receive control data */
                  )
{
    DRESULT res = RES_OK;
    //DWORD result;
    if (drv)
    { 
        return RES_ERROR;
    }
    
    switch (ctrl)
    { 
        case CTRL_SYNC:
                           break;
        case GET_SECTOR_COUNT:
        
                           *(DWORD*)buff = (DWORD) 4096;
                           break;                           //2M byte
                           
        case GET_SECTOR_SIZE:
                           
                           //*(DWORD*)buff = (DWORD) 2048;  //&gt;512时从这里获得扇区大小
                           break;  
                                                           //单扇区字节数
        case GET_BLOCK_SIZE:
                           
                           *(DWORD*)buff = (DWORD) 4096;
                           break;                          //族大小  
                           
        case CTRL_POWER :
                  break;
   case CTRL_LOCK :
                  break;
   case CTRL_EJECT :
                  break;
        default:
                           res = RES_ERROR;
                           break;        
    }
    return res;
}
 
 
int main(void)
{
UARTInit ();                    /* UARTInit               */
        PINSEL0 = PINSEL0 &amp; (~0x0F);    /* UART0,设置I/O连接到UART*/                         
        PINSEL0 = PINSEL0 | 0x05;       /* P0.0 = TXD0,P0.1 = RXD0*/   
    
UART0SendStr(&quot;\x0c\0&quot;);
UART0SendStr(&quot;\x0c\0&quot;);        //超级终端清屏
UART0SendStr(&quot;\033[1;40;32m&quot;); //设置超级终端背景为黑色,字符为绿色
UART0SendStr(&quot;\r\n*******************************************************************************&quot;);
UART0SendStr(&quot;\r\n*********************** Copyright 2012-10-10, liujiehan ***********************&quot;);
UART0SendStr(&quot;\r\n************************** http://www.upcomputer.com **************************&quot;);
UART0SendStr(&quot;\r\n***************************** All Rights Reserved *****************************&quot;);
UART0SendStr(&quot;\r\n*******************************************************************************&quot;);
UART0SendStr(&quot;\r\n&quot;);
 
/*初始化文件系统,检查芯片是否插入以及是否型号正确*/
res = disk_initialize(NORFLASH);
if(res == RES_OK)
{
   UART0SendStr(&quot;initialize filesystem successed!\n\r\n\r&quot;);
}
else
{
   UART0SendStr(&quot;initialize filesystem failed!\n\r\n\r&quot;);  
}
/*挂载文件系统*/
res = f_mount(NORFLASH,&amp;fs);
if(res == RES_OK)
{
   UART0SendStr(&quot;mount filesystem successed!\n\r\n\r&quot;);
}
else
{
   UART0SendStr(&quot;mount filesystem failed!\n\r\n\r&quot;);  
}
/*格式化磁盘*/
UART0SendStr(&quot;正在格式化磁盘,请稍候...\n\r\n\r&quot;);
//res = f_mkfs(NORFLASH,1,4096);//4096:每簇占用字节数
res = f_mkfs(NORFLASH,0,4096);//4096:每簇占用字节数
if(res == RES_OK)
{
UART0SendStr(&quot;format filesystem successed!\n\r&quot;);
 
}
else
{
   UART0SendStr(&quot;format filesystem failed!\n\r&quot;);
}
res = f_mount(NORFLASH,NULL);
/////////////////////////////////////////////////////////////////////////////////////////////////
res = f_mount(NORFLASH,&amp;fs);
 
/*写文件测试*/
UART0SendStr(&quot;write file test......\n\r&quot;);
    res = f_open(&amp;FileObject, &quot;test.txt&quot;, FA_CREATE_ALWAYS | FA_WRITE);
    。。。
}
 

所属标签

相似问题

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32Cube扩展软件包
意法半导体边缘AI套件
ST - 理想汽车豪华SUV案例
ST意法半导体智能家居案例
STM32 ARM Cortex 32位微控制器
关注我们
st-img 微信公众号
st-img 手机版