Relocate vector table to ITCM

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

Relocate vector table to ITCM

Jump to solution
4,742 Views
Davidino
Contributor IV

 

Goodmorning,

I'm a newbie nxp processor, I'm using imxrt1064-evk board and SDK version 2.9.1

I'm trying to move the IVT to RAM in order to have an increase with the performances. Looking at several threads in the forum, I didn't find a guide for that. So what I did is:

  1. Partition a RAM block from ITCM called SRAM_ITC_IVT that can contain the vector tableNuova immagine bitmap.bmp
  2. Using managed linker script to configure memory RAM_ITC_IVT as a KEEP(*(.isr_vector))Nuova immagine bitmap (2).bmp
  3. Copy the vector table from rom to ram and change the location pointed by SCB->VTOR

 

 

 

#define TABLE_SIZE	173

uint32_t ramVector[TABLE_SIZE+1] __attribute__((aligned(512))) __attribute__((section(".isr_vector")));

/*!
 * @brief Main function
 */
int main(void)
{
    __disable_irq();
    memcpy(ramVector, (uint32_t*)SCB->VTOR, sizeof(uint32_t) * TABLE_SIZE);
    SCB->VTOR = (uint32_t)ramVector;
    __enable_irq();

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_InitBootClocks();
    .....

 I didn't change anything else. Is it correct?

Thank you a lot,

Davidino

0 Kudos
Reply
1 Solution
4,657 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
1) Can you help me to sort out the above errors? Don't I need to partition the RAM for this, right?
-- To provide the fastest possible support, I'd highly recommend you to refer to the hello_demo code, it has integrated the BOARD_RelocateVectorTableToRam function successfully.
2) If I change the project configuration from nohost to none, can I expect an improvement in the performance?
-- No, I'm afraid not.
3) BOARD_RelocateVectorTableToRam function can copy the vector table to RAM from flash, and it needs to copy the corresponding interrupt service routines to the RAM too if you want to expect the performance boost up.
In MCUXpresso IDE User Guide, it illustrates how to place specific functions into RAM Blocks and you can give it a try.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

View solution in original post

0 Kudos
Reply
7 Replies
3,125 Views
Steve6745
Contributor I

Hi,

Thanks for this question and solution which helped me implement something similar on an RT1062 micro. However a problem occurred, the solution to which might help others attempting something similar. I believe that the alignment of the vector table needs to be 1024 not 512 because, as described in the arm documentation https://developer.arm.com/documentation/dui0646/c/The-Cortex-M7-Processor/Exception-model/Vector-tab...

Steve6745_0-1680072136744.png

The alignment needs to be the next power-of-two up from the size of the vector table. In the case of a vector table with 170-180 vectors the next power of two is 256 and converting that from words to bytes give a byte alignment of 1024 rather than 512.

Hope this helps someone with a similar issue

Steve 

0 Kudos
Reply
4,658 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
1) Can you help me to sort out the above errors? Don't I need to partition the RAM for this, right?
-- To provide the fastest possible support, I'd highly recommend you to refer to the hello_demo code, it has integrated the BOARD_RelocateVectorTableToRam function successfully.
2) If I change the project configuration from nohost to none, can I expect an improvement in the performance?
-- No, I'm afraid not.
3) BOARD_RelocateVectorTableToRam function can copy the vector table to RAM from flash, and it needs to copy the corresponding interrupt service routines to the RAM too if you want to expect the performance boost up.
In MCUXpresso IDE User Guide, it illustrates how to place specific functions into RAM Blocks and you can give it a try.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

0 Kudos
Reply
4,644 Views
Davidino
Contributor IV

Hello jeremyzhou,

thank you very much for your help. Following the project example that you gave me I could move the vector table to ram correctly. Besides following the MCUXpresso guide I could move time critical functions to RAM (with attribute _RAMFUNC(RAM)) and it made a huge difference.

I've got only one last question before considering the case solved. In MCUExpresso guide they also explain how to move data in different ram section. I don't get the purpose of using __DATA(RAM2), __BSS(RAM2), __NOINIT(RAM2). I understand the difference among them but I don't get why I should use them since variables are already in RAM and the linker should take care of it automatically.

