DSPRelated.com
Forums

Writing Data to MMCSD Card

Started by B S January 31, 2013
Hi,

I am using OMAP-L138 board which has SD card interface. I want to write large amount of processed data to SD card. I have sample code which checks if the SD card is present, it also reads and writes data in RAW format.

However, I want to write data to .txt file but don't know how to do that.

1. Do I need to make partition to SD card first ?
2. Do I simple need C code e.g. F_OPEN to create a file and call write function to dumb data over there ?
3. How can I define the path to create a file ?

I will appreciate if someone help with this.

Thanks.

-BAS
Hi,

You will need to use a file system and a software library
that implements one.

Rgds,

Andrew

> Writing Data to MMCSD Card
> Posted by: "B S" m...@yahoo.com matlab_fft
> Date: Thu Jan 31, 2013 8:36 am ((PST))
>
> Hi,
>
> I am using OMAP-L138 board which has SD card interface. I want to write
> large amount of processed data to SD card. I have sample code which checks if
> the SD card is present, it also reads and writes data in RAW format.
>
> However, I want to write data to .txt file but don't know how to do that.
>
> 1. Do I need to make partition to SD card first ?
> 2. Do I simple need C code e.g. F_OPEN to create a file and call write
> function to dumb data over there ?
> 3. How can I define the path to create a file ?
>
> I will appreciate if someone help with this.
>
> Thanks.
>
> -BAS
>

_____________________________________
Andrew,

Thanks for your help.

Can I use any software to have a file system on SD card then simple C code to create a file and write data to it ? 

Thanks.

-BAS
________________________________
From: Andrew Nesterov
To: c...
Sent: Friday, February 1, 2013 8:56 PM
Subject: [c6x] Re: Writing Data to MMCSD Card

 

Hi,

You will need to use a file system and a software library
that implements one.

Rgds,

Andrew

> Writing Data to MMCSD Card
> Posted by: "B S" m...@yahoo.com matlab_fft
> Date: Thu Jan 31, 2013 8:36 am ((PST))
>
> Hi,
>
> I am using OMAP-L138 board which has SD card interface. I want to write
> large amount of processed data to SD card. I have sample code which checks if
> the SD card is present, it also reads and writes data in RAW format.
>
> However, I want to write data to .txt file but don't know how to do that.
>
> 1. Do I need to make partition to SD card first ?
> 2. Do I simple need C code e.g. F_OPEN to create a file and call write
> function to dumb data over there ?
> 3. How can I define the path to create a file ?
>
> I will appreciate if someone help with this.
>
> Thanks.
>
> -BAS
>
B.S.

Per my understanding, the MMC/SD card is actually a USB storage device.
Therefore, it needs driver support in the kernel.

A good place to start would be:


R. Williams
---------- Original Message -----------
From: B S
To: "c..."
Sent: Thu, 31 Jan 2013 07:10:14 -0800 (PST)
Subject: [c6x] Writing Data to MMCSD Card

> Hi,
>
> I am using OMAP-L138 board which has SD card interface. I want to
> write large amount of processed data to SD card. I have sample code
> which checks if the SD card is present, it also reads and writes data
> in RAW format. 
>
> However, I want to write data to .txt file but don't know how to do that. 
>
> 1. Do I need to make partition to SD card first ? 
>
> 2. Do I simple need C code e.g. F_OPEN to create a file and call write
> function to dumb data over there ?
> 3. How can I define the path to create a file ?
>
> I will appreciate if someone help with this.
>
> Thanks.
>
> -BAS
------- End of Original Message -------

_____________________________________
R. Williams,

Thanks. I appreciate your help.

BAS

________________________________
From: Richard Williams
To: B S ; "c..."
Sent: Thursday, February 7, 2013 3:55 AM
Subject: Re: [c6x] Writing Data to MMCSD Card

B.S.

Per my understanding, the MMC/SD card is actually a USB storage device.
Therefore, it needs driver support in the kernel.

A good place to start would be:


R. Williams
---------- Original Message -----------
From: B S
To: "c..."
Sent: Thu, 31 Jan 2013 07:10:14 -0800 (PST)
Subject: [c6x] Writing Data to MMCSD Card

