2021-01-05 03:45 PM
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.
2021-01-05 05:53 PM
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
2021-01-06 04:39 PM
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.
/*###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 };
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
}
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
I am not able to put breakpoint in any of the handler also.
Any guess - why remap is not happening ?
Appreciate your help.
2021-01-06 04:40 PM
2021-01-06 05:50 PM
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.