cancel
Showing results for 
Search instead for 
Did you mean: 

Problems regarding Interrupt Vector Relocation with STM32F030CC

Posted on October 19, 2017 at 11:47

Hello all!.

I have problems loading one application program using one bootloader main program. I have tested and debugged that bootloader program takes entire bin application program right with all bytes right at starting at 0x8008000 FLASH position (This is the position for any application client program, bootloader is beginning at 0x8000000). I suppose problem is when application program is loaded with bootloading, into last calling from bootloader in order to execute application client. I post here all changes made from one normal application client that runs by itself when it is transformed to one application program that depends from one bootloader to be loaded.

Changes made into one application client:

into MAIN.C has been declared this variable for application vector table:

volatile uint32_t VectorTable[48] __attribute__((section('.RAMVectorTable')));

into MAIN.C, first line has following call:

int main()

{

remapMemToSRAM();

HAL_Init();

/* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init(); while (1) HAL_GPIO_WritePin(GPIOX13_GPIO_Port, GPIOX13_Pin, GPIO_PIN_SET); /// LED ON;

}

void remapMemToSRAM( void )

{ uint32_t vecIndex = 0; __disable_irq();

for(vecIndex = 0; vecIndex < 48; vecIndex++){

VectorTable[vecIndex] = *(volatile uint32_t*)(FW_START_ADDR + (vecIndex << 2)); }

__HAL_SYSCFG_REMAPMEMORY_SRAM();

__enable_irq();

}

FW_START_ADDR = 0x8008000

into STM32F030CC_FLASH.ld (or linker script) I have this:

MEMORY

{ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 256K-32K }

inside sections I have included this ram segment for application vector table:

.RAMVectorTable(NOLOAD):

{ KEEP(*(.RAMVectorTable)) } > VTRAM

....

Debugging bootloader program I have hardfault at this point when I try to launch application program with function:

Boot_StartApplication();

Where Boot_StartApplication is implemented as:

uint8_t Boot_StartApplication(void)

{ uint32_t startAddress, applicationStack; pFunction applicationEntry;

//The address where the application is written

startAddress = BOOT_APPLICATION_ADDR;

//Retrieve values

applicationStack = (uint32_t) (volatile unsigned int) (startAddress); applicationEntry = (pFunction) (volatile unsigned int) (startAddress + 4);

/*Set a valid stack pointer for the application */

__set_MSP(*(__IO uint32_t *)BOOT_APPLICATION_ADDR);

/*Start the application */

applicationEntry(); // executing this point i have Hard_Fault error

return 1; // OK (but in real app should never reach this point)

}

when applicationEntry(); is executed I can watch following:

0x8008004

later-> <signal handler called>() at 0xfffffff9 HardFault_Handler() at stm32f0xx_it.c:67 0x8006408

If iin linker file I substitute :

MEMORY

{ RAM (xrw) : ORIGIN = 0x20000000, LENGTH = 32K FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 256K }

And I comment the first line for remapping.

int main()

{

//remapMemToSRAM();

HAL_Init();

/* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */

/* USER CODE END SysInit */

/* Initialize all configured peripherals */

MX_GPIO_Init(); while (1) HAL_GPIO_WritePin(GPIOX13_GPIO_Port, GPIOX13_Pin, GPIO_PIN_SET); /// LED ON;

}

LED is on and application program works without bootloader, but using bootloader I have thes HardFault error.

Please, I would be very grateful if you can indicate where is problem, maybe some problem from compiler?. I use gcc GNU-ARM integrated into Atollic TrueStudio.

Thanks a lot!

6 REPLIES 6
Posted on October 19, 2017 at 12:20

It is a Vector Table, ie a table of addresses, you don't actually want to jump to 0x08008004, which as you observe will fault.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 19, 2017 at 14:41

Thanks Clive. There were errors using code through Skype from one colleague.

Now I have written righ the indexing with *

//Retrieve values

applicationStack = (uint32_t) *(volatile unsigned int *) (startAddress);

applicationEntry = (pFunction) *(volatile unsigned int *) (startAddress + 4);

/*Set a valid stack pointer for the application */

I have one similar hardfault now:

Thread #1 <main> (Suspended : Signal : SIGTRAP:Trace/breakpoint trap)

HardFault_Handler() at stm32f0xx_it.c:67 0x800640c

<signal handler called>() at 0xfffffff9

0x8011c74

0x80106a0

Before this hardfault:

applicationStack has 0x20008000 (hex value)

applicationEntry has 0x8012ad1 (hex value) . 

What is wrong?

Thanks.

Posted on October 19, 2017 at 14:57

Hello Clive!

We wrote at same time and I didn't see regarding some things I did not include into linker script in application client.

MEMORY

{

VTRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192

RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K-192

FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 256K-32K

}

Now It works!!

Thousand of thanks. !!!

Posted on October 19, 2017 at 13:44

Thanks Clive.

Then, What is the appropiate address in application client to jump?

BR.

Francisco.

Posted on October 19, 2017 at 14:12

The one IN the TABLE.

Right now it is like you have a letter and you are delivering it to ENVELOPE rather than to the ADDRESS on the envelope. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 19, 2017 at 14:42

0690X000006041DQAQ.jpg

MEMORY

{

VTRAM (xrw) : ORIGIN = 0x20000000, LENGTH = 192

RAM (xrw) : ORIGIN = 0x200000C0, LENGTH = 32K-192

FLASH (rx) : ORIGIN = 0x8008000, LENGTH = 256K-32K

}

//Retrieve values

applicationStack = (uint32_t) *((uint32_t *)(startAddress + 0)); // Initial SP

applicationEntry = (pFunction) *((uint32_t *)(startAddress + 4)); // Initial PC
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..