本帖最后由 石玉 于 2019-8-16 14:57 编辑
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) */
-
-
-
-
-
-
- /* USER CODE END */
-
- /* Include Files */
-
- /* USER CODE BEGIN (1) */
-
-
-
-
-
-
- /* 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文件。
-
-
-
-
-
-
-
-
-
- --retain="*(.intvecs)"
-
-
-
-
-
-
-
- MEMORY
- {
- VECTORS (X) : origin=0x00000000 length=0x00000020
- FLASH0 (RX) : origin=0x00000020 length=0x0017FFE0
-
- STACKS (RW) : origin=0x08000000 length=0x00001500
- RAM (RW) : origin=0x08001500 length=0x0003EB00
-
-
-
- }
-
-
-
-
-
-
-
-
- SECTIONS
- {
- .intvecs : {} > VECTORS
-
-
-
-
- .text : {} > FLASH0
- .const : {} > FLASH0
- .cinit : {} > FLASH0
- .pinit : {} > FLASH0
- .bss : {} > RAM
- .data : {} > RAM
- .sysmem : {} > RAM
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
因为bootload程序上电启动,所以从0x00000000开始,FLASH1段的位置正好是我们放应用程序的位置,所以屏蔽掉,SECTIONS中的text等段就只能放在FLASH0中,编译下载,可以看到板上的HET1[00]灯闪烁5次后熄灭,因为0x00180000处没有代码可以执行,程序跑飞。
2.编写应用程序
按TMS570学习1中的流程新建工程test,在hal下的sys_main.c中的编写主程序
-
-
-
-
-
- #include "sys_common.h"
-
-
- #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>
-
-
- /** @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.
- */
-
-
-
-
-
-
- uint8 emacAddress[6U] = {0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU, 0xFFU};
- uint32 emacPhyAddress = 0U;
-
- int main(void)
- {
-
- int i=0;
- int ret;
- int buff;
-
-
- gioInit();
- rtiInit();
- muxInit();
- sciInit();
- sciEnableNotification(sciREG, SCI_RX_INT);
-
-
- gioSetDirection(hetPORT1, 0xFFFFFFFF);
-
-
- rtiEnableNotification(rtiNOTIFICATION_COMPARE0);
-
-
-
- _enable_IRQ();
-
-
- rtiStartCounter(rtiCOUNTER_BLOCK0);
-
-
- for( i=0; i<10; i++)
- {
- gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<31));
- my_delay(1000);
- }
- systemREG1->SYSECR = 0x8000;
-
-
- while(1)
- {
-
-
- my_delay(1000);
- }
-
-
-
- return 0;
- }
-
-
-
-
- void rtiNotification(uint32_t notification)
- {
-
-
-
- gioSetPort(hetPORT1, gioGetPort(hetPORT1) ^ (1<<17));
-
- }
-
-
在主程序中,先初始化IO,然后让HET1[31]闪烁5次,然后让程序软复位,因为应用程序要放到0x00180000位置,所以要修改cmd文件
-
-
-
-
-
-
-
-
-
- --retain="*(.intvecs)"
-
-
-
-
-
-
-
- MEMORY
- {
-
- VECTORS (X) : origin=0x00180000 length=0x00000020
-
- FLASH1 (RX) : origin=0x00180020 length=0x0001FFE0
- STACKS (RW) : origin=0x08000000 length=0x00001500
- RAM (RW) : origin=0x08001500 length=0x0003EB00
-
-
-
- }
-
-
-
-
-
-
-
-
- SECTIONS
- {
- .intvecs : {} > VECTORS
-
-
-
-
- .text : {} > FLASH1
- .const : {} > FLASH1
- .cinit : {} > FLASH1
- .pinit : {} > FLASH1
- .bss : {} > RAM
- .data : {} > RAM
- .sysmem : {} > RAM
-
-
-
-
- }
-
-
-
-
-
-
-
-
-
-
-
-
因为程序要在0x00180000开始,所将起始地址改为0x00180000,屏蔽FLASH0,SECTIONS中的段放在FLASH1中,编译程序,此时不能仿真因为程序不是下载到0地址的
3.烧写引导程序和应用程序
用TI的CCS UniFlash工具一次性烧写引导和应用程序

点Add选择引导和应用程序的out文件,点击Program,按下开发板上的复位键,可以观察到HET1[0]闪烁5次后HET1[31]闪烁5次,然后重复,说明先运行了bootload程序,然后运行了应用程序,应用程序运行完后程序复位,又运行bootload程序。

此内容由EEWORLD论坛网友石玉原创,如需转载或用于商业用途需征得作者同意并注明出处