Thank you again for your help.

Davidino

0 Kudos
Reply
4,633 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thanks for your reply.
1) I don't get the purpose of using __DATA(RAM2), __BSS(RAM2), __NOINIT(RAM2). I understand the difference among them but I don't get why I should use them since variables are already in RAM and the linker should take care of it automatically.
-- These above different macros are used to make the linker tool allocate the variables and function to different sections, you can check the map file if you're interested in it.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

4,723 Views
Davidino
Contributor IV

After modyfing the Managed Linker Script as follow:

Nuova immagine bitmap.bmp

And the code as:

#define TABLE_SIZE	173

uint32_t __attribute__((section("RamVectorTable"))) __attribute__((aligned(512))) ramVector[TABLE_SIZE];

/*!
 * @brief Main function
 */
int main(void)
{
    __disable_irq();
    memcpy(ramVector, (uint32_t*)SCB->VTOR, sizeof(uint32_t) * TABLE_SIZE);
    SCB->VTOR = (uint32_t)ramVector;
    __enable_irq();

    /* Init board hardware. */
    BOARD_ConfigMPU();
    BOARD_InitPins();
    BOARD_InitBootClocks();
    ....

 I could allocate the vector in the right section (0-0x300) at address 0x0. However I didn't see any changes concerning the processor performance..

Am I missing something?

0 Kudos
Reply
4,694 Views
jeremyzhou
NXP Employee
NXP Employee

Hi,
Thank you for your interest in NXP Semiconductor products and for the opportunity to serve you.
Sorry for reply late.
1) Please refer to the below code to copy the vector table to RAM from flash.

void BOARD_RelocateVectorTableToRam(void)
{
    uint32_t n;
    uint32_t irqMaskValue;

    irqMaskValue = DisableGlobalIRQ();

    SCB_DisableDCache();
    SCB_DisableICache();

    /* Copy the vector table from ROM to RAM */
    for (n = 0; n < ((uint32_t)0x400) / sizeof(uint32_t); n++)
    {
        g_vectorTable[n] = __VECTOR_TABLE[n];
    }

    /* Set application defined stack pointer */
    volatile unsigned int vStackTop = (unsigned int)&__StackTop;
    g_vectorTable[0]                = vStackTop;

    /* Point the VTOR to the position of vector table */
    SCB->VTOR = (uint32_t)g_vectorTable;
    __DSB();

    SCB_EnableICache();
    SCB_EnableDCache();

    EnableGlobalIRQ(irqMaskValue);
}


2) Actually, I don't think the performance will boost obviously just by relocating the vector table.
So please refer to the application note to learn how to optimize the system performance running on the different memory devices.
Have a great day,
TIC

-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!

 

- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

4,688 Views
Davidino
Contributor IV

Hello jeremyzhou,

thank you for your answer. I decided to move vector table to ITCM because it's suggested in document Using the i.MX RT FlexRAM. It states:

3.1.2.1. Code memory footprint
The interrupt vector table and a couple of critical interrupt service routines must be placed in the ITCM (a 64-bit single-cycle access memory can pre-fetch 64-bit, 4 x 16-bit, or 2 x 32-bit instructions) to speed up its execution time. The interrupt vectors and corresponding interrupt service routines take 46 kB of memory.

That said, I tried your function but I get some errors:

error: '__Vectors' undeclared (first use in this function)
error: '__StackTop' undeclared (first use in this function); did you mean 'vStackTop'?

Regarding the document https://www.nxp.com/docs/en/application-note/AN12437.pdf, together with

https://www.nxp.com/docs/en/quick-reference-guide/MCUXpresso_IDE_SWO_Trace.pdf

and https://mcuoneclipse.com/2019/06/03/swo-with-nxp-i-mx-rt1064-evk-board/

I'm reading it altough I don't find easy to find out which function and data put in ITCM and DTCM respectively.

I have two questions:

Can you help me to sort out the above errors? Don't I need to partition the RAM for this, right?

If I change the project configuration from nohost to none, can I expect an improvement with the performance?

Thank you.

0 Kudos
Reply