Chinaunix首页 | 论坛 | 博客
  • 博客访问: 540703
  • 博文数量: 252
  • 博客积分: 1068
  • 博客等级: 少尉
  • 技术积分: 1775
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-05 21:33
文章分类

全部博文(252)

文章存档

2013年(21)

2012年(231)

分类: IT业界

2012-08-10 10:26:03

/***********************************************************************************************************************************************************************/
ads1.2 and jlinkv8
1.安装ads1.2和jlink驱动Setup_JLinkARM_V408i.exe
安装ads1.2时,最后在100%时如果持续时间长,耐心等一下吧。
没有等待而点了cancel,则之后就不好重装了。解决办法见
http://blog.ednchina.com/mengforever1981/216162/message.aspx
2.将线连好:pc的usb口连到jlink的usb口,jlink的jtag口连到板子的jtag口。由于我的jlink的jtag口20pin而板子jtag口10pin,所以中间用一个转接小板转接了一下
将板子的flash开关在nor或nand均可,将板子上电,在开始里打开jlink gdb server,应该会出现下图,恩,jlink没坏

3.确保TQ2440_Test工程的路径中不存在中文,
在TQ2440_Test中双击TQ2440_Test.mcp,出现

点击debug,弹出axd窗口如下,(貌似还弹出了load session的窗口,关闭了就行)

4.在axd中点击configure target

弹出下图

add 一个文件JLinkRDI.dll,默认在C:\Program Files\SEGGER\JLinkARM_V408i,添加后如下图

然后点configure,然后在弹出的窗口中点确定,然后点OK

5.在axd中点击configure interface,弹出串口,在session file标签页配置script脚本文件init_sdram.txt,路径中不要中文

init_sdram.txt内容如下
  1. Setmem 0x53000000 0x00000000 32
  2. Setmem 0x4A000008 0xFFFFFFFF 32
  3. Setmem 0x4A00001C 0x000007FF 32
  4. Setmem 0x53000000 0x00000000 32
  5. Setmem 0x56000050 0x000055AA 32
  6. Setmem 0x4C000014 0x00000007 32
  7. Setmem 0x4C000000 0x00FFFFFF 32
  8. Setmem 0x4C000004 0x00061012 32
  9. Setmem 0x4C000008 0x00040042 32
  10. Setmem 0x48000000 0x22111120 32
  11. Setmem 0x48000004 0x00002F50 32
  12. Setmem 0x48000008 0x00000700 32
  13. Setmem 0x4800000C 0x00000700 32
  14. Setmem 0x48000010 0x00000700 32
  15. Setmem 0x48000014 0x00000700 32
  16. Setmem 0x48000018 0x0007FFFC 32
  17. Setmem 0x4800001C 0x00018005 32
  18. Setmem 0x48000020 0x00018005 32
  19. Setmem 0x48000024 0x008E0459 32
  20. Setmem 0x48000028 0x00000032 32
  21. Setmem 0x4800002C 0x00000030 32
  22. Setmem 0x48000030 0x00000030 32
Setmem 0x53000000 0x00000000 32 Setmem 0x4A000008 0xFFFFFFFF 32 Setmem 0x4A00001C 0x000007FF 32 Setmem 0x53000000 0x00000000 32 Setmem 0x56000050 0x000055AA 32 Setmem 0x4C000014 0x00000007 32 Setmem 0x4C000000 0x00FFFFFF 32 Setmem 0x4C000004 0x00061012 32 Setmem 0x4C000008 0x00040042 32 Setmem 0x48000000 0x22111120 32 Setmem 0x48000004 0x00002F50 32 Setmem 0x48000008 0x00000700 32 Setmem 0x4800000C 0x00000700 32 Setmem 0x48000010 0x00000700 32 Setmem 0x48000014 0x00000700 32 Setmem 0x48000018 0x0007FFFC 32 Setmem 0x4800001C 0x00018005 32 Setmem 0x48000020 0x00018005 32 Setmem 0x48000024 0x008E0459 32 Setmem 0x48000028 0x00000032 32 Setmem 0x4800002C 0x00000030 32 Setmem 0x48000030 0x00000030 32然后确定,然后关闭axd,

