اطلاعیه

Collapse
No announcement yet.

make FAT for MMC/SD in keil

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    make FAT for MMC/SD in keil

    سلام دوستان
    من MMC رو روی هدر برد سایت x256 راه انداختم که اینچا میتونین سورس رو دانلود کنید
    http://www.eca.ir/forum2/index.php?topic=48166.0

    حالا میخوام روی FAT کار کنم
    اگر دوستان کسی پیشهادی داره یا اینکه میخواد روی سوسرس کار کنه بسم اله
    علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

    #2
    پاسخ : make FAT for MMC/SD in keil

    سلام به همگی
    کسی نیست که کمک کنه؟

    من این کد رو به برنامه اضافه میکنم که تو خود help keil هست وبی error میده
    کد:
    #include <rtl.h>
    #include <stdio.h>
    
    void tst_fopen (void) {
     FILE *f;
    
     /* Read a file from default drive. */
     f = fopen ("Test.txt","r");
     if (f == NULL) {
      printf ("File not found!\n");
     }
     else {
      // process file content
      fclose (f);
     }
    
     /* Create a file in subfolder on SD card. */
     f = fopen ("M:\\Temp_Files\\Dump_file.log","w");
     if (f == NULL) {
      printf ("Failed to create a file!\n");
     }
     else {
      // write data to file
      fclose (f);
     }
    }

    نکته جالبش اینجاست که اگه هدر usart.h رو پاک کنم compile میشه ولی دیگه مموری init نمیشه یعنی اصلا میشه گفت میکرو هنگ میکنه و تو همون خط اول میمونه

    به نظر دوستان مشکل تر کجاست؟
    علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

    دیدگاه


      #3
      پاسخ : make FAT for MMC/SD in keil

      سلام . به احتمال زیاد با توابع ff که توسط آقای چان نوشته شده آشنا هستید و احتمالا به این سایت سری زدید ولی گفتم شاید ندیده باشید .
      http://www.siwawi.arubi.uni-kl.de/av...anfat_at91sam7

      تو صفحه ی بالا یه پروژه برای AT91SAM7 نوشته شده که به احتمال زیاد به کارتون میاد

      راستی یه چیزی می تونید کمکم کنید که ورژن 4.14 keil رو دانلود کنم آخه من تو سایتش که می رم برای دانلود سریال نامبر می خواد . می تونید بگید شما چطور دانلود کردید .

      دیدگاه


        #4
        پاسخ : make FAT for MMC/SD in keil

        سلام
        اینجایی که ادرس دادین رو دیدم.اینجا keil نیست دوست من

        جواب سوالتون:
        سریال رو که واسه دانلودنمیخواد.فقط یک zip code هست که بزنید 12345
        از اینجا دانلود کنید
        https://www.keil.com/demo/eval/arm.htm
        واسه کرک هم که تو همین فروم arm جستجو کنید هست و خیلی ساده کرک میشه با یم برنتکه خیلی سبک و ساده
        علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

        دیدگاه


          #5
          پاسخ : make FAT for MMC/SD in keil

          بله درسته برای keil نوشته نشده اما بلاخره به زبان سی هستش و فکر کنم بتونید از توابعش استفاده کنید البته با یه سری تغییرات و تعریفات متغیری جدید .

          دقتقا مثل همون دوستمون که از این توابع برای AVR استفاه کردند و برای کار با کدویژن در حالی که برنامه ی نوشته شده ی اصلی برای winavr نوشته شده بود . به نظر من اینطوری خیلی زودتر به جواب می رسید اونم پاسخی با ضریب اطمینان بالا

          دیدگاه


            #6
            پاسخ : make FAT for MMC/SD in keil

            من فکر می کنم خود کیل می تونه فت رو ساپورت کنه
            از کدوم نسخه کیل استفاده می کنید ؟
            هر کسی می تونه جادوگر باشه --- بزرگترین جادوی عالم عشقه
            پس هر کسی که عاشق باشه جادوگره --- حتی اگر عاشق بازی باشه

            دیدگاه


              #7
              پاسخ : make FAT for MMC/SD in keil

              من از نسخه 4.14 دارم استفاده میکنم
              بالا گفتم که وفتی از rtl.h استفاده میکنم چی میشه
              الان دارم رو این کار میکنم
              Simplified MMC FAT16 - Reading a PC-made file on an MMC with a PIC (Part 1)

              I'm working on a project where I would love to work with data that is PC readable and writable on a removable flash memory card using my PIC16F876A, PBP and the MMC cards I have. A major issue that I had to be overcome was that, though there is tons of information about FAT16 on the web, there was little out there that cuts to the chase. When I say cut to the chase, I just want to find a file created on a PC (example: TEST123.TXT), read and write to it, move the card back to the PC and have it read the file. The scope of this "Part 1" is just in reading a file made by the PC.

              If you want to do this on a MMC card and you don't want to spend 10's of hours researching what it is you have to do, let alone the 10's of hours making mistakes (miss-assigned an array - that one hurt) , this thread is for you. I don't address PBP code in this post, but other posts will include some coding and logic steps that can help working with MMC. For now I'll just address the FAT, since that would be step one in getting to my goals.

              Some assumptions have to be made here. If you want to make this happen 'for real', you MUST have the hardware for the PIC and the MMC working correctly as well as have mastered addressing the MMC. Then again, if all you what do is learn enough about FAT16 to be dangerous, that's okay too. Just don't ask me to design your next project.

              The MMC card is formatted as FAT16. On XP PC's select "FAT", not "FAT32" when you format the card. The card size should be between 32M and 2G, else FAT assigns different standards (this would only affects my stated real-world data). The card's sector size is 512 bytes. Clusters are 4 sectors (2048 Bytes). Partition 1 is used in the example and only 1 partition exists.

              After formatting the MMC, only one file is put on the card from the PC. Use a text editor and make a file with whatever in it. I decided to make a file called (saved as) TEST123.TXT and the data in the file is "1234567890". I did this so the strings would be easy to see when 'looking for my lost dog' on the MMC when I first started all this.

              Numbers I use in "( )" are the 'real-world' data values I found. A record that is more than 1 byte long is shown like 31:32 which means 2 bytes and their locations. Addresses on the drive start with 0 and end in a sector with 511. Sectors are 512 bytes long, i.e. 0:511. All logical sector-starting addresses will have 0x00 (zero) LSB in the 4 byte address - handy to remember.

              Okay, I can see you're anxious to see what I have. Here it is:

              Step by step - finding a file on the MMC armed only with the file name that was made with the PC.

              Initialize the MMC card using the CMD0 and CMD1 process. (not expanded on here)

              Read sector 0 (Master Boot Record - MBR)

              Go to record 454.
              Read records 454:457 (4 Bytes (Dword), LSB first)
              This is the number of sectors between the start of the MBR (0x00) and the first partition. You have to do the math: 1 sector = 512 bytes. Save a copy of this for the next step.

              Read the FAT16 Boot Record (FBR) at the address you just got.

              At record 11:12 is a Word that is the Bytes Per Sector (LSB). This should be 512 but could be different on your MMC card. Save this data.

              At record 13 is a Byte giving the Sectors Per Cluster. This should be 4 but could be different on your MMC card. Save this data.

              At record 14:15 is a Word (LSB first) that gives the number of Reserved Sectors used by the FBR. For now, just store the value.

              At record 16, get the Byte that tells you how many copies there are of the FBR. 99% of the time the Byte will be "2", but don't bank on it. Save the value.

              At record 22:23 get the Sectors Per FAT. Again LSB first. Save it.

              Calculate the location of the Table Directory by adding these:
              Location of the FBR (32)
              FBR size (245) * number of copies (2) = (490)
              Reserved Sectors used by FBR (6)

              Table Directory SECTOR is 32 + 490 + 6 = 528
              Table Directory ADDRESS is 528 * 512 = 270,336

              Go to the Table Directory (TD) file at the above location.

              Sidebar:
              Records in the TD are organized in 32 or 0:31 'blocks' for each file entry. The file name is the first entry in these 32 byte 'blocks'. The easiest way to find your file is to scan the TD looking for a string matching for your file name. Something you need to know is the difference in what you named the file is and what you'll expect to find. All characters are in CAPS (no 'small' characters). All file names are saved to the MMC using "padded spaces". This means that EVERY file name will have 11 characters (8:3). The "dot" in the name is omitted. The file name fills the left side of the value. If you enter "TEST.TXT" on the PC will be saved as "TEST TXT" (4 spaces between TEST and TXT. These spaces are SPACES (ASCII character number 32) NOT null (ASCII 0) and you should fill expected spaces in your search string with ASCII 32. When searching for the string, make sure it's a 100% match. Thanks to VFAT which overlays modern FAT16 formats, the first character of your file name may have an unusually large value, like 235. VFAT uses this point to another sector to store LFN (Long File Name) information that we will not concern ourselves with here.

              Okay, all that out of the wayナ

              Starting at record 0 and read in bytes looking for your file name. Your file name will be the first 11 bytes of a 32 byte block. It should be within the first sector (there are 16, 32 byte blocks) if this is a clean format drive with only one file on it. On the first failure to match, simply jump to the next 'block' (add 32 to the previous read offset; "31" for the second block if the previous block was "0&quot. Keep repeating this search until you find you complete file name. The record number where your file name starts will be used for finding the offset location within the 32 byte block.

              Now that you have found the file name, get the starting CLUSTER (not Sector) location for your file at offset 26:27 as a 2 byte Word (LSB). FAT writes data (files) using clusters, not sectors. Sectors seem to be used for within the FAT and Clusters seem to be used for data areas of the drive. For a clean MMC with only one file this starting Cluster should be 2. Save this data at 26:27


              At offset 28:31 is a Word (LSB) that gives the file size in Bytes. Save this for after working with the data file.

              I can't quite get a grip on this, but the first 2 physical clusters of the data area are not available (clusters 0 and 1). Anyway, a touch of math will get us there. Take the starting Cluster (2) and add 1 to it ((3) result). Take this number and multiply it by 4. This is the offset Cluster to the start of the file from the END of the TD. The TD size is 20 clusters.

              Now, a bit of adding will give you the cluster location of the file. Add:

              TD Offset (528)
              TD Size (20)
              Starting Cluster + 1, times 4 (12)

              528 + 20 + 12 = 560

              560 is the starting SECTOR of my file "TEST123.TXT"

              So much for being simple to find it, but this method is the crudest way to find a file using FAT!

              Keep track of the file size you're are working with. When you are finished with the file, re-write file size information in the TD at the location offset you got it at (28:31) so that your PC will 'see' the correct size file. If you make the file larger when you work with it and you don't update this information your PC will not read the extra sized data. This is where you need 512 Byte RAM with your PIC. Up to now, we've just moved forward in reads and they did not have to be in a large RAM (whole sectors, that is). But when we write to the MMC, it has to be done in a 512 byte string.

              So, without 512 RAM (I'll be using FN42C64 FAST I2C EEPROM in a few days, but for now it's a slow standard 24C64) you can read the files 'till the cows come home. But if you want data to go the other way (PIC > MMC > PC) you'll have to plan on 512 bytes or more of RAM. That said, you can write sector after sector to the MMC without RAM, just don't expect your PC to see all of it with a smaller size value in 28:31. A work-around for this is to make you file large enough for you to work with it without over-filling it.


              If you've read this far, I have a treat for you. Every MMC card I have (2x64M and 4x128M) will start the first file on a CLEAN formatted MMC at sector 560. If you want the fastest, easiest, yet "take your chances" way of reading a file that the PC made, open the MMC for block read (CMD17) after you've initialized it and use address location 0,4,96,0 . This is the physical address of byte 286,720 (560 sectors * 512) or hex 46000 (remember I said all logical sector START locations will have "0" for the LSB?) Note that if there are bad sectors on your MMC, there's a fair chance this address won't work as the FAT16 would have mapped them out, shifting reference addresses afterwards.

              So, the 'simple' way to find a file is:

              Get location of Partition
              Get the FAT reserve, FAT size, FAT copies - calculate location of Table Directory
              Get the your file's starting cluster - calculate location of your file
              Go to the file

              Simple, no? [wink]

              BTW, in a few days I'll take delivery of my supper fast FM24C64 I2C EEROM to replace my sooooo slow 24C64. The whole code will be re-written to take advantage of fast local RAM which, in itself will not make the program run faster, but it will reduce the size of the code substantially by reducing TONS of read start/stops loops to move to new read addresses and make it more logical to move to needed addresses. Plus, as it is now, I found (in code) it's easier to reinitialize the MMC once I'm done reading a sector rather than to count out the exact number clock cycles needed to get to a valid NCR response. This adds unnecessary delays (all be it small). As it stands now, I'm compiled to 3360 lines of code (but that includes a lot of DEBUG code space).

              With the change to the FM24C64 I hope to stay under 2K code space and maybe pickup a bit of speed. I'll start publishing a fair bit of the code once the new I2C RAM is in place and new code is working stable. Incase you are wondering, I am not using the SPI port on the PIC, though it is wired up to it incase I have a change oh heart. The code bit-bangs the SPI to make it easier for us simple-minded people (simple as in KISS, not stupid!).











              علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

              دیدگاه


                #8
                پاسخ : make FAT for MMC/SD in keil

                خب پس اگه درست فهمیده باشم وقتی دو تا هدر رو با هم صدا می کنی دچار ارور میشی
                ممکنه کل فلدرت رو پلود کنی که اگه کمکی از دستم بر بیاد کمک کنم
                هر کسی می تونه جادوگر باشه --- بزرگترین جادوی عالم عشقه
                پس هر کسی که عاشق باشه جادوگره --- حتی اگر عاشق بازی باشه

                دیدگاه


                  #9
                  پاسخ : make FAT for MMC/SD in keil

                  لینک رو تو پست اول گزاشتم
                  نه
                  مشکل اینجاست که اصلا با این rtl.h مشکل داریم.یا کامپایل نمیشه یا اگر میشه بهد از اینکه میریزم رو میکرو هنگ میکنه
                  تو کدهایی که تو نت هم داوردم متاسفانه درک خوبی ازشون ندارم و چون زبان سی من ضغیف هست تو کامپایل کردنشون به keil مشکل دارم متاسفانه و گرنه یک نمونه کد دارم که واسه winarm هست مه زمینه میکنم

                  این 2 تا هست اگر کسی میتونه کمک کنه یا علی
                  فایل های پیوست شده
                  علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

                  دیدگاه


                    #10
                    پاسخ : make FAT for MMC/SD in keil

                    فکر کنم یک راه راحت پیدا کردم
                    من الان سمپل خود کیل رو روی بردم ریختم و داره به خوبی کار می کنه
                    می خوای در مورد سمپل کیل حرف بزنیم ؟
                    چون هم داره از سریال پورت استفاده می کنه و هم بدون مشکل بالا میاد
                    هر کسی می تونه جادوگر باشه --- بزرگترین جادوی عالم عشقه
                    پس هر کسی که عاشق باشه جادوگره --- حتی اگر عاشق بازی باشه

                    دیدگاه


                      #11
                      پاسخ : make FAT for MMC/SD in keil

                      100%
                      لطفا سورس رو بزار تا روی مموری تست کنم :read:
                      علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

                      دیدگاه


                        #12
                        پاسخ : make FAT for MMC/SD in keil

                        این سمپله کیله که از 4.14 بهش اضافه شده
                        می تونید توی شاخه keil\board\atmel\at91sam7x-ek\rl\flashFS پیداش کنید
                        http://jadogar.persiangig.com/SD_File.rar
                        هر کسی می تونه جادوگر باشه --- بزرگترین جادوی عالم عشقه
                        پس هر کسی که عاشق باشه جادوگره --- حتی اگر عاشق بازی باشه

                        دیدگاه


                          #13
                          پاسخ : make FAT for MMC/SD in keil

                          یه نکته جالب

                          به چند تا فایل گیر میده که یمیش این هست
                          کد:
                          #include <File_Config.h>
                          ببینید اینا رو واسم بزارین اگر میشه
                          تو محل نسب keil هست
                          نمیدونم چرا وایه من error میزنه :angry:
                          علم چندانکه بيشتر خواني چون عمل در تو نيست ناداني

                          دیدگاه


                            #14
                            پاسخ : make FAT for MMC/SD in keil

                            حلش می کنیم
                            راستی یک چیز خیلی جالب در مورد این فایل
                            من الان یک اس دی 4 گیگ روی برد گذاشتم و کار کرد
                            یعنی از SDHC هم پشتیبانی می کنه !!!
                            هر کسی می تونه جادوگر باشه --- بزرگترین جادوی عالم عشقه
                            پس هر کسی که عاشق باشه جادوگره --- حتی اگر عاشق بازی باشه

                            دیدگاه

                            لطفا صبر کنید...
                            X