-1

I need to place my program at the address in memory 0x20000000. In the project options in Keil I opened the tab "Target" and set the following settings (screenshot is here --> https://i.stack.imgur.com/EPGru.png):

IROM1 start = 0x20000000
IROM1 size  = 0x400
IRAM1 start = 0x20001000
IRAM1 size  = 0x20000

This is my code, which I wish to place at the address I need:

STACK_TOP EQU 0x20000100
    AREA RESET, DATA, READONLY
    DCD STACK_TOP 
    DCD Start
    AREA PROGRAM, CODE, READONLY
    ENTRY
Start
    NOP
    NOP
    NOP
    b Start
END

After compilation I get 0 Errors and 0 Warnings:

*** Using Compiler 'V5.06 update 6 (build 750)', folder: 'C:\Program Files\Keil_v5\ARM\ARMCC\Bin'
Build target 'Target 1'
".\Objects\main.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed:  00:00:00

Then in debug mode, I found my hex commands at the address I needed (screenshot is here -> https://i.stack.imgur.com/Yb8aD.png):

     8:     NOP 
0x20000008 BF00      NOP      
     9:         NOP 
0x2000000A BF00      NOP      
    10:         NOP 
0x2000000C BF00      NOP      
    11:         b Start 
0x2000000E E7FB      B        0x20000008

But the problem is that I cannot execute it, since the program counter is always 0x00000000 and does not change in either the run mode or step-by-step mode. What have I done wrong?

artless noise
  • 21,212
  • 6
  • 68
  • 105
MadEvil
  • 41
  • 2
  • before you get into building such a program how do you plan to load and execute it? the parts boot from 0x00000000 using a vector table 0x20000000 is ram so it is not loaded with a progfram (normally) on reset so you have to run from 0x00000000 or some other flash space first then once the program is in ram you can branch to it. – old_timer Mar 06 '19 at 15:36
  • @old_timer, I need to run from the address 0x20000000. That's the whole point. – MadEvil Mar 06 '19 at 16:14
  • I fully understand that it is not possible to do that until you load the program into ram from somewhere, what is your plan for loading the program into ram. copying it from flash is trivial and that is one path we can take if you are loading the program in a different way then that means a different solution perhaps. how you are launching using the boot pins or config bits or other also determines what that entry code needs to look like for this to work. THEN you can talk about how to setup the code and linker script – old_timer Mar 06 '19 at 20:15
  • as far as this SO question goes you are not at the code and linker script step yet, you personally might be but you need to catch us up...note if you used gnu tools this is trivial but you might lose some libraries you are relying on or some C language extensions not in other compilers. – old_timer Mar 06 '19 at 20:15

2 Answers2

1

Presumably the abort handler points to address 0, and you end up in lockup state. You can't avoid using at least address 0x4 with Cortex-M. It is OK to have 0x2000001 at address 0x4. (if still rather incomplete).

A more complete implementation might be to write 0x20000101 to 0x4, and set VTOR to point to a vector table starting at 0x20000000 (which you will want to arrange to populate ASAP).

Sean Houlihane
  • 1,698
  • 16
  • 22
1

In debugging mode, you can see the binary loaded in RAM because Keil does that for you via the debugger, e.g. ULINK. However, this is only 1 time, the RAM content will be cleared in the next power cycle, and your binary will be lost the moment you reset the processor. The idea is that, you can place your program in RAM, but the binary has to be stored in the persistent/non-volatile memory (NVM).

The instructions to achieve what you need is provided in this article from Keil.

Note that you still need code in your NVM to bootstrap your application. It is impossible to run with an empty NVM with Cortex-M processors.

Your Program Counter is stuck at 0x00000000 because there is no vector table there to proceed. At startup, Cortex-M3 will look at the vector table (located at address 0x00000000 by default) and look for the starting address of Reset Handler (this address is stored at address 0x00000004). In the Reset Handler, you can copy your binary to RAM as shown in the article, then call the main program in RAM and run as normal.

DinhQC
  • 133
  • 10