近来用国产的ARM起来越多了,想着把TRACE32利用起来,调试、抓取数据非常的方便,花了一周的时间找资料,验证算法,终于搞定了。
//***********************************************************************************************************
//  Ver 1.0
//      2022.04.02  1、新建文件。
//***********************************************************************************************************
//#include    "stdio.h"
//参数块定义
typedef struct{
    unsigned int  flashaddr;  //0x800,芯片起始地址
    unsigned int  flashwidth; //0x804,1=8bit,2=16bit,4=32bit
    unsigned int  width;      //0x808,数据总线位宽
    unsigned int  offset;     //0x80c,
    unsigned int  addr;       //0x810,FLASH操作地址
    unsigned int  size;       //0x814,擦除、写入字节数
    unsigned int  reserved;   //0x818,
    unsigned int  status;     //0x81c,in: 1=program, 2=erase, 5=chip erase, out: 0=o.k., 0x100=fail
    unsigned char   data[4096]; //0x820,缓冲区起始地址
}FlashParameter_Str;
//关键地址,TRACE32的数据交互都在这个结构体里面
static FlashParameter_Str FlashParameter __attribute__((at(0x20000800)));
#define FLASH_PAGE_SIZE     512
enum{
    FLASH_PROGRAM       = 0x01,
    FLASH_ERASE         = 0x02,
    FLASH_CHIP_ERASE    = 0x05,
};
#define FMC_FLPROT          *(unsigned int *)(0x40020000UL + 0x20)
#define FMC_FLOPMD1         *(unsigned int *)(0x40020000UL + 0x04)
#define FMC_FLOPMD2         *(unsigned int *)(0x40020000UL + 0x08)
#define FMC_FLSTS           *(unsigned int *)(0x40020000UL + 0x00)
#define FMC_FLERMD          *(unsigned int *)(0x40020000UL + 0x0c)
#define FMC_FLSTS_OVF_Msk   0x01
#define SCB_VTOR           *(unsigned int *)(0xE000E000UL + 0x0D00UL + 0x08)
//关键行,把main函数放到RAM首地址,找到这个问题花了不少时间。
#pragma arm section code = ".ARM.__at_0x20000000"
int main(void)
{     
    unsigned int errCnt = 65535;
    unsigned int tMs;
    unsigned int i;
    unsigned char *ptr,*buf;
    
    while(1)
    {
        switch(FlashParameter.status)
        {
            case FLASH_PROGRAM:
                ptr = (unsigned char *)FlashParameter.addr;
                buf = &FlashParameter.data[0];
                
                if(FlashParameter.size > 0xffff)
                {
                    FlashParameter.size = 0xffff;
                }
                
                FMC_FLPROT = 0xF1;
                
                for(i=0; i<FLASH_PAGE_SIZE; i++) 
                {
                    FMC_FLOPMD1 = 0xAA;
                    FMC_FLOPMD2 = 0x55;  
                    *ptr++ = *buf++;    
                    // polling OVER Flag
                    while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);
                    FMC_FLSTS |= FMC_FLSTS_OVF_Msk;
                }
                FMC_FLPROT = 0x00;
                FlashParameter.status = 0;
                return(0);
                break;
                    
            case FLASH_ERASE:
                FMC_FLERMD = 0x10;
                FMC_FLPROT = 0xF1;
                FMC_FLOPMD1 = 0x55;
                FMC_FLOPMD2 = 0xAA;  
                // Write data to start address of sector to trigger Erase Operation
                *(unsigned int *) FlashParameter.addr = 0xFFFFFFFF;
                
                // polling Erase Over Flag
                while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);
                FMC_FLSTS |= FMC_FLSTS_OVF_Msk;
                FMC_FLERMD = 0x00;
                FMC_FLPROT = 0x00;
                FlashParameter.status = 0;
                return(0);
                break; 
                    
            case FLASH_CHIP_ERASE:
                FMC_FLERMD = 0x08;
                FMC_FLPROT = 0xF1;
                FMC_FLOPMD1 = 0x55;
                FMC_FLOPMD2 = 0xAA;  
                *(unsigned char *) FlashParameter.addr = 0xff;    
                // polling OVER Flag
                while((FMC_FLSTS & FMC_FLSTS_OVF_Msk) == 0);
                FMC_FLSTS |= FMC_FLSTS_OVF_Msk;
                FMC_FLPROT = 0x00;
                FlashParameter.status = 0;
                return(0);
                break; 
              
            default:
                tMs = 65535;
                while(tMs--);
                break;
        }
        if(errCnt > 0) errCnt--;
        else           return(1);
    }
}
#pragma arm section离线
土豪,问一下,用这个算法可以把调试Tricore的变成调试Arm核的吗?
离线
trace32调试什么芯片,换对应的头子就可以了,楼上有Tricore的头子?我没有用过tricore的芯片不太清楚,手上还有两个支持arm的头子,也许可以交换一下
离线
trace32调试什么芯片,换对应的头子就可以了,楼上有Tricore的头子?我没有用过tricore的芯片不太清楚,手上还有两个支持arm的头子,也许可以交换一下
哦,我这是公司的工具,个人用不起,确实好用。
离线
个人可以弄个山寨的,原装货价格确实高了点
离线
用trace32来调试mcu有点奢侈啊
离线
trace32的特点:
1. 贵
2. 支持CPU多
3. 逼格高
但调试MCU,真没jlink之流方便.
离线
楼主太厉害了!请问下下载算法的资料能分享下吗?
离线
搞MCU开发JLINK是比较方便。很多都是拿来做逆向的,IDA+TRACE32,直接修改完调试,没更方便的了
离线
大神接受我的膝盖
离线
大佬,问一下相关资料,或者官方的模板在哪能找到
离线
官方没有提供模板,从网上查找的文档自己写的
离线