STM32F103 MDK-ARM5 NVIC can't change an address.
Hello comunity,
I trying to write a bootloader that will copy firmware from one memory range to other. And I need your help with understanding what is going on with my STM32F106C8T6 and what I doing wrong.
Incoming data:
-bootloader 0x08000 0000
-KEY 0x08000 4c00
-FW_main 0x08000 5000
-FW_Source 0x08000 A000
i'ts start addreses for each part of my program.
Logic of program:
Bootloader starts and chek is the KEY-dada exist on the KEY addres.
Here two ways:
- If KEY-data exist - bootloader starts copying data from FW_Source memory range to FW_main memory range. After copying all FW_Source data, we clean KEY-data, FW_Source-data and reboot.
-If KEY-data data other way it jumps to the address FW_main + 4.
On this stage all what we should to know.
Im using Keil MKD ARM 5 with HAL. When I want writing firmware to the address 0x08000 A000 I shoud to edit ProjectName.stc file
---
; *************************************************************
; *** Scatter-Loading Description File generated by uVision ***
; *************************************************************
LR_IROM1 0x0800A000 0x00010000 { ; load region size_region
ER_IROM1 0x0800A000 0x00010000 { ; load address = execution address
*.o (RESET, +First)
*(InRoot$$Sections)
.ANY (+RO)
}
RW_IRAM1 0x20000000 0x00005000 { ; RW data
.ANY (+RW +ZI)
}
}
---
Then I could to flush stm32f103 in the right memory ranege. I check it end everything is ok.
If after copying data from
FW_Source to
FW_main I
didn't erase theFW_Source
memory rage. The aplication works as i expexted it's jump to the0x080005000 and works fine.
But! If I ereasingFW_Source range it's stop worknig.
So, as I understand I need to move NVIC table to the new address (0x08005000), as HAL don't have a function
NVIC_SetVectorTable I deside to write it directly to the register SCB->VTOR = 0x08005000; But, this didn't help me.
--- User aplication code ---
int main(void)
{
/* USER CODE BEGIN 1 */
__set_PRIMASK(1);
SCB->VTOR = 0x08005000;
//__set_MSP(*(__IO uint32_t*) 0x08005000); //-- ???? ?? ?????
__set_PRIMASK(0);
/* USER CODE END 1 */
...
---
Then, I tryed to comment data in the systeminit() (
system_stm32f1xx.c).But this also didn't help me.
---
&sharpifdef VECT_TAB_SRAM
SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */&sharpelse //SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */&sharpendif---
Also I tryed set the SCB->VTOR in the bootloader jumb function, but and this didn't help.
---
void jumpToApplication(uint32_t addr)
{ typedef void (*pFunction)(void); pFunction Jump_To_Application; uint32_t JumpAddress;JumpAddress = *(__IO uint32_t*) (addr + 4);
Jump_To_Application = (pFunction) JumpAddress;SCB->VTOR = addr; //set NVIC table
__set_MSP(*(__IO uint32_t*) addr);
Jump_To_Application();}---
I'm confused, while reading manuals I didn't finde anything that can explain why it's didn't work. So, community I need your help .
Best regards,
Sergii Kirichok
#nvic #mdk-armv5 #stm32f1 #stm32 #bootloader