6.然后在ads中再次点击debug,如果此时弹出的画面是如下,就再次执行一下第 4 5步,貌似因为之前的配置没被保存


7.然后在ads中再次点击debug,如果此次弹出的画面如下,即要求定位到2440init.s文件,那就找到到ads工程源码中的这个文件,点击打开


点击打开之后,应该就可以出现以下窗口
接下来点击go或按F5 等调试就可以了

在操作过程中,点击debug后如果又出现一些问题,那么就执行一下configure interface或configure target


/***********************************************************************************************************************************************************************/
keil4 and jlinkv8
1.安装keil4 和jlink驱动Setup_JLinkARM_V408i.exe
2.打开keil4,新建一个工程,名为test

3.在接下来的框中选择samsung的s3c2440a芯片,如下

4.在接下来的框中选择是,使用官方启动脚本,如下

5.配置板子


target:


debug:

Ext_RAM.ini是手动在工程目录建立的文件,其内容如下
  1. /******************************************************************************/
  2. /* Ext_RAM.INI: External RAM (SDRAM) Initialization File */
  3. /******************************************************************************/
  4. // <<< Use Configuration Wizard in Context Menu >>> //
  5. /******************************************************************************/
  6. /* This file is part of the uVision/ARM development tools. */
  7. /* Copyright (c) 2005-2008 Keil Software. All rights reserved. */
  8. /* This software may only be used under the terms of a valid, current, */
  9. /* end user licence from KEIL for a compatible version of KEIL software */
  10. /* development tools. Nothing else gives you the right to use this software. */
  11. /******************************************************************************/
  12. FUNC void SetupForStart (void) {
  13. // Program Entry Point
  14. PC = 0x30000000;
  15. }
  16. FUNC void Init (void) {
  17. _WDWORD(0x4A000008, 0xFFFFFFFF); // Disable All Interrupts
  18. _WDWORD(0x53000000, 0x00000000); // Disable Watchdog Timer
  19. // Clock Setup
  20. // FCLK = 300 MHz, HCLK = 100 MHz, PCLK = 50 MHz
  21. _WDWORD(0x4C000000, 0x0FFF0FFF); // LOCKTIME
  22. _WDWORD(0x4C000014, 0x0000000F); // CLKDIVN
  23. _WDWORD(0x4C000004, 0x00043011); // MPLLCON
  24. _WDWORD(0x4C000008, 0x00038021); // UPLLCON
  25. _WDWORD(0x4C00000C, 0x001FFFF0); // CLKCON
  26. // Memory Controller Setup for SDRAM
  27. _WDWORD(0x48000000, 0x22000000); // BWSCON
  28. _WDWORD(0x4800001C, 0x00018005); // BANKCON6
  29. _WDWORD(0x48000020, 0x00018005); // BANKCON7
  30. _WDWORD(0x48000024, 0x008404F3); // REFRESH
  31. _WDWORD(0x48000028, 0x00000032); // BANKSIZE
  32. _WDWORD(0x4800002C, 0x00000020); // MRSRB6
  33. _WDWORD(0x48000030, 0x00000020); // MRSRB7
  34. _WDWORD(0x56000000, 0x000003FF); // GPACON: Enable Address lines for SDRAM
  35. }
  36. // Reset chip with watchdog, because nRST line is routed on hardware in a way
  37. // that it can not be pulled low with ULINK
  38. _WDWORD(0x40000000, 0xEAFFFFFE); // Load RAM addr 0 with branch to itself
  39. CPSR = 0x000000D3; // Disable interrupts
  40. PC = 0x40000000; // Position PC to start of RAM
  41. _WDWORD(0x53000000, 0x00000021); // Enable Watchdog
  42. g, 0 // Wait for Watchdog to reset chip
  43. Init(); // Initialize memory
  44. LOAD .\test.axf INCREMENTAL // Download program
  45. SetupForStart(); // Setup for Running
  46. g, main // Goto Main
