cancel
Showing results for 
Search instead for 
Did you mean: 

How to relocate Interrupt vector table from Flash to the internal SRAM for STM32L071CZ

SN
Associate II

Hi,

I'm facing a problem with remapping of the vector table to the internal SRAM from Flash. I am working with the STM32L071CZ (Cortex M0+)(using the IAR Workbench and CubeMX ) .

My __vector_table is presently at internal Flash @0x08000000

Presently trying to achieve that in the debug mode only of IAR workbench.

Do I need to modify stm32l071xx_flash.icf,startup_stm32l071xx.s ?

What are the changes required exactly?

Any document/guidance suggesting that will be of great help.

Thanks.

4 REPLIES 4

You need to do this why?

>>Do I need to modify stm32l071xx_flash.icf,startup_stm32l071xx.s ?

No, you need a table to be built by the linker.

>>What are the changes required exactly?

Depends on what you're trying to achieve

Typically you'd move up the base of RAM in the linker script to accommodate the table in RAM

memcpy() the table to 0x20000000

Then set SCB->VTOR = 0x20000000

For the non-plus CM0 your don't have the VTOR registers, and there you use the STM32's SYSCFG to remap/shadow the RAM at the 0x00000000 memory range. This becomes necessary when the base of the application is *not* 0x08000000

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi,

Thanks for your reply.

I tried to follow the same as mentioned in the document. Instead of CCMRAM I have used the SRAM , which starts at 0x20000000.

But while executing its going to Unknown Handler.

http://www.st.com/web/en/resource/technical/document/application_note/DM00083249.pdf.

  • Here is my linker file looks like:

/*###ICF### Section handled by ICF editor, don't touch! ****/

/*-Editor annotation file-*/

/* IcfEditorFile="$TOOLKIT_DIR$\config\ide\IcfEditor\cortex_v1_0.xml" */

/*-Specials-*/

define symbol __ICFEDIT_intvec_start__ = 0x08000000;

/*-Memory Regions-*/

define symbol __ICFEDIT_region_ROM_start__ = 0x08000000 ;

define symbol __ICFEDIT_region_ROM_end__  = 0x0802FFFF;

define symbol __ICFEDIT_region_RAM_start__ = 0x20000000;

define symbol __ICFEDIT_region_RAM_end__  = 0x20004FFF;

/*-Sizes-*/

define symbol __ICFEDIT_size_cstack__ = 0x400;

define symbol __ICFEDIT_size_heap__  = 0x200;

/**** End of ICF editor section. ###ICF###*/

define symbol RAM_intvec_start = 0x20000000;

define memory mem with size = 4G;

define region ROM_region   = mem:[from __ICFEDIT_region_ROM_start__  to __ICFEDIT_region_ROM_end__];

define region RAM_region   = mem:[from __ICFEDIT_region_RAM_start__  to __ICFEDIT_region_RAM_end__];

define block CSTACK  with alignment = 8, size = __ICFEDIT_size_cstack__  { };

define block HEAP   with alignment = 8, size = __ICFEDIT_size_heap__   { };

initialize by copy { readwrite, section .intvec_RAM, section .ram, ro object stm32l0xx_it.o };

do not initialize { section .noinit };

place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec };

place at address mem: RAM_intvec_start { section .intvec_RAM };

place in RAM_region {section .ram };

place in ROM_region  { readonly };

place in RAM_region  { readwrite,

            block CSTACK, block HEAP };

  • To remap the vector table to RAM :

In SystemInit function which is called from the startup file before the reset handler , I remap the vector table to SRAM by modifying the VTOR register as follows:

void SystemInit (void)

{   

/*!< Set MSION bit */

 RCC->CR |= (uint32_t)0x00000100;

 /*!< Reset SW[1:0], HPRE[3:0], PPRE1[2:0], PPRE2[2:0], MCOSEL[2:0] and MCOPRE[2:0] bits */

 RCC->CFGR &= (uint32_t) 0x88FF400C;

 

 /*!< Reset HSION, HSIDIVEN, HSEON, CSSON and PLLON bits */

 RCC->CR &= (uint32_t)0xFEF6FFF6;

  

 /*!< Reset HSI48ON bit */

 RCC->CRRCR &= (uint32_t)0xFFFFFFFE;

  

 /*!< Reset HSEBYP bit */

 RCC->CR &= (uint32_t)0xFFFBFFFF;

 /*!< Reset PLLSRC, PLLMUL[3:0] and PLLDIV[1:0] bits */

 RCC->CFGR &= (uint32_t)0xFF02FFFF;

 /*!< Disable all interrupts */

 RCC->CIER = 0x00000000;

    

 memcpy((void*)0x20000000,(void const*)0x08000000,0x1FF); // Move Vector Table from FLASH to RAM 

 /* Configure the Vector Table location add offset address ------------------*/

#ifdef VECT_TAB_SRAM //It has defined

 SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM */

#else

 SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH */

#endif

}

  • Here is the startup:

    MODULE ?cstartup

    ;; Forward declaration of sections.

    SECTION CSTACK:DATA:NOROOT(3)

     

     

    SECTION .intvec:CODE:NOROOT(2)

    EXTERN __iar_program_start

    EXTERN SystemInit     

    PUBLIC __vector_table

    DATA

     

__vector_table

    DCD   sfe(CSTACK)

    DCD   Reset_Handler_RAM       ; Reset Handler

    SECTION .intvec_RAM:CODE:NOROOT(2)

    PUBLIC __vector_table_RAM

    DATA

     

__vector_table_RAM

    DCD   sfe(CSTACK)

    DCD   Reset_Handler_RAM       ; Reset Handler

    DCD   NMI_Handler_RAM        ; NMI Handler

    DCD   HardFault_Handler_RAM     ; Hard Fault Handler

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   SVC_Handler_RAM        ; SVCall Handler

    DCD   0             ; Reserved

    DCD   0             ; Reserved

    DCD   PendSV_Handler_RAM      ; PendSV Handler

    DCD   SysTick_Handler_RAM      ; SysTick Handler

  • the VTOR during debug looks as below -

I am not able to put breakpoint in any of the handler also.

Any guess - why remap is not happening ?

Appreciate your help.

SN
Associate II
 

I don't think I'd be involving the .ICF in moving the vectors around, I'd just move the RAM base to accommodate them, and manage it in the code.

You should be able to uncheck the 'run to main()' type option in the debugger, and walk the code in from the Reset_Handler.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..