programming Altera AS Configuration Device without Byteblast

D

DIYByteblaster

Guest
Do you have an Altera ByteblasterMV an do you want to programm the
Configuration Device EPCS1 or EPCS4 for Cyclone ??

Use this:
Make a new VisualBasic Form with one ProgrammButton Command1 and one
CommonDialog1
add the source code below
download the InpOut32.DLL from http://www.logix4u.cjb.net/
Modfify your Byteblaster/ByteblasterMV:
connect PIN4 of your Printer SUBD25 Connector to PIN17 (2A4) of the 74HC244.
Use the same Pull Up Resistors like on the other Pins. Disconnect the Pin
from GND.
connect PIN3 of 74HC244 to Pin8 of the JTAG Connector.
Connect PIN4 of the JTAG to PIN6 to disable the cyclone device.


----------------
Option Explicit
Private Declare Function Inp Lib "inpout32.dll" Alias "Inp32" (ByVal
PortAddress As Integer) As Integer
Private Declare Sub Out Lib "inpout32.dll" Alias "Out32" (ByVal PortAddress
As Integer, ByVal Value As Integer)



Dim bytebuffer(524288) As Byte

Const ASNCONF = 2
Const ASD = 0

Const ASDIN = 64
Const ASCLK = 1
Const ASCS = 4

Const WRITE_ENABLE = 6
Const WRITE_DISABLE = 4
Const READ_STATUS = 5
Const READ_BYTES = 3
Const READ_ID = &HAB
Const WRITE_STATUS = 1
Const WRITE_BYTES = 2
Const ERASE_BULK = &HC7
Const ERASE_SECTOR = &HD8



Private Sub Command1_Click()
Dim filelength As Long
Dim l As Long
Dim ok As Boolean
Dim rs As Byte
Dim b As Byte
Dim chipid As Byte

For l = 0 To 524287
bytebuffer(l) = 255
Next l

chipid = ReadID
If chipid = 16 Then
MsgBox "ChipID: EPCS1"
Else
If chipid = 17 Then
MsgBox "ChipID: EPCS4"
Else
MsgBox "no configuration device found"
Exit Sub
End If
End If





CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Alle Dateien (*.*)|*.*|" & "AS File (*.rbf)|*.rbf"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Binary Access Read As #1
Seek #1, 1
filelength = LOF(1)
For l = 0 To (filelength - 1)
Get #1, l + 1, bytebuffer(l)
Next l

Close #1




WriteEnable
EraseBulk
Do
rs = ReadStatus
Loop Until (rs Mod 2) = 0

For l = 0 To (filelength - 1)
WriteEnable
b = bytebuffer(l)
WriteB l, b
Do
rs = ReadStatus
Loop Until (rs Mod 2) = 0

If (l Mod 100) = 0 Then
Form1.Caption = "programming: " + Str(1 + l * 100 \ filelength) + "%"
DoEvents
End If

Next l

ok = True
For l = 0 To (filelength - 1)
If bytebuffer(l) <> ReadB(l) Then
ok = False
End If

If (l Mod 100) = 0 Then
Form1.Caption = "verifing: " + Str(1 + l * 100 \ filelength) + "%"
DoEvents
End If


Next l

If ok Then
MsgBox "OK"
Else
MsgBox "NOT OK"
End If


Exit Sub

ErrHandler:
MsgBox "File Open Error"
Close #1
End Sub
Private Sub Form_Load()
enablePar
End Sub
Private Sub ChipDeSelect()
Out &H378, ASCS
End Sub
Private Sub ChipSelect()
Out &H378, 0
End Sub
Private Sub enablePar()
Out &H37A, 2
End Sub

Private Sub disablePar()
ChipDeSelect
Out &H37A, 0
End Sub

Private Sub Form_Unload(Cancel As Integer)
disablePar
End Sub

Private Sub WriteByte(b As Byte)
Dim i As Integer
Dim bit As Byte
For i = 1 To 8
If b > 127 Then
bit = ASDIN
b = b - 128
Else
bit = 0
End If

b = b * 2
Out &H378, bit
'DoEvents
Out &H378, bit + ASCLK
'DoEvents
Next i
End Sub

