首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 嵌入开发 > 单片机 >

请问关于STM32的JTAG编程有关问题

2012-02-26 
请教关于STM32的JTAG编程问题最近要做一个手持下载器,用AT89S52通过JTAG方式给STM32下载程序。由于原来没做

请教关于STM32的JTAG编程问题
最近要做一个手持下载器,用AT89S52通过JTAG方式给STM32下载程序。由于原来没做过相关的东西,所以网上找了一下相关的资料,照着现有的历程测试了下,发现的以下几个问题

1,STM32对应的BSD文件中,写着  
attribute INSTRUCTION_OPCODE of STM32F103C8: entity is 
  "BYPASS (11111)," &
  "EXTEST (00000)," &
  "SAMPLE (00010)," &
  "PRELOAD (00010)," &
  "IDCODE (00001)";
那么我用IDCODE指令去读取CPUID,代码如下
  //P1_3 P1_5 P1_6引脚对应TDI TCK TMS
  //P3_0对应TDO

  #define JTAG_DELAY() _nop_() 
  #define JTAG_GET_TDO()((P3_0==1) ? 1:0)

  void nvdJTAG_Set(unsigned char Control)
  {
P1 = Control;
  }

  void JTAG_ReadId(void)
  {
inti;
charid[32];

JTAG_RunTestldleState();

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); // Select-DR Scan Status

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); // Select-IR Scan Status

nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // Capture-IR Status

nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // Shift-IR Status

//STM32F103XX IDCODE Instruction "00001"
nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // '1'

nvdJTAG_Set(TDI_L | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_L | TMS_L | TCK_H);JTAG_DELAY(); // '0'

nvdJTAG_Set(TDI_L | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_L | TMS_L | TCK_H);JTAG_DELAY(); // '0'

nvdJTAG_Set(TDI_L | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_L | TMS_L | TCK_H);JTAG_DELAY(); // '0'

nvdJTAG_Set(TDI_L | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_L | TMS_H | TCK_H);JTAG_DELAY(); // '0', //Exit1-IR

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); // Update_IR

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); // Select-DR-Scan

nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); //Capture-DR

nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); //Shift-DR

// Read IDcode..
for( i=0 ; i<=30 ; i++) {
nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); //Shift-DR
id[i] = (char)JTAG_GET_TDO();
}

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); //Exit1_DR
id[i] = (char)JTAG_GET_TDO();

nvdJTAG_Set(TDI_H | TMS_H | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_H | TCK_H);JTAG_DELAY(); // Update_DR

nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY(); //
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // Run-Test/Idle
nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // Run-Test/Idle
nvdJTAG_Set(TDI_H | TMS_L | TCK_L);JTAG_DELAY();
nvdJTAG_Set(TDI_H | TMS_L | TCK_H);JTAG_DELAY(); // Run-Test/Idle
  }

可是取到的32位ID值,每一位总是常为1,不是正确值。现在STM32的板子可以通过ULink正常写程序。
请问这是怎么回事,是不是JTAG_DELAY()函数的延时不对?还是硬件上需要有特殊的电路?


[解决办法]
您好
我现在也正在做stm32的手持下载器,一头雾水,能帮忙指点下吗,要访问stm32的flash寄存器,其jtag命令是什么?我的qq147171234 一起讨论下,我是用AVR单片机。
[解决办法]
没具体弄过这方面的东西,MARK

帮顶下、


[解决办法]
lz做下载器还是做加密器呀,读id,是为了加密吧

S52的flash 空间好像不大, 能下载什么给stm32单片机呀, 

st的spi下载程序是开源的,你可以做串口下载器,或者加密器,

我做了一个串口的,硬件很简单,主要是软件实现的,你也可以自己做一个,

我做的是加密器,hoho,

热点排行