DSP_bootloader 在线下载程序核心源码带解释

//###########################################################################
// 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——-

stm32f10x_iap_bootloader是基于STM32F10x系列微控制器的一个引导程序下载工具。这个工具的作用是用于从外部存储设备(如SD卡)中下载和更新应用程序到系统的Flash内存中。 在进行stm32f10x_iap_bootloader程序下载之前,首先需要准备好一些硬件和软件条件。硬件上,需要一个有串口或USB接口的STM32F10x系列开发板,以及一个能够供电并适配开发板的电源。软件上,需要一个能够将应用程序转换为可执行文件(如bin或hex格式)的编译器,以及一个支持bootloader功能的下载工具(如ST-Link或Flasher)。 下载stm32f10x_iap_bootloader程序的步骤如下: 1. 将开发板连接到计算机,并确保与计算机的连接正常。 2. 使用编译器编译并生成stm32f10x_iap_bootloader的可执行文件。 3. 将生成的可执行文件保存到外部存储设备(如SD卡)中。 4. 将外部存储设备插入到开发板中的相应插槽中。 5. 打开下载工具,并选择正确的设备和接口。 6. 设置下载参数(如存储设备类型和地址)。 7. 开始下载过程,并等待下载完成。 8. 下载完成后,重启开发板,系统将从外部存储设备中加载并运行新的应用程序。 值得注意的是,下载stm32f10x_iap_bootloader程序之前,应先了解和熟悉stm32f10x_iap_bootloader的使用说明和相关文档,确保正确理解和掌握其功能和操作流程,以避免不必要的错误和损坏。此外,下载过程可能因实际情况而有所差异,请根据具体情况进行相应调整和操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值