FAT32 library for MMC/SD cards

Discuss with MikroElektronika software developers about current library development.
Author
Message
ebeinecke
Posts: 32
Joined: 20 Apr 2010 21:54

Re: FAT32 library for MMC/SD cards

#31 Post by ebeinecke » 09 Aug 2012 00:27

When the Hardware stuck the message "Logando" is displayed in the display
so the problem occurs after status=FAT32_Exists(posi.nomearquivo);
and before FAT32_Close(fhandle);

I am sending the complete code.

Best regards.

Edmundo
Attachments
Logger.rar
(27.42 KiB) Downloaded 601 times

ebeinecke
Posts: 32
Joined: 20 Apr 2010 21:54

Re: FAT32 library for MMC/SD cards

#32 Post by ebeinecke » 21 Aug 2012 02:29

Bump ?

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#33 Post by Dany » 21 Aug 2012 16:23

ebeinecke wrote:My buffer size is 1024 (FAT32 formatted in 1024 bytes per sector) ...
Are you sure the card is formatted for 1024 bytes per sector? If so, are you sure the Fat32 library can handle this well? Normally cards have 512 bytes per sector, and that is also the spec in the mmc library.
Of course your own buffer can be bigger (I assume, the documentation is not very detailed regarding this type of issues).

Extra questions/comments:

A.
I do see also some alarming code parts in the (commented out, I know, but still...) code:

