This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Instructions to load program counter with a flash memory address in case of TM4C129DNCPDT

Other Parts Discussed in Thread: TM4C129DNCPDT, UNIFLASH

hI,

I want to load the program counter of my TM4C129DNCPDT with a register address of 0x2000 which of my flash memory.

Currently i am doing it in the below way:

__asm(" ldr r0, [r0, #4]")

But i found that when this instruction gets executed the PC register gets loaded with address 0x51e. I think it is based on some offset. Not sure.

Instead cannot i directly write the PC with 0x2000 like example:  load PC, 0x2000

Is there any instruction which can do it?

Thanks in advance

  • Hello Shrikant

    Did you use the sample code that were sent in the previous post from me?

    Regards

    Amit

  • Hi Amit,

    I am trying to use that also. But before doing it, i thought of using the existing things with correct code. As i found the bug in the existing code.

    Can you suggest any such instruction using which i can load PC with 0x2000

    like in 8085 we have register direct addressing modes in which we can directly give the address to load in the required register

  • Hi Amit,

    I had a look on the sample code sent by you. My code also do the same kind of clock settings and then i have jumping logic implemented which in your case is done by a function called cal_applicaiton. It is also using the same code that is written in call_applicaiton. Narrowing down to the problem i reached a point where i came to know that PC is not getting written with the application start address.

    Hence can you help me with some other set of assembly instructions to write the PC with apllication start address.

    Thanks.

  • Hi,

    Some observations for your problem(s):

    A) If you need to load registers with immediate values, (supposing you work with CCS if I remember well), aka:

    LDR R0,=0x1A2B3C4D ; (or equivalent #0x1A2B3C4D)

    you need the following approach (only for CCS):

    -declare this:

    IMDVAL .field 0X1A2B3C4D, 32

    -use it as:

    LDR R0, IMDVAL

    One more note here: the asm line used by you/Amit is as good as one setting PC, my opinion is to use this. Take into account where do you do such thing (stack problems)

    B) Did you linked your application with modified memory regions? (aka starting in flash from 0x2000 - or whatever is your value)? then examine the .map file and see if it is OK - your value 0x51e of coarse is not good, and more, being the address of the ResetISR function, should be an odd number, not even. Same can be checked also on .bin file.

    C) Some other posters had the same problem in the past - seems you did not searched the forum. Here it is one thread, with responses by TI's Dave Wilson:

    http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/p/46237/896536.aspx#896536

  • shrikant dhapke said:
    I want to load the program counter of my TM4C129DNCPDT with a register address of 0x2000 which of my flash memory.

    Doesn't the TM4C129DNCPDT only support THUMB mode?

    i.e. the least significant bit of the program counter must be set to indicate THUMB mode, otherwise a fault or lockup will occur.

    In which case does the code need to jump to address 0x2001 instead?

  • 6507.mapfile.docxHi Amit,

    First of all thanks for your reply.

    I am trying to use the above mehod or writing PC regtister and soon let you know my observations.

    I also had a look on my MAP file and have some queries regarding that.

    Actually i am flashing my apllication using UNIFLASH and XDS200 from memory address 0X2000 on flash memory of TM4C129DNCPDT. Then on CCS i start the debug of my boot loader verifier project which gets loaded into flash from address 0x0.

    When i see the MAP file after the debugger gets launched, it shows only the sized of my boot loader verifier project's binary which got loaded into flash from address 0x0. I saw the size under column "used". But as the flash memory is also containing my appllication's(where i want to jump to) binary from address 0x2000, so should not the size be more than that what it is showing?

    Also should the map file also contain information of application start address? I don't know much about what all a MAP file contains.

    Fore your reference i am attaching the MAP file of my project. Please have a look on it. I have copied its content to a word file for attaching.

    I am also attaching you some snapshots  step by step: Please have a look on them beow

    1. When  i start my debug session below is the state of CPU core registers, diassembly code and memory browser showing my aplication binary at address 0x2000. Please see below 3snapshots for these three cases seperately.

    2. moving on in debugging please see the below two snapshots for the diassembly and registers:

    3. Moving on into debugging. Showing the disassembly and register windows changes:

    4. Executing assembly statement where we actually loads the PC and tries to jump:

    5. Executing branch instruction and the register status at that time.

    6. As you can see that PC is having some different address and so as the R0. I manually changed contents in R0 from 0x51f to 0x2000(where i want to jump) and then executed the branch instruction. Here is what i get. It jumps to the 0x2000 location but as PC is not set with that location address it do not run my application code at that address.When i just click on the free run or resume button i get the hard fault/NMI error. Have a look on below snapshots:

    Can you think of what's the problem with PC not getting loaded with Proper value. Can you please suggest any solution. Please have a look on the MAP file attached also.

    Waiting for your reply.

     

  • Hello Shrikant

    The Flash Sector size is 16KB and you are loading the second jump to code at 0x2000 which is 8K. so when you load the main test at 0x0 it will erase the jump to code

    Keep the jump code at 0x10000

    Regards

    Amit

  • Hi Amit,

    Thanks for the reply. Do you mean to say that my application's(where i want to jump and execute it) binary should be kept at address 0x10000(ten thousand hexadecimal) on flash memory? I have tried to do it using UNIFLASH. I am getting below error:

    [17:22:32] Begin Writing flash memory operation.

    [17:22:32] Loading program at 0x10000: C:\Users\E9937226\Desktop\SampleProject.bin

    [17:22:32] ERROR >> CORTEX_M4_0: File Loader: Data verification failed at address 0x00010000 Please verify target memory and memory map.

    [17:22:32] ERROR >> CORTEX_M4_0: GEL: File: C:\Users\E9937226\Desktop\SampleProject.bin: a data verification error occurred, file load failed.

    [17:22:32] File: C:\Users\E9937226\Desktop\SampleProject.bin: a data verification error occurred, file load failed.

    [17:22:32] Operation Writing flash memory returned.

    What is going wrong?