cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103C8T6 Firmware for Bootloader

Chlaban
Associate

Greetings to the community,

I have a problem with creating a firmware for the bootloader. I'll start a little differently:

Some time ago I made a bootloader for STM32F407VET6. The only thing I did was change the memory length in the STM32F407VETX_FLASH.ld file to:
FLASH (rx) : ORIGIN = 0x8000000, LENGTH = 16K
and after jumping to the FW I jump to the correct address
In the FW I changed the STM32F407VETX_FLASH.ld file:
FLASH (rx) : ORIGIN = 0x8004000, LENGTH = 496K
and in the main.c file I added the line:
int main(void)
{

/* USER CODE BEGIN 1 */
SCB->VTOR = 0x08004000;
/* USER CODE END 1 */
......
Everything works without any problems, even when I run the debugger from FW, the bootloader is not deleted and the program jumps directly to the FW address. I am satisfied.

Now I am making a bootloader for STM32F103C8T6, I proceed exactly the same way and nothing works. The program is correctly written to the required address. I have tried all sorts of options from discussions on the Internet.
Change the SystemInit (void) function, which is run before the main program loop,
change the USER_VECT_TAB_ADDRESS constants
None of this helps, the program either ends with the HardFault_Handler function (after calling the bl __libc_init_array function) or by accessing an invalid address.
The disassembled code is also strange:
00004000: str r0, [r0, r0]
00004002: movs r0, #0
00004004: ldr r4, [pc, #404] @ (0x419c)
00004006: lsrs r0, r0, #32
00004008: bx lr
0000400a: lsrs r0, r0, #32
0000400c: bx pc
0000400e: lsrs r0, r0, #32
00004010: bx pc
00004012: lsrs r0, r0, #32
00004014: @ <UNDEFINED> instruction: 0x4781
00004016: lsrs r0, r0, #32
00004018: @ <UNDEFINED> instruction: 0x4785
.....
Does anyone have experience with this, can anyone advise? Thanks

2 REPLIES 2
Imen.D
ST Employee

Hello @Chlaban ,

Are you sure that the vector table is correctly relocated to the address where the application is loaded?

Verify also that the VECT_TAB_OFFSET constants is correctly defined.

You should check the STM32F103 reference manual and programming manual on memory mapping, vector table relocation, and system initialization.

When your question is answered, please close this topic by clicking "Accept as Solution".
Thanks
Imen
Chlaban
Associate

Thanks for the advice,
but it seems that the problem is not in the interrupt vector settings, they are probably fine, the code is well placed. The only difference that happens when reallocating flash memory is that the value of the SP register changes from 0x20005000 to 0xfffffffc. When I manually change this value to 0x20005000 while debugging, everything works fine. Does anyone know why this is happening and how to solve it elegantly?
Thanks for the answer.