Quote by pvs-deck
Quote by rh
Hallo Thorsten,
die BootApp sollte (wenns geht) allein programmiert werden.
Beim ersten Start fordert die BootApp dann eine Applikation zum downloaden an.
Fuses werden und sollten nur in der BootApp programmiert werden.
Die meisten Fuses können nur auf 0 programmiert werden und nicht auf 1.
Das geht nur wenn ein komplettes Chip Erase durchgeführt wird.
rolf
Hallo Rolf,
ich habe jetzt mal etwas mit dem XMEGA_BootAppU rumgespielt und bekomme es nicht richtig zum laufen.
Sobald ich in die BootApp gehe, kommt nur noch die Info, dass das USB-Gerät nicht erkannt wird?
Pid 0 und Vid 0
Der USBSmart aus der MainApp läuft und wird erkannt, also ist die Hardware OK.
Gibt es mit der Demo noch Probleme unter dem XMEGA?
Und eigentlich müsste doch der "AvrCo Flash Downloader" nach dem einstellen der USB Schnittstelle laufen oder? Hier kommt immer Target not found, könnte aber mit dem Fehlverhalten des USBboot Flashloaders zu tun haben. Wenn Windows das Gerät nicht erkennt, kann wahrscheinlich auch der FlashLoader nicht funktionieren oder?
Hier mal der Code der BootApp:
Code
program PVS2014_BOOT;
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = xmega256A3U, VCC = 3.3;
{$BootApplication}
Define_Fuses
Override_Fuses;
// NoteBook = A;
ProgMode = PDI;
COMport = USB;
// LockBits0 = [BLBB0, BLBB1, LB0, LB1]; // protect boot and app against read back
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [BootRst]; // mandatory !!
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
// AutoRelease = true; // or false – Release Target // Wichtig für Programmierung über UPP !!
AddApp = 'D:\Data\PVS_AVR_CPU\PVS_AVRco\pvs2014';
// Info for programmer, joining hexfiles, using this project name
Import SysTick, USBboot, FlashLoader, SysLEDblink;
From System Import Tasks, Traps;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
StackSize = $0100, iData;
FrameSize = $0100, iData;
IDATA1 = $1ff0;
SysTick = 10;
Scheduler = iData;
TaskStack = $80, iData;
TaskFrame = $100;
maxTraps = 2; // optional, 2..16
USBmanufact = 'PVS Thorsten Deck'; // max 31 bytes
// USBprodName = 'PVS2014-CPU'; // In der BootApp gibt es das nicht ??? Warum?
USBpid = $1234;
USBvid = $1234;
USBprodRel = 201;
USBcurrent = 200;
USBvBUS = PortA.7; // port and pin
SysLEDblink = mSec500; {10..1000 msec}
SysLedPort = @LEDram, $00; // byte-var, polarity
Implementation
{$IDATA}
{------------------------------------------------------------------------------}
{ Type Declarations }
Type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
const
// Bootapp und Mainapp muss das gleiche nutzen
DownLoaderID : word = $1234; // important constant
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA1}
var
bo : boolean;
bb : byte;
{$IDATA}
var
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : byte, align2; // USB outgoing Buffer
RxCount : byte;
RxIndex : byte;
RxB : byte;
Header : tUSB_Request_Header;
// Test LED
HxOK [@PORTB, 7 ] : bit;
{--------------------------------------------------------------}
// The USB_ControlJob must be repeatedly called to process common PC requests
Task ControlJob(iData, suspended);
begin
USB_ControlJob;
end;
{--------------------------------------------------------------}
{$Validate $}
Function myUSB_ControlRequest(bRequest : byte; wValue : word) : boolean;
// need always answer from device
// time-critical - fast work off !!!!!!!!!!!!
var
b : byte;
begin
Header:= USB_ReadHeader;
case Header.bmRequestType of
$C0 :
case bRequest of // Dev to Host
0 :
if Header.wLength > 0 then
b:= $FF;
USB_ControlSend(@b, 1);
return(true);
endif;
|
1 :
if Header.wLength > 0 then
b:= $00;
USB_ControlSend(@b, 1);
return(true);
endif;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
return(true);
endcase;
|
$40 :
case bRequest of // Host to Dev
0 :
USB_ControlSend(nil, 0);
USB_RxSetBuf(@RxBuf);
return(true);
|
1 :
if Header.wLength > 0 then
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
endif;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
return(true);
endcase;
|
else
return(true);
endcase;
end;
{--------------------------------------------------------------}
procedure FlashLoaderInit; // mandatory
begin
USB_SetControlCallback(@myUSB_ControlRequest);
Resume(ControlJob);
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
repeat
until USBDEV_State = UsbDev_STATE_Configured;
USB_RxSetBuf(@RxBuf);
end;
{--------------------------------------------------------------}
Function FlashLoaderRecv : byte; // mandatory
begin
repeat
until USB_RxDataAvail;
loop
if RxCount > 0 then // already bytes in RxBuf ?
RxB:= RxBuf[RxIndex];
inc(RxIndex);
dec(RxCount);
if RxCount = 0 then
USB_RxSetBuf(@RxBuf); // we need more data ..
endif;
return(RxB);
endif;
RxCount:= USB_RxCount;
RxIndex:= 0;
endloop;
end;
{--------------------------------------------------------------}
procedure FlashLoaderTransm(arg : byte); // mandatory
var
bo : boolean;
begin
TxBuf:= arg;
USB_TXsend(@TxBuf, 1);
while not USB_TXcomplete do // wait TX send complete
NOP; // user todo - save this with 2 sec. timeout
endwhile;
end;
{--------------------------------------------------------------}
procedure FlashLoaderExit; // mandatory
begin
if Application_Valid then // Flag in the Flash Loader
EEprom[EEpromEnd]:= $00; // validate application for Boot usage
endif;
mDelay(1000);
HardWareReset; // restart with a jump into the Boot
end;
{--------------------------------------------------------------}
// optional Trap which can be called from the main
Function BootFunction : boolean; Trap;
begin
NOP; // do anything
NOP;
NOP;
return(bo);
end;
{--------------------------------------------------------------}
// optional Trap which can be called from the main
procedure BootProc(x : byte); Trap;
begin
bb:= x;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
// Inits
// HxOK [@PORTB, 7 ] : bit;
//PIN0CTRLF := %00000000; // pullup und INVERT
DDRB.7:= 1; // 0=EINGANG 1=Ausgang
//Reset Input Taste
PIN3CTRLE := %01011000; // pullup und INVERT
DDRE.3:= 0; // 0=EINGANG 1=Ausgang
//Run Stop Schalter
PIN0CTRLR := %01011000; // pullup und INVERT
DDRR.0:= 0; // 0=EINGANG 1=Ausgang
//ServTaste
PIN1CTRLR := %01011000; // pullup und INVERT
DDRR.1:= 0; // 0=EINGANG 1=Ausgang
// optional a port pin can be checked for a forced download
// if Pin.x = false then ...
// ...
if EEprom[EEpromEnd] = $00 then
// if a Download failed or the app was never programmed then there is no $00
// if the main app forces a download then the last byte in the EEprom must be $FF
//
Application_Startup;
endif;
EnableInts($87);
SysLEDflashOn( 0 ); // OKLED; // Zyklus LED starten
loop
HxOK:= NOT (LEDram.0); // Setzte OK LED zum flashen ...TEST
FlashDownLoader;
// Downloader does an exit to the main app if
// a valid main has been downloaded
endloop;
end PVS2014_BOOT.
{$NOSHADOW}
{ $WG} {global Warnings off}
Device = xmega256A3U, VCC = 3.3;
{$BootApplication}
Define_Fuses
Override_Fuses;
// NoteBook = A;
ProgMode = PDI;
COMport = USB;
// LockBits0 = [BLBB0, BLBB1, LB0, LB1]; // protect boot and app against read back
FuseBits0 = [];
FuseBits1 = [];
FuseBits2 = [BootRst]; // mandatory !!
// Brown-out is obligatory with USB !!!
FuseBits5 = [BODACT0, BodLevel0, BodLevel1, BodLevel2];
// AutoRelease = true; // or false – Release Target // Wichtig für Programmierung über UPP !!
AddApp = 'D:\Data\PVS_AVR_CPU\PVS_AVRco\pvs2014';
// Info for programmer, joining hexfiles, using this project name
Import SysTick, USBboot, FlashLoader, SysLEDblink;
From System Import Tasks, Traps;
Define
// XMega USB must use the internal 32MHz OSC. So the system must use the 2MHz OSC
OSCtype = int2MHz,
PLLmul = 16,
prescB = 1,
prescC = 1;
StackSize = $0100, iData;
FrameSize = $0100, iData;
IDATA1 = $1ff0;
SysTick = 10;
Scheduler = iData;
TaskStack = $80, iData;
TaskFrame = $100;
maxTraps = 2; // optional, 2..16
USBmanufact = 'PVS Thorsten Deck'; // max 31 bytes
// USBprodName = 'PVS2014-CPU'; // In der BootApp gibt es das nicht ??? Warum?
USBpid = $1234;
USBvid = $1234;
USBprodRel = 201;
USBcurrent = 200;
USBvBUS = PortA.7; // port and pin
SysLEDblink = mSec500; {10..1000 msec}
SysLedPort = @LEDram, $00; // byte-var, polarity
Implementation
{$IDATA}
{------------------------------------------------------------------------------}
{ Type Declarations }
Type
tBuf64 = Array[0..63] of byte;
{--------------------------------------------------------------}
{ Const Declarations }
const
// Bootapp und Mainapp muss das gleiche nutzen
DownLoaderID : word = $1234; // important constant
{--------------------------------------------------------------}
{ Var Declarations }
{$IDATA1}
var
bo : boolean;
bb : byte;
{$IDATA}
var
// these two buffers must be aligned to even addresses !!
RxBuf : tBuf64, align2; // USB incomming Buffer
TxBuf : byte, align2; // USB outgoing Buffer
RxCount : byte;
RxIndex : byte;
RxB : byte;
Header : tUSB_Request_Header;
// Test LED
HxOK [@PORTB, 7 ] : bit;
{--------------------------------------------------------------}
// The USB_ControlJob must be repeatedly called to process common PC requests
Task ControlJob(iData, suspended);
begin
USB_ControlJob;
end;
{--------------------------------------------------------------}
{$Validate $}
Function myUSB_ControlRequest(bRequest : byte; wValue : word) : boolean;
// need always answer from device
// time-critical - fast work off !!!!!!!!!!!!
var
b : byte;
begin
Header:= USB_ReadHeader;
case Header.bmRequestType of
$C0 :
case bRequest of // Dev to Host
0 :
if Header.wLength > 0 then
b:= $FF;
USB_ControlSend(@b, 1);
return(true);
endif;
|
1 :
if Header.wLength > 0 then
b:= $00;
USB_ControlSend(@b, 1);
return(true);
endif;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
return(true);
endcase;
|
$40 :
case bRequest of // Host to Dev
0 :
USB_ControlSend(nil, 0);
USB_RxSetBuf(@RxBuf);
return(true);
|
1 :
if Header.wLength > 0 then
USB_ControlSend(nil, 0);
mDelay(100);
HardWareReset;
endif;
|
else
USB_ControlSend(nil, 0); // unknown vendor request, do an ACK
return(true);
endcase;
|
else
return(true);
endcase;
end;
{--------------------------------------------------------------}
procedure FlashLoaderInit; // mandatory
begin
USB_SetControlCallback(@myUSB_ControlRequest);
Resume(ControlJob);
USB_Init(@RxBuf); // Attach USB and connect RxBuf for FIRST RX INT
repeat
until USBDEV_State = UsbDev_STATE_Configured;
USB_RxSetBuf(@RxBuf);
end;
{--------------------------------------------------------------}
Function FlashLoaderRecv : byte; // mandatory
begin
repeat
until USB_RxDataAvail;
loop
if RxCount > 0 then // already bytes in RxBuf ?
RxB:= RxBuf[RxIndex];
inc(RxIndex);
dec(RxCount);
if RxCount = 0 then
USB_RxSetBuf(@RxBuf); // we need more data ..
endif;
return(RxB);
endif;
RxCount:= USB_RxCount;
RxIndex:= 0;
endloop;
end;
{--------------------------------------------------------------}
procedure FlashLoaderTransm(arg : byte); // mandatory
var
bo : boolean;
begin
TxBuf:= arg;
USB_TXsend(@TxBuf, 1);
while not USB_TXcomplete do // wait TX send complete
NOP; // user todo - save this with 2 sec. timeout
endwhile;
end;
{--------------------------------------------------------------}
procedure FlashLoaderExit; // mandatory
begin
if Application_Valid then // Flag in the Flash Loader
EEprom[EEpromEnd]:= $00; // validate application for Boot usage
endif;
mDelay(1000);
HardWareReset; // restart with a jump into the Boot
end;
{--------------------------------------------------------------}
// optional Trap which can be called from the main
Function BootFunction : boolean; Trap;
begin
NOP; // do anything
NOP;
NOP;
return(bo);
end;
{--------------------------------------------------------------}
// optional Trap which can be called from the main
procedure BootProc(x : byte); Trap;
begin
bb:= x;
end;
{--------------------------------------------------------------}
{ Main Program }
{$IDATA}
begin
// Inits
// HxOK [@PORTB, 7 ] : bit;
//PIN0CTRLF := %00000000; // pullup und INVERT
DDRB.7:= 1; // 0=EINGANG 1=Ausgang
//Reset Input Taste
PIN3CTRLE := %01011000; // pullup und INVERT
DDRE.3:= 0; // 0=EINGANG 1=Ausgang
//Run Stop Schalter
PIN0CTRLR := %01011000; // pullup und INVERT
DDRR.0:= 0; // 0=EINGANG 1=Ausgang
//ServTaste
PIN1CTRLR := %01011000; // pullup und INVERT
DDRR.1:= 0; // 0=EINGANG 1=Ausgang
// optional a port pin can be checked for a forced download
// if Pin.x = false then ...
// ...
if EEprom[EEpromEnd] = $00 then
// if a Download failed or the app was never programmed then there is no $00
// if the main app forces a download then the last byte in the EEprom must be $FF
//
Application_Startup;
endif;
EnableInts($87);
SysLEDflashOn( 0 ); // OKLED; // Zyklus LED starten
loop
HxOK:= NOT (LEDram.0); // Setzte OK LED zum flashen ...TEST
FlashDownLoader;
// Downloader does an exit to the main app if
// a valid main has been downloaded
endloop;
end PVS2014_BOOT.
Bis auf leichte Anpassung ist es fast der Original Code.
Gruß
pvs-deck
Hallo Rolf,
Hallo miparo,
leider funktioniert der USB-Bootloader trotz update immer noch nicht, gleiches Fehlerbild.
Wie ist hier der Stand?
Gruß