2023-05-12 08:30 AM
2023-05-12 08:42 AM
Hi all,
Here a method , writed with mikroC, to jump to application.
It works for STM32F051, it doesn't for STM32L151
Could you help me ?
Thanks
void Set_VectorsCodes(unsigned long SP,unsigned long PC)
{
unsigned int x2;
unsigned long *ptr=VECT_PG_ADDR+8,x4,y4;
x4=*ptr;
ptr++;
y4=*ptr;
if(x4!=SP || y4!=PC )
{
FLASH_Unlock();
FLASH_ErasePage(VECT_PG_ADDR);
/* following codes works for STM32F051
FLASH_Write_Word(VECT_PG_ADDR, 0x48014685);
FLASH_Write_Word(VECT_PG_ADDR+4, 0x48014700);
FLASH_Write_Word(VECT_PG_ADDR+8, SP);
FLASH_Write_Word(VECT_PG_ADDR+12,PC);
*/
// those codes doesn't work for STM32L151
FLASH_Write_Word(VECT_PG_ADDR, 0xA4046012);
FLASH_Write_Word(VECT_PG_ADDR+4, 0xA4046811);
FLASH_Write_Word(VECT_PG_ADDR+8, 0x46984612);
FLASH_Write_Word(VECT_PG_ADDR+12, 0x68084700);
FLASH_Write_Word(VECT_PG_ADDR+16, SP);
FLASH_Write_Word(VECT_PG_ADDR+20, PC);
FLASH_Lock();
#ifdef OLED
Display_LineCode(5,"SP: ",VALUETYPE_HEXA32,SP,0);
Display_LineCode(6,"PC: ",VALUETYPE_HEXA32,PC,0);
#endif
}
}
My application is at 0x400 (before calling "Set_VectorsCodes" it had minimum led flash function), my bootloader at 0x5B000 ( asm codes at VECT_PG_ADDR=0x5FF00 )
If I look at registers, I can see PC is in bootloader area (soft freeze as soon I try to launch it)
Thanks for help
2023-05-15 08:16 AM
Hello @JFELI.13,
I suggest you refer to this article : How to switch from one STM32 to another using STM32CubeMX
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-05-15 08:32 AM
I tried it -and it's usefull for some needs- but there is nothing to do with my problem.
If the purpose is to change MikroC to STMCube , the BIG problem should be to convert a large code !
2023-05-15 08:35 AM
So, I recommend you to start a new STM32 project base on STM32CubeIDE and then copy, paste it on your new project.
Foued
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2023-05-15 08:45 AM
The CM0 doesn't have a SCB->VTOR, for the STM32F0 what you need to do is carve out a small area, say 192-bytes at the base of RAM (0x20000000)
Copy/Create the vector table there, and then REMAP the ZERO address where the VECTORS are to map/shadow the 0x20000000 region.
I'll look for some example / IAP code, but basically SYSCFG clock gets enabled and MEMRMP or something similar. Look at the REFERENCE MANUAL
2023-05-15 08:48 AM
FLASH_Write_Word(VECT_PG_ADDR, 0xA4046012);
FLASH_Write_Word(VECT_PG_ADDR+4, 0xA4046811);
FLASH_Write_Word(VECT_PG_ADDR+8, 0x46984612);
FLASH_Write_Word(VECT_PG_ADDR+12, 0x68084700);
What do these code do?
JW
2023-05-15 08:50 AM
STM32Cube_FW_F0_V1.11.4\Projects\STM32091C_EVAL\Applications\IAP\IAP_Binary_Template\Src\main.c
...
#if (defined ( __CC_ARM ))
__IO uint32_t VectorTable[48] __attribute__((at(0x20000000)));
#elif (defined (__ICCARM__))
#pragma location = 0x20000000
__no_init __IO uint32_t VectorTable[48];
#elif defined ( __GNUC__ )
__IO uint32_t VectorTable[48] __attribute__((section(".RAMVectorTable")));
#endif
...
/* Relocate by software the vector table to the internal SRAM at 0x20000000 ***/
/* Copy the vector table from the Flash (mapped at the base of the application
load address 0x08004000) to the base address of the SRAM at 0x20000000. */
for(i = 0; i < 48; i++)
{
VectorTable[i] = *(__IO uint32_t*)(APPLICATION_ADDRESS + (i<<2));
}
/* Enable the SYSCFG peripheral clock*/
__HAL_RCC_SYSCFG_CLK_ENABLE();
/* Remap SRAM at 0x00000000 */
__HAL_SYSCFG_REMAPMEMORY_SRAM();
2023-05-15 10:58 AM
I think you're wright
I tried to use VTOR with some values and obsevre it changed the PC register value so it should be interesting to look at it.
I'm french speaking/writing so here I'm trying to clarify what you wrote:
First I need to create an array (here "VectorTable") starting at 0x20000000 and copy values from flash (my application is at 0x400 so I need to copy to 0x0800400 ?).
No, I don't think you mean this because my bin file contain vectors SP PC from application at (applicationAdress-8) . I merge bootloader file with application file so bootloader vectors are at 0x0 and 0x4 and application vectors are at ApplicationAdress+8
Here is my adresses values
#define BOOTLOADER_ADRESS 0x5B000
#define VECT_PG_ADDR 0x5FF00
#define PROGRAM1_ADDR 0x400
#define PROGRAM2_ADDR 0x2E000
#pragma orgall BOOTLOADER_ADRESS
I call the "Set_VectorsCodes" like this
unsigned long SP2,PC2,*ptr;
StartingAdress=0x400-8; // (for example)
ptr=StartingAdress;
SP2=*ptr;
if(SP2!=0xFFFFFFFF)
{
ptr++;
y4=*ptr;
Set_VectorsCodes(SP2,PC2);
}
2023-05-15 10:59 AM
Thos code are assembler codes ... and are completely wrong :smirking_face: (gived by chatgpt)
The should be probably
FLASH_Write_Word(VECT_PG_ADDR, 0x46854801);
FLASH_Write_Word(VECT_PG_ADDR+4, 0x47004801);
FLASH_Write_Word(VECT_PG_ADDR+8, SP2);
FLASH_Write_Word(VECT_PG_ADDR+12,PC2);