If anyone needs help with slave serial configuration from a CPU, look here: http://www.kamptec.com/blog/doku.php?id=hardware:xilinx-bin2h
----------------------------------------
Xilinx Bitstream Converter
If you need to configure a Xilinx FPGA using a microprocessor, you need to have an appropriate electrical interface to the FPGA and a piece of code to do the programming.
But first, you need to get the FPGA-bitstream into your microprocessor. One way is to read the bitstream out of an external bit-file, which is located somewhere in the filesystem of your embedded system. This is flexible, since you can change the bitstream without touching any other software.
But if you don't have any filesystem, you need to embed the bitstream into you code.
The following small C-program helps you to convert a binary Xilinx bitstream file into a C-header file.
It's a brief one, but works fine for me.
#include <stdio.h> int main( int argc, char *argv[]) {
FILE *binfile, *hfile;
int c, bytes = 0; binfile = fopen( argv[1], "r");
hfile = fopen( argv[2], "w");
if (!(binfile && hfile)) {
printf( "error: unable to open files\n");
exit( 0);
}
fprintf( hfile, "const unsigned char fpgabits [] = {\n");
while ((c = fgetc( binfile)) != EOF) {
fprintf( hfile, "%i,%s", c, ++bytes % 16 ? " " : "\n");
}
fprintf( hfile, "};\n");
fprintf( hfile, "const int fpgabits_size = %i;\n", bytes);
exit( 0);
}
Save it as bin2h.c
and compile it with
gcc bin2h.c -o bin2h
Now use your Xilinx IDE to setup the properties for the Generate Programming File process.
Enable Create Binary Configuration File to create a file containing the bitstream in a plain binary format.
Use the output file myfpga.bin
as input to bin2h
.
bin2h myfpga.bin myfpga.h
This creates a c-header file myfpga.h
with the following format:
const unsigned char fpgabits [] = {
255, 255, 255, 255, 170, 153, 85, 102,
48, 0, 128, 1, 0, 0, 0, 7,
...
32, 0, 0, 0, 32, 0, 0, 0,
};
const int fpgabits_size = 169216;
Now include that file in your FPGA driver code and use this routine or your own to configure your FPGA.
Send questions, comments, suggestions or corrections to me.
Keywords: xilinx, fpga, mcu, cpu, configuration, bitstream
댓글 없음:
댓글 쓰기