Transfer a file byte by byte to microcontroller

luhai

Junior Member
May 12, 2006
10
0
66
Hi everyone,
I'm doing a project for lab, its basically an mp3 player. My goal is to able to download a mp3 file from PC to memory blocks on an microcontroller (Xilinx Microblaze) and playback using an MP3 decoder.

Basically that problem is I have no easy way of getting the data from the computer to Microcontroller (softcore on FPGA). I am currently think about sending the data byte-wise via the Serial Com Port interface, and have an UART take this data and store it into RAM of microcontroller system. However, I goggled for a few days now and can?t find a program that do this on the computer end. (that?s free) The program should simply pick up a file from the computer and send it byte-wise down the serial COM port. We will do our best to handle the data and control signals?

If you know such program or know a better way to implement this please contact me at luhai167@163.com or post (I?ll check back quite often)

Anyways here?s some details on the system we are using.
I have
---------
Microblaze processor softcore
http://www.xilinx.com/xlnx/xebiz/design...ip_product_details.jsp?key=micro_blaze

In our system an 8k bram and various I/O core can be added to the System on Chip system. (sounds weird saying that)

The main board with FPGA-D2FT
https://digilent.us/Products/Detail.cfm...d=D2FT&Nav1=Products&Nav2=Programmable

The I/O Board (DIO5) attached to D2FT PDF
https://digilent.us/Data/Products/DIO5/DIO5-brochure.pdf

RAM and Flash board attached to D2FT PDF
https://digilent.us/Data/Products/MEM1/MEM1-brochure.pdf

I can buy
--------------
Choice of Peripherals (Don?t pick anything too expensive, I?m a college student after all)
https://digilent.us/Products/Catalog.cf...=Products&Nav2=Accessory&Cat=Accessory
https://digilent.us/Products/Catalog.cf...roducts&Nav2=Peripheral&Cat=Peripheral

Thanks,

Xian
 

PsYcHoCoW

Member
Mar 29, 2005
133
0
0
Have you considered transferring the file over Hyperterminal? There are protocols built-in for transferring files (Zmodem, Xmodem, Kermit)... might be the easiest thing to try out. The protocols seem documented on google, so you might be able to get something to work from that..
 

luhai

Junior Member
May 12, 2006
10
0
66
I though about HyperTerminal before... I'm afraid it will exceed the 8k bram (for instructions and cache if needed) on the FPGA. Since I have to implement a mp3 player like user interface and I2C bus controller (for the mp3 encoder) on the same chip too. KERMIT PROTOCOL seems to be promising, I'll look into how much code space is needed to implement a simple file transfer. Btw, the coding is done in C on register level and the project is due in 3 weeks and the entire program should compile to less than 8kb. Hmm... I'm beginning to think that I need to pick another project...
 

Special K

Diamond Member
Jun 18, 2000
7,098
0
76
Use LabVIEW from National Instruments. You will have to learn how to write programs with it, as everything is done graphcially instead of with text, but they already have predefined functions for sending data over the serial port.
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
Or, don't use a file transfer protocoll at all. Just send the file to the COM Port (device COM1:), just "pretend" it is a text file. Since there is no error control (unless you implement it) chances are you will get some errors. However, if you limit the transfer speed to 300-2400 it should work.
In principle you can actually use the copy command (to e.g. the device COM1:) but I suspect the best thing is to write a simple program using e.g C or Pascal that does this for you.


Edit: Forgot to check the "do not parse emotions" box....

 

krotchy

Golden Member
Mar 29, 2006
1,942
0
76
One option, if your into programming is to pick a language (C/Visual Basic/C++/Java), and then look on the internet for a pre-written RS-232 module, there are tons. I reccomend VB or C++ personally. After you have the module its just a matter of creating a user interface or command prompt program which loads a file and writes it byte by byte to the RS-232 port.

This isnt that difficult, as my friends and I accomplished it in our senior projects lab last semester. My senior project was a Computer Controlled Security Robot, whose main form of communication was through wireless RS-232 modules. None of us had ever worked with Serial communication in our lives and we figured it out in a day or 2.

However I cant help you too much on the computer side, because I did all the microcontroller programming (PIC 18F8722), but I know the person who wrote the GUI found a pre-writen visual basic RS-232 module, and implemented it to sequentially write bytes to tell me what I was supposed to do.

*EDIT* I also know for a fact that two other groups in my capstone lab used a picoblaze (on a spartan chip) with RS-232 serial communication implemented. Since microblaze is more powerful than picoblaze I imagine this being fairly simple.

I also dont see it being difficult to create a C++ program to read a .mp3 file and write the file byte by byte to the serial port. Plus you could probably run baud rates up to 57600 pretty successfully.

*Edit 2* I also DO NOT reccomend using USB. On group in capstone implemented USB, only to find out that the overhead processing costs of using USB on their microcontroller actually made it slower than using RS-232 at 57600. They originally used RS-232 for their communication but "ugraded" to USB because its faster. However it ended up being slower and insanely difficult to implement.
 

f95toli

