This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Problem running copied code into flash

Hi everyone,

So I have a question.

I have a ARM-M4 and for what I can tell this has both ARM and Thumb assembly. Meaning sometimes it interprets a 32 bit instruction as 2 16bit ones, some of the times.

How does that work? How does it know how to go about it?

I ask this because of a project.

I have a bootloader like code. And another application code.
I configured the linker in the application code to start at 0x4000. To avoid developing the communication already, I converted the binary to a C array.

I pasted that array as a const in the bootloader code. The bootloader test code as of now just copies the array into the flash at 0x4000 and changes the vector table address to 0x4000 after that. Once all that's done, it jumps the PC to 0x4000.
The jump is done this way - I created a empty function at 0x4000. This way I just have to call it to start the app code.

The problem seems to be that the first instruction is 32bits. It seems the PC is jumping each 16bits instead of each 32. And after a few jumps it just go crazy to a really big address in the RAM.
I checked the memory and the copy was successful, exactly the same as the app code at 0x4000.

Parents
  • The Cortex-M series of embedded controllers does not support ARM instructions, it only supports Thumb-2 instructions. The instructions can be either 16 or 32 bits long but the 32 bit ones can be on halfword boundaries unlike ARM instructions. For instance a branch and link to a subroutine would be very limited if it had to fit into 16 bits. The embedded processors deal with memory and interrupts rather differently from the applications processors which support ARM instructions as well as Thumb-2 ones.

    The Thumb-2 instruction set is an extension of the original Thumb. If you look up the documentation centre on the arm website  it is a Cortex-M4 processor and the ARM architecture is ARMv7-M, and the supplier will have specific documentation for the chip.

Reply
  • The Cortex-M series of embedded controllers does not support ARM instructions, it only supports Thumb-2 instructions. The instructions can be either 16 or 32 bits long but the 32 bit ones can be on halfword boundaries unlike ARM instructions. For instance a branch and link to a subroutine would be very limited if it had to fit into 16 bits. The embedded processors deal with memory and interrupts rather differently from the applications processors which support ARM instructions as well as Thumb-2 ones.

    The Thumb-2 instruction set is an extension of the original Thumb. If you look up the documentation centre on the arm website  it is a Cortex-M4 processor and the ARM architecture is ARMv7-M, and the supplier will have specific documentation for the chip.

Children