MDK 代码烧录到RAM区运行
- 环境
- 配置
- 设置分散加载文件
- 启动文件修改
- 设置外部调试器烧录
- 建立函数入口
- 半主机问题导致BKPT 0xAB
有一个需求,除了IAR以及GCC的版本工程还需要MDK版本,为了实现最小的工程环境,flash烧录算法也没有,这时需要直接跑在RAM中
这里以一个最小的平台为例(不含外设驱动)
关联 制作flash算法文件参考
环境
MDK:v5.39
编译器:armclang
平台:arm cortex-m3
配置
我的内存地址:0x10000000 - 0x100FFFFF
编写调试配置文件(设置栈、PC、中断向量表)RAM_Debug.ini
/*----------------------------------------------------------------------------* Name: RAM_Debug.ini* Purpose: RAM Debug Initialization File* Note(s):*----------------------------------------------------------------------------* This file is part of the uVision/ARM development tools.* 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.** This software is supplied "AS IS" without warranties of any kind.** Copyright (c) 2008-2011 Keil - An ARM Company. All rights reserved.*----------------------------------------------------------------------------*//*----------------------------------------------------------------------------Setup() configure PC & SP for RAM Debug*----------------------------------------------------------------------------*/
FUNC void Setup (void) {SP = _RDWORD(0x10000000); // Setup Stack PointerPC = _RDWORD(0x10000004); // Setup Program Counter_WDWORD(0xE000ED08, 0x10000000); // Setup Vector Table Offset Register
}FUNC void OnResetExec (void) { // executes upon software RESETSetup(); // Setup for Running
}load %L incremental // load %L incremental 增量下载模式节省时间Setup(); // Setup for Runningg, main
设置应用
设置分散加载文件
前512KB用于代码段只读
后512KB用于变量
命名xxx.sct
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************LR_IROM1 0x10000000 0x80000 { ; load region size_regionER_IROM1 0x10000000 0x80000 { ; load address = execution address*.o (RESET, +First)*(InRoot$$Sections).ANY (+RO).ANY (+XO)}RW_IRAM1 0x10080000 0x7F000 { ; 512KB Data;*(USE_VAR_SPACE).ANY (+RW +ZI)};ARM_LIB_HEAP 0x100FF000 EMPTY 0x800 {;};ARM_LIB_STACK 0x100FF800 EMPTY 0x800 {;};ARM_LIB_STACKHEAP 0x100FF000 EMPTY 0x1000 {;}
}
设置应用
这里保持一致
启动文件修改
命名为xxx.s
Stack_Size EQU 0x400AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp; <h> Heap Configuration
; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>Heap_Size EQU 0x400AREA HEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_Mem SPACE Heap_Size
__heap_limitPRESERVE8THUMB; Vector Table Mapped to Address 0 at ResetAREA RESET, DATA, READONLYEXPORT __VectorsEXPORT __Vectors_EndEXPORT __Vectors_SizeIMPORT SysTick_Handler__Vectors DCD __initial_sp ; Top of StackDCD Reset_Handler ; Reset HandlerDCD NMI_Handler ; NMI HandlerDCD HardFault_Handler ; Hard Fault HandlerDCD MemManage_Handler ; MPU Fault HandlerDCD BusFault_Handler ; Bus Fault HandlerDCD UsageFault_Handler ; Usage Fault HandlerDCD 0 ; ReservedDCD 0 ; ReservedDCD 0 ; ReservedDCD 0 ; ReservedDCD SVC_Handler ; SVCall HandlerDCD DebugMon_Handler ; Debug Monitor HandlerDCD 0 ; ReservedDCD PendSV_Handler ; PendSV HandlerDCD SysTick_Handler ; SysTick Handler; External Interrupts;DCD WWDG_IRQHandler ; Window WatchDog interrupt ( wwdg1_it)__Vectors_End__Vectors_Size EQU __Vectors_End - __VectorsAREA |.text|, CODE, READONLY; Reset handler
Reset_Handler PROCEXPORT Reset_Handler [WEAK]IMPORT SystemInitIMPORT __mainLDR R0, =SystemInitBLX R0LDR R0, =__mainBX R0ENDP; Dummy Exception Handlers (infinite loops which can be modified)NMI_Handler PROCEXPORT NMI_Handler [WEAK]B .ENDP
HardFault_Handler\PROCEXPORT HardFault_Handler [WEAK]B .ENDP
MemManage_Handler\PROCEXPORT MemManage_Handler [WEAK]B .ENDP
BusFault_Handler\PROCEXPORT BusFault_Handler [WEAK]B .ENDP
UsageFault_Handler\PROCEXPORT UsageFault_Handler [WEAK]B .ENDP
SVC_Handler PROCEXPORT SVC_Handler [WEAK]B .ENDP
DebugMon_Handler\PROCEXPORT DebugMon_Handler [WEAK]B .ENDP
PendSV_Handler PROCEXPORT PendSV_Handler [WEAK]B .ENDP
; SysTick_Handler PROC
; EXPORT SysTick_Handler [WEAK]
; B .
; ENDPDefault_Handler PROC;EXPORT WWDG_IRQHandler [WEAK];WWDG_IRQHandlerB .ENDPALIGN;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************IF :DEF:__MICROLIBEXPORT __initial_spEXPORT __heap_baseEXPORT __heap_limitELSEIMPORT __use_two_region_memoryEXPORT __user_initial_stackheap__user_initial_stackheapLDR R0, = Heap_MemLDR R1, =(Stack_Mem + Stack_Size)LDR R2, = (Heap_Mem + Heap_Size)LDR R3, = Stack_MemBX LRALIGNENDIFEND
设置外部调试器烧录
建立函数入口
/*** @brief 函数主入口**/
int main(void)
{return 0;
}
半主机问题导致BKPT 0xAB
MDK开启系统函数重定向功能
ref: https://developer.arm.com/documentation/ka002219/latest