> Hi,
>
> I am using OMAP-L138 board which has SD card interface. I want to
> write large amount of processed data to SD card. I have sample code
> which checks if the SD card is present, it also reads and writes data
> in RAW format.
>
> However, I want to write data to .txt file but don't know how to do that.
>
> 1. Do I need to make partition to SD card first ?
>
> 2. Do I simple need C code e.g. F_OPEN to create a file and call write
> function to dumb data over there ?
> 3. How can I define the path to create a file ?
>
> I will appreciate if someone help with this.
>
> Thanks.
>
> -BAS
------- End of Original Message -------
I guess yes, any good FS software, but you would have to write a driver code
for the MMC/SD controller for the OMAP silicon. Here I even do not mention
a Linux or whatever OS driver. I mean a basic routine that would sercive the
controller events.

I might be wrong, so please correct me, but it seem that the controller does
not depend on the USB controller, it is a separate one. At least on the DM6446
device.

Rgds,

Andrew

> Can I use any software to have a file system on SD card then simple C code
> to create a file and write data to it ???
> Thanks.
>
> -BAS
> Posted by: "Richard Williams" r...@lewiscounty.com rkwill98356
> Date: Wed Feb 6, 2013 6:08 pm ((PST))
> B.S.
>
> Per my understanding, the MMC/SD card is actually a USB storage device.
> Therefore, it needs driver support in the kernel.
>
> A good place to start would be:
> R. Williams

_____________________________________
Hi,

I managed to have file system on SD card, successfully created a file and write char data in there but I am unable to write int or float data to file. Pointer to buffer is always char so I did type-cast but no success, it is still writing char to text file.

write(fptr, (char*)writebuf, BYTE_COUNT);
Any help ?
Regards,
BAS
________________________________
From: Andrew Nesterov
To: c...
Sent: Thursday, February 7, 2013 11:35 PM
Subject: [c6x] Re: Writing Data to MMCSD Card

 

I guess yes, any good FS software, but you would have to write a driver code
for the MMC/SD controller for the OMAP silicon. Here I even do not mention
a Linux or whatever OS driver. I mean a basic routine that would sercive the
controller events.

I might be wrong, so please correct me, but it seem that the controller does
not depend on the USB controller, it is a separate one. At least on the DM6446
device.

Rgds,

Andrew

> Can I use any software to have a file system on SD card then simple C code
> to create a file and write data to it ???
> Thanks.
>
> -BAS
> Posted by: "Richard Williams" r...@lewiscounty.com rkwill98356
> Date: Wed Feb 6, 2013 6:08 pm ((PST))
> B.S.
>
> Per my understanding, the MMC/SD card is actually a USB storage device.
> Therefore, it needs driver support in the kernel.
>
> A good place to start would be:
> http://e2e.ti.com/support/embedded/linux/f/354/t/43807.aspx> R. Williams
B.S.,

My first check would be:
What is the value in BYTE_COUNT?

If the byte count value is >1, then
You could try..