Golden Member
Nov 21, 2002
1,547
0
0
On the "computer side" you do as I recommended above. I.e write a program that reads the mp3-file and then writes it one byte (or Char, same thing) at a time to to COM1:.
You can just use the usual I/O routines in C/Pascal/Ada/Labview/whatever for this.
(but I would not recommend Labview for something like this, it works but the low level I/O VIs in Labview are a PITA, I don't know how many hours I've spent trying to get them to behave properly)

 

tex1138

Junior Member
Apr 5, 2005
11
0
0
To expand on the PC side of the discussion: When I first tried to implement serial comm uin a C program using the appropriate Win32 API calls, I never had any success... too many configuration options with no clear explanation of how they worked. Then, I found this, which worked immediately and which I have used many times since:

http://www.tetraedre.com/advanced/serial.php

The source code on this page is effectively an API to an API... that is, it provides its own API to your application and it makes the appropriate Win32 API calls with the most commonly-used parameters to hide the details. I have tweaked a few things with respect to error reporting, but otherwise I've found it to be invaluable.
 

luhai

Junior Member
May 12, 2006
10
0
66
Thanks for all your help, your ideas ready made this project seem possible. Come to think of it, I almost abandoned this idea and gone for digital filter...


I just discovered that Xilinx software is nice enough not erasing the RAM module during a re-program. As it allows me to get around the 8k limitation of the bram, and use two different Microblaze cores to do the job. So I convince another group to focus on the file transfer aspect and make it a joint project. While my group focus on the MP3 decoder chip and reading the memory.

On the computer end, file transfer will be implemented via hyper-terminal or using win32 API. Since now I have more memory space 2 more people to work with, which path will be easier (and less trouble) to implement. Win32 API or Hyper-terminal using existing a protocols? (if protocol, which one) All transfer will be done over the RS-232 port.
I really don't want get into too much trouble, as time is pretty tight. My plan is to have the two parts done in two weeks, so we can start integrating the two parts together.

My vision now is to have a core made only to transfer to the data to RAM. After the transfer is finished, another core will be programmed to read the mp3 information send to the decoder and eventually the speaker. This is all I can think of right now, tell what you think...

Again thank you for all your help,

luhai
 

velis

Senior member
Jul 28, 2005
600
14
81
Just in case you didn't know, you can simple transfer a file over COM port (no protocols, just bytes) with "copy xxxx.mp3 com1" command from the command prompt (replace com1 with your actual port used and xxxx with your MP3 of choice). Just be sure to set the communication port properties in the control panel to the values that suit you most (high speed very desired if you don't want to grow a beard or something).
What I don't understand is how you intend to stuff MP3 decoder / audio player / RS232 comm code into 8KB of RAM you say you have available + any MP3 on top of that. Or do you intend to play the MP3 as it comes in? Still leaves one helluva little space to do it all in anyway.
 

harrkev

Senior member
May 10, 2004
659
0
71
It seems to be the best way is by using the parallel port. One byte at a time with one control wire each way for handshaking.

The serial port could work, but is only worth it if you can use Xilinx Coregen parts. We have a site licence where I work, so I never have to worry about paying for them. If you can get a UART for free, that might be worth it. Try www.opencores.org. The problem with UARTs is that they can be somewhat complicated. They will work, but it might take some time to get one configured properly. Plus, you need to convert between RS-232 to TTL levels with a serial port.

A parallel interface is dead simple. You could write one in 15 minutes, and the signals are already TTL (I am assuming that your Xilinx part is 5V tolerant). The only hard part would be writing the PC program to transfer the files, but if you use the right lines, you might just be able to do "copy song.mp3 lpt:". Simple, huh?

**EDIT**
If your configuration memory has enough space, you could throw the MP3 in there - this is assuming that you have a configuration memory and are not tethered to JTAG all the time.
 

SamurAchzar

Platinum Member
Feb 15, 2006
2,422
3
76
From my experience, I couldn't get over 115,200bps using the COM port under Windows (VC++, for the matter).

You'll probably have to limit yourself for rates up to 112k.

 

luhai

Junior Member
May 12, 2006
10
0
66
Come clarification:
MP3 file will be stored in 512 SRAM modules on the MEM1 board. It is because data can't be directly written to the 512 RAM that started the whole topic.

Two core will be used to transfer data to Microblaze. The process will be
Impact FPGA with MB-data transfer code (Mainly done by another group now)
Load data into RAM via COM
Impact FPGA with MB-mp3 player code (Mainly done by my group)
play mp3 via decoder

code size for each is limited to 8k (Block ram, direct fast access for MB)
MP3 files are stored in 512K RAM in a attachment module.

Since file transfer part is another group project now, my main worry is to get the decoder working. (Actually I'm having a lot of trouble with DAC now.... regretting gotten the sta013 chip instead of uda1380 chip...)

hmm.. 112k data transfer. Since I'll using only 32kbit MP3 files, is it possible to just feed the mp3 and bypass the RAM all together?

Also it is too late to do parallel, as I don't have time to order parallel module and have it shipped in time.