cancel
Showing results for 
Search instead for 
Did you mean: 

STM32C031 does not jump correctly from bootloader to application

shank
Associate III

I am using an STM32C031 and am trying to write the bootloader program and application program as a single .bin file.
However, I have designed the boot loader program to start up when the power is turned on and jump to the application program by specifying the flash memory if the specified signal has not been received for a while, but I cannot get it to jump properly. It seems to jump to the application program from the flash memory location, but the application program does not work properly.
What kind of program should I use to make the boot loader program start working correctly when it jumps to the application program?

Also attached are the documents to which we are referring.

 

The usage of flash memory is as follows.
Boot program: 0x08000000~0x080027FF
Application program: 0x08003800~0x080077FF

The program for the jump part described in the boot loader program is as follows.

void jump_main(){ HAL_TIM_Base_Stop_IT(&htim17); huart1.Instance->CR1 &= ~0x20; //Disable all interrupts NVIC->ICER[0] = 0xFFFFFFFFFF; NVIC->ICER[1] = 0xFFFFFFFFFF; NVIC->ICER[2] = 0xFFFFFFFFFFFF; //Clear pendings NVIC->ICPR[0] = 0xFFFFFFFFFFFF; NVIC->ICPR[1] = 0xFFFFFFFFFFFF; NVIC->ICPR[2] = 0xFFFFFFFFFF; int *user_app = (int *)(0x08003800+0x04); __set_MSP(*(uint32_t *)0x08003800); *(int*)0xE000ED08 = 0x08003800; ((void(*)())(*user_app))(); while(1){ }; }

 

4 REPLIES 4
Karl Yamashita
Lead III

Probably your application code with the file system_stm32c0xx.c does not have the vector offset updated to your application start address. 

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

Shouldn't it be loading the CONTENT of the vector .

The vector table does not contain executable code.

Step the transition in the debug. 

Instrument and print content to understand what the MCU sees

Have a working HardFault_Handler so you can see if it ends up there.

I would setup SP and SCB->VTOR on the application side

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I am trying to set the FLASH address in “stm32c031xx_flash.icf” which is generated when generating code from STMCubeMX.Do you think these do not make sense?

<bootloader stm32c031xx_flash.icf> /*###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__ = 0x080027FF; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; define symbol __ICFEDIT_region_RAM_end__ = 0x20002FFF; /*-Sizes-*/ define symbol __ICFEDIT_size_cstack__ = 0x400; define symbol __ICFEDIT_size_heap__ = 0x200; /**** End of ICF editor section. ###ICF###*/ 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 }; do not initialize { section .noinit }; place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; place in ROM_region { readonly }; place in RAM_region { readwrite, block CSTACK, block HEAP }; export symbol __ICFEDIT_region_RAM_start__; export symbol __ICFEDIT_region_RAM_end__;
View more
<Application stm32c031xx_flash.icf> /*###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__ = 0x08003800; /*-Memory Regions-*/ define symbol __ICFEDIT_region_ROM_start__ = 0x08003800; define symbol __ICFEDIT_region_ROM_end__ = 0x080077FF; define symbol __ICFEDIT_region_RAM_start__ = 0x20000000; define symbol __ICFEDIT_region_RAM_end__ = 0x20002FFF; /*-Sizes-*/ define symbol __ICFEDIT_size_cstack__ = 0x400; define symbol __ICFEDIT_size_heap__ = 0x200; /**** End of ICF editor section. ###ICF###*/ 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 }; do not initialize { section .noinit }; place at address mem:0x08000000 { section .bootloader }; place at address mem:__ICFEDIT_intvec_start__ { readonly section .intvec }; place in ROM_region { readonly }; place in RAM_region { readwrite, block CSTACK, block HEAP }; export symbol __ICFEDIT_region_RAM_start__; export symbol __ICFEDIT_region_RAM_end__;
View more

 

I found that if I separate the bootloader and application programs and run the bootloader only program, I get into "jump main()"and then a Hard Fault error. Is this related to your comment?

HardFault.png