Private Function ReadByte()
Dim b, hb As Byte
Dim i As Integer
Dim bit As Byte
b = 0
For i = 1 To 8
Out &H378, 0
'DoEvents
b = b * 2
hb = Inp(&H379)
hb = hb Mod 32
If (hb > 15) Then
bit = 1
Else
bit = 0
End If
Out &H378, ASCLK
'DoEvents
b = b + bit

Next i
ReadByte = b
End Function



Public Function ReadStatus() As Byte
ChipSelect
WriteByte READ_STATUS
ReadStatus = ReadByte
ChipDeSelect
End Function

Public Sub WriteEnable()
ChipSelect
WriteByte WRITE_ENABLE

ChipDeSelect
End Sub
Public Sub WriteDisable()
ChipSelect
WriteByte WRITE_DISABLE

ChipDeSelect
End Sub

Public Sub EraseBulk()
ChipSelect
WriteByte ERASE_BULK

ChipDeSelect
End Sub

Public Sub WriteB(ad As Long, b As Byte)
ChipSelect
WriteByte WRITE_BYTES
WriteByte (ad \ 65536) Mod 256
WriteByte (ad \ 256) Mod 256
WriteByte (ad \ 1) Mod 256
WriteByte b
ChipDeSelect
End Sub

Public Function ReadB(ad As Long) As Byte
ChipSelect
WriteByte READ_BYTES
WriteByte (ad \ 65536) Mod 256
WriteByte (ad \ 256) Mod 256
WriteByte (ad \ 1) Mod 256
ReadB = ReadByte
ChipDeSelect
End Function

Public Function ReadID() As Byte
ChipSelect
WriteByte READ_ID
WriteByte 0
WriteByte 0
WriteByte 0
ReadID = ReadByte
ChipDeSelect
End Function
 
Bugfix (the bit order in the rbf file is revers)
------------------------
Private Sub Command1_Click()
Dim filelength As Long
Dim l As Long
Dim ok As Boolean
Dim rs As Byte
Dim b As Byte
Dim chipid As Byte
Dim i As Integer
Dim tb As Byte

For l = 0 To 524287
bytebuffer(l) = 255
Next l

chipid = ReadID
If chipid = 16 Then
MsgBox "ChipID: EPCS1"
Else
If chipid = 17 Then
MsgBox "ChipID: EPCS4"
Else
MsgBox "no configuration device found"
Exit Sub
End If
End If





CommonDialog1.CancelError = True
On Error GoTo ErrHandler
CommonDialog1.Flags = cdlOFNHideReadOnly
CommonDialog1.Filter = "Alle Dateien (*.*)|*.*|" & "AS File (*.rbf)|*.rbf"
CommonDialog1.FilterIndex = 2
CommonDialog1.ShowOpen

Open CommonDialog1.FileName For Binary Access Read As #1
Seek #1, 1
filelength = LOF(1)
For l = 0 To (filelength - 1)

Get #1, l + 1, b

tb = 0

For i = 1 To 8
tb = tb \ 2
If b > 127 Then
tb = tb + 128
b = b - 128
End If
b = b * 2
Next i
bytebuffer(l) = tb
Next l

Close #1




WriteEnable
EraseBulk
Do
rs = ReadStatus
Loop Until (rs Mod 2) = 0

For l = 0 To (filelength - 1)
WriteEnable
b = bytebuffer(l)
WriteB l, b
Do
rs = ReadStatus
Loop Until (rs Mod 2) = 0

If (l Mod 100) = 0 Then
Form1.Caption = "programming: " + Str(1 + l * 100 \ filelength) + "%"
DoEvents
End If

Next l

ok = True
For l = 0 To (filelength - 1)
If bytebuffer(l) <> ReadB(l) Then
ok = False
End If

If (l Mod 100) = 0 Then
Form1.Caption = "verifing: " + Str(1 + l * 100 \ filelength) + "%"
DoEvents
End If


Next l

If ok Then
MsgBox "OK"
Else
MsgBox "NOT OK"
End If


Exit Sub

ErrHandler:
MsgBox "File Open Error"
Close #1
End Sub
 

Welcome to EDABoard.com

Sponsor

Back
Top