Relocating Code and Data Using the MCUXpresso IDE

Showing results for 
Show  only  | Search instead for 
Did you mean: 

Relocating Code and Data Using the MCUXpresso IDE

Relocating Code and Data Using the MCUXpresso IDE

This document provides some sample codes and steps for relocating Code and Data into RAM/FLASH. Please look at them with projects in attachment. It is based on “MCUXpresso_IDE_User_Guide.pdf”, so about the understanding of some macros, you can check on that document.

This document is based on FRDM-K64, MCUXpressoIDE_10.0.2_411. You can use it on other chips too.


1. Introduce the “Memory configuration editor”

2.1. Relocating Data into RAM

2.1 Relocating Code into RAM

2.3 Relocating Code into Flash



Labels (1)

Hi Alice_Yang‌ , once the PROGRAM_FLASH location has been changed (e.g. from 0x0 to 0xa000 to support the bootloader), is there something else that needs to be changed to support debugging? For example, do I need to add code that sets SCB->VTOR to my application starting address?

I have followed your documentation on relocating application code and my application is loaded properly by the bootloader (flashed using blhost and j-link tools). However, after stepping through the application code and getting inside `CMSIS_I2CInterfaceTransfer()` a signal handler is called and I not able to debug any further. I don't see anything wrong in this function (for example, when it tries to release the I2C bus). Is this because VTOR is not set correctly?

After changing the PROGRAM_FLASH location back to 0x0 debugging single steps past the same code without issue.

Are more changes required after moving the application location in flash?

If I add the following to my application code loaded by the debugger, it appears to work again. Is this the correct change and approach?

int main(void)
// either, use the define from the linker map
extern const uint32_t __vectors_start__;
SCB->VTOR = (unsigned)&__vectors_start__;

// or, use the define from the startup_*.c code
extern void (* const g_pfnVectors[])(void);
SCB->VTOR = (unsigned)g_pfnVectors;


Hello Lucas,

Relocate vector table need to be done in Bootlaoder project, before jump to APP.



Relocate vector table need to be done in Bootlaoder project, before jump to APP.

Hi Alice, I understand the normal boot process. However, when debugging the CPU is reset and the debugger starts executing the application directly bypassing the bootloader. Therefore, the relocating of the vector table does not take place. This is why it appears that I have to do it manually in my application firmware. Is this the correct approach or should the GDB debugger scripts do it?

Alice_Yang‌, can you add a section on "Relocating Data into FLASH"? Specifically, a section on how split PROGRAM_FLASH to add the Bootloader Configuration Area at (BL_APP_VECTOR_TABLE_ADDRESS + 0x3C0) while also allowing .FlashConfig at offset 0x400 to be inserted by the managed linker? I can't seem to get the MCUXpresso managed linker to not overlap the FlashConfig section with program .text.

I seem to be experiencing the same issues as Lucas has mentioned. I however am using the ROM bootloader on a KL27. His request would benefit me greatly as well.

Could you please follow up on this Alice_Yang‌?

No ratings
Version history
Last update:
‎09-01-2017 03:27 AM
Updated by: