ljxh401的笔记 https://passport2.21ic.com/?150030 [收藏] [复制] [RSS]

日志

2440 在MDK平台上点亮LED

已有 1884 次阅读2009-12-20 05:51 |系统分类:单片机| 2440, MDK, JLINK

买了一个友善之臂的mini2440的板子,


2440都是玩linux 或者 wince的,而且即使是裸奔 也在ads上面,我十分不爽ads,


喜欢IAR(在avr上面,编译质量一流gcc无法比),MDK(keil的51),因为前段时间学习stm32,所以安装了mdk的环境,所以目标用mdk来移植ucos


但是我先想移植ucos过去,


习惯的单片机的从底层往上走的思想,在这里发表博客 就是为了使得自己一步一步往上走


首先来玩点亮一个 led


led的连线为 nXBACK/GPB5 --led--res--vdd3.3v


首先创建一个 2440的项目


Project-->New uVision Project  名称为 2440_led   


然后cpu选择 s3c2440a


采用mdk默认的启动代码


(这个代码有点不爽的,他是以用户模式进入main函数的,在用户模式修改cache是会出错误的,但是可以点亮led,先点灯再说)


以下是各种设置


定义程序在内存中的位置,


UploadFiles/2009-12/201424230363.jpg


定义使用J-LINK进行调试


UploadFiles/2009-12/201427565240.jpg


定义下载到ram中运行,不用烧录flash


UploadFiles/2009-12/201428964263.jpg


在J-LINK设置的时候 要对系统进行一次初始化 使用文件   Ext_RAM.ini


因为J-LINK  要将程序下载到sdram中,cpu必须将sdram进行设置,线宽,等待时间等等


文件如下:


/******************************************************************************/
/* 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) {


// <o> Program Entry Point
  PC = 0x30000000;
}



FUNC void Init (void) {


  _WDWORD(0x53000000, 0x00000000);      // Disable Watchdog Timer
  _WDWORD(0x4A000008, 0xFFFFFFFF);      // Disable All Interrupts
  _WDWORD(0x4A00001C, 0X000007FF);
 
                                        // Clock Setup
                                        // FCLK = 300 MHz, HCLK = 100 MHz, PCLK = 50 MHz
  _WDWORD(0x4C000000, 0x00FFFFFF);      // LOCKTIME
  _WDWORD(0x4C000004, 0x0005C042);      // MPLLCON


                                        // Memory Controller Setup for SDRAM
  _WDWORD(0x48000000, 0x22111120);      // BWSCON
  _WDWORD(0x48000004, 0x00000700);      // BWSCON
  _WDWORD(0x48000008, 0x00000700);      // BWSCON
  _WDWORD(0x4800000C, 0x00000700);      // BWSCON
  _WDWORD(0x48000010, 0x00000700);      // BWSCON
  _WDWORD(0x48000014, 0x00000700);      // BWSCON
  _WDWORD(0x48000018, 0x00000700);      // BWSCON
  _WDWORD(0x4800001C, 0x00018005);      // BWSCON
  _WDWORD(0x48000020, 0x00018005);      // BWSCON
  _WDWORD(0x48000024, 0x008E0459);      // BWSCON
  _WDWORD(0x48000028, 0x00000032);      // BWSCON
  _WDWORD(0x4800002C, 0x00000030);      // BWSCON
  _WDWORD(0x48000030, 0x00000030);      // BWSCON


  //_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 Led.axf INCREMENTAL         // Download program
SetupForStart();                        // Setup for Running
g, main                                 // Goto Main


准备工作差不多了,下面开始写自己的程序了


#include <S3C2440.h>
int  main (void)
{
    int i;


    GPBCON &=~((0x03L)<<10);GPBCON |=(0x01L)<<10 ;
    GPBDAT &= ~(1<<5);


    while (1){
        //GPBDAT |= 1;
     GPBDAT &= ~(1<<5);
        for (i = 0; i < 200000; i++);
        //GPBDAT &= ~1;
     GPBDAT |= (1<<5);
        for (i = 0; i < 200000; i++);
    }
 //return  0;
}


由axf 生成 bin


UploadFiles/2009-12/20155644795.jpg


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)