system( "rm "..." );
FILE* pFP = fopen( "...", "ab" );

then
fwrite( &data, 1, sizeof(data), pFP );

--or--

for(int i =0; i < sizeof(data), i++)
{
fwrite( (char*)(&data)+i, 1, 1, pFP );
}

----However----
it sounds like your opening the file for ascii rather than binary data
and that your system is "little endian".
(with little endian, an int=5 looks like: 0x05, 0x00, 0x00, 0x00)
Note:An ascii write will stop at the first null

I suggest you look at the way the file is being opened.
For a full Linux system, like Ubuntu Linux, the 'b' in the open statement has no
effect, but since your running something else, I would suspect that is the problem.

R. Williams

---------- Original Message -----------
From: B S
To: "c..."
Sent: Fri, 15 Feb 2013 06:24:19 -0800 (PST)
Subject: Re: [c6x] Re: Writing Data to MMCSD Card

> Hi,
>
> I managed to have file system on SD card, successfully created a file
> and write char data in there but I am unable to write int or float
> data to file. Pointer to buffer is always char so I did type-cast but
> no success, it is still writing char to text file.
>
> write(fptr, (char*)writebuf, BYTE_COUNT);
>
> Any help ?
>
> Regards,
> BAS
>
> ________________________________
> From: Andrew Nesterov
> To: c...
> Sent: Thursday, February 7, 2013 11:35 PM
> Subject: [c6x] Re: Writing Data to MMCSD Card
>
>  
>
> I guess yes, any good FS software, but you would have to write a
> driver code for the MMC/SD controller for the OMAP silicon. Here I
> even do not mention a Linux or whatever OS driver. I mean a basic
> routine that would sercive the controller events.
>
> I might be wrong, so please correct me, but it seem that the
> controller does not depend on the USB controller, it is a separate
> one. At least on the DM6446 device.
>
> Rgds,
>
> Andrew
>
> > Can I use any software to have a file system on SD card then simple C code
> > to create a file and write data to it ???
> > Thanks.
> >
> > -BAS
> >
> >
> > Posted by: "Richard Williams" r...@lewiscounty.com rkwill98356
> > Date: Wed Feb 6, 2013 6:08 pm ((PST))
> >
> >
> > B.S.
> >
> > Per my understanding, the MMC/SD card is actually a USB storage device.
> > Therefore, it needs driver support in the kernel.
> >
> > A good place to start would be:
> > http://e2e.ti.com/support/embedded/linux/f/354/t/43807.aspx>
> >
> > R. Williams
> >
> >
------- End of Original Message -------

_____________________________________
R. Williams,

Thanks for your reply. It took so long for my previous post to get approved by the group but i managed to fix it.
There was nothing wrong with the code itself. Actyally the content of the file was pure binary, therefore, I was unable to see float or int data. Opening the binary file in matlab showing the same data contents.

Thanks.

BAS
________________________________
From: Richard Williams
To: B S ; "c..."
Sent: Thursday, February 21, 2013 8:21 PM
Subject: Re: [c6x] Re: Writing Data to MMCSD Card

B.S.,

My first check would be:
What is the value in BYTE_COUNT?

If the byte count value is >1, then
You could try..

system( "rm "..." );
FILE* pFP = fopen( "...", "ab" );

then
fwrite( &data, 1, sizeof(data), pFP );

--or--

for(int i =0; i < sizeof(data), i++)
{
fwrite( (char*)(&data)+i, 1, 1, pFP );
}

----However----
it sounds like your opening the file for ascii rather than binary data
and that your system is "little endian".
(with little endian, an int=5 looks like: 0x05, 0x00, 0x00, 0x00)
Note:An ascii write will stop at the first null

I suggest you look at the way the file is being opened.
For a full Linux system, like Ubuntu Linux, the 'b' in the open statement has no
effect, but since your running something else, I would suspect that is the problem.

R. Williams

---------- Original Message -----------
From: B S
To: "c..."
Sent: Fri, 15 Feb 2013 06:24:19 -0800 (PST)
Subject: Re: [c6x] Re: Writing Data to MMCSD Card

> Hi,
>
> I managed to have file system on SD card, successfully created a file
> and write char data in there but I am unable to write int or float
> data to file. Pointer to buffer is always char so I did type-cast but
> no success, it is still writing char to text file.
>
> write(fptr, (char*)writebuf, BYTE_COUNT);
>
> Any help ?
>
> Regards,
> BAS
>
> ________________________________
> From: Andrew Nesterov
> To: c...
> Sent: Thursday, February 7, 2013 11:35 PM
> Subject: [c6x] Re: Writing Data to MMCSD Card
>
>
>
> I guess yes, any good FS software, but you would have to write a
> driver code for the MMC/SD controller for the OMAP silicon. Here I
> even do not mention a Linux or whatever OS driver. I mean a basic
> routine that would sercive the controller events.
>
> I might be wrong, so please correct me, but it seem that the
> controller does not depend on the USB controller, it is a separate
> one. At least on the DM6446 device.
>
> Rgds,
>
> Andrew
>
> > Can I use any software to have a file system on SD card then simple C code
> > to create a file and write data to it ???
> > Thanks.
> >
> > -BAS
> >
> >
> > Posted by: "Richard Williams" r...@lewiscounty.com rkwill98356
> > Date: Wed Feb 6, 2013 6:08 pm ((PST))
> >
> >
> > B.S.
> >
> > Per my understanding, the MMC/SD card is actually a USB storage device.
> > Therefore, it needs driver support in the kernel.
> >
> > A good place to start would be:
> > http://e2e.ti.com/support/embedded/linux/f/354/t/43807.aspx>
> >
> > R. Williams
> >
> >
------- End of Original Message -------