/******************************************************************************/ /* Ext_RAM.INI: External RAM (SDRAM) Initialization File */ /******************************************************************************/ // <<< Use Configuration Wizard in Context Menu >>> // /******************************************************************************/ /* This file is part of the uVision/ARM development tools. */ /* Copyright (c) 2005-2008 Keil Software. All rights reserved. */ /* This software may only be used under the terms of a valid, current, */ /* end user licence from KEIL for a compatible version of KEIL software */ /* development tools. Nothing else gives you the right to use this software. */ /******************************************************************************/ FUNC void SetupForStart (void) { // Program Entry Point PC = 0x30000000; } FUNC void Init (void) { _WDWORD(0x4A000008, 0xFFFFFFFF); // Disable All Interrupts _WDWORD(0x53000000, 0x00000000); // Disable Watchdog Timer // Clock Setup // FCLK = 300 MHz, HCLK = 100 MHz, PCLK = 50 MHz _WDWORD(0x4C000000, 0x0FFF0FFF); // LOCKTIME _WDWORD(0x4C000014, 0x0000000F); // CLKDIVN _WDWORD(0x4C000004, 0x00043011); // MPLLCON _WDWORD(0x4C000008, 0x00038021); // UPLLCON _WDWORD(0x4C00000C, 0x001FFFF0); // CLKCON // Memory Controller Setup for SDRAM _WDWORD(0x48000000, 0x22000000); // BWSCON _WDWORD(0x4800001C, 0x00018005); // BANKCON6 _WDWORD(0x48000020, 0x00018005); // BANKCON7 _WDWORD(0x48000024, 0x008404F3); // REFRESH _WDWORD(0x48000028, 0x00000032); // BANKSIZE _WDWORD(0x4800002C, 0x00000020); // MRSRB6 _WDWORD(0x48000030, 0x00000020); // MRSRB7 _WDWORD(0x56000000, 0x000003FF); // GPACON: Enable Address lines for SDRAM } // Reset chip with watchdog, because nRST line is routed on hardware in a way // that it can not be pulled low with ULINK _WDWORD(0x40000000, 0xEAFFFFFE); // Load RAM addr 0 with branch to itself CPSR = 0x000000D3; // Disable interrupts PC = 0x40000000; // Position PC to start of RAM _WDWORD(0x53000000, 0x00000021); // Enable Watchdog g, 0 // Wait for Watchdog to reset chip Init(); // Initialize memory LOAD .\test.axf INCREMENTAL // Download program SetupForStart(); // Setup for Running g, main // Goto Main 上面倒数第三行是需要改动的,在本例中是test.axf。一般为工程名.axf。编译输出窗口也有指示,如下。

另外,此文件还规定了pc的开始指向,在debug图中点击ext_ram.ini右侧的edit,如下

可以编辑此文件,有两种编辑方式:文本和图形。如下

可见设置pc要指向0x30000000,即代码段的起始地址。而代码段区域是在target标签页设定,见上面target图(即read only memory area,但也放在了sdram中)

utilities:


6.选择file/new,新建一个文件,并保存为main.c

并将此文件加入工程中,如下


7.编辑main.c,输入如下测试代码
  1. #include
  2. void delay(int x)
  3. { int i = 0;
  4. while(x--){
  5. for(i=0;i<5000;i++){
  6. ;
  7. }
  8. }
  9. }
  10. int main()
  11. {
  12. while(1)
  13. {
  14. GPBCON|=(1<<2*5);//GPB5 LED1,0 on
  15. GPBCON&=~(1<<11);
  16. GPBDAT&=~(1<<5);//light on
  17. delay(100);
  18. GPBDAT|=(1<<1*5);//light off
  19. delay(100);
  20. GPBCON|=(1<<2*6);//GPB6 LED2
  21. GPBCON&=~(1<<13);
  22. GPBDAT&=~(1<<6);
  23. delay(100);
  24. GPBDAT|=(1<<1*6);
  25. delay(100);
  26. GPBCON|=(1<<2*7);//GPB7 LED3
  27. GPBCON&=~(1<<15);
  28. GPBDAT&=~(1<<7);
  29. delay(100);
  30. GPBDAT|=(1<<1*7);
  31. delay(100);
  32. GPBCON|=(1<<2*8);//GPB8 LED4
  33. GPBCON&=~(1<<17);
  34. GPBDAT&=~(1<<8);
  35. delay(100);
  36. GPBDAT|=(1<<1*8);
  37. delay(100);
  38. GPBCON|=(1<<2*0);//GPB0 BUZZER, 1 on
  39. GPBCON&=~(1<<1);
  40. GPBDAT|=(1<<1*0);
  41. delay(100);
  42. GPBDAT&=~(1<<0);
  43. delay(100);
  44. }
  45. }
