以AT91SAM7S256为例用Keil MDK创建从RAM启动的简单应用

安装MDK5 和 ARM7/ARM9支持包
https://armkeil.blob.core.windows.net/eval/MDK531.EXE
https://armkeil.blob.core.windows.net/legacy/MDK79525.EXE

准备 RAM.ini

FUNC void Setup (void) {
  PC = 0x00200000;
}

_WDWORD(0xFFFFFD44, 0x00008000);     // WDT_WDMR: Disable Watchdog

// Switching from Slow Clock to Main Oscillator for faster Download
_WDWORD(0xFFFFFC20, 0x00000601);     // PMC_MOR: Enable Main Oscillator
_sleep_(10);                         // Wait for stable Main Oscillator
_WDWORD(0xFFFFFC30, 0x00000001);     // PMC_MCKR: Switch to Main Oscillator

LOAD %L INCREMENTAL       // Download

Setup();                             // Setup for Running

g, main
准备Main.c
此应用是一个MCU的hello world, 用GPIO驱动LED闪烁
#include "AT91SAM7S256.h"
#define LED_A (1U<<0) // PA0, pin 48
#define LED_B (1U<<1) // PA1, pin 47

void sleep_ms(unsigned int msec)
{
  volatile unsigned int i;
  for (i = 0; i < 1000 * msec; i++) {
    __asm ("NOP");
  }
}

int main(void) {
  /* Configure the pins as outputs */
  AT91C_BASE_PIOA->PIO_OER = (LED_A | LED_B);
  /* Enable PIOC control on the pins*/
  AT91C_BASE_PIOA->PIO_PER = (LED_A | LED_B);
  /* Disable pull-ups */
  AT91C_BASE_PIOA->PIO_PPUDR = (LED_A | LED_B);

  while(1)
  {
    /* Turn LED on, high level */
    AT91C_BASE_PIOA->PIO_SODR = LED_A;
    sleep_ms(1);

    /* Turn LED off, low level */
    AT91C_BASE_PIOA->PIO_CODR = LED_A;
    sleep_ms(1);
  }
}

开启MDK,新建Project,选择存储位置
选择设备,从Legacy Device Database里选取AT91SAM7S256
同意复制启动文件SAM7.s到项目中
在 左侧项目管理选择Target1, 右键选取Manage Project Items
双击Target1,将其改名为Flash, 新增加一个RAM的Target. 将Source Group 1改名为Startup, 新增一个Source的Group,并增加一个Main.c的文件
项目左侧,选中RAM这个Target,右键选取Options for RAM Target
切换到Linker这个标签页
取消选中Use Memory Layout from Target Dialog, 在右侧设置R/O Base为0x00200000, R/W Base为0x00202000, 删除Scatter File, 也就是留空
切换到Debug标签
选中 Use ULink2/ME ARM Debugger,   取消 选择 Load Application at Startup,  添加Initilization File, 选择 RAM.ini
切换到Utilities, 取消Update Target before Debugging
点击菜单栏,Project–Build Target, 然后,Debug–Start Debug Session即可开始调试

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注