[SOLVED] Unable to jump to RAM address using 'G' command.

Discussion around product based on ARM Cortex M4 core.

Moderators: nferre, ncollot

sonyqrio
Posts: 9
Joined: Mon Sep 02, 2013 6:58 pm

[SOLVED] Unable to jump to RAM address using 'G' command.

Mon Oct 03, 2016 6:04 am

Hello,

I am unable to jump to and execute from an arbitrary RAM address on my Cortex-M4 using the SAM-BA. The part number is ATSAM4S16B.

I have successfully loaded the SAM-BA over USART0 and it responds to commands as expected. I can use the 'S' command to move data from USART0 into RAM at any location of my choosing. The chip is verifiably running out of ROM and I've verified that I've loaded some little-endian thumb machine code for the armv7-m architecture into RAM at address 0x2001000. When I jump to 0x2001001 (for thumb), however, the subroutine never returns. I've also tried omitting the thumb bit from the address, but that yields the same behavior. What's even more odd is that if I give it the instructions 'movs r0, lr' and 'bx r0', it doesn't work. But if I stick two or more nop's in between those two instructions, it appears to return from the subroutine successfully (i.e. the chip returns to the SAM-BA). However, no code that I stick in-between those instructions seems to execute. I think this has something to do with movs generating a 32-bit Thumb2 instruction, but it doesn't appear to be an alignment issue. I've used multiple load and store instructions to try and write debug values to RAM and read them back using the SAM-BA, but none of those efforts have succeeded. I'm so stuck, I've begun scouring the datasheet for register values that might prevent execution from RAM, but that seems absurd.

I've tried compiling many different ways, adjusting the endianness, and changing the target architecture, all with no avail. My security bit is cleared. The baud rate is correct, so the clock must have been detected appropriately (I'm using a 20 MHz external clock). The voltage to the chip and its peripherals are all correct.

Let me know if any of you may have a clue as to why I'm observing this behavior.

Thanks!
Last edited by sonyqrio on Wed Oct 05, 2016 8:03 pm, edited 1 time in total.
sonyqrio
Posts: 9
Joined: Mon Sep 02, 2013 6:58 pm

Re: Unable to jump to RAM address using 'G' command from SAM

Wed Oct 05, 2016 8:03 pm

I ended up figuring it out.

The SAM_BA actually ends up dereferencing the address given to it + 4 before performing the jump. This is so that the reset vector table can be remapped to where the 'applet' was loaded. On chip reset, the applet would be jumped to without having to invoke it again from the SAM_BA. So, by restructuring my assembly to have two words above my instructions, with the second word as the address of the first instruction in my routine, everything now behaves as expected.

So, basically, construct your applet as if it were a real firmware image for the Cortex-M4 and use the SAM_BA to 'GO' to its load address without the thumb bit set.

Return to “SAM4 Cortex-M4 MCU”

Who is online

Users browsing this forum: No registered users and 1 guest