#include void delay(int x) { int i = 0; while(x--){ for(i=0;i<5000;i++){ ; } } } int main() { while(1) { GPBCON|=(1<<2*5);//GPB5 LED1,0 on GPBCON&=~(1<<11); GPBDAT&=~(1<<5);//light on delay(100); GPBDAT|=(1<<1*5);//light off delay(100); GPBCON|=(1<<2*6);//GPB6 LED2 GPBCON&=~(1<<13); GPBDAT&=~(1<<6); delay(100); GPBDAT|=(1<<1*6); delay(100); GPBCON|=(1<<2*7);//GPB7 LED3 GPBCON&=~(1<<15); GPBDAT&=~(1<<7); delay(100); GPBDAT|=(1<<1*7); delay(100); GPBCON|=(1<<2*8);//GPB8 LED4 GPBCON&=~(1<<17); GPBDAT&=~(1<<8); delay(100); GPBDAT|=(1<<1*8); delay(100); GPBCON|=(1<<2*0);//GPB0 BUZZER, 1 on GPBCON&=~(1<<1); GPBDAT|=(1<<1*0); delay(100); GPBDAT&=~(1<<0); delay(100); } } 按下ctrl + F5开始调试-------开关拨到nand测
refer to

一些位操作

某位置1,其余位不变:如置GPBCON第10位1,其余不变 (从第0位开始算起)
GPBCON |= (1<<10);
某连续几位置1,其余位不变:如置GPBCON第10,11位1,其余不变
GPBCON |= (3<<10);

如果置bit0,可以GPBCON |=1;
GPBCON |= ~0 ; 或直接 GPBCON= 0xFFFFFFFF;//这样不太好不如 GPBCON|= ~0


某位清0,其余位不变:如清GPBCON第10位0,其余不变(从第0位开始算起)
GPBCON &= ~(1<<10);
某连续几位清0,其余位不变:如清GPBCON第10,11位0,其余不变
GPBCON &= ~(3<<10);

GPBCON &= ~1;
所有位清零 GPBCON&=0 ; 或直接 GPBCON=0;

同时某位清零和置1,而其他位不变
置GPBCON第10位为1,清GPBCON第11位为0,置GPBCON第12位为1
GPBCON =GPBCON |(1<<10)& (~(1<<11)) |(1<<12);
也可以
GPBCON|= 0x05<<10;//或许不能保证第11位清零(如果原来第11位=1,执行后仍为1)

从位组合数据,8位
data=0;//组合之前先清零
for(i=0;i<8;i++){
data<<1;
data |= bit_value;
}


读取中间某几位
如 val = rCLKDIVN;
m = (val>>1)&3;//读取bit2 bit1到m
switch (m) {
case 0:
HCLK = FCLK;
break;
case 1:
HCLK = FCLK>>1;
break;
case 2:
if(s&2)
HCLK = FCLK>>3;
else
HCLK = FCLK>>2;
break;
case 3:
if(s&1)
HCLK = FCLK/6;
else
HCLK = FCLK/3;
break;
}



keil c中嵌入汇编--c51
1.在c代码中加入汇编标志,比如
main()
{ InitAll();
#pragma ASM
SETB P3.5 //buzzer on
NOP
#pragma ENDASM

ctrlprocess();
}
2.设置一下
在 Project 窗口中包含汇编代码的 C 文件上右键,选择“Options for ...”,点击右边的“Generate Assembler SRC File”和“Assemble SRC File”,使检查框由灰色变成黑色(有效)状态;如下



keil c中嵌入汇编--arm
按照如下方式直接加入代码即可
__asm
{
mov r0,#1
mov r1,#0x56000014 //buzzer on
strb r0 ,[r1]
}
复杂一点的例子参考
http://bbs.mcu123.net/bbs/archiver/tid-7777.html
阅读(1808) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

kangear2013-02-03 14:11:23

学习了,对我有帮助!!!