//###########################################################################
// Description:
//! \addtogroup f2833x_example_list
//!
F28335 Flash Kernel (f28335_flash_kernel)
//!
//! This example is for use with the SerialLoader2000 utility. This
//! application is intended to be loaded into the device’s RAM via the
//! SCI boot mode. After successfully loaded this program implements a
//! modified version of the SCI boot protocol that allows a user application
//! to be programmed into flash
//
//###########################################################################
// TIRelease:F2833x/F2823xHeaderFilesandPeripheralExamplesV140 T I R e l e a s e : F 2833 x / F 2823 x H e a d e r F i l e s a n d P e r i p h e r a l E x a m p l e s V 140
// ReleaseDate:March4,2015 R e l e a s e D a t e : M a r c h 4 , 2015
// $Copyright: Copyright (C) 2007-2015 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
include “DSP28x_Project.h” // Device Headerfile and Examples Include File
extern Uint32 SCI_Boot();
void (*ApplicationPtr) (void);
Uint32 main(void)
{
//GPIO and SCI are still setup from Sci_Boot()
//Setup sysctl and pll
DisableDog();
InitPll(DSP28_PLLCR,DSP28_DIVSEL);
DELAY_US(100);
return SCI_Boot();
}
===========================================
//###########################################################################
//
// FILE: SCI_Boot.c
//
// TITLE: SCI Boot mode routines
//
// Functions:
//
// Uint32 SCI_Boot(void)
// inline void SCIA_Init(void)
// inline void SCIA_AutobaudLock(void)
// Uint32 SCIA_GetWordData(void)
//
// Notes:
//
//###########################################################################
//
TIRelease:F2833x/F2823xHeaderFilesandPeripheralExamplesV140
T
I
R
e
l
e
a
s
e
:
F
2833
x
/
F
2823
x
H
e
a
d
e
r
F
i
l
e
s
a
n
d
P
e
r
i
p
h
e
r
a
l
E
x
a
m
p
l
e
s
V
140
//
ReleaseDate:March4,2015
R
e
l
e
a
s
e
D
a
t
e
:
M
a
r
c
h
4
,
2015
// $Copyright: Copyright (C) 2007-2015 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
include “Boot.h”
// Private functions
inline void SCIA_Init(void);
inline void SCIA_AutobaudLock(void);
Uint16 SCIA_GetWordData(void);
Uint16 SCIA_GetOnlyWordData(void);
// External functions
extern void CopyData(void);
Uint32 GetLongData(void);
extern void ReadReservedFn(void);
extern unsigned int checksum;
extern Uint32 byteData1;
//#################################################
// Uint32 SCI_Boot(void)
//——————————————–
// This module is the main SCI boot routine.
// It will load code via the SCI-A port.
//
// It will return a entry point address back
// to the InitBoot routine which in turn calls
// the ExitBoot routine.
//——————————————–
Uint32 SCI_Boot()
{
Uint32 EntryAddr;
//0.0 UART½ÓÊÕº¯Êý£¬µØÖ·¸´ÖÆ
GetOnlyWordData = SCIA_GetOnlyWordData;
//1.0 UART³õʼ»¯
SCIA_Init();
//2.0 UART×Ô¶¯Ê¶±ð²¨ÌØÂÊ
SCIA_AutobaudLock();
//3.0 È«¾Ö±äÁ¿£»UARTÊý¾ÝУÑ鸴λ
checksum = 0;
//4.0 UART½ÓÊÕÌøתµ½³ÌÐòÖØÆôλÖÃ
if (SCIA_GetOnlyWordData() != 0x08AA) return FLASH_ENTRY_POINT ;
//5.0 UART½ÓÊÕ8¸öÎÞÓÃ×Ö
ReadReservedFn();
//6.0 UART½ÓÊÕFLASH¶ÎµÄÆðʼµØÖ·
EntryAddr = GetLongData();
//7.0 UARTÔ´³ÌÐò¿ªÊ¼½ÓÊÕ
CopyData();
return EntryAddr;
}
//#################################################
// void SCIA_Init(void)
//———————————————-
// Initialize the SCI-A port for communications
// with the host.
//———————————————-
inline void SCIA_Init()
{
// Enable the SCI-A clocks
EALLOW;
SysCtrlRegs.PCLKCR0.bit.SCIAENCLK=1;
SysCtrlRegs.LOSPCP.all = 0x0002;
SciaRegs.SCIFFTX.all=0x8000;
// 1 stop bit, No parity, 8-bit character
// No loopback
SciaRegs.SCICCR.all = 0x0007;
// Enable TX, RX, Use internal SCICLK
SciaRegs.SCICTL1.all = 0x0003;
// Disable RxErr, Sleep, TX Wake,
// Disable Rx Interrupt, Tx Interrupt
SciaRegs.SCICTL2.all = 0x0000;
// Relinquish SCI-A from reset
SciaRegs.SCICTL1.all = 0x0023;
// Enable pull-ups on SCI-A pins
// GpioCtrlRegs.GPAPUD.bit.GPIO28 = 0;
// GpioCtrlRegs.GPAPUD.bit.GPIO29 = 0;
GpioCtrlRegs.GPAPUD.all &= 0xCFFFFFFF;
// Enable the SCI-A pins
// GpioCtrlRegs.GPAMUX2.bit.GPIO28 = 1;
// GpioCtrlRegs.GPAMUX2.bit.GPIO29 = 1;
GpioCtrlRegs.GPAMUX2.all |= 0x05000000;
// Input qual for SCI-A RX is asynch
GpioCtrlRegs.GPAQSEL2.bit.GPIO28 = 3;
EDIS;
return;
}
//#################################################
// void SCIA_AutobaudLock(void)
//————————————————
// Perform autobaud lock with the host.
// Note that if autobaud never occurs
// the program will hang in this routine as there
// is no timeout mechanism included.
//————————————————
inline void SCIA_AutobaudLock()
{
Uint16 byteData;
// Must prime baud register with >= 1
SciaRegs.SCILBAUD = 1;
// Prepare for autobaud detection
// Set the CDC bit to enable autobaud detection
// and clear the ABD bit
SciaRegs.SCIFFCT.bit.CDC = 1;
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
// Wait until we correctly read an
// 'A' or 'a' and lock
while(SciaRegs.SCIFFCT.bit.ABD != 1) {}
// After autobaud lock, clear the ABD and CDC bits
SciaRegs.SCIFFCT.bit.ABDCLR = 1;
SciaRegs.SCIFFCT.bit.CDC = 0;
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
byteData = SciaRegs.SCIRXBUF.bit.RXDT;
SciaRegs.SCITXBUF = byteData;
return;
}
//#################################################
// Uint16 SCIA_GetWordData(void)
//———————————————–
// This routine fetches two bytes from the SCI-A
// port and puts them together to form a single
// 16-bit value. It is assumed that the host is
// sending the data in the order LSB followed by MSB.
//———————————————–
Uint16 SCIA_GetWordData()
{
Uint16 wordData;
Uint16 byteData;
wordData = 0x0000;
byteData = 0x0000;
// Fetch the LSB and verify back to the host
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
wordData = (Uint16)SciaRegs.SCIRXBUF.bit.RXDT;
SciaRegs.SCITXBUF = wordData;
// Fetch the MSB and verify back to the host
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
byteData = (Uint16)SciaRegs.SCIRXBUF.bit.RXDT;
SciaRegs.SCITXBUF = byteData;
checksum += wordData + byteData;
// form the wordData from the MSB:LSB
wordData |= (byteData << 8);
return wordData;
}
Uint16 SCIA_GetOnlyWordData()
{
Uint16 wordData;
Uint16 byteData;
wordData = 0x0000;
byteData = 0x0000;
// Fetch the LSB and verify back to the host
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
wordData = (Uint16)SciaRegs.SCIRXBUF.bit.RXDT;
//SciaRegs.SCITXBUF = wordData;
// Fetch the MSB and verify back to the host
while(SciaRegs.SCIRXST.bit.RXRDY != 1) { }
byteData = (Uint16)SciaRegs.SCIRXBUF.bit.RXDT;
checksum += wordData + byteData;
// form the wordData from the MSB:LSB
wordData |= (byteData << 8);
return wordData;
}
// EOF——-