Friday 20 April 2012

VHDL to Spartan tutorial

We will be attempting (and succeeding) to make a simple vhdl execute in spartan 3 fpga board, I am using the one from digilient.But if your's is different don't fret this tutorial will work just fine.

So go ahead and click on the xilinx ise (the one used here is 10.1 again if your's is different it works just fine),

Provide a meaningful name (unlike what a lazy guy like me have done) then click next


Please make sure it is selected to your board version ,here being spartan 3 and if you care to simulate then select an appropriate simulator.


Select a new source to create a new instance of a vhdl file.






We are here creating a vhdl file hence select the same,but in case you need to create any other instance you have to do the same sequence of operation

 

Specify the input and output port identities ,note even if you skip this step ,you can still edit in the entity of the program the same port data


  Code your program and check the syntax by clicking synthesize - XST - > Check Syntax

You can simulate the same by choosing behavioural and simulate using the specified simulator ,ise comes inherently with a ise simulator .You can even procure another simulator by the name modelsim



With that done we have verified the program syntax and logic

 
We need the vhdl module to communicate with the external world once synthesized into the fpga and hence we need to map the programming ports onto the peripheral present ,we do so by observing the peripheral id which in some instance (The spartan 3 of digilent provides the peripheral id just below the peripheral) will be provided on the board itself.The peripheral may be switches or LED's or 7 segment and so on.
Also note that you are forced to use the peripherals on the board and you will not be blessed by additional peripherals so in case your program needs a 32 bit data to be fed and you intend to feed the data through switches ,Then you are forced to use 8 such slide switches provided on the board .A possible way out is to use the 8 slide switches 4 times thus you may hence need a enable signal and map it to one of the four push buttons,to indicate a 8 bit is entered to the board.



The xilinx pace above will allow you to provide the location of the ports mapped to the peripherals.
In case it does not work you may create a new source as a implementation constraint file or the UCF and manually edit it.It looks something like:

#PACE: Start of Constraints generated by PACE

#PACE: Start of PACE I/O Pin Assignments
NET "a"  LOC = "g12"  ;
NET "b"  LOC = "f12"  ;
NET "c"  LOC = "p13"  ;
#PACE: Start of PACE Area Constraints

#PACE: Start of PACE Prohibit Constraints

#PACE: End of Constraints generated by PACE

Where a and b are mapped to switches and c to a led


Save it.and observe the ucf  file,you can also check the ucf file in the directory where you have saved this program


With that done we (most optimistically ) go to the end of the tool chain and execute the last task (Doing so will cause all the subsequent tasks to be executed but hey,it's a leap of faith all the same).




Select Boundary scan and if any other dialog boxes do open just press OK,





Whoa we are pretty close ,the impact gui tool will ask for your bit file ,select the vhdl-program-name.bit file and press ok,It the opens up another window just press bypass this time.




We then select our device ,that would be the green one and right click it to program.If everything is correct you will be greeted with a program succeeded message

Any day i'll vouch for one spartan board instead of 300 spartans

Wednesday 18 April 2012

Porting guide to port on virtex5 fpga

Porting Rtlinux on virtex 5 fpga ,We will be using the linux environment for developing the bit or an ace file.The reason being is linux offers certain cross compiling tools which offers greater flexibility of usage.

We shall procure the rtlinux 3.1 (even 3.2 would be just fine) then we shall use the patch obtained from link ,(get a .bz2 file).This patch contains the real time constraints which we can incorporate with a linux kernel ,I suggest you to use a linux kernel 2.6 or greater as the linux kernels before 2.6 were non premptive and those after 2.6 are premptive,The premptiveness is needed for a real time environment.

I have used a 2.6.33.9

then enter to the directory where the linux kernel is stored by specifying cd directory-path-name

  cd linux-kernel-directory-path-name
     patch –p1 < /path-to-kernel-patch

(please note for beginners the path name eg would be something like '/home/proton/CA_Project/os/os3/fin' )

This creates a patch to the linux kernel with rt constraints,then we need a cross compiler

We can use  -crosstool-0.43
or crosstool-ng
or you can use ELDK ,I recommend the usage of ELDK as its usage is pretty simple unlike the others where you may have to alter some parameters in the shell scripts

Download the ELDK from here.,download the ppc-2008-04-01.iso

Installing ELDK:
change the directory to the one containing the EDLK image file

Now we got to mount this image by

>mount -o loop -t iso9660 ppc-2008-04-01.iso /folderpath

note the folder path indicates the path where the mounting is carried out,once mounted

>cd folderpath

and install by

>./install -d ~/directorypath
directory path indicate the destination where installation occurs.

After this for usage we may have to set the environment parametersfor which we go to the directory where the eldk is installed and run
 
>source eldk_init 4xx

This automatically sets up the environmemnt variables,which means certain parameters will be assigned certain values









mounting




installing






setting up environment variables (note that i have renamed the temp2 to crosscompilereldk ,just to make sense!)

executing
>ppc_4xx-gcc
shows that it is actually working,now you can specify
>ppc_4xx-gcc /pathtofile
path to file indicate the path to file for crosscrompiling wit respect to ppc-4xx

where xx corresponds to any number it may be 405,440 etc

now we have successfully installed ELDK by mounting it and also we can crosscompile any file to ppc architecture.

For porting we need to perform another operation,we need to make a device tree..oops why i didn't tell you before ?,gee i didn't want you to be scared by all these jargons eh ?.

But relax building a device tree is pretty simple (very easy ) it's easy because now we can use the edk gui to build it ,yes no more linux terminal for the time being.

To put it crudely ,device tree contains basic information of the hardware (on which OS is to be ported) .

Now i'll switch over to windows to use the edk ,however YOU CAN CARRY OUT THIS STEP IN LINUX EDK ITSELF

<Development of device tree procedure will be made available as soon as possible>


Now that the device tree is donet.We shall use this .dts file with the kernel .

enter the linux-xx file (file where the linux is stored go inside this linux kernel file which has been already patched) ,now copy the .dts file to /arch/powerpc/boot/dts  after copying you have to RENAME it to  virtex440-anyname.dts (for the virtex 2 pro its virtex405-anyname.dts)


you can also acquire the ram disk image for powerpc linux from here download the ramdisk_image.gz
and save it in /arch/powerpc/boot ,don't extract it ,save it as such.

This ramdisk contains data that allows the real root file system to be mounted so during booting this is first used and unmounted when the actual root file system takes over using the support from ramdisk
Its also called initial ramdisk.

We need to edit a wrapper file in /arch/powerpc/boot file name wrapper

check line 145

ksection=.kernel:vmlinux.strip
isection=.kernel:initrd
link_address='0x400000'

change the link_address='0x400000' to link_address='0x800000'

This is an effort to provide more memory to the kernel

Now we have to configure the kernel or sort of tell the kernel , Ok you are going to be ported to this hardware so make yourself ready.
check the /arch/powerpc/configs it contain 40x and 44x inside this folders are the config files related to various hardwares ,we shall be using the virtex5_defconfig in 44x ,execute
>make ARCH=powerpc 44x/virtex5_defconfig


now its configured ,we will now generate a .elf file by

before this we got to set the system parameters of cross compiler
 by using source eldk_init 4xx in the directory where we have developed the cross compiler so the binutils use the ppc_4xx as the cross compiler


>make ARCH=powerpc simpleImage.virtex440-anyname

virtex440-anyname is our .dts file,you can also equivalently use a 405

for the ramdisk incorporated .elf file

>make ARCH=powerpc simpleImage.intrd.virtex440-anyname

we have a kernel image with a ramdisk for supporting rootfile systems

check /arch/powerpc/boot there you can find the elf file as simpleImage.virtex405-anyname.elf  or  simpleImage.intrd.virtex405-anyname.elf



LAND ahoy!!!

to port we use the xmd

XMD% connect ppc hw -debugdevice deviceNr 3 cpunr 1
XMD% dow arch/powerpc/boot/simpleImage.virtex405-anyname.elf
XMD%run

Porting complete!!!!!!!!!