我如何在Cortex-M3的(STM32)执行从RAM功能? [英] How do I execute a function from RAM on a Cortex-M3 (STM32)?

查看:2150
本文介绍了我如何在Cortex-M3的(STM32)执行从RAM功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Cortex-M3处理器(STM32)从RAM中执行的功能。该功能可以擦除和重写内置闪存,所以我肯定需要在RAM,但我怎么做呢?

I'm trying to execute a function from RAM on a Cortex-M3 processor (STM32). The function erases the and rewrites the internal flash, so i definitely needs to be in RAM but how do I do that?

我已经试过这就是:功能复制到使用的memcpy(检查它被正确对齐)RAM中的字节数组,设置一个函数指针指向字节数组中,然后调用的函数(指针)。

What I have tried is this: Copy the function to a byte array in RAM using memcpy (checking that it gets aligned correctly), setting a function pointer to point to the byte array an then calling the the function(pointer).

这工作得很好,也许10个指令(我可以按照与调试器执行),但是我得到一个错误总线和处理器复位。在第二次通过循环出现的错误母线所以code应罚款(因为它工作的第一道关口)。我想,越快RAM访问渣土了总线时序以某种方式...

This works fine for maybe 10 instructions (I can follow the execution with the debugger) but then I get a buss error and the processor resets. The buss error occurs on the second pass through a loop so the code should be fine (as it works the first pass). I'm thinking that the faster RAM access mucks up the buss timing in some way...

反正有没有做到这一点正确的方法是什么?如何将分散的文件看起来像在RAM中就自动功能(我使用的Keil uVision用于Cortex-M3)?

Anyway is there a correct way to do this? How would a scatter file look like that places a function in RAM automatically (I'm using Keil uVision for Cortex-M3)?

编辑:更多信息:
工具链:的RealView MDK-ARM V 4.10
编译:ARMCC v4.0.0.728
汇编:ARMASM v4.0.0.728
链接器:armlink将v4.0.0.728
处理器:STM32F103ZE

More info: Toolchain: RealView MDK-ARM V 4.10 Compiler: Armcc v4.0.0.728 Assembler: Armasm v4.0.0.728 Linker: ArmLink v4.0.0.728 Processor: STM32F103ZE

在IM preCISERR位在母线故障寄存器设置当复位发生。

The IMPRECISERR bit is set in the buss fault register when the reset happens.

推荐答案

在循环迭代失事可能是因为该功能跳转到一个绝对地址和相对到RAM中的新功能定位是没有的。将在该点访问原来的code位置的原因因为闪存擦除操作的总线错误?

The crash upon loop iteration is probably because the function is branching to an absolute address and is not relative to the new function location in RAM. Would accessing the original code location at that point cause a bus error because of the flash erase operation?

我相信你可以标记功能进行编译和复制通过附加 __ RAM 指令函数定义与CARM正确RAM。有关如何做同样的编译器的RealView看的执行功能RAM 的技术支持文章:

I believe you can mark a function to be compiled and copied to RAM correctly with CARM by appending the __ram directive to the function definition. For instruction on how to do the same with the RealView compiler see the EXECUTING FUNCTIONS IN RAM technical support article:

的μVision可以查找模块
  到该特定的存储区
  对话框的项目中输入 -
  选项​​ - 目标
即可。要做到这一点,对不对
  点击一个源文件(或文件组)
  并打开对话框选项 -
  属性
即可。然后选择内存
  根据地区的内存分配

µVision allows you to locate modules to specific memory areas that are entered in the dialog Project - Options - Target. To do so, right click on a source file (or file group) and open the dialog Options - Properties. Then select the memory regions under Memory Assignment.

有夹中的示例的 ARMExamplesRAM_Function

这应该生成启动code采取复制到RAM功能并正确连接到该位置的呼叫服务。否则,如果您需要动态复制任意函数到RAM中,然后看看编译位置无关code( PIC)随RealView。

That should generate startup code to take care of copying the function to RAM and linking calls to that location correctly. Otherwise, if you need to dynamically copy arbitrary functions to RAM, then look into compiling position independent code (PIC) with RealView.

这篇关于我如何在Cortex-M3的(STM32)执行从RAM功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