其他分享
首页 > 其他分享> > 使用keil SDK方式点亮mini2440的led灯

使用keil SDK方式点亮mini2440的led灯

作者:互联网

最近在使用mini2440做开发,网上很多教程和实际操作不太一致,导致入门花费时间长。经过整理,目前mini2440点亮led灯方法有,keil mdk,linux环境编译,使用minitools下载即可。

mini2440分为nor flash和nand flash两种,一般小于4k程序可以直接运行,大于4K的程序需要预先加载引导程序,从存储位置拷贝至内存中。下面来说说mini2440究竟是如何点亮led灯的。

方法一:使用keil mdk的方式,首先下载MDK,使keil包含s3c2440这款芯片。根据该芯片创建工程,添加S3C2440.S文件。工程创建完成后,编写led.c文件代码如下

#define      rGPBCON     (*(volatile unsigned long *)0x56000010)
#define      rGPBDAT    (*(volatile unsigned long *)0x56000014)
#define      rGPBUP     (*(volatile unsigned long *)0x56000018)

#define GPB5_IN ~(3<<10)
#define GPB6_IN ~(3<<12)
#define GPB7_IN ~(3<<14)
#define GPB8_IN ~(3<<16)

#define GPB5_OUT (1<<10)
#define GPB6_OUT (1<<12)
#define GPB7_OUT (1<<14)
#define GPB8_OUT (1<<16)

#define LED1_ON ~(1<<5)
#define LED2_ON ~(1<<6)
#define LED3_ON ~(1<<7)
#define LED4_ON ~(1<<8)

#define LED1_OFF (1<<5)
#define LED2_OFF (1<<6)
#define LED3_OFF (1<<7)
#define LED4_OFF (1<<8)

void Led_Port_Init(void);
void Delay(int tt);

void main()
{
Led_Port_Init();

rGPBDAT |= (LED1_OFF|LED2_OFF|LED3_OFF|LED4_OFF);
rGPBDAT |= (LED1_OFF|LED2_OFF|LED3_OFF|LED4_OFF);

while(1)
{
    rGPBDAT = rGPBDAT&(LED1_ON);
    Delay(10);
    rGPBDAT = rGPBDAT|((LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF));
    Delay(10);
    rGPBDAT = rGPBDAT&(LED2_ON);
    Delay(10);
    rGPBDAT = rGPBDAT|((LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF));
    Delay(10);

    rGPBDAT = rGPBDAT&(LED3_ON);
    Delay(10);
    rGPBDAT = rGPBDAT|((LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF));
    Delay(10);

    rGPBDAT = rGPBDAT&(LED4_ON);
    Delay(10);
    rGPBDAT = rGPBDAT|((LED1_OFF)|(LED2_OFF)|(LED3_OFF)|(LED4_OFF));
    Delay(10);
    }
}

void Led_Port_Init(void)
{
rGPBCON &= ~((3<<10)|(3<<12)|(3<<14)|(3<<16));
rGPBCON |= (1<<10)|(1<<12)|(1<<14)|(1<<16);
}

void Delay(int tt)
{
int a,b;
for(a=0;a<=tt;a++)
for(b=0;b<=10000;b++);
}
View Code

完成编辑后进入到关键环节,就是配置界面要选择好。(需说明的是Keil MDK 支持Nor Flash下载和仿真状态,nand flash目前没找到下载方法)

                  图1 程序配置

 目标界面设置如改图1所示,从配置界面可以看出,程序将拷贝至ROM空间,空间大小为2M。芯片上电运行将程序拷贝至RAM地址空间0x30000000处大小为2M开始运行。

               图2  烧写驱动选择J-LINK / J-TRACE ARM

                 图3 配置Jlink的flash烧写函数

如图2、3所示,配置目标芯片的烧写函数,选择应用的nor flash芯片。Use Target Driver勾选,取消Use debug driver和Upadate Target选项勾选。

                 图3 使目标编译程序产生bin文件

               图4 勾选产生HEX File

其他界面如图3、图4所示。

                     图5 设置Ext_RAM.ini

设置完成后,编译程序,点击Load下载目标程序。下载目标前注意图5Ext_RAM.ini中的设置。函数设置如下:

/******************************************************************************/
/* 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.  */
/******************************************************************************/


0x200000

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
//CPSR = 0x00000063;                      // 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 obj\led.axf INCREMENTAL         // Download program
PC = 0x30000000;                       // Setup for Running

g, main                                 // Goto Main
View Code

 

注意修改该行代码与当前工程生成文件名一致,LOAD obj\led.axf INCREMENTAL         // Download program

标签:RAM,led,keil,flash,mini2440,WDWORD,Disable
来源: https://www.cnblogs.com/luxingsh/p/11965082.html