Code: Select all

      Lcd_Cmd(_LCD_CLEAR);
             Lcd_Out(1,1,"Logando");
             d=0;
             status=FAT32_Exists(posi.nomearquivo);
             if (status==0) {           //se o arquivo nao existe grava coodernadas
                    strcat(buf,posi.lat1);
                    strcat(buf,posi.lon1);
                    strcat(buf,posi.date1);
                    strcat(buf,posi.hora1);
             
                    /*//fhandle = FAT32_Open(posi.nomearquivo, FILE_WRITE);
                    //FAT32_Write(fhandle, posi.lat1, 16);
                    FAT32_Dev_Write_Sector(swapStartSc+d, posi.lat1);   <---------------------------
                    //FAT32_Write(fhandle, posi.lon1, 17);
                    d++;
                    FAT32_Dev_Write_Sector(swapStartSc+d, posi.lon1);  <----------------------------
                    d++;
In your code the routines FAT32_Dev_Write_Sector and FAT32_Dev_Read_Sector should not be called. They are meant to be called by the Fat32 library. The routines to use are FAT32_Write and FAT32_Read after "Fat32_Open".

B. Where is the implementation of FAT32_Dev_Write_Sector and FAT32_Dev_Read_Sector? Are they in the standard "Fat32_Driver" unit?
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#34 Post by Dany » 02 Oct 2012 12:29

Hi,

The possibility exists now to use the Fat32 library of mE together with the USB MSD host library (see http://www.mikroe.com/forum/viewtopic.p ... 50#p197339), making it possible to access files on a USB memory stick:

Adapted the hardware driver for the Fat32 library of MikroElektronika to be able to handle the USB stick software, see http://www.rosseeld.be/DRO/PIC/__Lib_FAT32_Driver.mpas.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: FAT32 library for MMC/SD cards

#35 Post by LGR » 02 Oct 2012 15:07

Excellent! There have been many requests for FAT on a stick.
If you know what you're doing, you're not learning anything.

serkansatuk
Posts: 38
Joined: 31 May 2012 07:05

Re: FAT32 library for MMC/SD cards

#36 Post by serkansatuk » 03 Dec 2012 09:28

Hi.
When "long file names" will be supported? Any idea about it?

I tried Dany's FAT32_1 library, but it doesn't support dsPIC33 series.

I am working on mikroMMB for dsPIC and it has dsPIC33FJ256GP710A microcontroller. I am using mikroBasic.

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#37 Post by Dany » 03 Dec 2012 16:25

serkansatuk wrote:Hi.
When "long file names" will be supported? Any idea about it?

I tried Dany's FAT32_1 library, but it doesn't support dsPIC33 series.

I am working on mikroMMB for dsPIC and it has dsPIC33FJ256GP710A microcontroller. I am using mikroBasic.
Hi, I see that a lot of libraries can be used by both PIC24 and PIC30/33, see e.g. the Fat32 library as example (http://www.libstock.com/projects/view/108/fat32-library). Perhaps you can try switch on the P33 Pic's in the package manager for the Fat32_1 and/or Fat32_2 libraries and try to install and use them? :D
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

serkansatuk
Posts: 38
Joined: 31 May 2012 07:05

Re: FAT32 library for MMC/SD cards

#38 Post by serkansatuk » 03 Dec 2012 21:47

Dany wrote: Hi, I see that a lot of libraries can be used by both PIC24 and PIC30/33, see e.g. the Fat32 library as example (http://www.libstock.com/projects/view/108/fat32-library). Perhaps you can try switch on the P33 Pic's in the package manager for the Fat32_1 and/or Fat32_2 libraries and try to install and use them? :D
Hi Dany.
I tried your library. I'm using mikroBasic.
I added "FAT32_1.mcl" and "StrngUtils.mcl" inside project files.

I wrote the following code before main program.

Code: Select all

sub function FAT32_Dev_Read_Sector(dim sc as longword, dim buf as ^byte) as short
  if (Mmc_Read_Sector(sc, buf) <> 0) then
     result = -1
  else
      result = 0
  end if
end sub

sub function FAT32_Dev_Write_Sector(dim sc as longword, dim buf as ^byte) as short
    if (Mmc_Write_Sector(sc, buf) <> 0) then
       result = -1
    else
       result = 0
    end if
end sub

I wrote "Fat32_Init()" in main. when i compile project it gave me an error like this.
"0 360 Unresolved extern 'Mul_16x16_U' Fat32_1.mpas"
"0 360 Unresolved extern 'Mul_32x32_U' Fat32_1.mpas"

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#39 Post by Dany » 04 Dec 2012 13:20

serkansatuk wrote:
Dany wrote: Hi, I see that a lot of libraries can be used by both PIC24 and PIC30/33, see e.g. the Fat32 library as example (http://www.libstock.com/projects/view/108/fat32-library). Perhaps you can try switch on the P33 Pic's in the package manager for the Fat32_1 and/or Fat32_2 libraries and try to install and use them? :D
Hi Dany.
I tried your library. I'm using mikroBasic.
I added "FAT32_1.mcl" and "StrngUtils.mcl" inside project files.

I wrote the following code before main program.

Code: Select all

sub function FAT32_Dev_Read_Sector(dim sc as longword, dim buf as ^byte) as short
  if (Mmc_Read_Sector(sc, buf) <> 0) then
     result = -1
  else
      result = 0
  end if
end sub

sub function FAT32_Dev_Write_Sector(dim sc as longword, dim buf as ^byte) as short
    if (Mmc_Write_Sector(sc, buf) <> 0) then
       result = -1
    else
       result = 0
    end if
end sub

I wrote "Fat32_Init()" in main. when i compile project it gave me an error like this.
"0 360 Unresolved extern 'Mul_16x16_U' Fat32_1.mpas"
"0 360 Unresolved extern 'Mul_32x32_U' Fat32_1.mpas"
1. the FAT32_Dev_Read_Sector and FAT32_Dev_Write_Sector should return boolean values (true=255, false = 0)
2. I will have a look into the unresolved errors.
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#40 Post by Dany » 04 Dec 2012 14:42

Hi,

About the unresolved externals:
I wrote "Fat32_Init()" in main. when i compile project it gave me an error like this.
"0 360 Unresolved extern 'Mul_16x16_U' Fat32_1.mpas"
"0 360 Unresolved extern 'Mul_32x32_U' Fat32_1.mpas"
The routines 'Mul_16x16_U' and 'Mul_32x32_U' are P18 routines, not P24 dsPic30/33 routines. Are you sure you have the correct Fat32_1.mcl file (the one for mB for PIC24)?
To be sure the 2 .mcl files attached.
Attachments
Fat32.zip
(158.7 KiB) Downloaded 387 times
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

serkansatuk
Posts: 38
Joined: 31 May 2012 07:05

Re: FAT32 library for MMC/SD cards

#41 Post by serkansatuk » 04 Dec 2012 15:46

Dany wrote:Hi,

About the unresolved externals:
I wrote "Fat32_Init()" in main. when i compile project it gave me an error like this.
"0 360 Unresolved extern 'Mul_16x16_U' Fat32_1.mpas"
"0 360 Unresolved extern 'Mul_32x32_U' Fat32_1.mpas"
The routines 'Mul_16x16_U' and 'Mul_32x32_U' are P18 routines, not P24 dsPic30/33 routines. Are you sure you have the correct Fat32_1.mcl file (the one for mB for PIC24)?
To be sure the 2 .mcl files attached.
thanks for your interest.
I will try again and write the results.

serkansatuk
Posts: 38
Joined: 31 May 2012 07:05

Re: FAT32 library for MMC/SD cards

#42 Post by serkansatuk » 04 Dec 2012 17:41

Hi Dany.
I created a new project with dsPIC33FJ256GP710A with your files attached to previous message.
the program has failed in two projects.

Code: Select all

program MyProject

dim Mmc_Chip_Select           as sbit at LATG9_bit
dim Mmc_Chip_Select_Direction as sbit at TRISG9_bit
dim Mmc_Card_Detect           as sbit at LATB14_bit     ' for detecting microSD card presence
dim Mmc_Card_Detect_Direction as sbit at TRISB14_bit

sub function FAT32_Dev_Read_Sector(dim _Sector as longword, dim byref Buffer as byte[512]) as boolean
  if (Mmc_Read_Sector(_Sector, Buffer) <> 0) then
     result = true
  else
      result = false
  end if
end sub

sub function FAT32_Dev_Write_Sector(dim _Sector as longword, dim byref Buffer as byte[512]) as boolean
    if (Mmc_Write_Sector(_Sector, Buffer) <> 0) then
       result = true
    else
       result = false
    end if
end sub

main:
'   Main program
    Fat32_Init()

end.
fat32_1.jpg
fat32_1.jpg (216.23 KiB) Viewed 12547 times

Code: Select all

program MyProject

dim Mmc_Chip_Select           as sbit at LATG9_bit
dim Mmc_Chip_Select_Direction as sbit at TRISG9_bit
dim Mmc_Card_Detect           as sbit at LATB14_bit     ' for detecting microSD card presence
dim Mmc_Card_Detect_Direction as sbit at TRISB14_bit

dim DirItem as TFileVar

sub function FAT32_Dev_Read_Sector(dim _Sector as longword, dim byref Buffer as byte[512]) as boolean
  if (Mmc_Read_Sector(_Sector, Buffer) <> 0) then
     result = true
  else
      result = false
  end if
end sub

sub function FAT32_Dev_Write_Sector(dim _Sector as longword, dim byref Buffer as byte[512]) as boolean
    if (Mmc_Write_Sector(_Sector, Buffer) <> 0) then
       result = true
    else
       result = false
    end if
end sub

main:
'   Main program
    Fat32_Init(DirItem)
end.
fat32_2.jpg
fat32_2.jpg (216.7 KiB) Viewed 12547 times

Dany
Posts: 3854
Joined: 18 Jun 2008 11:43
Location: Nieuwpoort, Belgium
Contact:

Re: FAT32 library for MMC/SD cards

#43 Post by Dany » 05 Dec 2012 15:55

Hi, I can reproduce the problems.

Unfortunately I have no solution for this, apparently the mB and mP compilers differ somehow in the generation/usage of .mcl files. I do not know why...

The "StrngUtils", "Fat32_1" and "Fat32_2" .mcl files are all generated with the mP v5.7.0 for PIC compiler and link together flawlessly using mP.

However, linking goes wrong with mB v5.7.0 for PIC compiler when using .mcl files generated with the mP v.5.7.0 for PIC compiler.

I have no idea why, perhaps mE should have a look to this issue.

I am very sorry that I gave you idle hope... :cry:

I think I will have to remove all my mB related packages in LibStock. I am not able to test them anyway... :oops: :cry:
Kind regards, Dany.
Forget your perfect offering. There is a crack in everything, that's how the light gets in... (L. Cohen)
Remember when we were young? We shone like the sun. (David Gilmour)

LGR
Posts: 3204
Joined: 23 Sep 2004 20:07

Re: FAT32 library for MMC/SD cards

#44 Post by LGR » 05 Dec 2012 16:39

Maybe I shouldn't butt into this, since it's none of my business, but I would think that it would be smart for mE to supply all compilers for all languages and platforms to Dany, considering the enormous value of his contributions. Then he can test these variants.
If you know what you're doing, you're not learning anything.

Toley
Posts: 922
Joined: 03 Sep 2008 16:17

Re: FAT32 library for MMC/SD cards

#45 Post by Toley » 05 Dec 2012 17:18

LGR wrote:Maybe I shouldn't butt into this, since it's none of my business, but I would think that it would be smart for mE to supply all compilers for all languages and platforms to Dany, considering the enormous value of his contributions. Then he can test these variants.
+1
Serge T.
Learning is an endeless process but it must start somewhere!

Post Reply

Return to “Library Development Discussion”