QQ:971586331
软件环境:
操作系统:windows 10
IDE:CCS7.4
代码生成工具:HALCoGen 04.07.01
烧写工具:CCS UniFlash
硬件环境:
目标板:TMDS570LS31HDK
本文内容:详细描述了TMS570系统处理器bootload跳转原理,编写2份程序,一个是bootload,一个是应用程序,在bootload中,使LED D5(HET1[00])闪烁5次后跳转到0x00180000处开始执行应用程序,应用程序中使LED D4(HET1[31])闪烁5次后软复位,再次执行bootload,如此往复。
1.编写bootload程序
按TMS570学习1中的流程新建工程boot_test,在hal下的sys_main.c中的编写主程序
/* USER CODE BEGIN (0) */
#include "sys_common.h"
#include "gio.h"
#include "delay.h"
#include "het.h"
#include "pinmux.h"
#include "F021.h"
/* USER CODE END */
/* Include Files */
/* USER CODE BEGIN (1) */
#define APP1_START_ADDRESS (0x00180000)
#define APP2_START_ADDRESS (0x00040000)
#define APP3_START_ADDRESS (0x00060000)
#define APP4_START_ADDRESS (0x00080000)
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
uint32 g_ulTransferAddress;
/* USER CODE END */
uint8 emacAddress[6U] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
uint32 emacPhyAddress = 1U;
int main(void)
{
/* USER CODE BEGIN (3) */
int i = 0;
gioInit();
muxInit();
/* Set high end timer GIO port hetPort pin direction to all output */
gioSetDirection(hetPORT1, 0xFFFFFFFF);
for( i=0; i<10; i++)
{
gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<0));
my_delay(1000);
}
g_ulTransferAddress = (uint32_t)APP1_START_ADDRESS;
((void (*)(void))g_ulTransferAddress)(); //跳转程序指针
while(1)
{
}
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
/* USER CODE END */
在主程序中,我们先初始化IO,让HET1[00]闪烁5次,然后让程序指针跳转到0x00180000处开始运行,因为要下载2个程序,为了把程序下载到指定地址和防止程序地址空间冲突,修改cmd文件。
/* */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN (0) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Linker Settings */
--retain="*(.intvecs)"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Memory Map */
MEMORY
{
VECTORS (X) : origin=0x00000000 length=0x00000020
FLASH0 (RX) : origin=0x00000020 length=0x0017FFE0
//FLASH1 (RX) : origin=0x00180000 length=0x00180000
STACKS (RW) : origin=0x08000000 length=0x00001500
RAM (RW) : origin=0x08001500 length=0x0003EB00
/* USER CODE BEGIN (2) */
/* USER CODE END */
}
/* USER CODE BEGIN (3) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Section Configuration */
SECTIONS
{
.intvecs : {} > VECTORS
//.text : {} > FLASH0 | FLASH1
//.const : {} > FLASH0 | FLASH1
//.cinit : {} > FLASH0 | FLASH1
//.pinit : {} > FLASH0 | FLASH1
.text : {} > FLASH0
.const : {} > FLASH0
.cinit : {} > FLASH0
.pinit : {} > FLASH0
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM
/* USER CODE BEGIN (4) */
/* USER CODE END */
}
/* USER CODE BEGIN (5) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Misc */
/* USER CODE BEGIN (6) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
因为bootload程序上电启动,所以从0x00000000开始,FLASH1段的位置正好是我们放应用程序的位置,所以屏蔽掉,SECTIONS中的text等段就只能放在FLASH0中,编译下载,可以看到板上的HET1[00]灯闪烁5次后熄灭,因为0x00180000处没有代码可以执行,程序跑飞。
2.编写应用程序
按TMS570学习1中的流程新建工程test,在hal下的sys_main.c中的编写主程序
/* USER CODE BEGIN (0) */
/* USER CODE END */
/* Include Files */
#include "sys_common.h"
/* USER CODE BEGIN (1) */
#include "rti.h"
#include "het.h"
#include "gio.h"
#include "emif.h"
#include "pinmux.h"
#include "sci.h"
#include "delay.h"
#include <stdio.h>
#include <reg_system.h>
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
/* USER CODE END */
uint8 emacAddress[6U] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
uint32 emacPhyAddress = 0U;
int main(void)
{
/* USER CODE BEGIN (3) */
int i=0;
int ret;
int buff;
/* Initialize RTI driver */
gioInit();
rtiInit();
muxInit();
sciInit();
sciEnableNotification(sciREG, SCI_RX_INT);
/* Set high end timer GIO port hetPort pin direction to all output */
gioSetDirection(hetPORT1, 0xFFFFFFFF);
/* Enable RTI Compare 0 interrupt notification */
rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
/* Enable IRQ - Clear I flag in CPS register */
/* Note: This is usually done by the OS or in an svc dispatcher */
_enable_IRQ();
/* Start RTI Counter Block 0 */
rtiStartCounter(rtiCOUNTER_BLOCK0);
//让HET1[31]闪烁5次
for( i=0; i<10; i++)
{
gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<31));
my_delay(1000);
}
systemREG1->SYSECR = 0x8000; //软件复位
/* Run forever */
while(1)
{
//gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<0));
my_delay(1000);
}
/* USER CODE END */
return 0;
}
/* USER CODE BEGIN (4) */
/* Note-You need to remove rtiNotification from notification.c to avoid redefinition */
void rtiNotification(uint32_t notification)
{
/* enter user code between the USER CODE BEGIN and USER CODE END. */
/* Toggle HET pin 0 */
gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<17));
}
/* USER CODE END */
在主程序中,先初始化IO,然后让HET1[31]闪烁5次,然后让程序软复位,因为应用程序要放到0x00180000位置,所以要修改cmd文件
/* */
/*----------------------------------------------------------------------------*/
/* USER CODE BEGIN (0) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Linker Settings */
--retain="*(.intvecs)"
/* USER CODE BEGIN (1) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Memory Map */
MEMORY
{
//VECTORS (X) : origin=0x00000000 length=0x00000020
VECTORS (X) : origin=0x00180000 length=0x00000020
//FLASH0 (RX) : origin=0x00000020 length=0x0017FFE0
FLASH1 (RX) : origin=0x00180020 length=0x0001FFE0
STACKS (RW) : origin=0x08000000 length=0x00001500
RAM (RW) : origin=0x08001500 length=0x0003EB00
/* USER CODE BEGIN (2) */
/* USER CODE END */
}
/* USER CODE BEGIN (3) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Section Configuration */
SECTIONS
{
.intvecs : {} > VECTORS
//.text : {} > FLASH0 | FLASH1
//.const : {} > FLASH0 | FLASH1
//.cinit : {} > FLASH0 | FLASH1
//.pinit : {} > FLASH0 | FLASH1
.text : {} > FLASH1
.const : {} > FLASH1
.cinit : {} > FLASH1
.pinit : {} > FLASH1
.bss : {} > RAM
.data : {} > RAM
.sysmem : {} > RAM
/* USER CODE BEGIN (4) */
/* USER CODE END */
}
/* USER CODE BEGIN (5) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
/* Misc */
/* USER CODE BEGIN (6) */
/* USER CODE END */
/*----------------------------------------------------------------------------*/
因为程序要在0x00180000开始,所将起始地址改为0x00180000,屏蔽FLASH0,SECTIONS中的段放在FLASH1中,编译程序,此时不能仿真因为程序不是下载到0地址的
3.烧写引导程序和应用程序
用TI的CCS UniFlash工具一次性烧写引导和应用程序
点Add选择引导和应用程序的out文件,点击Program,按下开发板上的复位键,可以观察到HET1[0]闪烁5次后HET1[31]闪烁5次,然后重复,说明先运行了bootload程序,然后运行了应用程序,应用程序运行完后程序复位,又运行bootload程序。
此内容由EEWORLD论坛网友石玉原创,如需转载或用于商业用途需征得作者同意并注明出处
引用: 石玉 发表于 2019-8-16 14:03 有一个地方没看明白,cmd文件中VECTORS段占用了起始的0x20个字节,是作什么用的?
明白了,是异常向量表